mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-25 14:29:03 -06:00
smooth movement, but position offset due to precision errors. Clean up in shaders
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
local assetHelper = asset.require('util/asset_helper')
|
||||
local shared = asset.require('../satellites_shared')
|
||||
|
||||
local group = {
|
||||
Title = "Indian ASAT test Debris",
|
||||
Url = "http://www.celestrak.com/NORAD/elements/2019-006.txt",
|
||||
TrailColor = { 1.0, 1.0, 1.0 }
|
||||
}
|
||||
|
||||
local tle = shared.downloadTLEFile(asset, group.Url, group.Title)
|
||||
|
||||
|
||||
local objectNames = {}
|
||||
|
||||
asset.onInitialize(function ()
|
||||
objectNames = shared.addSatelliteGroupObjects(group, tle, true)
|
||||
end)
|
||||
@@ -0,0 +1,17 @@
|
||||
local assetHelper = asset.require('util/asset_helper')
|
||||
local shared = asset.require('../satellites_shared')
|
||||
|
||||
local group = {
|
||||
Title = "Breeze-M Breakup",
|
||||
Url = "http://www.celestrak.com/NORAD/elements/2012-044.txt",
|
||||
TrailColor = { 1.0, 1.0, 1.0 }
|
||||
}
|
||||
|
||||
local tle = shared.downloadTLEFile(asset, group.Url, group.Title)
|
||||
|
||||
|
||||
local objectNames = {}
|
||||
|
||||
asset.onInitialize(function ()
|
||||
objectNames = shared.addSatelliteGroupObjects(group, tle, true)
|
||||
end)
|
||||
@@ -0,0 +1,16 @@
|
||||
local assetHelper = asset.require('util/asset_helper')
|
||||
local shared = asset.require('../satellites_shared')
|
||||
|
||||
local group = {
|
||||
Title = "Fengyun Debris",
|
||||
Url = "http://www.celestrak.com/NORAD/elements/1999-025.txt",
|
||||
TrailColor = { 0.784, 1.0, 0.737 }
|
||||
}
|
||||
|
||||
local tle = shared.downloadTLEFile(asset, group.Url, group.Title)
|
||||
|
||||
|
||||
local objectNames = {}
|
||||
asset.onInitialize(function ()
|
||||
objectNames = shared.addSatelliteGroupObjects(group, tle, true)
|
||||
end)
|
||||
@@ -0,0 +1,17 @@
|
||||
local assetHelper = asset.require('util/asset_helper')
|
||||
local shared = asset.require('../satellites_shared')
|
||||
|
||||
local group = {
|
||||
Title = "Iridium 33 Debris",
|
||||
Url = "http://www.celestrak.com/NORAD/elements/iridium-33-debris.txt",
|
||||
TrailColor = { 0.8, 0.0, 0.3 }
|
||||
}
|
||||
|
||||
local tle = shared.downloadTLEFile(asset, group.Url, group.Title)
|
||||
|
||||
|
||||
local objectNames = {}
|
||||
|
||||
asset.onInitialize(function ()
|
||||
objectNames = shared.addSatelliteGroupObjects(group, tle, true)
|
||||
end)
|
||||
@@ -0,0 +1,17 @@
|
||||
local assetHelper = asset.require('util/asset_helper')
|
||||
local shared = asset.require('../satellites_shared')
|
||||
|
||||
local group = {
|
||||
Title = "Kosmos 2251 Debris",
|
||||
Url = "http://www.celestrak.com/NORAD/elements/cosmos-2251-debris.txt",
|
||||
TrailColor = { 0.66, 0.8, 0.5 }
|
||||
}
|
||||
|
||||
local tle = shared.downloadTLEFile(asset, group.Url, group.Title)
|
||||
|
||||
|
||||
local objectNames = {}
|
||||
|
||||
asset.onInitialize(function ()
|
||||
objectNames = shared.addSatelliteGroupObjects(group, tle, true)
|
||||
end)
|
||||
@@ -59,7 +59,7 @@ local registerSatelliteGroupObjects = function(containingAsset, group, tleFolder
|
||||
|
||||
-- The initialization with "-" is just a placeholder.
|
||||
-- (needed to be initialized)
|
||||
Segments = 128,
|
||||
Segments = 160,
|
||||
EccentricityColumn = "-",
|
||||
SemiMajorAxisColumn = "-",
|
||||
SemiMajorAxisUnit = 1,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
asset.request('./debris/debris_asat')
|
||||
asset.request('./debris/debris_breezem')
|
||||
asset.request('./debris/debris_fengyun')
|
||||
asset.request('./debris/debris_iridium33')
|
||||
asset.request('./debris/debris_kosmos2251')
|
||||
--asset.request('./debris/debris_fengyun')
|
||||
--asset.request('./debris/debris_iridium33')
|
||||
--asset.request('./debris/debris_kosmos2251')
|
||||
|
||||
asset.request('./satellites_debris_old')
|
||||
@@ -0,0 +1,2 @@
|
||||
asset.request('./debris/debris_breezem_old')
|
||||
asset.request('./debris/debris_asat_old')
|
||||
@@ -360,15 +360,15 @@ std::vector<KeplerParameters> RenderableSatellites::readTLEFile(const std::strin
|
||||
file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||
file.open(filename);
|
||||
|
||||
int numberOfLines = std::count(std::istreambuf_iterator<char>(file),
|
||||
__int64 numberOfLines = std::count(std::istreambuf_iterator<char>(file),
|
||||
std::istreambuf_iterator<char>(), '\n' );
|
||||
file.seekg(std::ios_base::beg); // reset iterator to beginning of file
|
||||
|
||||
// 3 because a TLE has 3 lines per element/ object.
|
||||
int numberOfObjects = numberOfLines/3;
|
||||
__int64 numberOfObjects = numberOfLines/3;
|
||||
|
||||
std::string line = "-";
|
||||
for (int i = 0; i < numberOfObjects; i++) {
|
||||
for (__int64 i = 0; i < numberOfObjects; i++) {
|
||||
|
||||
std::getline(file, line); // get rid of title
|
||||
|
||||
@@ -579,9 +579,8 @@ void RenderableSatellites::render(const RenderData& data, RendererTasks&) {
|
||||
//glEnableVertexAttribArray(0); // We like submitting vertices on stream 0 for no special reason
|
||||
//glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(TrailVBOLayout), 0);
|
||||
|
||||
// const size_t nrOrbits = static_cast<GLsizei>(_vertexBufferData.size()) / _nSegments;
|
||||
const size_t nrOrbits = _TLEData.size();
|
||||
size_t vertices = 0;
|
||||
gl::GLint vertices = 0;
|
||||
|
||||
//glDepthMask(false);
|
||||
//glBlendFunc(GL_SRC_ALPHA, GL_ONE)
|
||||
@@ -623,41 +622,23 @@ void RenderableSatellites::updateBuffers() {
|
||||
size_t index = orbitindex * nVerticesPerOrbit + i;
|
||||
|
||||
double timeOffset = orbit.period *
|
||||
static_cast<double>(i)/ static_cast<double>(_nSegments);
|
||||
|
||||
// LINFO(fmt::format("Vertex offset: {} ", timeOffset ));
|
||||
static_cast<double>(i)/ static_cast<double>(_nSegments);
|
||||
|
||||
glm::vec3 position = _keplerTranslator.debrisPos(orbit.epoch + timeOffset);
|
||||
|
||||
glm::dvec3 position = _keplerTranslator.debrisPos(timeOffset + orbit.epoch);
|
||||
|
||||
_vertexBufferData[index].x = position.x;
|
||||
_vertexBufferData[index].y = position.y;
|
||||
_vertexBufferData[index].z = position.z;
|
||||
_vertexBufferData[index].time = timeOffset;
|
||||
_vertexBufferData[index].x = static_cast<float>(_keplerTranslator.debrisPos(timeOffset + orbit.epoch).x);
|
||||
_vertexBufferData[index].y = static_cast<float>(position.y);
|
||||
_vertexBufferData[index].z = static_cast<float>(position.z);
|
||||
_vertexBufferData[index].time = static_cast<float>(timeOffset);
|
||||
_vertexBufferData[index].epoch = static_cast<float>(orbit.epoch);
|
||||
_vertexBufferData[index].period = static_cast<float>(orbit.period);
|
||||
|
||||
// LINFO(fmt::format("Vertex position: {} ", position ));
|
||||
|
||||
// The difference in the print below resulted in large differences, up to 0.23.
|
||||
//LINFO(fmt::format("diff : {} ", position.x - _vertexBufferData[index].x));
|
||||
|
||||
}
|
||||
|
||||
for(int i=0 ; i < nVerticesPerOrbit ; ++i) {
|
||||
for(int j=0 ; j < nVerticesPerOrbit ; ++j){
|
||||
if (i != 0 && j != 0) {
|
||||
if (i == j)
|
||||
continue;
|
||||
}
|
||||
if((i+_nSegments*orbitindex) % _nSegments != 0 ){
|
||||
if (_vertexBufferData[i + _nSegments*orbitindex].x == _vertexBufferData[j + _nSegments*orbitindex].x) {
|
||||
LINFO(fmt::format("Same position: {} ", _vertexBufferData[i + _nSegments*orbitindex].x));
|
||||
LINFO(fmt::format("what index thoudh: {} ", i + _nSegments*orbitindex));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
++orbitindex;
|
||||
|
||||
}
|
||||
@@ -673,10 +654,10 @@ void RenderableSatellites::updateBuffers() {
|
||||
);
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(TrailVBOLayout), (GLvoid*)0); // stride : 4*sizeof(GL_FLOAT) + 2*sizeof(GL_DOUBLE)
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(TrailVBOLayout), (GLvoid*)0); // stride : 4*sizeof(GL_FLOAT) + 2*sizeof(GL_DOUBLE)
|
||||
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(TrailVBOLayout), (GLvoid*)(4*sizeof(GL_FLOAT)) );
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(TrailVBOLayout), (GLvoid*)(3*sizeof(GL_FLOAT)) );
|
||||
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
||||
@@ -95,7 +95,7 @@ namespace openspace {
|
||||
private:
|
||||
/// The layout of the VBOs
|
||||
struct TrailVBOLayout {
|
||||
float x, y, z, time, epoch, period;
|
||||
float x, y, z, time, epoch, period;
|
||||
};
|
||||
// static_assert(sizeof(struct TrailVBOLayout)==4*sizeof(float)+2*sizeof(double),"Implementation error!");
|
||||
|
||||
|
||||
@@ -25,53 +25,39 @@
|
||||
#include "fragment.glsl"
|
||||
//#include "floatoperations.glsl"
|
||||
|
||||
//layout(location = 0) in vec4 vertex_data; // 1: x, 2: y, 3: z, 4: timeOffset
|
||||
//layout(location = 1) in vec2 orbit_data; // 1: epoch, 2: period
|
||||
|
||||
uniform vec3 color;
|
||||
uniform float opacity = 1.0;
|
||||
|
||||
uniform float lineFade;
|
||||
//uniform double inGameTime;
|
||||
uniform int numberOfSegments;
|
||||
|
||||
|
||||
// uniform int numberOfSegments;
|
||||
|
||||
in vec4 viewSpacePosition;
|
||||
|
||||
in vec4 vs_position;
|
||||
//in float fade;
|
||||
|
||||
//in vec4 vertex_data_out;
|
||||
//in vec2 orbit_data_out;
|
||||
in float periodFraction_f;
|
||||
in float offsetPeriods;
|
||||
in float vertexID_f;
|
||||
// in float vertexID_f;
|
||||
|
||||
Fragment getFragment() {
|
||||
|
||||
/*
|
||||
// calculate nr of periods, get fractional part to know where
|
||||
// the vertex closest to the debris part is right now
|
||||
double nrOfPeriods = (inGameTime - orbit_data_out.x) / orbit_data_out.y;
|
||||
double periodFraction = fract(nrOfPeriods); //mod(nrOfPeriods, 1.0);
|
||||
float periodFraction_f = float(periodFraction);
|
||||
|
||||
// same procedure for the current vertex
|
||||
float offsetPeriods = vertex_data_out.w / orbit_data_out.y;
|
||||
// check difference of these two locations
|
||||
*/
|
||||
// This is now done in the fragment shader instead
|
||||
// to make smooth movement between vertecies.
|
||||
// We want vertexDistance to be double up to this point, I think.
|
||||
// (hence the unnessesary float to float conversion)
|
||||
float vertexDistance = periodFraction_f - offsetPeriods;
|
||||
float vertexDistance_f = float(vertexDistance);
|
||||
|
||||
// float vertexDistance = periodFraction_f - offsetPeriods;
|
||||
float vertexID_perOrbit = mod(vertexID_f, numberOfSegments);
|
||||
float nrOfSegments_f = float(numberOfSegments);
|
||||
float vertexDistance = periodFraction_f - (vertexID_perOrbit/nrOfSegments_f) ;
|
||||
// This is the alternative way of calculating
|
||||
// the offsetPeriods: (vertexID_perOrbit/nrOfSegments_f)
|
||||
// float vertexID_perOrbit = mod(vertexID_f, numberOfSegments);
|
||||
// float nrOfSegments_f = float(numberOfSegments);
|
||||
// float vertexDistance = periodFraction_f - (vertexID_perOrbit/nrOfSegments_f);
|
||||
|
||||
if (vertexDistance < 0.0) {
|
||||
vertexDistance += 1.0;
|
||||
if (vertexDistance_f < 0.0) {
|
||||
vertexDistance_f += 1.0;
|
||||
}
|
||||
|
||||
float invert = 1.0 - vertexDistance; // * lineFade;
|
||||
float invert = 1.0 - vertexDistance_f;
|
||||
float fade = clamp(invert * lineFade, 0.0, 1.0);
|
||||
|
||||
Fragment frag;
|
||||
@@ -80,6 +66,11 @@ Fragment getFragment() {
|
||||
frag.gPosition = viewSpacePosition;
|
||||
frag.gNormal = vec4(1, 1, 1 , 0);
|
||||
|
||||
// to debug using colors use this if-statment.
|
||||
// if( vertexDistance < 0.0 || vertexDistance >= 0.0){
|
||||
// frag.color = vec4(1, 0, 0, 1);
|
||||
// }
|
||||
|
||||
return frag;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,56 +26,53 @@
|
||||
|
||||
#include "PowerScaling/powerScalingMath.hglsl"
|
||||
|
||||
layout (location = 0) in vec4 vertex_data; // 1: x, 2: y, 3: z, 4: timeOffset
|
||||
layout (location = 1) in vec2 orbit_data; // 1: epoch, 2: period
|
||||
layout (location = 0) in vec3 vertex_data; // 1: x, 2: y, 3: z
|
||||
layout (location = 1) in vec3 orbit_data; // 1: timeOffset, 2: epoch, 3: period
|
||||
|
||||
uniform dmat4 modelViewTransform;
|
||||
uniform mat4 projectionTransform;
|
||||
|
||||
//uniform float lineFade;
|
||||
uniform double inGameTime;
|
||||
// uniform int numberOfSegments;
|
||||
|
||||
|
||||
out vec4 viewSpacePosition;
|
||||
out vec4 vs_position;
|
||||
//out float fade;
|
||||
|
||||
//out vec4 vertex_data_out;
|
||||
//out vec2 orbit_data_out;
|
||||
out float periodFraction_f;
|
||||
out float offsetPeriods;
|
||||
out float vertexID_f;
|
||||
|
||||
// out float vertexID_f;
|
||||
|
||||
void main() {
|
||||
|
||||
/** The way the position and line fade is calculated is:
|
||||
* By using inGameTime, epoch and period of this orbit,
|
||||
* we get how many revolutions it has done since epoch.
|
||||
* The fract of that, is how far into a revolution it has traveld since epoch.
|
||||
* Similarly we do the same but for this vertex, but calculating offsetPeriods.
|
||||
* In the fragment shader the difference between
|
||||
* periodFraction_f and offsetPeriods is calculated to know how much to fade
|
||||
* that specific fragment.
|
||||
*/
|
||||
|
||||
float offset = float(orbit_data.x);
|
||||
float epoch = float(orbit_data.y);
|
||||
float period = float(orbit_data.z);
|
||||
|
||||
// calculate nr of periods, get fractional part to know where
|
||||
// the vertex closest to the debris part is right now
|
||||
double nrOfPeriods = (inGameTime - orbit_data.x) / orbit_data.y;
|
||||
double periodFraction = fract(nrOfPeriods); //mod(nrOfPeriods, 1.0);
|
||||
double nrOfRevolutions = (inGameTime - epoch) / period;
|
||||
double periodFraction = fract(nrOfRevolutions); //mod(nrOfRevolutions, 1.0);
|
||||
periodFraction_f = float(periodFraction);
|
||||
|
||||
// same procedure for the current vertex
|
||||
offsetPeriods = vertex_data.w / orbit_data.y;
|
||||
offsetPeriods = offset / period;
|
||||
|
||||
vertexID_f = float(gl_VertexID);
|
||||
|
||||
|
||||
|
||||
/*// check difference of these two locations
|
||||
float vertexDistance = periodFraction_f - offsetPeriods;
|
||||
// offsetPeriods can also be calculated by passing the vertexID as a float
|
||||
// to the fragment shader and deviding it by nrOfSegments.
|
||||
// vertexID_f = float(gl_VertexID);
|
||||
|
||||
if(vertexDistance < 0.0) {
|
||||
vertexDistance += 1.0;
|
||||
}
|
||||
|
||||
float invert = 1.0 - vertexDistance; // * lineFade;
|
||||
fade = clamp(invert * lineFade, 0.0, 1.0) ;*/
|
||||
//vertex_data_out = vertex_data;
|
||||
//orbit_data_out = orbit_data;
|
||||
|
||||
viewSpacePosition = vec4(modelViewTransform * dvec4(vertex_data.xyz, 1));
|
||||
dvec4 vertexPosition = dvec4(vertex_data.xyz, 1);
|
||||
viewSpacePosition = vec4(modelViewTransform * vertexPosition);
|
||||
vs_position = z_normalization( projectionTransform * viewSpacePosition);
|
||||
gl_Position = vs_position;
|
||||
|
||||
|
||||
@@ -382,7 +382,7 @@ std::vector<glm::dvec3> getPositionBuffer(std::vector<KeplerParameters> tleData,
|
||||
orbit.epoch
|
||||
);
|
||||
double timeInSeconds = Time::convertTime(timeStamp);
|
||||
glm::dvec3 position = keplerTranslator.debrisPos(static_cast<float>(timeInSeconds));
|
||||
glm::dvec3 position = keplerTranslator.debrisPos(timeInSeconds);
|
||||
positionBuffer.push_back(position);
|
||||
|
||||
}
|
||||
|
||||
@@ -310,7 +310,7 @@ glm::dvec3 KeplerTranslation::debrisPos(const double& time) const {
|
||||
_orbitPlaneDirty = false;
|
||||
}
|
||||
|
||||
const double t = time - _epoch;
|
||||
const double t = time -_epoch;
|
||||
const double meanMotion = glm::two_pi<double>() / _period;
|
||||
const double meanAnomaly = glm::radians(_meanAnomalyAtEpoch.value()) + t * meanMotion;
|
||||
const double e = eccentricAnomaly(meanAnomaly);
|
||||
|
||||
Reference in New Issue
Block a user