Merge branch 'solarsystem2' into cleanup

Conflicts:
	src/util/factorymanager.cpp
This commit is contained in:
Jonas Strandstedt
2014-10-27 19:03:36 +01:00
30 changed files with 783 additions and 382 deletions

View File

@@ -0,0 +1,53 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __MODELGEOMETRY_H__
#define __MODELGEOMETRY_H__
#include <openspace/properties/propertyowner.h>
#include <openspace/rendering/model/renderablemodel.h>
#include <ghoul/misc/dictionary.h>
namespace openspace {
namespace modelgeometry {
class ModelGeometry : public properties::PropertyOwner {
public:
static ModelGeometry* createFromDictionary(const ghoul::Dictionary& dictionary);
ModelGeometry();
virtual ~ModelGeometry();
virtual bool initialize(RenderableModel* parent);
virtual void deinitialize();
virtual void render() = 0;
protected:
RenderableModel* _parent;
};
} // namespace modelgeometry
} // namespace openspace
#endif // __MODELGEOMETRY_H__

View File

@@ -0,0 +1,75 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __RENDERABLEMODEL_H__
#define __RENDERABLEMODEL_H__
// open space includes
#include <openspace/rendering/renderable.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/util/updatestructures.h>
// ghoul includes
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
namespace openspace {
namespace modelgeometry {
class ModelGeometry;
}
class RenderableModel : public Renderable {
public:
RenderableModel(const ghoul::Dictionary& dictionary);
~RenderableModel();
bool initialize() override;
bool deinitialize() override;
void render(const RenderData& data) override;
void update(const UpdateData& data) override;
protected:
void loadTexture();
private:
properties::StringProperty _colorTexturePath;
ghoul::opengl::ProgramObject* _programObject;
ghoul::opengl::Texture* _texture;
modelgeometry::ModelGeometry* _geometry;
glm::dmat3 _stateMatrix;
std::string _source;
std::string _destination;
};
} // namespace openspace
#endif // __RENDERABLEMODEL_H__

View File

@@ -0,0 +1,73 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __WAVEFRONTOBJECT_H__
#define __WAVEFRONTOBJECT_H__
#include <openspace/rendering/model/modelgeometry.h>
namespace openspace {
class RenderableModel;
namespace modelgeometry {
class WavefrontGeometry : public ModelGeometry {
public:
WavefrontGeometry(const ghoul::Dictionary& dictionary);
~WavefrontGeometry();
bool initialize(RenderableModel* parent) override;
void deinitialize() override;
void render() override;
typedef struct
{
GLfloat location[4];
GLfloat tex[2];
GLfloat normal[3];
//GLubyte padding[4]; // Pads the struct out to 64 bytes for performance increase
} Vertex;
protected:
void loadObj(const char *filename);
private:
void createSphere();
GLuint _vaoID = 6;
GLuint _vBufferID = 7;
GLuint _iBufferID = 8;
GLenum _mode;
unsigned int _isize;
unsigned int _vsize;
Vertex* _varray;
int* _iarray;
};
} // namespace modelgeometry
} // namespace openspace
#endif // __WAVEFRONTOBJECT_H__

View File

@@ -57,7 +57,6 @@ protected:
private:
properties::StringProperty _colorTexturePath;
ghoul::opengl::ProgramObject* _programObject;
ghoul::opengl::Texture* _texture;
planetgeometry::PlanetGeometry* _geometry;

View File

@@ -21,9 +21,9 @@
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __RENDERABLEWAVEFRONTOBJECT_H__
#define __RENDERABLEWAVEFRONTOBJECT_H__
/*
#ifndef __RENDERABLEMODEL_H__
#define __RENDERABLEMODEL_H__
// open space includes
#include <openspace/rendering/renderable.h>
@@ -37,10 +37,14 @@
namespace openspace {
class RenderableWavefrontObject : public Renderable {
namespace modelgeometry {
class ModelGeometry;
}
class RenderableModel : public Renderable {
public:
RenderableWavefrontObject(const ghoul::Dictionary& dictionary);
~RenderableWavefrontObject();
RenderableModel(const ghoul::Dictionary& dictionary);
~RenderableModel();
bool initialize() override;
bool deinitialize() override;
@@ -53,12 +57,11 @@ public:
GLfloat location[4];
GLfloat tex[2];
GLfloat normal[3];
/* GLfloat color[4];
GLfloat attribute[3];
GLfloat float_attribute;*/
//GLubyte padding[4]; // Pads the struct out to 64 bytes for performance increase
} Vertex;
protected:
void loadTexture();
void loadObj(const char *filename);
@@ -67,9 +70,9 @@ private:
properties::StringProperty _colorTexturePath;
ghoul::opengl::ProgramObject* _programObject;
ghoul::opengl::Texture* _texture;
modelgeometry::ModelGeometry* _geometry;
ghoul::opengl::ProgramObject* _fovProgram;
float abc;
GLuint _vaoID = 6;
GLuint _vBufferID = 7;
@@ -83,22 +86,13 @@ private:
glm::dmat3 _stateMatrix; // might need this
std::string _target;
///NH FOV
GLuint _vaoFOV = 10;
GLuint _vboFOV = 11;
GLuint _iboFOV = 12;
unsigned int _isizeFOV;
unsigned int _vsizeFOV;
std::vector<float> _varrayFOV;
int *_iarrayFOV;
std::string _source;
std::string _destination;
};
} // namespace openspace
#endif // __RENDERABLEWAVEFRONTOBJECT_H__
#endif // __RENDERABLEMODEL_H__
*/

View File

@@ -58,16 +58,16 @@ public:
std::string _target;
std::string _observer;
std::string _frame;
std::string _orbitVariety;
// color
glm::vec3 _c;
double _r, _g, _b;
float _r, _g, _b;
// orbit relational data
double _tropic;
double _ratio;
double _day;
float _tropic;
float _ratio;
float _day;
// 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;
@@ -88,12 +88,13 @@ public:
int* _iarray;
bool _once = false;
double lightTime;
//used for update of trail
psc _pscpos, _pscvel;
double _increment;
double _time = 0;
double _oldTime = 0;
float _increment;
float _time = 0;
float _oldTime = 0;
float _dtEt;
int _delta = 0;
int _dtprogress = 0;

View File

@@ -43,7 +43,6 @@ namespace configurationmanager {
const std::string keyStartupScript = "StartupScripts";
const std::string keySpiceTimeKernel = "SpiceKernel.Time";
const std::string keySpiceLeapsecondKernel = "SpiceKernel.LeapSecond";
const std::string keySpiceNewHorizons = "SpiceKernel.NewHorizons";
} // namespace configurationmanager
namespace scenegraph {
@@ -68,17 +67,22 @@ namespace renderable {
} // namespace renderable
namespace renderableplanet {
const std::string keyGeometry = "Geometry";
const std::string keyFrame = "Frame";
const std::string keyGeometry = "Geometry";
} // namespace renderableplanet
namespace planetgeometry {
const std::string keyType = "Type";
} // namespace planetgeometry
namespace renderablewavefrontobject {
namespace renderablemodel {
const std::string keyGeometry = "Geometry";
} // namespace renderablemodel
namespace modelgeometry {
const std::string keyType = "Type";
const std::string keyObjFile = "ObjFile";
} // namespace renderableplanet
} // namespace modelgeometry
namespace renderablestars {
const std::string keySpeckFile = "SpeckFile";

View File

@@ -134,6 +134,18 @@ public:
*/
double advanceTime(double tickTime);
/**
* Retreats the simulation time using the deltaTime() and the <code>tickTime</code>.
* The deltaTime() is the number of simulation seconds that pass for each real-time
* second. <code>tickTime</code> is the number of real-time seconds that passed since
* the last call to this method. If this method is called in the render loop, the
* <code>tickTime</code> should be equivalent to the frame time.
* \param tickTime The number of real-time seconds that passed since the last call
* to this method
* \return The new time value after retreating the time
*/
double retreatTime(double tickTime);
/**
* Returns the Lua library that contains all Lua functions available to change the
* current time, retrieve the current time etc. The functions contained are

View File

@@ -1,8 +1,10 @@
--openspace.setPropertyValue('Earth.renderable.colorTexture', '${OPENSPACE_DATA}/modules/mars/textures/mars.png')
openspace.time.setTime("2007-02-26T12:00:00")
openspace.time.setTime("2007-02-26T17:30:00")
--openspace.time.setTime("2006-08-22T20:00:00")
--openspace.time.setDeltaTime(200000.0)
openspace.time.setDeltaTime(0.0)
--openspace.time.setDeltaTime(30000.0)
--openspace.time.setDeltaTime(5000.00)
--openspace.time.setDeltaTime(864000)
openspace.time.setDeltaTime(100.0)
-- print(openspace.time.currentTimeUTC())

View File

@@ -0,0 +1,2 @@
#define MAX_VOLUMES 0
#define MAX_TF 0

View File

View File

@@ -0,0 +1,3 @@
float showfunc_size = 20.0;
float SCREEN_HEIGHTf = float(SCREEN_HEIGHT);
float SCREEN_WIDTHf = float(SCREEN_WIDTH);

View File

@@ -0,0 +1,7 @@
#define SCREEN_WIDTH 1280
#define SCREEN_HEIGHT 720
#define MAX_LAYERS 32
#define ABUFFER_SINGLE_LINKED 1
#define ABUFFER_FIXED 2
#define ABUFFER_DYNAMIC 3
#define ABUFFER_IMPLEMENTATION ABUFFER_SINGLE_LINKED

View File

@@ -40,13 +40,13 @@ void main()
//diffuse = vec4(depth*5,0.0, 0.0, 1.0);
//diffuse = vec4(vs_position.w,0.0, 0.0, 1.0);
vec4 diffuse = vec4(1,0,0,1);
if( floor(vs_st[0]) == -2){
vec4 diffuse = vec4(0.4,0.4,0.4,1);
/*if( floor(vs_st[0]) == -2){
diffuse = gridColor*2.f;
}else{
diffuse = gridColor;
}
diffuse = gridColor;
}*/
diffuse = gridColor;
vec4 position = vs_position;

View File

@@ -71,7 +71,7 @@ void main()
}
*/
diffuse = max(intensity * diffuse, ambient);
//diffuse = vec4(1);
ABufferStruct_t frag = createGeometryFragment(diffuse, position, depth);
addToBuffer(frag);

View File

@@ -90,6 +90,12 @@ file(GLOB RENDERING_STARS_HEADER ${HEADER_ROOT_DIR}/openspace/rendering/stars/*.
set(OPENSPACE_HEADER ${OPENSPACE_HEADER} ${RENDERING_STARS_HEADER})
source_group(Rendering\\Stars FILES ${RENDERING_STARS_SOURCE} ${RENDERING_STARS_HEADER})
file(GLOB RENDERING_MODEL_SOURCE ${SOURCE_ROOT_DIR}/rendering/model/*.cpp)
set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${RENDERING_MODEL_SOURCE})
file(GLOB RENDERING_MODEL_HEADER ${HEADER_ROOT_DIR}/openspace/rendering/model/*.h)
set(OPENSPACE_HEADER ${OPENSPACE_HEADER} ${RENDERING_MODEL_HEADER})
source_group(Rendering\\Model FILES ${RENDERING_MODEL_SOURCE} ${RENDERING_MODEL_HEADER})
file(GLOB SCENEGRAPH_SOURCE ${SOURCE_ROOT_DIR}/scenegraph/*.cpp)
set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${SCENEGRAPH_SOURCE})
file(GLOB SCENEGRAPH_HEADER ${HEADER_ROOT_DIR}/openspace/scenegraph/*.h ${HEADER_ROOT_DIR}/openspace/scenegraph/*.inl)

View File

@@ -403,7 +403,7 @@ void OpenSpaceEngine::preSynchronization() {
_interactionHandler.update(dt);
_interactionHandler.lockControls();
Time::ref().advanceTime(dt);
//Time::ref().advanceTime(dt);
}
}

View File

@@ -412,8 +412,11 @@ void InteractionHandler::keyboardCallback(int key, int action) {
glm::quat rot = glm::quat(euler);
orbit(rot);
}
if (key == SGCT_KEY_Q) {
Time::ref().advanceTime(dt);
if (key == SGCT_KEY_Z) {
Time::ref().advanceTime(sgct::Engine::instance()->getDt());
}
if (key == SGCT_KEY_X) {
Time::ref().retreatTime(sgct::Engine::instance()->getDt());
}
if (key == 262) {
glm::vec3 euler(0.0, speed * dt, 0.0);

View File

@@ -0,0 +1,78 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <openspace/rendering/model/modelgeometry.h>
#include <openspace/util/factorymanager.h>
#include <openspace/util/constants.h>
#include <openspace/util/factorymanager.h>
namespace {
const std::string _loggerCat = "ModelGeometry";
}
namespace openspace {
namespace modelgeometry {
ModelGeometry* ModelGeometry::createFromDictionary(const ghoul::Dictionary& dictionary)
{
std::string geometryType;
const bool success = dictionary.getValue(
constants::modelgeometry::keyType, geometryType);
if (!success) {
LERROR("ModelGeometry did not contain a correct value of the key '"
<< constants::modelgeometry::keyType << "'");
return nullptr;
}
ghoul::TemplateFactory<ModelGeometry>* factory
= FactoryManager::ref().factory<ModelGeometry>();
ModelGeometry* result = factory->create(geometryType, dictionary);
if (result == nullptr) {
LERROR("Failed to create a ModelGeometry object of type '" << geometryType
<< "'");
return nullptr;
}
return result;
}
ModelGeometry::ModelGeometry()
: _parent(nullptr)
{
setName("ModelGeometry");
}
ModelGeometry::~ModelGeometry()
{
}
bool ModelGeometry::initialize(RenderableModel* parent){
_parent = parent;
return true;
}
void ModelGeometry::deinitialize()
{
}
} // namespace modelgeometry
} // namespace openspace

View File

@@ -0,0 +1,177 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
// temporary includes (will fix as soon as I figure out how class hierarchy should work,
// ie after I see model on screen)
// open space includes
#include <openspace/rendering/model/renderablemodel.h>
#include <openspace/util/constants.h>
#include <openspace/rendering/model/modelgeometry.h>
#include <ghoul/opengl/texturereader.h>
#include <ghoul/opengl/textureunit.h>
#include <ghoul/filesystem/filesystem.h>
#include <openspace/util/time.h>
#include <openspace/util/spicemanager.h>
#include <openspace/engine/openspaceengine.h>
#include <sgct.h>
namespace {
const std::string _loggerCat = "RenderableModel";
const std::string keySource = "Rotation.Source";
const std::string keyDestination = "Rotation.Destination";
}
namespace openspace {
RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _colorTexturePath("colorTexture", "Color Texture")
, _programObject(nullptr)
, _texture(nullptr)
, _geometry(nullptr)
{
std::string name;
bool success = dictionary.getValue(constants::scenegraphnode::keyName, name);
assert(success);
std::string path;
success = dictionary.getValue(constants::scenegraph::keyPathModule, path);
assert(success);
ghoul::Dictionary geometryDictionary;
success = dictionary.getValue(
constants::renderablemodel::keyGeometry, geometryDictionary);
if (success) {
geometryDictionary.setValue(constants::scenegraphnode::keyName, name);
geometryDictionary.setValue(constants::scenegraph::keyPathModule, path);
_geometry = modelgeometry::ModelGeometry::createFromDictionary(geometryDictionary);
}
std::string texturePath = "";
success = dictionary.getValue("Textures.Color", texturePath);
if (success)
_colorTexturePath = path + "/" + texturePath;
addPropertySubOwner(_geometry);
addProperty(_colorTexturePath);
_colorTexturePath.onChange(std::bind(&RenderableModel::loadTexture, this));
assert(dictionary.getValue(keySource, _source));
assert(dictionary.getValue(keyDestination, _destination));
}
RenderableModel::~RenderableModel(){
deinitialize();
}
bool RenderableModel::initialize(){
bool completeSuccess = true;
if (_programObject == nullptr)
completeSuccess
&= OsEng.ref().configurationManager().getValue("pscShader", _programObject);
loadTexture();
completeSuccess &= (_texture != nullptr);
completeSuccess &= _geometry->initialize(this);
return completeSuccess;
}
bool RenderableModel::deinitialize(){
_geometry->deinitialize();
delete _geometry;
_geometry = nullptr;
delete _texture;
_texture = nullptr;
return true;
}
void RenderableModel::render(const RenderData& data)
{
if (!_programObject) return;
if (!_texture) return;
// activate shader
_programObject->activate();
// scale the planet to appropriate size since the planet is a unit sphere
glm::mat4 transform = glm::mat4(1);
glm::mat4 tmp = glm::mat4(1);
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++){
tmp[i][j] = _stateMatrix[i][j];
}
}
transform *= tmp;
glm::mat4 modelview = data.camera.viewMatrix()*data.camera.modelMatrix();
glm::vec3 camSpaceEye = (-(modelview*data.position.vec4())).xyz;
// setup the data to the shader
// _programObject->setUniform("camdir", camSpaceEye);
_programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
_programObject->setUniform("ModelTransform", transform);
setPscUniforms(_programObject, &data.camera, data.position);
// Bind texture
ghoul::opengl::TextureUnit unit;
unit.activate();
_texture->bind();
_programObject->setUniform("texture1", unit);
_geometry->render();
// disable shader
_programObject->deactivate();
}
void RenderableModel::update(const UpdateData& data){
// set spice-orientation in accordance to timestamp
openspace::SpiceManager::ref().getPositionTransformMatrix(_source, _destination, data.time, _stateMatrix);
}
void RenderableModel::loadTexture()
{
delete _texture;
_texture = nullptr;
if (_colorTexturePath.value() != "") {
_texture = ghoul::opengl::loadTexture(absPath(_colorTexturePath));
if (_texture) {
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
_texture->uploadTexture();
}
}
}
} // namespace openspace

View File

@@ -21,81 +21,55 @@
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
// temporary includes (will fix as soon as I figure out how class hierarchy should work,
// ie after I see model on screen)
#include<fstream>
// open space includes
#include <openspace/rendering/renderablewavefrontobject.h>
#include <openspace/rendering/model/wavefrontgeometry.h>
#include <openspace/util/constants.h>
#include <ghoul/opengl/texturereader.h>
#include <ghoul/opengl/textureunit.h>
#include <ghoul/filesystem/filesystem.h>
#include <openspace/util/time.h>
#include <openspace/util/spicemanager.h>
#include <openspace/engine/openspaceengine.h>
#include <sgct.h>
namespace {
const std::string _loggerCat = "RenderableWavefrontObject";
const std::string _loggerCat = "WavefrontGeometry";
}
namespace openspace {
RenderableWavefrontObject::RenderableWavefrontObject(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _colorTexturePath("colorTexture", "Color Texture")
, _programObject(nullptr)
, _fovProgram(nullptr)
, _texture(nullptr)
, _isize(0)
, _vsize(0)
, _varray(nullptr)
, _iarray(nullptr)
namespace modelgeometry {
WavefrontGeometry::WavefrontGeometry(const ghoul::Dictionary& dictionary)
: ModelGeometry()
, _mode(GL_TRIANGLES)
, _isize(0)
, _vsize(0)
, _varray(nullptr)
, _iarray(nullptr)
{
std::string name;
bool success = dictionary.getValue(constants::scenegraphnode::keyName, name);
using constants::scenegraphnode::keyName;
// The name is passed down from the SceneGraphNode
std::string name;
bool success = dictionary.getValue(keyName, name);
assert(success);
std::string path;
dictionary.getValue(constants::scenegraph::keyPathModule, path);
std::string texturePath = "";
if (dictionary.hasKey("Textures.Color")) {
dictionary.getValue("Textures.Color", texturePath);
_colorTexturePath = path + "/" + texturePath;
}
addProperty(_colorTexturePath);
_colorTexturePath.onChange(std::bind(&RenderableWavefrontObject::loadTexture, this));
_mode = GL_TRIANGLES;
std::string file;
dictionary.getValue(constants::renderablewavefrontobject::keyObjFile, file);
success = dictionary.getValue(constants::modelgeometry::keyObjFile, file);
if (!success) {
LERROR("SimpleSphereGeometry of '" << name << "' did not provide a key '"
<< constants::modelgeometry::keyObjFile << "'");
}
const std::string filename = FileSys.absolutePath(file);
std::cout << "OBJECT LOADER FILENAME : " << filename << std::endl;
std::ifstream ifile(filename.c_str());
if (ifile){
LDEBUG("Found file..\n");
ifile.close();
loadObj(filename.c_str());
}else {
}
else {
LERROR("Did not find file..\n");
}
}
void RenderableWavefrontObject::loadObj(const char *filename){
void WavefrontGeometry::loadObj(const char *filename){
// temporary
int vertexSize = 0;
int vertexNormalSize = 0;
@@ -136,21 +110,20 @@ void RenderableWavefrontObject::loadObj(const char *filename){
}
}
}
/* END LINE COUNT */
// allocate memory for all arrays
_isize = indicesSize;
_vsize = indicesSize;
// float arrays
float *tempVertexArray = (float*)malloc(vertexSize*sizeof(float));
float *tempVertexNormalArray = (float*)malloc(vertexNormalSize*sizeof(float));
float *tempVertexTextureArray = (float*)malloc(vertexTextureSize*sizeof(float));
_varray = (Vertex*)malloc(_vsize*sizeof(Vertex));
float *tempVertexArray = new float[vertexSize];
float *tempVertexNormalArray = new float[vertexNormalSize];
float *tempVertexTextureArray = new float[vertexTextureSize];
_varray = new Vertex[_vsize];
// int arrays
_iarray = (int*)malloc(_isize*sizeof(int));
int *tempNormalIndicesArray = (int*)malloc(_isize*sizeof(int));
int *tempTextureIndicesArray = (int*)malloc(_isize*sizeof(int));
_iarray = new int[_isize];
int *tempNormalIndicesArray = new int[_isize];
int *tempTextureIndicesArray = new int[_isize];
// keeping track of the array indexes
unsigned int i = 0;
@@ -189,15 +162,15 @@ void RenderableWavefrontObject::loadObj(const char *filename){
if (sscanf(line, "f %i/%i/%i %i/%i/%i %i/%i/%i", &i1, &i2, &i3, &i4, &i5, &i6, &i7, &i8, &i9)){
(_iarray)[m] = i1 - 1;
(tempTextureIndicesArray)[m] = i2 - 1;
(tempNormalIndicesArray)[m] = i3 - 1;
(tempNormalIndicesArray)[m] = i3 - 1;
m++;
(_iarray)[m] = i4 - 1;
(tempTextureIndicesArray)[m] = i5 - 1;
(tempNormalIndicesArray)[m] = i6 - 1;
(tempNormalIndicesArray)[m] = i6 - 1;
m++;
(_iarray)[m] = i7 - 1;
(tempTextureIndicesArray)[m] = i8 - 1;
(tempNormalIndicesArray)[m] = i9 - 1;
(tempNormalIndicesArray)[m] = i9 - 1;
m++;
}
}
@@ -229,11 +202,11 @@ void RenderableWavefrontObject::loadObj(const char *filename){
vertexIndex = _iarray[m] * 3;
_iarray[m] = m;
_varray[m].location[3] = 2;
_varray[m].location[3] = 7; // I need to set this proper at some point.
int q = 0;
while (q < 3){
_varray[m].location[q] = tempVertexArray[vertexIndex + q];
_varray[m].normal[q] = tempVertexNormalArray[normalIndex + q];
_varray[m].normal[q] = tempVertexNormalArray[normalIndex + q];
q++;
}
@@ -248,36 +221,22 @@ void RenderableWavefrontObject::loadObj(const char *filename){
m++;
}
// free up memory
free(tempVertexArray);
free(tempVertexNormalArray);
free(tempNormalIndicesArray);
free(tempVertexTextureArray);
free(tempTextureIndicesArray);
delete[] tempVertexArray;
delete[] tempVertexNormalArray;
delete[] tempNormalIndicesArray;
delete[] tempVertexTextureArray;
delete[] tempTextureIndicesArray;
}
RenderableWavefrontObject::~RenderableWavefrontObject(){
deinitialize();
WavefrontGeometry::~WavefrontGeometry(){
}
bool RenderableWavefrontObject::initialize()
{
if(_isize == 0)
return false;
bool completeSuccess = true;
if (_programObject == nullptr)
completeSuccess
&= OsEng.ref().configurationManager().getValue("pscShader", _programObject);
loadTexture();
completeSuccess &= (_texture != nullptr);
//completeSuccess &= _geometry->initialize(this);
PowerScaledScalar ps = PowerScaledScalar(1,2);
setBoundingSphere(ps);
GLuint errorID;
bool WavefrontGeometry::initialize(RenderableModel* parent){
bool success = ModelGeometry::initialize(parent);
createSphere();
if (_isize == 0) return false;
glGenVertexArrays(1, &_vaoID);
glGenBuffers(1, &_vBufferID);
glGenBuffers(1, &_iBufferID);
@@ -290,125 +249,47 @@ bool RenderableWavefrontObject::initialize()
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex),
reinterpret_cast<const GLvoid*>(offsetof(Vertex, location)));
reinterpret_cast<const GLvoid*>(offsetof(Vertex, location)));
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex),
reinterpret_cast<const GLvoid*>(offsetof(Vertex, tex)));
reinterpret_cast<const GLvoid*>(offsetof(Vertex, tex)));
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex),
reinterpret_cast<const GLvoid*>(offsetof(Vertex, normal)));
reinterpret_cast<const GLvoid*>(offsetof(Vertex, normal)));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, _isize * sizeof(int), _iarray, GL_STATIC_DRAW);
glBindVertexArray(0);
errorID = glGetError();
GLint errorID = glGetError();
if (errorID != GL_NO_ERROR) {
LERROR("OpenGL error: " << glewGetErrorString(errorID));
return false;
}
return completeSuccess;
return success;
}
bool RenderableWavefrontObject::deinitialize()
{
void WavefrontGeometry::deinitialize(){
delete[] _varray;
delete[] _iarray;
glDeleteBuffers(1, &_vBufferID);
glDeleteBuffers(1, &_iBufferID);
glDeleteVertexArrays(1, &_vaoID);
delete _texture;
_texture = nullptr;
return true;
}
void RenderableWavefrontObject::render(const RenderData& data)
{
if (!_programObject)
return;
if (!_texture)
return;
// activate shader
_programObject->activate();
// fetch data
psc currentPosition = data.position;
psc campos = data.camera.position();
glm::mat4 camrot = data.camera.viewRotationMatrix();
// PowerScaledScalar scaling = camera->scaling();
// scale the planet to appropriate size since the planet is a unit sphere
glm::mat4 transform = glm::mat4(1);
glm::mat4 scaler = glm::scale(transform, glm::vec3(0, 0, -1));
//earth needs to be rotated for that to work.
glm::mat4 rot_x = glm::rotate(transform, 90.f, glm::vec3(1, 0, 0));
glm::mat4 tmp = glm::mat4(1);
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++){
tmp[i][j] = _stateMatrix[i][j];
}
}
transform *= tmp;
transform *= rot_x;
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("ViewProjection", data.camera.viewProjectionMatrix());
_programObject->setUniform("ModelTransform", transform);
setPscUniforms(_programObject, &data.camera, data.position);
// Bind texture
ghoul::opengl::TextureUnit unit;
unit.activate();
_texture->bind();
_programObject->setUniform("texture1", unit);
// render
void WavefrontGeometry::render(){
// render
glBindVertexArray(_vaoID); // select first VAO
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferID);
glDrawElements(_mode, _isize, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
// disable shader
_programObject->deactivate();
std::string shape, name;
shape.resize(32);
name.resize(32);
std::vector<glm::dvec3> bounds;
glm::dvec3 boresight;
bool found = openspace::SpiceManager::ref().getFieldOfView("NH_LORRI", shape, name, boresight, bounds);
glm::vec4 a(boresight, 1);
a = transform*a;
//std::cout << a[0] << " " << a[1] << " " << a[2] << std::endl;
}
void RenderableWavefrontObject::update(const UpdateData& data)
{
glm::dvec3 position(0, 0, 0);
// set spice-orientation in accordance to timestamp
openspace::SpiceManager::ref().getPositionTransformMatrix("NH_SPACECRAFT", "GALACTIC", data.time, _stateMatrix);
}
void RenderableWavefrontObject::loadTexture()
{
delete _texture;
_texture = nullptr;
if (_colorTexturePath.value() != "") {
_texture = ghoul::opengl::loadTexture(absPath(_colorTexturePath));
if (_texture) {
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
_texture->uploadTexture();
}
}
void WavefrontGeometry::createSphere(){
// create the power scaled scalar
PowerScaledScalar ps = PowerScaledScalar::PowerScaledScalar(1, 0); // will set proper bounding soon.
_parent->setBoundingSphere(ps);
}
} // namespace modelgeometry
} // namespace openspace

View File

@@ -82,13 +82,11 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
_colorTexturePath.onChange(std::bind(&RenderablePlanet::loadTexture, this));
}
RenderablePlanet::~RenderablePlanet()
{
RenderablePlanet::~RenderablePlanet(){
deinitialize();
}
bool RenderablePlanet::initialize()
{
bool RenderablePlanet::initialize(){
bool completeSuccess = true;
if (_programObject == nullptr)
completeSuccess
@@ -96,14 +94,12 @@ bool RenderablePlanet::initialize()
loadTexture();
completeSuccess &= (_texture != nullptr);
completeSuccess &= _geometry->initialize(this);
return completeSuccess;
}
bool RenderablePlanet::deinitialize()
{
bool RenderablePlanet::deinitialize(){
_geometry->deinitialize();
delete _geometry;
_geometry = nullptr;
@@ -114,10 +110,8 @@ bool RenderablePlanet::deinitialize()
void RenderablePlanet::render(const RenderData& data)
{
if (!_programObject)
return;
if (!_texture)
return;
if (!_programObject) return;
if (!_texture) return;
// activate shader
_programObject->activate();
@@ -155,7 +149,6 @@ void RenderablePlanet::render(const RenderData& data)
// disable shader
_programObject->deactivate();
}
void RenderablePlanet::update(const UpdateData& data){

View File

@@ -70,71 +70,21 @@ namespace openspace{
}
}
void RenderableFov::fullYearSweep(){
double lightTime = 0.0;
double et = _startTrail;
double planetYear = 31540000;
int segments = 2;
_increment = planetYear / 4;
_isize = (segments);
_vsize = (segments);
int points = 8;
_stride = 8;
_isize = points;
_iarray = new int[_isize];
SpiceManager::ref().getTargetState("NEW HORIZONS", "SUN", "GALACTIC", "LT+S", et, _pscpos, _pscvel, lightTime);
_pscpos[3] += 3;
_varray.push_back(_pscpos[0]);
_varray.push_back(_pscpos[1]);
_varray.push_back(_pscpos[2]);
_varray.push_back(_pscpos[3]);
_varray.push_back(1.f );
_varray.push_back(0.f );
_varray.push_back(0.f );
_varray.push_back(1.f );
_iarray[0] = 0;
glm::mat4 tmat = glm::mat4(1);
glm::mat4 rot_x = glm::rotate(tmat, 90.f, glm::vec3(1, 0, 0));
openspace::SpiceManager::ref().getPositionTransformMatrix("NH_SPACECRAFT", "GALACTIC", et, _stateMatrix);
glm::mat4 tmp = glm::mat4(1);
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++){
tmp[i][j] = _stateMatrix[i][j];
for (int i = 0; i < points; i++){
for (int j = 0; j < 4; j++){
_varray.push_back(0); // pos
}
for (int j = 0; j < 4; j++){
_varray.push_back(0); // col
}
_iarray[i] = i;
}
tmat *= tmp;
tmat *= rot_x;
std::string shape, name;
shape.resize(32);
name.resize(32);
std::vector<glm::dvec3> bounds;
glm::dvec3 boresight;
bool found = openspace::SpiceManager::ref().getFieldOfView("NH_LORRI", shape, name, boresight, bounds);
glm::vec4 bsight_t(boresight[0], boresight[1], boresight[2], 1);
//psc bor = PowerScaledCoordinate::CreatePowerScaledCoordinate(boresight[0], boresight[1], boresight[2]);
bsight_t = tmat*bsight_t;
_varray.push_back(bsight_t[0]);
_varray.push_back(bsight_t[1]);
_varray.push_back(bsight_t[2]);
_varray.push_back(2);
_varray.push_back(1.f);
_varray.push_back(0.f);
_varray.push_back(0.f);
_varray.push_back(1.f);
_iarray[1] = 1;
_stride = 8;
_vsize = _varray.size();
@@ -173,11 +123,10 @@ void RenderableFov::sendToGPU(){
bool RenderableFov::initialize(){
bool completeSuccess = true;
if (_programObject == nullptr)
completeSuccess
&= OsEng.ref().configurationManager().getValue("EphemerisProgram", _programObject);
completeSuccess &= OsEng.ref().configurationManager().getValue("EphemerisProgram", _programObject);
_startTrail;
SpiceManager::ref().getETfromDate("2007 feb 26 12:00:00", _startTrail);
SpiceManager::ref().getETfromDate("2007 feb 26 20:00:00", _startTrail);
fullYearSweep();
sendToGPU();
@@ -201,29 +150,69 @@ void RenderableFov::render(const RenderData& data){
_programObject->activate();
// fetch data
psc currentPosition = data.position;
psc campos = data.camera.position();
glm::mat4 camrot = data.camera.viewRotationMatrix();
glm::mat4 tmat = glm::mat4(1);
glm::mat4 rot_x = glm::rotate(tmat, 90.f, glm::vec3(1, 0, 0));
glm::mat4 transform(1);
glm::mat4 tmp = glm::mat4(1);
glm::mat4 rot = glm::rotate(transform, 90.f, glm::vec3(0, 1, 0));
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++){
tmp[i][j] = _stateMatrix[i][j];
}
}
tmat *= tmp;
tmat *= rot_x;
transform = tmp*rot;
glm::mat4 transform(1);
// setup the data to the shader
_programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
_programObject->setUniform("ModelTransform", transform);
setPscUniforms(_programObject, &data.camera, data.position);
//updateData();
//boresight vector
std::string shape, name;
shape.resize(32);
name.resize(32);
std::vector<glm::dvec3> bounds;
glm::dvec3 boresight;
bool found = openspace::SpiceManager::ref().getFieldOfView("NH_LORRI", shape, name, boresight, bounds);
float size = 4 * sizeof(float);
float *begin = &_varray[0];
glm::vec4 origin(0);
glm::vec4 col_start(1.00, 0.89, 0.00, 1);
glm::vec4 col_end(1.00, 0.29, 0.00, 1);
glm::vec4 bsight_t(boresight[0], boresight[1], boresight[2], data.position[3]-3);
float sc = 2.2;
glm::vec4 corner1(bounds[0][0], bounds[0][1], bounds[0][2], data.position[3]-sc);
memcpy(begin, glm::value_ptr(origin), size);
memcpy(begin + 4, glm::value_ptr(col_start), size);
memcpy(begin + 8, glm::value_ptr(corner1), size);
memcpy(begin + 12, glm::value_ptr(col_end), size);
glm::vec4 corner2(bounds[1][0], bounds[1][1], bounds[1][2], data.position[3]-sc);
memcpy(begin + 16, glm::value_ptr(origin), size);
memcpy(begin + 20, glm::value_ptr(col_start), size);
memcpy(begin + 24, glm::value_ptr(corner2), size);
memcpy(begin + 28, glm::value_ptr(col_end), size);
glm::vec4 corner3(bounds[2][0], bounds[2][1], bounds[2][2], data.position[3]-sc);
memcpy(begin + 32, glm::value_ptr(origin), size);
memcpy(begin + 36, glm::value_ptr(col_start), size);
memcpy(begin + 40, glm::value_ptr(corner3), size);
memcpy(begin + 44, glm::value_ptr(col_end), size);
glm::vec4 corner4(bounds[3][0], bounds[3][1], bounds[3][2], data.position[3]-sc);
memcpy(begin + 48, glm::value_ptr(origin), size);
memcpy(begin + 52, glm::value_ptr(col_start), size);
memcpy(begin + 56, glm::value_ptr(corner4), size);
memcpy(begin + 60, glm::value_ptr(col_end), size);
updateData();
glBindVertexArray(_vaoID);
glDrawArrays(_mode, 0, _vtotal);

View File

@@ -80,6 +80,7 @@ namespace openspace{
void RenderablePath::fullYearSweep(){
double lightTime = 0.0;
SpiceManager::ref().getETfromDate("2006 jan 20 19:00:00", _time);
// -------------------------------------- ^ this has to be simulation start-time, not passed in here though --
double et2 = 0;
//SpiceManager::ref().getETfromDate("2008 apr 01 00:00:00", et2);

View File

@@ -33,7 +33,13 @@
#include <openspace/util/spicemanager.h>
#include <iomanip>
#include <utility>
#include <utility>
/* TODO for this class:
* In order to add geometry shader (for pretty-draw),
* need to pack each consecutive point pair into a vec2
* in order to draw quad between them.
*/
namespace {
const std::string _loggerCat = "RenderableTrail";
//constants
@@ -82,54 +88,58 @@ namespace openspace{
// values in modfiles set from here
// http://nssdc.gsfc.nasa.gov/planetary/factsheet/marsfact.html
//white is default col
//white is default col
if (!dictionary.getValue(keyColor, _c)){
_c = glm::vec3(0.0);
}else{
}else{ //to understand, ref to line 115.
_r = 1 / _c[0];
_g = 1 / _c[1];
_b = 1 / _c[2];
}
}
/* This algorithm estimates and precomputes the number of segments required for
* any planetary object in space, given a tropical orbit period and earth-to-planet
* orbit ratio. In doing so, it finds the exact increment of time corresponding
* to a planetary year.
* Therefore all planets need said constants, for other objects we need a different,
* and most likely heuristic measure to easily estimate a nodal time-increment.
* Trivial, yet - a TODO.
*/
void RenderableTrail::fullYearSweep(){
double lightTime = 0.0;
// -------------------------------------- ^ this has to be simulation start-time, not passed in here though --
if (_target == "JUPITER BARYCENTER"){
_tropic *= 20;
}
double et = _startTrail;
double planetYear = 31540000 * _ratio;
int segments = _tropic;
_increment = planetYear / _tropic;
_increment = planetYear / _tropic;
_isize = (segments + 2);
_vsize = (segments + 2);
_iarray = new int[_isize];
double p = 1.0 / _tropic;
for (int i = 0; i < segments + 1; i++){
for (int i = 0; i < segments+2; i++){
SpiceManager::ref().getTargetState(_target, _observer, _frame, "LT+S", et, _pscpos, _pscvel, lightTime);
_pscpos[3] += 3;
_varray.push_back(_pscpos[0]);
_varray.push_back(_pscpos[1]);
_varray.push_back(_pscpos[2]);
_varray.push_back(_pscpos[3]);
for (int k = 0; k < 4; k++)
_varray.push_back(_pscpos[k]);
#ifndef DEBUG
_varray.push_back(1.f - ((double)i / _tropic * _r));
_varray.push_back(1.f - ((double)i / _tropic * _g));
_varray.push_back(1.f - ((double)i / _tropic * _b));
_varray.push_back(1.f - ((double)i / _tropic));
float p = (float)i / _tropic;
_varray.push_back(1.f - p * _r);
_varray.push_back(1.f - p * _g);
_varray.push_back(1.f - p * _b);
_varray.push_back(1.f - p);
#else
_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!
_iarray[i] = i;
if (i != 0) //very first point needs to be alllocated twice.
et -= _increment;
}
_stride = 8;
@@ -177,14 +187,12 @@ bool RenderableTrail::initialize(){
completeSuccess &= (_texture != nullptr);
_startTrail;
SpiceManager::ref().getETfromDate("2007 feb 26 12:00:00", _startTrail);
//SpiceManager::ref().getETfromDate("2006 aug 22 20:00:00", _startTrail);
fullYearSweep();
sendToGPU();
// SpiceManager::ref().getETfromDate("2006 Aug 22 17:00:00", _startTrail);
SpiceManager::ref().getETfromDate("2007 feb 26 17:30:00", _startTrail);
_dtEt = _startTrail;
fullYearSweep();
sendToGPU();
return completeSuccess;
}
@@ -195,32 +203,60 @@ bool RenderableTrail::deinitialize(){
return true;
}
// Tried interpolation but then realised this still gives straight lines (latenight thing).
// Not allowed Splines so therefore - query spice for each point (bah...)
// From psc paper:
/*
psc pscInterpolate(psc p0, psc p1, float t){
assert(t >= 0 && t <= 1);
float s = (1.f - t)*p0[3] + t*p1[3];
float x = ((1.f - t)*p0[0] + t*p1[0]);
float y = ((1.f - t)*p0[1] + t*p1[1]);
float z = ((1.f - t)*p0[2] + t*p1[2]);
return PowerScaledCoordinate::PowerScaledCoordinate(x,y,z,s);
}
*/
void RenderableTrail::updateTrail(){
if (_oldTime != _time){ // only update when time actually progresses
_dtprogress += _delta*sgct::Engine::instance()->getDt(); // compute how far time has progressed
if (_dtprogress > _increment){
//reset progress counter
_dtprogress = 0;
int m = _stride;
float *begin = &_varray[0];
float *end = &_varray[_vsize - 1] + 1;
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
_pscpos[3] += 3;
memcpy(&_varray[0], glm::value_ptr(_pscpos.vec4()), 4 * sizeof(double));
// update only when time progresses
if (_oldTime != _time){
// if time progressed more than N _increments
while (_dtEt < _time){
// get intermediary points
psc dtPoint;
SpiceManager::ref().getTargetState(_target, _observer, _frame, "NONE", _dtEt, dtPoint, _pscvel, lightTime);
dtPoint[3] += 3;
// overwrite the old position
memcpy(begin, glm::value_ptr(dtPoint.vec4()), 4 * sizeof(float));
// shift array
for (int k = _vsize-m; k > 0; k -= m){
memcpy(&_varray[k], &_varray[k - m], 4 * sizeof(float));
}
// keep track of progression
_dtEt += _increment;
}
//add earths current position
memcpy(&_varray[0], glm::value_ptr(_pscpos.vec4()), 4 * sizeof(float));
_varray[4] = 1.f;
_varray[5] = 1.f;
_varray[6] = 1.f;
_varray[7] = 1.f;
}_oldTime = _time;
// update GPU
// NOTE: vbo interleaved, makes possible color update more efficient - tightly packed.
// if NO color update : would be more efficient to have these as separate
// => N/2 updates per drawcall.
glBindBuffer(GL_ARRAY_BUFFER, _vBufferID);
glBufferSubData(GL_ARRAY_BUFFER, 0, _vsize * sizeof(GLfloat), &_varray[0]);
}
@@ -231,10 +267,8 @@ void RenderableTrail::render(const RenderData& data){
// fetch data
psc currentPosition = data.position;
psc campos = data.camera.position();
glm::mat4 camrot = data.camera.viewRotationMatrix();
// PowerScaledScalar scaling = camera->scaling();
PowerScaledScalar scaling = glm::vec2(1, -6);
psc campos = data.camera.position();
glm::mat4 camrot = data.camera.viewRotationMatrix();
glm::mat4 transform = glm::mat4(1);
@@ -244,28 +278,28 @@ void RenderableTrail::render(const RenderData& data){
_programObject->setUniform("ModelTransform", transform);
setPscUniforms(_programObject, &data.camera, data.position);
updateTrail();
glBindVertexArray(_vaoID);
glDrawArrays(_mode, 0, _vtotal);
glBindVertexArray(0);
/*
glPointSize(2.f);
// nodes of equal time
glBindVertexArray(_vaoID);
glDrawArrays(GL_POINTS, 0, _vtotal);
glBindVertexArray(0);
*/
_programObject->deactivate();
}
void RenderableTrail::update(const UpdateData& data){
double lightTime;
_time = data.time;
_delta = data.delta;
SpiceManager::ref().getTargetState(_target, _observer, _frame, "NONE", data.time+_increment, _pscpos, _pscvel, lightTime);
SpiceManager::ref().getTargetState(_target, _observer, _frame, "NONE", data.time, _pscpos, _pscvel, lightTime);
_pscpos[3] += 3; // KM to M
}
void RenderableTrail::loadTexture()

View File

@@ -75,7 +75,8 @@ void SpiceEphemeris::update(const UpdateData& data) {
glm::dvec3 position(0,0,0);
double lightTime = 0.0;
SpiceManager::ref().getTargetPosition(_targetName, _originName, "GALACTIC", "NONE", data.time, position, lightTime);
SpiceManager::ref().getTargetPosition(_targetName, _originName, "GALACTIC", "CN+S", data.time, position, lightTime);
_position = psc::CreatePowerScaledCoordinate(position.x, position.y, position.z);
_position[3] += 3;
}

View File

@@ -25,7 +25,7 @@
#include <openspace/util/factorymanager.h>
// renderables
#include <openspace/rendering/renderablewavefrontobject.h>
#include <openspace/rendering/model/renderablemodel.h>
#include <openspace/rendering/stars/renderablestars.h>
#include <openspace/rendering/renderableephemeris.h>
#include <openspace/rendering/renderabletrail.h>
@@ -34,9 +34,12 @@
#include <openspace/rendering/renderablesphericalgrid.h>
#include <openspace/rendering/renderablefieldlines.h>
#include <openspace/rendering/planets/renderableplanet.h>
#include <openspace/rendering/planets/simplespheregeometry.h>
#include <openspace/rendering/renderableplane.h>
#include <openspace/rendering/renderablevolumegl.h>
#include <openspace/rendering/planets/simplespheregeometry.h>
#include <openspace/rendering/model/modelgeometry.h>
#include <openspace/rendering/model/wavefrontgeometry.h>
// positioninformation
#include <openspace/scenegraph/staticephemeris.h>
@@ -74,13 +77,14 @@ void FactoryManager::initialize()
"RenderableFov");
_manager->factory<Renderable>()->registerClass<RenderableSphericalGrid>(
"RenderableSphericalGrid");
_manager->factory<Renderable>()->registerClass<RenderableWavefrontObject>(
"RenderableWavefrontObject");
_manager->factory<Renderable>()->registerClass<RenderableModel>(
"RenderableModel");
_manager->factory<Renderable>()->registerClass<RenderablePlane>(
"RenderablePlane");
"RenderablePlane");
_manager->factory<Renderable>()->registerClass<RenderableVolumeGL>(
"RenderableVolumeGL");
_manager->factory<Renderable>()->registerClass<RenderableFieldlines>("RenderableFieldlines");
"RenderableVolumeGL");
_manager->factory<Renderable>()->registerClass<RenderableFieldlines>(
"RenderableFieldlines");
// Add Ephimerides
_manager->addFactory(new ghoul::TemplateFactory<Ephemeris>);
@@ -91,6 +95,11 @@ void FactoryManager::initialize()
_manager->addFactory(new ghoul::TemplateFactory<planetgeometry::PlanetGeometry>);
_manager->factory<planetgeometry::PlanetGeometry>()
->registerClass<planetgeometry::SimpleSphereGeometry>("SimpleSphere");
// Add ModelGeometry
_manager->addFactory(new ghoul::TemplateFactory<modelgeometry::ModelGeometry>);
_manager->factory<modelgeometry::ModelGeometry>()
->registerClass<modelgeometry::WavefrontGeometry>("WavefrontGeometry");
}
void FactoryManager::deinitialize()

View File

@@ -184,6 +184,10 @@ double Time::advanceTime(double tickTime) {
return _time += _deltaTimePerSecond * tickTime;
}
double Time::retreatTime(double tickTime) {
return _time -= _deltaTimePerSecond * tickTime;
}
void Time::setDeltaTime(double deltaT) {
_deltaTimePerSecond = std::move(deltaT);
}