new class - renderabletrail - will later be renamed and current replace renderableephemeris.

Right now just adding a bunch of mod files, i know this is rather ugly but i just need it to work for friday.
This commit is contained in:
michal
2014-10-07 18:44:14 -04:00
parent 96853d579b
commit 21745b91a5
11 changed files with 145 additions and 152 deletions
+32 -34
View File
@@ -47,47 +47,45 @@ public:
void render(const RenderData& data) override;
void update(const UpdateData& data) override;
private:
properties::StringProperty _colorTexturePath; // not used now, will be later though.
properties::StringProperty _colorTexturePath;
ghoul::opengl::ProgramObject* _programObject;
ghoul::opengl::Texture* _texture;
void loadTexture();
void fullYearSweep();
ghoul::opengl::ProgramObject* _programObject;
ghoul::opengl::Texture* _texture;
void loadTexture();
// spice
std::string _target;
std::string _observer;
std::string _frame;
double _r, _g, _b;
/* typedef struct {
GLfloat location[4];
GLfloat velocity[4];
GLubyte padding[32]; // Pads the struct out to 64 bytes for performance increase
} Vertex;
*/
// need to write robust method for vbo id selection
// (right now galactic grid has to be present) (why though?) solve later...
GLuint _vaoID = 6;
GLuint _vBufferID = 7;
GLuint _iBufferID = 8;
// need to write robust method for vbo id selection
// (right now galactic grid has to be present) (why though?) solve later...
GLuint _vaoID ;
GLuint _vBufferID ;
GLuint _iBufferID;
void nextIndex();
void nextIndex();
GLenum _mode;
unsigned int _isize;
unsigned int _vsize;
unsigned int _vtotal;
unsigned int _stride;
GLenum _mode;
unsigned int _isize;
unsigned int _vsize;
unsigned int _vtotal;
unsigned int _stride;
glm::vec3 _c;
//Vertex* _varray;
std::vector<float> _varray;
int* _iarray;
//Vertex* _varray;
std::vector<float> _varray;
int* _iarray;
//used for update of trail
psc _pscpos, _pscvel;
double _increment;
double _time = 0;
double _oldTime = 0;
bool* _updated;
psc _pscpos, _pscvel;
std::vector<std::pair<int, double>> _intervals;
double _increment;
// etc...
double _time = 0;
double _oldTime = 0;
int _delta = 0;
int _dtprogress = 0;
};
}
#endif
+7 -13
View File
@@ -26,7 +26,7 @@
uniform vec4 campos;
uniform vec4 objpos;
uniform vec4 camdir;
//uniform vec3 camdir; // add this for specular
uniform float time;
@@ -51,19 +51,17 @@ void main()
vec3 origin = vec3(0.0);
vec4 spec = vec4(0.0);
vec4 tmp = camdir;
vec3 n = normalize(vs_normal.xyz);
vec3 e = normalize(tmp.xyz);
//vec3 e = normalize(camdir);
vec3 l_pos = vec3(0.0); // sun.
vec3 l_dir = normalize(l_pos-objpos.xyz);
float intensity = max(dot(n,l_dir), 0.0)*1.5;
float intensity = min(max(5*dot(n,l_dir), 0.0), 1);
float shine = 19.0;
float shine = 0.0001;
vec4 specular = vec4(0.5);
vec4 ambient = vec4(0.0,0.0,0.0,1);
/*
if(intensity > 0.f){
// halfway vector
vec3 h = normalize(l_dir + e);
@@ -71,14 +69,10 @@ void main()
float intSpec = max(dot(h,n),0.0);
spec = specular * pow(intSpec, shine);
}
diffuse = max(intensity * diffuse , ambient);
*/
diffuse = max(intensity * diffuse, ambient);
// if(position.w > 9.0) {
// diffuse = vec4(1,0,0,1);
// }
ABufferStruct_t frag = createGeometryFragment(diffuse, position, depth);
addToBuffer(frag);
-2
View File
@@ -27,8 +27,6 @@
uniform mat4 ViewProjection;
uniform mat4 ModelTransform;
uniform vec4 camdir;
layout(location = 0) in vec4 in_position;
//in vec3 in_position;
layout(location = 1) in vec2 in_st;
+3
View File
@@ -241,6 +241,9 @@ bool OpenSpaceEngine::initialize()
using constants::configurationmanager::keySpiceTimeKernel;
std::string timeKernel;
bool success = OsEng.configurationManager().getValue(keySpiceTimeKernel, timeKernel);
std::cout << "timeKernel = " << timeKernel << std::endl;
if (!success) {
LERROR("Configuration file does not contain a '" << keySpiceTimeKernel << "'");
return false;
+4 -8
View File
@@ -122,8 +122,6 @@ void RenderablePlanet::render(const RenderData& data)
// activate shader
_programObject->activate();
PowerScaledScalar scaling = glm::vec2(1, -6);
// scale the planet to appropriate size since the planet is a unit sphere
glm::mat4 transform = glm::mat4(1);
@@ -138,10 +136,10 @@ void RenderablePlanet::render(const RenderData& data)
transform = transform* rot;
glm::mat4 modelview = data.camera.viewMatrix()*data.camera.modelMatrix();
glm::vec4 camSpaceEye = -(modelview*data.position.vec4());
glm::vec3 camSpaceEye = (-(modelview*data.position.vec4())).xyz;
// setup the data to the shader
_programObject->setUniform("camdir", camSpaceEye);
// _programObject->setUniform("camdir", camSpaceEye);
_programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
_programObject->setUniform("ModelTransform", transform);
setPscUniforms(_programObject, &data.camera, data.position);
@@ -160,11 +158,9 @@ void RenderablePlanet::render(const RenderData& data)
}
void RenderablePlanet::update(const UpdateData& data)
{
void RenderablePlanet::update(const UpdateData& data){
// set spice-orientation in accordance to timestamp
openspace::SpiceManager::ref().getPositionTransformMatrix("IAU_EARTH", "GALACTIC", data.time, _stateMatrix);
openspace::SpiceManager::ref().getPositionTransformMatrix(_target, "GALACTIC", data.time, _stateMatrix);
}
void RenderablePlanet::loadTexture()
+1 -1
View File
@@ -179,7 +179,7 @@ void RenderableSphericalGrid::render(const RenderData& data){
setPscUniforms(_gridProgram, &data.camera, data.position);
_gridProgram->setUniform("gridColor", _gridColor);
glLineWidth(1.0f);
//glLineWidth(1.0f);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH);
+93 -88
View File
@@ -35,87 +35,83 @@
namespace {
const std::string _loggerCat = "RenderableTrail";
const std::string keyColor = "RGB";
const std::string keyBody = "Body";
const std::string keyObserver = "Observer";
const std::string keyFrame = "Frame";
const std::string keyPathModule = "ModulePath";
}
//#define DEBUG
namespace openspace{
RenderableTrail::RenderableTrail(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _colorTexturePath("colorTexture", "Color Texture")
, _programObject(nullptr)
, _texture(nullptr)
, _vaoID(0)
, _vBufferID(0)
, _iBufferID(0)
, _mode(GL_LINE_STRIP){
: Renderable(dictionary)
, _colorTexturePath("colorTexture", "Color Texture")
, _programObject(nullptr)
, _texture(nullptr)
, _vaoID(0)
, _vBufferID(0)
, _iBufferID(0)
, _mode(GL_LINE_STRIP){
assert(dictionary.getValue(keyBody, _target));
assert(dictionary.getValue(keyObserver, _observer));
assert(dictionary.getValue(keyFrame, _frame));
//white is default col
if (!dictionary.getValue(keyColor, _c)){
_c = glm::vec3(0.0);
}else{
_r = 1 / _c[0];
_g = 1 / _c[1];
_b = 1 / _c[2];
}
}
void RenderableTrail::fullYearSweep(){
double lightTime = 0.0;
double planetYear = 31536000;
SpiceManager::ref().getETfromDate("2005 nov 01 00:00:00", _time);
// -------------------------------------- ^ this has to be simulation start-time, not passed in here though --
double et = _time - planetYear;
int segments = 40; // note to self: code not look nice. cleanup for clarity later.
psc pscpos, pscvel;
_isize = (segments+2);
_vsize = (segments+2);
//_varray = new float[_vsize];
_iarray = new int[_isize];
_updated = new bool[_vsize];
std::fill(_updated, _updated + _vsize, false);
//static_assert(sizeof(Vertex) == 64, "The size of the Vertex needs to be 64 for performance");
double et = _time;
// Need to pass in each planets individual year (w. local or earth time?)
double planetYear = 31536000;
int segments = 365;
_increment = planetYear / segments;
for (int i = 0; i < segments+1; i++){
_isize = (segments + 2);
_vsize = (segments + 2);
_iarray = new int[_isize];
double p = 1.0 / segments;
for (int i = 0; i < segments + 1; i++){
SpiceManager::ref().getTargetState(_target, _observer, _frame, "LT+S", et, _pscpos, _pscvel, lightTime);
//psc tmppos = glm::vec4(i, i, i, 7);
_varray.push_back(_pscpos[0]);
_varray.push_back(_pscpos[1]);
_varray.push_back(_pscpos[2]);
_varray.push_back(_pscpos[3]);
SpiceManager::ref().getTargetState("EARTH", "SUN", "GALACTIC", "LT+S", et, pscpos, pscvel, lightTime);
psc tmppos = glm::vec4(i, i, i, 7);
_varray.push_back(tmppos[0]);
_varray.push_back(tmppos[1]);
_varray.push_back(tmppos[2]);
_varray.push_back(tmppos[3]);
//memcpy(_varray[i].location, glm::value_ptr(pscpos.vec4()), 4 * sizeof(double));
glm::vec4 color = glm::vec4(1, (i % 2 == 0), 1, 1);
_varray.push_back(color[0]);
_varray.push_back(color[1]);
_varray.push_back(color[2]);
_varray.push_back(color[3]);
_intervals.push_back(std::pair<int, double>(i, et));
_iarray[i] = i; // remove indx in this class at some point!
et += _increment;
}
#ifndef DEBUG
_varray.push_back(1.f - ((double)i / 365 * _r));
_varray.push_back(1.f - ((double)i / 365 * _g));
_varray.push_back(1.f - ((double)i / 365 * _b));
_varray.push_back(1.f - ((double)i / 365));
#elif
_varray.push_back(1.f );
_varray.push_back(1.f );
_varray.push_back(1.f );
_varray.push_back(1.f );
#endif
_iarray[i] = i; // remove indx in this class at some point!
et -= _increment;
}
_stride = 8;
_vsize = _varray.size();
_vtotal = static_cast<int>(_vsize / _stride);
/*
std::cout << "before : " << std::endl;
for (int i = 0; i < _vsize-1; i++){
std::cout << _varray[i] << std::endl;
}
/// how to std::move()
int m = 8;
for (int i = _vsize-1; i+1-m != 0; i--){
std:: cout << i << " " << i-m << std::endl;
_varray[i] = std::move(_varray[i - m]);
}
/*
std::cout << "after : " << std::endl;
for (int i = 0; i < _vsize - 1; i++){
std::cout << _varray[i] << std::endl;
}
*/
}
RenderableTrail::~RenderableTrail(){
@@ -127,30 +123,30 @@ bool RenderableTrail::initialize(){
if (_programObject == nullptr)
completeSuccess
&= OsEng.ref().configurationManager().getValue("EphemerisProgram", _programObject);
loadTexture();
//TEXTURES DISABLED FOR NOW
//loadTexture();
completeSuccess &= (_texture != nullptr);
fullYearSweep();
// Initialize and upload to graphics card
glGenVertexArrays(1, &_vaoID);
glGenBuffers(1, &_vBufferID);
glGenBuffers(1, &_iBufferID);
glBindVertexArray(_vaoID);
glBindBuffer(GL_ARRAY_BUFFER, _vBufferID);
glBufferData(GL_ARRAY_BUFFER, _vsize * sizeof(GLfloat), NULL, GL_STREAM_DRAW); // orphaning the buffer, sending NULL data.
glBufferSubData(GL_ARRAY_BUFFER, 0, _vsize * sizeof(GLfloat), &_varray[0]);
GLsizei st = sizeof(GLfloat) * _stride;
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, st, (void*)0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, st, (void*) 0);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, st, (void*)(4 * sizeof(GLfloat)));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, _isize * sizeof(int), _iarray, GL_STATIC_DRAW);
@@ -180,30 +176,38 @@ void RenderableTrail::render(const RenderData& data){
// setup the data to the shader
//_programObject->setUniform("objectVelocity", pscvel.vec4());
_programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
_programObject->setUniform("ModelTransform", transform);
_programObject->setUniform("campos", campos.vec4());
_programObject->setUniform("objpos", currentPosition.vec4());
_programObject->setUniform("camrot", camrot);
_programObject->setUniform("scaling", scaling.vec2());
if (_oldTime != _time){
int m = 8;
for (int i = _vsize - 1; i + 1 - m != 0; i--){
_varray[i] = std::move(_varray[i - m]);
}
memcpy(&_varray[0], glm::value_ptr(_pscpos.vec4()), 4 * sizeof(double));
_varray[4] = 1;
_varray[5] = 1;
_varray[6] = 1;
_varray[7] = 1;
}_oldTime = _time;
if (_oldTime != _time){ // only update when time actually progresses
_dtprogress += _delta*sgct::Engine::instance()->getDt(); // compute how far time has progressed
if (_dtprogress > 86400){
//reset progress counter
_dtprogress = 0;
int m = 8;
for (int i = _vsize - 1; i + 1 - m != 0; i--){
_varray[i] = std::move(_varray[i - m]);
}
int n = 4;
while (n < _vsize - 8){
for (int i = 0; i < 4; i++){
_varray[n + i] = _varray[n + 8 + i];
}
n += 8;
}
//add last pt
memcpy(&_varray[0], glm::value_ptr(_pscpos.vec4()), 4 * sizeof(double));
}
}_oldTime = _time;
glBindBuffer(GL_ARRAY_BUFFER, _vBufferID);
glBufferSubData(GL_ARRAY_BUFFER, 0, _vsize * sizeof(GLfloat), &_varray[0]);
glBindVertexArray(_vaoID);
glDrawArrays(_mode, 0, _vtotal);
@@ -220,9 +224,10 @@ void RenderableTrail::render(const RenderData& data){
void RenderableTrail::update(const UpdateData& data){
double lightTime;
_time = data.time;
_time = data.time;
_delta = data.delta;
SpiceManager::ref().getTargetState("EARTH", "SUN", "GALACTIC", "LT+S", data.time, _pscpos, _pscvel, lightTime);
SpiceManager::ref().getTargetState(_target, _observer, _frame, "LT+S", data.time, _pscpos, _pscvel, lightTime);
}
void RenderableTrail::loadTexture()
+1 -2
View File
@@ -352,9 +352,8 @@ void RenderableWavefrontObject::render(const RenderData& data)
glm::mat4 modelview = data.camera.viewMatrix()*data.camera.modelMatrix();
glm::vec4 camSpaceEye = -(modelview*currentPosition.vec4());
// setup the data to the shader
_programObject->setUniform("camdir", camSpaceEye);
// _programObject->setUniform("camdir", camSpaceEye);
_programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
_programObject->setUniform("ModelTransform", transform);
setPscUniforms(_programObject, &data.camera, glm::vec4(0, 0, -1,8 ));
+2 -2
View File
@@ -114,8 +114,8 @@ bool RenderEngine::initializeGL()
// set the close clip plane and the far clip plane to extreme values while in
// development
// sgct::Engine::instance()->setNearAndFarClippingPlanes(0.01f,100.0f);
sgct::Engine::instance()->setNearAndFarClippingPlanes(0.1f, 1000.00f);
sgct::Engine::instance()->setNearAndFarClippingPlanes(0.01f,10000.0f);
// sgct::Engine::instance()->setNearAndFarClippingPlanes(0.1f, 1000.00f);
// sgct::Engine::instance()->setNearAndFarClippingPlanes(0.0001f, 100.0f);
// sgct::Engine::instance()->setNearAndFarClippingPlanes(0.1f, 200.0f);
+1 -1
View File
@@ -71,7 +71,7 @@ PowerScaledCoordinate::PowerScaledCoordinate(const PowerScaledCoordinate& rhs) {
PowerScaledCoordinate
PowerScaledCoordinate::CreatePowerScaledCoordinate(double d1, double d2, double d3)
{
char buff[30];
char buff[60];
// find the number with maximum number of digits
double ad1 = abs(d1);