mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-06 19:39:56 -05:00
Merge branch 'develop' into properties
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
---
|
||||
Language: Cpp
|
||||
AccessModifierOffset: -4
|
||||
AlignEscapedNewlinesLeft: false
|
||||
AlignTrailingComments: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortFunctionsOnASingleLine: false
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakBeforeMultilineStrings: true
|
||||
AlwaysBreakTemplateDeclarations: true
|
||||
BinPackParameters: true
|
||||
BreakBeforeBinaryOperators: true
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: true
|
||||
ColumnLimit: 90
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 6
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerBinding: false
|
||||
IndentCaseLabels: true
|
||||
#Check next
|
||||
IndentFunctionDeclarationAfterType: true
|
||||
IndentWidth: 4
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerBindsToType: true
|
||||
#Check next
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 2
|
||||
SpacesInAngles: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
Standard: Cpp11
|
||||
UseTab: Never
|
||||
...
|
||||
+1
-1
Submodule ext/ghoul updated: f6a96f6767...8c1bd08e06
@@ -25,8 +25,8 @@
|
||||
#ifndef __OPENSPACEENGINE_H__
|
||||
#define __OPENSPACEENGINE_H__
|
||||
|
||||
#include "interaction/interactionhandler.h"
|
||||
#include "rendering/renderengine.h"
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <ghoul/misc/configurationmanager.h>
|
||||
|
||||
namespace openspace {
|
||||
@@ -39,7 +39,9 @@ public:
|
||||
static void destroy();
|
||||
static OpenSpaceEngine& ref();
|
||||
|
||||
static bool isInitialized();
|
||||
bool initialize();
|
||||
static bool registerFilePaths();
|
||||
|
||||
ghoul::ConfigurationManager& configurationManager();
|
||||
InteractionHandler& interactionHandler();
|
||||
@@ -67,43 +69,9 @@ private:
|
||||
RenderEngine* _renderEngine;
|
||||
ScriptEngine* _scriptEngine;
|
||||
};
|
||||
|
||||
|
||||
#define OsEng (openspace::OpenSpaceEngine::ref())
|
||||
|
||||
/*
|
||||
class RenderEngine: public Object {
|
||||
public:
|
||||
|
||||
// constructors & destructor
|
||||
RenderEngine(int argc, char **argv);
|
||||
~RenderEngine();
|
||||
|
||||
// sgct wrapped functions
|
||||
bool init();
|
||||
void preSync();
|
||||
void postSyncPreDraw();
|
||||
void render();
|
||||
void postDraw();
|
||||
void keyboardCallback(int key, int action);
|
||||
void mouseButtonCallback(int key, int action);
|
||||
void mousePosCallback(int x, int y);
|
||||
void mouseScrollCallback(int pos);
|
||||
|
||||
// object extensions
|
||||
virtual void encode();
|
||||
virtual void decode();
|
||||
|
||||
private:
|
||||
double masterTime_;
|
||||
Camera *mainCamera_;
|
||||
//MouseExternalControl *mouseControl_;
|
||||
//KeyboardExternalControl *keyboardControl_;
|
||||
|
||||
SceneGraph *sceneGraph_;
|
||||
glm::vec3 eyePosition_;
|
||||
};
|
||||
*/
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACEENGINE_H__
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
#ifndef EXTERNALCONNECTIONCONTROLLER_H
|
||||
#define EXTERNALCONNECTIONCONTROLLER_H
|
||||
|
||||
#include "interaction/externalcontrol/externalcontrol.h"
|
||||
#include <openspace/interaction/externalcontrol/externalcontrol.h>
|
||||
#include <vector>
|
||||
|
||||
namespace openspace {
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
#ifndef EXTERNALCONTROL_H
|
||||
#define EXTERNALCONTROL_H
|
||||
|
||||
#include "util/pss.h"
|
||||
#include <openspace/util/pss.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
|
||||
#include "interaction/externalcontrol/externalcontrol.h"
|
||||
#include <openspace/interaction/externalcontrol/externalcontrol.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
+3
-14
@@ -2,9 +2,9 @@
|
||||
#define INTERACTIONHANDLER_H
|
||||
|
||||
// open space includes
|
||||
#include "util/camera.h"
|
||||
#include "externalcontrol/externalcontrol.h"
|
||||
#include "scenegraph/scenegraphnode.h"
|
||||
#include <openspace/util/camera.h>
|
||||
#include <openspace/interaction/externalcontrol/externalcontrol.h>
|
||||
#include <openspace/scenegraph/scenegraphnode.h>
|
||||
|
||||
// std includes
|
||||
#include <vector>
|
||||
@@ -12,17 +12,6 @@
|
||||
#include <mutex>
|
||||
#include <memory>
|
||||
|
||||
// hack until we have a file/path manager
|
||||
//#ifdef __WIN32__
|
||||
//#ifdef NDEBUG
|
||||
//#define RELATIVE_PATH ""
|
||||
//#else
|
||||
//#define RELATIVE_PATH "../../../"
|
||||
//#endif
|
||||
//#else
|
||||
//#define RELATIVE_PATH "../"
|
||||
//#endif
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class InteractionHandler {
|
||||
@@ -2,26 +2,30 @@
|
||||
#define RENDERABLE_H
|
||||
|
||||
// open space includes
|
||||
#include "util/psc.h"
|
||||
#include "util/pss.h"
|
||||
#include "util/camera.h"
|
||||
#include <openspace/util/psc.h>
|
||||
#include <openspace/util/pss.h>
|
||||
#include <openspace/util/camera.h>
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class Renderable {
|
||||
public:
|
||||
|
||||
|
||||
// constructors & destructor
|
||||
Renderable();
|
||||
Renderable(const pss &boundingSphere);
|
||||
virtual ~Renderable();
|
||||
Renderable(const ghoul::Dictionary& dictionary);
|
||||
virtual ~Renderable();
|
||||
|
||||
virtual bool initialize() = 0;
|
||||
virtual bool deinitialize() = 0;
|
||||
|
||||
void setBoundingSphere(const pss &boundingSphere);
|
||||
const pss &getBoundingSphere();
|
||||
|
||||
virtual void render(const Camera *camera, const psc &thisPosition) = 0;
|
||||
virtual void update();
|
||||
|
||||
protected:
|
||||
Renderable();
|
||||
private:
|
||||
pss boundingSphere_;
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
#define RENDERABLEBODY_H
|
||||
|
||||
// open space includes
|
||||
#include "renderable.h"
|
||||
#include "util/sphere.h"
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/util/sphere.h>
|
||||
|
||||
// ghoul includes
|
||||
#include "ghoul/opengl/programobject.h"
|
||||
#include "ghoul/opengl/texture.h"
|
||||
|
||||
namespace openspace {
|
||||
|
||||
/*
|
||||
class RenderableBody: public Renderable {
|
||||
public:
|
||||
|
||||
@@ -31,7 +31,7 @@ private:
|
||||
|
||||
gl4::Sphere *planet_;
|
||||
};
|
||||
|
||||
*/
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
@@ -2,12 +2,12 @@
|
||||
#define RENDERABLEPLANET_H
|
||||
|
||||
// open space includes
|
||||
#include "renderable.h"
|
||||
#include "util/planet.h"
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/util/powerscaledsphere.h>
|
||||
|
||||
// ghoul includes
|
||||
#include "ghoul/opengl/programobject.h"
|
||||
#include "ghoul/opengl/texture.h"
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
@@ -15,21 +15,29 @@ class RenderablePlanet: public Renderable {
|
||||
public:
|
||||
|
||||
// constructors & destructor
|
||||
RenderablePlanet(const pss &radius);
|
||||
RenderablePlanet(const ghoul::Dictionary& dictionary);
|
||||
~RenderablePlanet();
|
||||
|
||||
bool initialize();
|
||||
bool deinitialize();
|
||||
|
||||
void setProgramObject(ghoul::opengl::ProgramObject *programObject);
|
||||
void setProgramObject(ghoul::opengl::ProgramObject *programObject = nullptr);
|
||||
void setTexture(ghoul::opengl::Texture *texture);
|
||||
|
||||
virtual void render(const Camera *camera, const psc &thisPosition);
|
||||
virtual void update();
|
||||
|
||||
private:
|
||||
ghoul::opengl::ProgramObject *programObject_;
|
||||
|
||||
// shader
|
||||
ghoul::opengl::ProgramObject *programObject_;
|
||||
|
||||
// texture
|
||||
std::string _texturePath;
|
||||
ghoul::opengl::Texture *texture_;
|
||||
// double rad_;
|
||||
|
||||
Planet *planet_;
|
||||
|
||||
// Object
|
||||
PowerScaledSphere *planet_;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
@@ -25,7 +25,7 @@
|
||||
#ifndef __RENDERENGINE_H__
|
||||
#define __RENDERENGINE_H__
|
||||
|
||||
#include "scenegraph/scenegraph.h"
|
||||
#include <openspace/scenegraph/scenegraph.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
RenderEngine();
|
||||
~RenderEngine();
|
||||
|
||||
bool initialize(const std::string& sceneGraph);
|
||||
bool initialize();
|
||||
|
||||
SceneGraph* sceneGraph();
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 __CONSTANTPOSITIONINFORMATION_H__
|
||||
#define __CONSTANTPOSITIONINFORMATION_H__
|
||||
|
||||
#include "positioninformation.h"
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class ConstantPositionInformation: public PositionInformation {
|
||||
public:
|
||||
ConstantPositionInformation(const ghoul::Dictionary& dictionary);
|
||||
virtual ~ConstantPositionInformation();
|
||||
virtual bool initialize();
|
||||
virtual const psc& position() const;
|
||||
virtual void update();
|
||||
protected:
|
||||
private:
|
||||
psc _position;
|
||||
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
#endif
|
||||
@@ -0,0 +1,47 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 __POSITIONINFORMATION_H__
|
||||
#define __POSITIONINFORMATION_H__
|
||||
|
||||
#include <openspace/util/psc.h>
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class PositionInformation {
|
||||
public:
|
||||
PositionInformation(const ghoul::Dictionary& dictionary);
|
||||
virtual ~PositionInformation();
|
||||
virtual bool initialize() = 0;
|
||||
virtual const psc& position() const = 0;
|
||||
virtual void update() = 0;
|
||||
protected:
|
||||
PositionInformation();
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
#endif
|
||||
@@ -0,0 +1,103 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 SCENEGRAPH_H
|
||||
#define SCENEGRAPH_H
|
||||
|
||||
// open space includes
|
||||
#include <openspace/scenegraph/scenegraphnode.h>
|
||||
|
||||
// std includes
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
// ghoul includes
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class SceneGraph {
|
||||
public:
|
||||
|
||||
// constructors & destructor
|
||||
SceneGraph();
|
||||
~SceneGraph();
|
||||
|
||||
/**
|
||||
* Initalizes the SceneGraph by loading modules from the ${SCENEPATH} directory
|
||||
*/
|
||||
bool initialize();
|
||||
|
||||
/*
|
||||
* Clean up everything
|
||||
*/
|
||||
bool deinitialize();
|
||||
|
||||
/*
|
||||
* Load the scenegraph from the provided folder
|
||||
*/
|
||||
bool loadFromModulePath(const std::string& path);
|
||||
|
||||
/*
|
||||
* Updates all SceneGraphNodes relative positions
|
||||
*/
|
||||
void update();
|
||||
|
||||
/*
|
||||
* Evaluates if the SceneGraphNodes are visible to the provided camera
|
||||
*/
|
||||
void evaluate(Camera *camera);
|
||||
|
||||
/*
|
||||
* Render visible SceneGraphNodes using the provided camera
|
||||
*/
|
||||
void render(Camera *camera);
|
||||
|
||||
/*
|
||||
* Prints the SceneGraph tree. For debugging purposes
|
||||
*/
|
||||
void printChildren() const;
|
||||
|
||||
/*
|
||||
* Returns the root SceneGraphNode
|
||||
*/
|
||||
SceneGraphNode* root() const;
|
||||
|
||||
private:
|
||||
|
||||
void loadModulesFromModulePath(const std::string& modulePath);
|
||||
|
||||
std::string _focus, _position;
|
||||
|
||||
// actual scenegraph
|
||||
SceneGraphNode *_root;
|
||||
std::vector<SceneGraphNode*> _nodes;
|
||||
std::map<std::string, SceneGraphNode*> _allNodes;
|
||||
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,103 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 SCENEGRAPHNODE_H
|
||||
#define SCENEGRAPHNODE_H
|
||||
|
||||
// open space includes
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/scenegraph/positioninformation.h>
|
||||
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
|
||||
// std includes
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class SceneGraphNode {
|
||||
public:
|
||||
|
||||
// constructors & destructor
|
||||
SceneGraphNode(const ghoul::Dictionary& dictionary);
|
||||
~SceneGraphNode();
|
||||
|
||||
bool initialize();
|
||||
bool deinitialize();
|
||||
|
||||
// essential
|
||||
void update();
|
||||
void evaluate(const Camera *camera, const psc &parentPosition = psc());
|
||||
void render(const Camera *camera, const psc &parentPosition = psc());
|
||||
|
||||
// set & get
|
||||
void addNode(SceneGraphNode* child);
|
||||
|
||||
void setName(const std::string &name);
|
||||
void setParent(SceneGraphNode *parent);
|
||||
const psc& getPosition() const;
|
||||
psc getWorldPosition() const;
|
||||
std::string nodeName() const;
|
||||
|
||||
SceneGraphNode* parent() const;
|
||||
const std::vector<SceneGraphNode*>& children() const;
|
||||
|
||||
// bounding sphere
|
||||
pss calculateBoundingSphere();
|
||||
|
||||
SceneGraphNode* get(const std::string& name);
|
||||
|
||||
void print() const;
|
||||
|
||||
// renderable
|
||||
void setRenderable(Renderable *renderable);
|
||||
const Renderable * getRenderable() const;
|
||||
|
||||
private:
|
||||
|
||||
// essential
|
||||
std::vector<SceneGraphNode*> _children;
|
||||
SceneGraphNode* _parent;
|
||||
std::string _nodeName;
|
||||
PositionInformation* _position;
|
||||
|
||||
// renderable
|
||||
Renderable *_renderable;
|
||||
bool _renderableVisible;
|
||||
|
||||
// bounding sphere
|
||||
bool _boundingSphereVisible;
|
||||
pss _boundingSphere;
|
||||
|
||||
// private helper methods
|
||||
bool sphereInsideFrustum(const psc s_pos, const pss & s_rad, const Camera *camera);
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#include <openspace/scenegraph/scenegraphnode.inl>
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,60 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 SCENEGRAPHNODE_INL
|
||||
#define SCENEGRAPHNODE_INL
|
||||
|
||||
#include <openspace/util/factorymanager.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
template<class T>
|
||||
bool safeCreationWithDictionary( T** object,
|
||||
const std::string& key,
|
||||
ghoul::Dictionary* dictionary,
|
||||
const std::string& path = "")
|
||||
{
|
||||
if(dictionary->hasKey(key)) {
|
||||
ghoul::Dictionary tmpDictionary;
|
||||
if(dictionary->getValue(key, tmpDictionary)) {
|
||||
if ( ! tmpDictionary.hasKey("Path") && path != "") {
|
||||
tmpDictionary.setValue("Path", path);
|
||||
}
|
||||
std::string renderableType;
|
||||
if(tmpDictionary.getValue("Type", renderableType)) {
|
||||
ghoul::TemplateFactory<T>* factory = FactoryManager::ref().factoryByType<T>();
|
||||
T* tmp = factory->create(renderableType, tmpDictionary);
|
||||
if(tmp != nullptr) {
|
||||
*object = tmp;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,51 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 __SPICEPOSITIONINFORMATION_H__
|
||||
#define __SPICEPOSITIONINFORMATION_H__
|
||||
|
||||
#include <openspace/scenegraph/positioninformation.h>
|
||||
|
||||
#include <openspace/util/psc.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class SpicePositionInformation: public PositionInformation {
|
||||
public:
|
||||
SpicePositionInformation(const ghoul::Dictionary& dictionary);
|
||||
virtual ~SpicePositionInformation();
|
||||
virtual bool initialize();
|
||||
virtual const psc& position() const;
|
||||
virtual void update();
|
||||
protected:
|
||||
private:
|
||||
|
||||
std::string _targetName, _originName;
|
||||
int _target, _origin;
|
||||
psc _position;
|
||||
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
#endif
|
||||
@@ -0,0 +1,111 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* GHOUL *
|
||||
* General Helpful Open Utility Library *
|
||||
* *
|
||||
* Copyright (c) 2012-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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifdef GHL_TIMING_TESTS
|
||||
|
||||
#ifdef WIN32
|
||||
#define START_TIMER(__name__, __stream__, __num__) \
|
||||
__stream__ << #__name__; \
|
||||
double __name__##Total = 0.0; \
|
||||
unsigned int __name__##Num = 0; \
|
||||
for (__name__##Num = 0; __name__##Num < __num__; ++__name__##Num) { \
|
||||
reset(); \
|
||||
LARGE_INTEGER __name__##Start; \
|
||||
LARGE_INTEGER __name__##End; \
|
||||
QueryPerformanceCounter(&__name__##Start)
|
||||
|
||||
#define START_TIMER_NO_RESET(__name__, __stream__, __num__) \
|
||||
__stream__ << #__name__; \
|
||||
double __name__##Total = 0.0; \
|
||||
unsigned int __name__##Num = 0; \
|
||||
for (__name__##Num = 0; __name__##Num < __num__; ++__name__##Num) { \
|
||||
LARGE_INTEGER __name__##Start; \
|
||||
LARGE_INTEGER __name__##End; \
|
||||
QueryPerformanceCounter(&__name__##Start)
|
||||
|
||||
#define START_TIMER_PREPARE(__name__, __stream__, __num__, __prepare__) \
|
||||
__stream__ << #__name__; \
|
||||
double __name__##Total = 0.0; \
|
||||
unsigned int __name__##Num = 0; \
|
||||
for (__name__##Num = 0; __name__##Num < __num__; ++__name__##Num) { \
|
||||
reset(); \
|
||||
__prepare__; \
|
||||
LARGE_INTEGER __name__##Start; \
|
||||
LARGE_INTEGER __name__##End; \
|
||||
QueryPerformanceCounter(&__name__##Start)
|
||||
|
||||
#define FINISH_TIMER(__name__, __stream__) \
|
||||
QueryPerformanceCounter(&__name__##End); \
|
||||
LARGE_INTEGER freq; \
|
||||
QueryPerformanceFrequency(&freq); \
|
||||
const double freqD = double(freq.QuadPart) / 1000000.0; \
|
||||
const double res = ((__name__##End.QuadPart - __name__##Start.QuadPart) / freqD);\
|
||||
__name__##Total += res; \
|
||||
} \
|
||||
__stream__ << '\t' << __name__##Total / __name__##Num << "us\n";
|
||||
|
||||
#else
|
||||
|
||||
#include <chrono>
|
||||
|
||||
#define START_TIMER(__name__, __stream__, __num__) \
|
||||
__stream__ << #__name__; \
|
||||
std::chrono::nanoseconds __name__##Total = std::chrono::nanoseconds(0); \
|
||||
unsigned int __name__##Num = 0; \
|
||||
for (__name__##Num = 0; __name__##Num < __num__; ++__name__##Num) { \
|
||||
reset(); \
|
||||
std::chrono::high_resolution_clock::time_point __name__##End; \
|
||||
std::chrono::high_resolution_clock::time_point __name__##Start = \
|
||||
std::chrono::high_resolution_clock::now()
|
||||
|
||||
#define START_TIMER_NO_RESET(__name__, __stream__, __num__) \
|
||||
__stream__ << #__name__; \
|
||||
std::chrono::nanoseconds __name__##Total = std::chrono::nanoseconds(0); \
|
||||
unsigned int __name__##Num = 0; \
|
||||
for (__name__##Num = 0; __name__##Num < __num__; ++__name__##Num) { \
|
||||
std::chrono::high_resolution_clock::time_point __name__##End; \
|
||||
std::chrono::high_resolution_clock::time_point __name__##Start = \
|
||||
std::chrono::high_resolution_clock::now()
|
||||
|
||||
#define START_TIMER_PREPARE(__name__, __stream__, __num__, __prepare__) \
|
||||
__stream__ << #__name__; \
|
||||
std::chrono::nanoseconds __name__##Total = std::chrono::nanoseconds(0); \
|
||||
unsigned int __name__##Num = 0; \
|
||||
for (__name__##Num = 0; __name__##Num < __num__; ++__name__##Num) { \
|
||||
reset(); \
|
||||
__prepare__; \
|
||||
std::chrono::high_resolution_clock::time_point __name__##End; \
|
||||
std::chrono::high_resolution_clock::time_point __name__##Start = \
|
||||
std::chrono::high_resolution_clock::now()
|
||||
|
||||
#define FINISH_TIMER(__name__, __stream__) \
|
||||
__name__##End = std::chrono::high_resolution_clock::now(); \
|
||||
const std::chrono::nanoseconds d = __name__##End - __name__##Start; \
|
||||
__name__##Total += d; \
|
||||
} \
|
||||
__stream__ << #__name__ << '\t' << __name__##Total.count() / 1000.0 << "us" << '\n';
|
||||
#endif
|
||||
|
||||
#endif // GHL_TIMING_TESTS
|
||||
@@ -0,0 +1,83 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* GHOUL *
|
||||
* General Helpful Open Utility Library *
|
||||
* *
|
||||
* Copyright (c) 2012-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 "gtest/gtest.h"
|
||||
|
||||
#include <openspace/util/psc.h>
|
||||
#include <openspace/util/pss.h>
|
||||
|
||||
class PowerscaleCoordinatesTest : public testing::Test {
|
||||
protected:
|
||||
PowerscaleCoordinatesTest() {
|
||||
}
|
||||
|
||||
~PowerscaleCoordinatesTest() {
|
||||
}
|
||||
|
||||
void reset() {
|
||||
}
|
||||
|
||||
openspace::SceneGraph* scenegraph;
|
||||
};
|
||||
|
||||
|
||||
TEST_F(PowerscaleCoordinatesTest, psc) {
|
||||
|
||||
openspace::psc reference(2.0, 1.0, 1.1, 1.0);
|
||||
|
||||
openspace::psc first(1.0,0.0,1.0,0.0);
|
||||
openspace::psc second(1.9,1.0,1.0,1.0);
|
||||
|
||||
EXPECT_EQ(reference, first + second);
|
||||
EXPECT_TRUE(reference == (first + second));
|
||||
|
||||
openspace::psc third = first;
|
||||
first[0] = 0.0;
|
||||
|
||||
EXPECT_TRUE(third != first);
|
||||
|
||||
|
||||
}
|
||||
|
||||
TEST_F(PowerscaleCoordinatesTest, pss) {
|
||||
|
||||
openspace::pss first(1.0,1.0);
|
||||
openspace::pss second(1.0,-1.0);
|
||||
EXPECT_EQ(openspace::pss(1.01,1.0), first + second);
|
||||
EXPECT_EQ(openspace::pss(1.01,1.0), second + first);
|
||||
/*
|
||||
EXPECT_TRUE(first < (first + second));
|
||||
bool retu =(second < (first + second));
|
||||
|
||||
std::cout << "retu: " << retu << std::endl;
|
||||
EXPECT_TRUE(retu);
|
||||
|
||||
EXPECT_FALSE(first > (first + second));
|
||||
EXPECT_FALSE(second > (first + second));
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* GHOUL *
|
||||
* General Helpful Open Utility Library *
|
||||
* *
|
||||
* Copyright (c) 2012-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 "gtest/gtest.h"
|
||||
|
||||
#include <openspace/scenegraph/scenegraph.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/spice.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
|
||||
class SceneGraphTest : public testing::Test {
|
||||
protected:
|
||||
SceneGraphTest() {
|
||||
_scenegraph = new openspace::SceneGraph;
|
||||
}
|
||||
|
||||
~SceneGraphTest() {
|
||||
_scenegraph = new openspace::SceneGraph;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
delete _scenegraph;
|
||||
_scenegraph = new openspace::SceneGraph;
|
||||
}
|
||||
|
||||
openspace::SceneGraph* _scenegraph;
|
||||
};
|
||||
|
||||
TEST_F(SceneGraphTest, SceneGraphNode) {
|
||||
|
||||
openspace::SceneGraphNode* node = new openspace::SceneGraphNode(ghoul::Dictionary());
|
||||
|
||||
// Should not have a renderable and position should be 0,0,0,0 (undefined).
|
||||
EXPECT_EQ(nullptr, node->getRenderable());
|
||||
EXPECT_EQ(openspace::psc(), node->getPosition());
|
||||
|
||||
delete node;
|
||||
ghoul::Dictionary nodeDictionary;
|
||||
|
||||
ghoul::Dictionary positionDictionary;
|
||||
ghoul::Dictionary positionPositionArrayDictionary;
|
||||
|
||||
ghoul::Dictionary renderableDictionary;
|
||||
|
||||
renderableDictionary.setValue("Type", std::string("RenderablePlanet"));
|
||||
|
||||
positionPositionArrayDictionary.setValue("1", 1.0);
|
||||
positionPositionArrayDictionary.setValue("2", 1.0);
|
||||
positionPositionArrayDictionary.setValue("3", 1.0);
|
||||
positionPositionArrayDictionary.setValue("4", 1.0);
|
||||
|
||||
positionDictionary.setValue("Type", std::string("Static"));
|
||||
positionDictionary.setValue("Position", positionPositionArrayDictionary);
|
||||
|
||||
nodeDictionary.setValue("Position", positionDictionary);
|
||||
nodeDictionary.setValue("Renderable", renderableDictionary);
|
||||
|
||||
node = new openspace::SceneGraphNode(nodeDictionary);
|
||||
|
||||
// This node should have a renderable (probably no good values but an existing one)
|
||||
EXPECT_TRUE(node->getRenderable());
|
||||
|
||||
// position should be initialized
|
||||
EXPECT_EQ(openspace::psc(1.0,1.0,1.0,1.0), node->getPosition());
|
||||
|
||||
delete node;
|
||||
}
|
||||
|
||||
TEST_F(SceneGraphTest, Loading) {
|
||||
|
||||
|
||||
// Should not successfully load a non existing scenegraph
|
||||
EXPECT_FALSE(_scenegraph->loadFromModulePath(absPath("${TESTDIR}/ScenegraphTestNonExisting")));
|
||||
|
||||
// Existing scenegraph should load
|
||||
EXPECT_TRUE(_scenegraph->loadFromModulePath(absPath("${TESTDIR}/ScenegraphTest")));
|
||||
|
||||
// This loading should fail regardless of existing or not since the
|
||||
// scenegraph is already loaded
|
||||
EXPECT_FALSE(_scenegraph->loadFromModulePath(absPath("${TESTDIR}/ScenegraphTest")));
|
||||
}
|
||||
|
||||
TEST_F(SceneGraphTest, Reinitializing) {
|
||||
|
||||
// Existing scenegraph should load
|
||||
EXPECT_TRUE(_scenegraph->loadFromModulePath(absPath("${TESTDIR}/ScenegraphTest")));
|
||||
|
||||
_scenegraph->deinitialize();
|
||||
|
||||
// Existing scenegraph should load
|
||||
EXPECT_TRUE(_scenegraph->loadFromModulePath(absPath("${TESTDIR}/ScenegraphTest")));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define CAMERA_H
|
||||
|
||||
// open space includes
|
||||
#include "util/psc.h"
|
||||
#include <openspace/util/psc.h>
|
||||
|
||||
// glm includes
|
||||
#include <glm/glm.hpp>
|
||||
@@ -0,0 +1,84 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 __FACTORYMANAGER_H__
|
||||
#define __FACTORYMANAGER_H__
|
||||
|
||||
// ghoul includes
|
||||
#include <ghoul/misc/templatefactory.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
|
||||
#include <openspace/scenegraph/positioninformation.h>
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class FactoryManager {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Static initializer that initializes the static member. This needs to be done before
|
||||
* the FactoryManager can be used. If the manager has been already initialized, an
|
||||
* assertion will be triggered.
|
||||
*/
|
||||
static void initialize();
|
||||
static void deinitialize();
|
||||
|
||||
/**
|
||||
* This method returns a reference to the initialized FactoryManager. If the manager
|
||||
* has not been initialized, an assertion will be triggered.
|
||||
* \return An initialized reference to the singleton manager
|
||||
*/
|
||||
static FactoryManager& ref();
|
||||
|
||||
template<class T>
|
||||
ghoul::TemplateFactory<T>* factoryByType();
|
||||
|
||||
private:
|
||||
FactoryManager();
|
||||
|
||||
/// Not implemented on purpose, using this should result in an error
|
||||
FactoryManager(const FactoryManager& c);
|
||||
|
||||
/// Not implemented on purpose, using this should result in an error
|
||||
~FactoryManager();
|
||||
|
||||
static FactoryManager* _manager; ///<Singleton member
|
||||
|
||||
ghoul::TemplateFactory<Renderable> _renderableFactory;
|
||||
ghoul::TemplateFactory<PositionInformation> _positionInformationFactory;
|
||||
|
||||
};
|
||||
|
||||
// Forward declare template specializations
|
||||
template<>
|
||||
ghoul::TemplateFactory<Renderable()>* FactoryManager::factoryByType();
|
||||
template<>
|
||||
ghoul::TemplateFactory<PositionInformation()>* FactoryManager::factoryByType();
|
||||
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
@@ -11,7 +11,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
#define GEOMETRY_H
|
||||
|
||||
// open space includes
|
||||
#include "util/vbo.h"
|
||||
#include <openspace/util/vbo.h>
|
||||
|
||||
namespace gl4
|
||||
{
|
||||
@@ -11,8 +11,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
#define PLANET_H
|
||||
|
||||
// open space includes
|
||||
#include "util/pss.h"
|
||||
#include "util/vbo_template.h"
|
||||
#include <openspace/util/pss.h>
|
||||
#include <openspace/util/vbo_template.h>
|
||||
|
||||
// std includes
|
||||
#include <string>
|
||||
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
Copyright (C) 2012-2014 Jonas Strandstedt
|
||||
|
||||
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 __POWERSCALEDSPHERE_H__
|
||||
#define __POWERSCALEDSPHERE_H__
|
||||
|
||||
// open space includes
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
#include <openspace/util/psc.h>
|
||||
#include <openspace/util/pss.h>
|
||||
|
||||
|
||||
namespace openspace {
|
||||
|
||||
|
||||
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GLfloat location[4];
|
||||
GLfloat tex[2];
|
||||
GLfloat normal[3];
|
||||
GLubyte padding[28]; // Pads the struct out to 64 bytes for performance increase
|
||||
} Vertex;
|
||||
|
||||
|
||||
class PowerScaledSphere
|
||||
{
|
||||
public:
|
||||
//initializers
|
||||
PowerScaledSphere(const pss radius, int segments = 8);
|
||||
~PowerScaledSphere();
|
||||
|
||||
bool initialize();
|
||||
|
||||
void render();
|
||||
|
||||
private:
|
||||
GLuint _vaoID;
|
||||
GLuint _vBufferID;
|
||||
GLuint _iBufferID;
|
||||
|
||||
GLenum _mode;
|
||||
unsigned int _isize;
|
||||
unsigned int _vsize;
|
||||
Vertex *_varray;
|
||||
int *_iarray;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace openspace
|
||||
{
|
||||
@@ -64,7 +65,8 @@ public:
|
||||
const psc operator*(const pss &rhs) const;
|
||||
|
||||
// comparasion
|
||||
bool operator==(const psc &other) const;
|
||||
bool operator==(const psc &other) const;
|
||||
bool operator!=(const psc &other) const;
|
||||
bool operator<(const psc &other) const;
|
||||
bool operator>(const psc &other) const;
|
||||
bool operator<=(const psc &other) const;
|
||||
@@ -75,6 +77,8 @@ public:
|
||||
psc & operator=(const glm::vec3 &rhs);
|
||||
psc & operator=(const glm::dvec4 &rhs);
|
||||
psc & operator=(const glm::dvec3 &rhs);
|
||||
|
||||
friend std::ostream& operator<<(::std::ostream& os, const psc& rhs);
|
||||
|
||||
// allow the power scaled scalars to acces private members
|
||||
friend class pss;
|
||||
@@ -6,6 +6,8 @@
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace openspace
|
||||
{
|
||||
|
||||
@@ -68,6 +70,8 @@ public:
|
||||
pss & operator=(const float &rhs);
|
||||
pss & operator=(const glm::dvec2 &rhs);
|
||||
pss & operator=(const double &rhs);
|
||||
|
||||
friend std::ostream& operator<<(::std::ostream& os, const pss& rhs);
|
||||
|
||||
// allow the power scaled coordinates to acces private members
|
||||
friend class psc;
|
||||
@@ -11,7 +11,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
#define SPHERE_H
|
||||
|
||||
// open space includes
|
||||
#include "util/geometry.h"
|
||||
#include <openspace/util/geometry.h>
|
||||
|
||||
namespace gl4
|
||||
{
|
||||
+1
-1
Submodule openspace-data updated: 500458eba3...b59ef502a9
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
Copyright (C) 2012-2014 Jonas Strandstedt
|
||||
|
||||
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.
|
||||
*/
|
||||
#version 400 core
|
||||
|
||||
uniform mat4 ViewProjection;
|
||||
uniform mat4 ModelTransform;
|
||||
uniform vec4 campos;
|
||||
uniform vec4 objpos;
|
||||
uniform float time;
|
||||
uniform sampler2D texture1;
|
||||
uniform sampler2D texture2;
|
||||
uniform sampler2D texture3;
|
||||
uniform float TessLevel;
|
||||
uniform bool Wireframe;
|
||||
uniform bool Lightsource;
|
||||
uniform bool UseTexture;
|
||||
|
||||
in vec2 vs_st;
|
||||
//in vec3 vs_stp;
|
||||
in vec4 vs_normal;
|
||||
in vec4 vs_position;
|
||||
|
||||
out vec4 diffuse;
|
||||
|
||||
const float k = 10.0;
|
||||
|
||||
vec4 psc_normlization(vec4 invec) {
|
||||
|
||||
float xymax = max(invec.x,invec.y);
|
||||
|
||||
if(invec.z > 0.0f || invec.z < 0.0f) {
|
||||
return invec / abs(invec.z);
|
||||
} else if (xymax != 0.0f) {
|
||||
return invec / xymax;
|
||||
} else {
|
||||
return invec / -.0;
|
||||
}
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
|
||||
// Observable universe is 10^27m, setting the far value to extremely high, aka 30!! ERMAHGERD!
|
||||
float s_far = 27.0; //= gl_DepthRange.far; // 40
|
||||
float s_farcutoff = 12.0;
|
||||
float s_nearcutoff = 7.0;
|
||||
float s_near = 0.0f;// gl_DepthRange.near; // 0.1
|
||||
float depth;
|
||||
|
||||
// the value can be normalized to 1
|
||||
|
||||
vec4 p = vs_position;
|
||||
if(vs_position.w <= 0.5) {
|
||||
//depth = abs(vs_position.z * pow(10, vs_position.w)) / pow(k,s_far);
|
||||
depth = (vs_position.w+log(abs(vs_position.z)))/pow(k, vs_position.w);
|
||||
} else if(vs_position.w < 3.0) {
|
||||
depth = vs_position.w+log(abs(vs_position.z))/pow(k, vs_position.w);
|
||||
} else {
|
||||
depth = vs_position.w+log(abs(vs_position.z));
|
||||
}
|
||||
|
||||
|
||||
// DEBUG
|
||||
float depth_orig = depth;
|
||||
float x = 0.0f;
|
||||
float cutoffs = 0.0;
|
||||
float orig_z = vs_position.z;
|
||||
|
||||
// calculate a normalized depth [0.0 1.0]
|
||||
if((depth > s_near && depth <= s_nearcutoff) || (depth > s_farcutoff && depth < s_far)) {
|
||||
|
||||
// completely linear interpolation [s_near .. depth .. s_far]
|
||||
depth = (depth - s_near) / (s_far - s_near);
|
||||
|
||||
} else if(depth > s_nearcutoff && depth < s_farcutoff) {
|
||||
|
||||
// DEBUG
|
||||
cutoffs = 1.0;
|
||||
|
||||
// interpolate [10^s_nearcutoff .. 10^depth .. 10^s_farcutoff]
|
||||
// calculate between 0..1 where the depth is
|
||||
x = (pow(10,depth) - pow(10, s_nearcutoff)) / (pow(10,s_farcutoff) - pow(10, s_nearcutoff));
|
||||
|
||||
// remap the depth to the 0..1 depth buffer
|
||||
depth = s_nearcutoff + x * (s_farcutoff - s_nearcutoff);
|
||||
depth = (depth - s_near) / (s_far - s_near);
|
||||
|
||||
} else {
|
||||
// where am I?
|
||||
// do I need to be discarded?
|
||||
// discard;
|
||||
}
|
||||
|
||||
|
||||
// set the depth
|
||||
gl_FragDepth = depth;
|
||||
//gl_FragDepth = 0.5;
|
||||
|
||||
// color
|
||||
diffuse = texture(texture1, vs_st);
|
||||
//diffuse = vec4(vs_position.z,0.0, 0.0, 1.0);
|
||||
// diffuse = vec4(vs_position.xyz * pow(10, vs_position.w), 1.0);
|
||||
//diffuse = vec4(vs_st, 0.0, 1.0);
|
||||
//diffuse = vec4(1.0,1.0, 0.0, 1.0);
|
||||
//diffuse = vec4(depth*5,0.0, 0.0, 1.0);
|
||||
//diffuse = vec4(vs_position.w,0.0, 0.0, 1.0);
|
||||
//diffuse = vec4(1.0,0.0,0.0,1.0);
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
Copyright (C) 2012-2014 Jonas Strandstedt
|
||||
|
||||
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.
|
||||
*/
|
||||
#version 400 core
|
||||
|
||||
uniform mat4 ViewProjection;
|
||||
uniform mat4 ModelTransform;
|
||||
uniform vec4 campos;
|
||||
uniform mat4 camrot;
|
||||
uniform vec2 scaling;
|
||||
uniform vec4 objpos;
|
||||
uniform float time;
|
||||
uniform sampler2D texture1;
|
||||
uniform sampler2D texture2;
|
||||
uniform sampler2D texture3;
|
||||
uniform float TessLevel;
|
||||
uniform bool Wireframe;
|
||||
uniform bool Lightsource;
|
||||
uniform bool UseTexture;
|
||||
|
||||
layout(location = 0) in vec4 in_position;
|
||||
//in vec3 in_position;
|
||||
layout(location = 1) in vec2 in_st;
|
||||
layout(location = 2) in vec3 in_normal;
|
||||
|
||||
out vec2 vs_st;
|
||||
out vec3 vs_stp;
|
||||
out vec4 vs_normal;
|
||||
out vec4 vs_position;
|
||||
|
||||
const float k = 10.0;
|
||||
const float dgr_to_rad = 0.0174532925;
|
||||
|
||||
vec4 psc_addition(vec4 v1, vec4 v2) {
|
||||
float ds = v2.w - v1.w;
|
||||
if(ds >= 0) {
|
||||
float p = pow(k,-ds);
|
||||
return vec4(v1.x*p + v2.x, v1.y*p + v2.y, v1.z*p + v2.z, v2.w);
|
||||
} else {
|
||||
float p = pow(k,ds);
|
||||
return vec4(v1.x + v2.x*p, v1.y + v2.y*p, v1.z + v2.z*p, v1.w);
|
||||
}
|
||||
}
|
||||
|
||||
vec4 psc_to_meter(vec4 v1, vec2 v2) {
|
||||
float factor = v2.x * pow(k,v2.y + v1.w);
|
||||
return vec4(v1.xyz * factor, 1.0);
|
||||
}
|
||||
|
||||
vec4 psc_scaling(vec4 v1, vec2 v2) {
|
||||
float ds = v2.y - v1.w;
|
||||
if(ds >= 0) {
|
||||
return vec4(v1.xyz * v2.x * pow(k,v1.w), v2.y);
|
||||
} else {
|
||||
return vec4(v1.xyz * v2.x * pow(k,v2.y), v1.w);
|
||||
}
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
// set variables
|
||||
vs_st = in_st;
|
||||
//vs_stp = in_position.xyz;
|
||||
vs_normal = normalize(ModelTransform * vec4(in_normal,0));
|
||||
|
||||
// fetch model and view translation
|
||||
//vec4 vertex_translate = ModelTransform[3];
|
||||
|
||||
// rotate and scale vertex with model transform and add the translation
|
||||
vec3 local_vertex_pos = mat3(ModelTransform) * in_position.xyz;
|
||||
//vec4 lvp = ModelTransform * in_position;
|
||||
|
||||
// PSC addition; local vertex position and the object power scaled world position
|
||||
vs_position = psc_addition(vec4(local_vertex_pos,in_position.w),objpos);
|
||||
//vs_position = psc_addition(lvp,objpos);
|
||||
|
||||
// PSC addition; rotated and viewscaled vertex and the cmaeras negative position
|
||||
vs_position = psc_addition(vs_position,vec4(-campos.xyz,campos.w));
|
||||
|
||||
// rotate the camera
|
||||
local_vertex_pos = mat3(camrot) * vs_position.xyz;
|
||||
vs_position = vec4(local_vertex_pos, vs_position.w);
|
||||
//vs_position = camrot* vs_position;
|
||||
|
||||
// rescales the scene to fit inside the view frustum
|
||||
// is set from the main program, but these are decent values
|
||||
// scaling = vec2(1.0, -8.0);
|
||||
|
||||
// project using the rescaled coordinates,
|
||||
//vec4 vs_position_rescaled = psc_scaling(vs_position, scaling);
|
||||
vec4 vs_position_rescaled = psc_to_meter(vs_position, scaling);
|
||||
//vs_position = vs_position_rescaled;
|
||||
|
||||
|
||||
// project the position to view space
|
||||
gl_Position = ViewProjection * vs_position_rescaled;
|
||||
}
|
||||
+16
-37
@@ -26,35 +26,29 @@
|
||||
#set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||
|
||||
set(SOURCE_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
set(HEADER_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
file(GLOB MAIN_SOURCE ${SOURCE_ROOT_DIR}/*.cpp)
|
||||
set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${MAIN_SOURCE})
|
||||
file(GLOB MAIN_HEADER ${SOURCE_ROOT_DIR}/*.h)
|
||||
set(OPENSPACE_HEADER ${OPENSPACE_HEADER} ${MAIN_HEADER})
|
||||
source_group(Main FILES ${MAIN_SOURCE} ${MAIN_HEADER})
|
||||
set(HEADER_ROOT_DIR ${CMAKE_SOURCE_DIR}/include)
|
||||
|
||||
file(GLOB CONFIGURATION_SOURCE ${SOURCE_ROOT_DIR}/configuration/*.cpp)
|
||||
set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${CONFIGURATION_SOURCE})
|
||||
file(GLOB CONFIGURATION_HEADER ${HEADER_ROOT_DIR}/configuration/*.h)
|
||||
file(GLOB CONFIGURATION_HEADER ${HEADER_ROOT_DIR}/openspace/configuration/*.h)
|
||||
set(OPENSPACE_HEADER ${OPENSPACE_HEADER} ${CONFIGURATION_HEADER})
|
||||
source_group(Configuration FILES ${CONFIGURATION_SOURCE} ${CONFIGURATION_HEADER})
|
||||
|
||||
file(GLOB ENGINE_SOURCE ${SOURCE_ROOT_DIR}/engine/*.cpp)
|
||||
set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${ENGINE_SOURCE})
|
||||
file(GLOB ENGINE_HEADER ${HEADER_ROOT_DIR}/engine/*.h)
|
||||
file(GLOB ENGINE_HEADER ${HEADER_ROOT_DIR}/openspace/engine/*.h)
|
||||
set(OPENSPACE_HEADER ${OPENSPACE_HEADER} ${ENGINE_HEADER})
|
||||
source_group(Engine FILES ${ENGINE_SOURCE} ${ENGINE_HEADER})
|
||||
|
||||
file(GLOB INTERACTION_SOURCE ${SOURCE_ROOT_DIR}/interaction/*.cpp)
|
||||
set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${INTERACTION_SOURCE})
|
||||
file(GLOB INTERACTION_HEADER ${HEADER_ROOT_DIR}/interaction/*.h)
|
||||
file(GLOB INTERACTION_HEADER ${HEADER_ROOT_DIR}/openspace/interaction/*.h)
|
||||
set(OPENSPACE_HEADER ${OPENSPACE_HEADER} ${INTERACTION_HEADER})
|
||||
source_group(Interaction FILES ${INTERACTION_SOURCE} ${INTERACTION_HEADER})
|
||||
|
||||
file(GLOB INTERACTION_EXTERNALCONTROL_SOURCE ${SOURCE_ROOT_DIR}/interaction/externalcontrol/*.cpp)
|
||||
set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${INTERACTION_EXTERNALCONTROL_SOURCE})
|
||||
file(GLOB INTERACTION_EXTERNALCONTROL_HEADER ${HEADER_ROOT_DIR}/interaction/externalcontrol/*.h)
|
||||
file(GLOB INTERACTION_EXTERNALCONTROL_HEADER ${HEADER_ROOT_DIR}/openspace/interaction/externalcontrol/*.h)
|
||||
set(OPENSPACE_HEADER ${OPENSPACE_HEADER} ${INTERACTION_EXTERNALCONTROL_HEADER})
|
||||
source_group(Interaction\\ExternalControl FILES ${INTERACTION_EXTERNALCONTROL_SOURCE} ${INTERACTION_EXTERNALCONTROL_HEADER})
|
||||
|
||||
@@ -68,25 +62,25 @@ source_group(Properties FILES ${PROPERTY_SOURCE_CPP} ${PROPERTY_SOURCE_C} ${PROP
|
||||
file(GLOB QUERY_SOURCE_CPP ${SOURCE_ROOT_DIR}/query/*.cpp)
|
||||
file(GLOB QUERY_SOURCE_C ${SOURCE_ROOT_DIR}/query/*.c)
|
||||
set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${QUERY_SOURCE_CPP} ${QUERY_SOURCE_C})
|
||||
file(GLOB QUERY_HEADER ${HEADER_ROOT_DIR}/query/*.h)
|
||||
file(GLOB QUERY_HEADER ${HEADER_ROOT_DIR}/openspace/query/*.h)
|
||||
set(OPENSPACE_HEADER ${OPENSPACE_HEADER} ${QUERY_HEADER})
|
||||
source_group(Query FILES ${QUERY_SOURCE_CPP} ${QUERY_SOURCE_C} ${QUERY_HEADER})
|
||||
|
||||
file(GLOB RENDERING_SOURCE ${SOURCE_ROOT_DIR}/rendering/*.cpp)
|
||||
set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${RENDERING_SOURCE})
|
||||
file(GLOB RENDERING_HEADER ${HEADER_ROOT_DIR}/rendering/*.h)
|
||||
file(GLOB RENDERING_HEADER ${HEADER_ROOT_DIR}/openspace/rendering/*.h)
|
||||
set(OPENSPACE_HEADER ${OPENSPACE_HEADER} ${RENDERING_HEADER})
|
||||
source_group(Rendering FILES ${RENDERING_SOURCE} ${RENDERING_HEADER})
|
||||
|
||||
file(GLOB SCENEGRAPH_SOURCE ${SOURCE_ROOT_DIR}/scenegraph/*.cpp)
|
||||
set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${SCENEGRAPH_SOURCE})
|
||||
file(GLOB SCENEGRAPH_HEADER ${HEADER_ROOT_DIR}/scenegraph/*.h)
|
||||
file(GLOB SCENEGRAPH_HEADER ${HEADER_ROOT_DIR}/openspace/scenegraph/*.h ${HEADER_ROOT_DIR}/openspace/scenegraph/*.inl)
|
||||
set(OPENSPACE_HEADER ${OPENSPACE_HEADER} ${SCENEGRAPH_HEADER})
|
||||
source_group(SceneGraph FILES ${SCENEGRAPH_SOURCE} ${SCENEGRAPH_HEADER})
|
||||
|
||||
file(GLOB UTIL_SOURCE ${SOURCE_ROOT_DIR}/util/*.cpp)
|
||||
set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${UTIL_SOURCE})
|
||||
file(GLOB UTIL_HEADER ${HEADER_ROOT_DIR}/util/*.h)
|
||||
file(GLOB UTIL_HEADER ${HEADER_ROOT_DIR}/openspace/util/*.h)
|
||||
set(OPENSPACE_HEADER ${OPENSPACE_HEADER} ${UTIL_HEADER})
|
||||
source_group(Util FILES ${UTIL_SOURCE} ${UTIL_HEADER})
|
||||
|
||||
@@ -96,27 +90,7 @@ include_directories(${HEADER_ROOT_DIR})
|
||||
set(OPENSPACE_SOURCE ${OPENSPACE_SOURCE} ${OPENSPACE_EXT_DIR}/tinythread.cpp)
|
||||
include_directories(${GHOUL_ROOT_DIR}/ext/boost)
|
||||
|
||||
if (APPLE)
|
||||
find_library(FRAMEWORK_IOKit
|
||||
NAMES IOKit
|
||||
PATHS ${CMAKE_OSX_SYSROOT}/System/Library
|
||||
PATH_SUFFIXES Frameworks
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
find_library(FRAMEWORK_CoreVideo
|
||||
NAMES CoreVideo
|
||||
PATHS ${CMAKE_OSX_SYSROOT}/System/Library
|
||||
PATH_SUFFIXES Frameworks
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
find_library(FRAMEWORK_Cocoa
|
||||
NAMES Cocoa
|
||||
PATHS ${CMAKE_OSX_SYSROOT}/System/Library
|
||||
PATH_SUFFIXES Frameworks
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
set(SGCT_DEPENDENCIES ${SGCT_DEPENDENCIES} ${FRAMEWORK_IOKit} ${FRAMEWORK_CoreVideo} ${FRAMEWORK_Cocoa})
|
||||
endif (APPLE)
|
||||
add_definitions(-DBASE_PATH="${CMAKE_SOURCE_DIR}")
|
||||
|
||||
if (APPLE)
|
||||
add_definitions(-D__APPLE__)
|
||||
@@ -131,5 +105,10 @@ if (UNIX AND NOT APPLE)
|
||||
endif (UNIX AND NOT APPLE)
|
||||
|
||||
|
||||
add_executable(OpenSpace ${OPENSPACE_HEADER} ${OPENSPACE_SOURCE})
|
||||
include_directories("${HEADER_ROOT_DIR}")
|
||||
|
||||
add_executable(OpenSpace ${SOURCE_ROOT_DIR}/main.cpp ${OPENSPACE_HEADER} ${OPENSPACE_SOURCE})
|
||||
target_link_libraries(OpenSpace ${DEPENDENT_LIBS})
|
||||
|
||||
add_subdirectory(tests)
|
||||
|
||||
|
||||
@@ -22,22 +22,39 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include "openspaceengine.h"
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
|
||||
// sgct header has to be included before all others due to Windows header
|
||||
#include "sgct.h"
|
||||
|
||||
#include "interaction/deviceidentifier.h"
|
||||
#include "interaction/interactionhandler.h"
|
||||
#include "rendering/renderengine.h"
|
||||
#include "util/time.h"
|
||||
#include "util//spice.h"
|
||||
#include <openspace/interaction/deviceidentifier.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util//spice.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem>
|
||||
#include <ghoul/logging/logging>
|
||||
#include <ghoul/misc/configurationmanager.h>
|
||||
#include <ghoul/systemcapabilities/systemcapabilities.h>
|
||||
|
||||
#ifdef __WIN32__
|
||||
// Windows: Binary two folders down
|
||||
#define FIXED_BASE_PATH "../.."
|
||||
#elif __APPLE__
|
||||
// OS X : Binary three folders down
|
||||
#define FIXED_BASE_PATH "../../.."
|
||||
#else
|
||||
// Linux : Binary three folders down
|
||||
#define FIXED_BASE_PATH ".."
|
||||
#endif
|
||||
|
||||
// Check if CMake have provided a base path.
|
||||
#ifndef BASE_PATH
|
||||
#define BASE_PATH FIXED_BASE_PATH
|
||||
#endif
|
||||
|
||||
using namespace ghoul::filesystem;
|
||||
using namespace ghoul::logging;
|
||||
|
||||
@@ -54,9 +71,7 @@ OpenSpaceEngine::OpenSpaceEngine()
|
||||
, _interactionHandler(nullptr)
|
||||
, _renderEngine(nullptr)
|
||||
, _scriptEngine(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
{}
|
||||
|
||||
OpenSpaceEngine::~OpenSpaceEngine() {
|
||||
delete _configurationManager;
|
||||
@@ -86,18 +101,9 @@ void OpenSpaceEngine::create(int argc, char** argv, int& newArgc, char**& newArg
|
||||
newArgv = new char*[3];
|
||||
newArgv[0] = "prog";
|
||||
newArgv[1] = "-config";
|
||||
#ifdef __WIN32__
|
||||
// Windows uses fixed path to OpenSpace data
|
||||
newArgv[2] = "../../config/single.xml";
|
||||
#elif __APPLE__
|
||||
// OS X uses local path to OpenSpace data
|
||||
newArgv[2] = "../../../config/single.xml";
|
||||
#else
|
||||
// Linux is is a bin folder
|
||||
newArgv[2] = "../config/single.xml";
|
||||
#endif
|
||||
|
||||
// Create the engine objects
|
||||
newArgv[2] = FIXED_BASE_PATH"/config/single.xml";
|
||||
|
||||
// create objects
|
||||
_engine = new OpenSpaceEngine;
|
||||
_engine->_renderEngine = new RenderEngine;
|
||||
_engine->_interactionHandler = new InteractionHandler;
|
||||
@@ -108,28 +114,21 @@ void OpenSpaceEngine::destroy() {
|
||||
delete _engine;
|
||||
}
|
||||
|
||||
bool OpenSpaceEngine::isInitialized() {
|
||||
return _engine != nullptr;
|
||||
}
|
||||
|
||||
bool OpenSpaceEngine::initialize() {
|
||||
|
||||
// Initialize the logmanager
|
||||
// initialize ghou logging
|
||||
LogManager::initialize(LogManager::LogLevel::Debug, true);
|
||||
LogMgr.addLog(new ConsoleLog);
|
||||
|
||||
// Initialize the filesystem module and register filesystem paths
|
||||
ghoul::filesystem::FileSystem::initialize();
|
||||
#ifdef __WIN32__
|
||||
// Windows: Binary two folders down
|
||||
FileSys.registerPathToken("${BASE_PATH}", "../..");
|
||||
#elif __APPLE__
|
||||
// OS X : Binary three folders down
|
||||
FileSys.registerPathToken("${BASE_PATH}", "../../..");
|
||||
#else
|
||||
// Linux : Binary three folders down
|
||||
FileSys.registerPathToken("${BASE_PATH}", "..");
|
||||
#endif
|
||||
FileSys.registerPathToken("${SCRIPTS}", "${BASE_PATH}/scripts");
|
||||
FileSys.registerPathToken("${OPENSPACE-DATA}", "${BASE_PATH}/openspace-data");
|
||||
|
||||
// Initialize configuration
|
||||
// Register the filepaths from static function enables easy testing
|
||||
ghoul::filesystem::FileSystem::initialize();
|
||||
registerFilePaths();
|
||||
|
||||
// initialize the configurationmanager with the default configuration
|
||||
_configurationManager->initialize();
|
||||
_configurationManager->loadConfiguration(absPath("${SCRIPTS}/DefaultConfig.lua"));
|
||||
|
||||
@@ -145,16 +144,27 @@ bool OpenSpaceEngine::initialize() {
|
||||
Time::init();
|
||||
Spice::init();
|
||||
Spice::ref().loadDefaultKernels();
|
||||
FactoryManager::initialize();
|
||||
|
||||
// TODO add scenegraph file name
|
||||
// Initilize scene graph and RenderEngine
|
||||
_renderEngine->initialize("");
|
||||
// initialize the RenderEngine, needs ${SCENEPATH} to be set
|
||||
_renderEngine->initialize();
|
||||
|
||||
// Initialize OpenSPace input devices
|
||||
DeviceIdentifier::init();
|
||||
DeviceIdentifier::ref().scanDevices();
|
||||
|
||||
_engine->_interactionHandler->connectDevices();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OpenSpaceEngine::registerFilePaths() {
|
||||
|
||||
FileSys.registerPathToken("${BASE_PATH}", FileSys.relativePath(BASE_PATH));
|
||||
FileSys.registerPathToken("${SCRIPTS}", "${BASE_PATH}/scripts");
|
||||
FileSys.registerPathToken("${OPENSPACE-DATA}", "${BASE_PATH}/openspace-data");
|
||||
FileSys.registerPathToken("${SCENEPATH}", "${OPENSPACE-DATA}/scene");
|
||||
FileSys.registerPathToken("${SHADERS}", "${BASE_PATH}/shaders");
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
// open space includes
|
||||
#include "deviceidentifier.h"
|
||||
#include <openspace/interaction/deviceidentifier.h>
|
||||
|
||||
// sgct includes
|
||||
//#include "sgct.h"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "interaction/externalcontrol/externalconnectioncontroller.h"
|
||||
#include <openspace/interaction/externalcontrol/externalconnectioncontroller.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "interaction/externalcontrol/externalcontrol.h"
|
||||
#include "interaction/interactionhandler.h"
|
||||
#include "openspaceengine.h"
|
||||
#include <openspace/interaction/externalcontrol/externalcontrol.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <cstdio>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "interaction/externalcontrol/randomexternalcontrol.h"
|
||||
#include <openspace/interaction/externalcontrol/randomexternalcontrol.h>
|
||||
|
||||
#include <cstdio>
|
||||
#ifndef __WIN32__
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
|
||||
// open space includes
|
||||
#include "interactionhandler.h"
|
||||
#include "deviceidentifier.h"
|
||||
#include "externalcontrol/randomexternalcontrol.h"
|
||||
#include "externalcontrol/joystickexternalcontrol.h"
|
||||
#include "query/query.h"
|
||||
#include "openspaceengine.h"
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/interaction/deviceidentifier.h>
|
||||
#include <openspace/interaction/externalcontrol/randomexternalcontrol.h>
|
||||
#include <openspace/interaction/externalcontrol/joystickexternalcontrol.h>
|
||||
#include <openspace/query/query.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
|
||||
// std includes
|
||||
#include <cassert>
|
||||
@@ -227,7 +227,7 @@ double InteractionHandler::getDt() {
|
||||
|
||||
void InteractionHandler::keyboardCallback(int key, int action) {
|
||||
// TODO package in script
|
||||
const double speed = 0.75;
|
||||
const double speed = 2.75;
|
||||
const double dt = getDt();
|
||||
if (key == 'S') {
|
||||
glm::vec3 euler(speed * dt, 0.0, 0.0);
|
||||
@@ -277,6 +277,7 @@ void InteractionHandler::keyboardCallback(int key, int action) {
|
||||
pss dist(speed * dt, 8.0);
|
||||
distance(dist);
|
||||
}
|
||||
/*
|
||||
if (key == '1') {
|
||||
SceneGraphNode* node = getSceneGraphNode("sun");
|
||||
|
||||
@@ -301,7 +302,7 @@ void InteractionHandler::keyboardCallback(int key, int action) {
|
||||
getCamera()->setPosition(node->getWorldPosition() + psc(0.0, 0.0, 0.5, 8.0));
|
||||
getCamera()->setCameraDirection(glm::vec3(0.0, 0.0, -1.0));
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
void InteractionHandler::mouseButtonCallback(int key, int action) {
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@
|
||||
|
||||
|
||||
// open space includes
|
||||
#include "openspaceengine.h"
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
|
||||
// sgct includes
|
||||
#include "sgct.h"
|
||||
|
||||
+2
-2
@@ -22,9 +22,9 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include "query/query.h"
|
||||
#include <openspace/query/query.h>
|
||||
|
||||
#include "openspaceengine.h"
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
|
||||
// open space includes
|
||||
#include "renderable.h"
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
Renderable::Renderable() {}
|
||||
|
||||
Renderable::Renderable() {
|
||||
|
||||
}
|
||||
|
||||
Renderable::Renderable(const pss &boundingSphere) {
|
||||
boundingSphere_ = boundingSphere;
|
||||
}
|
||||
Renderable::Renderable(const ghoul::Dictionary& dictionary) {}
|
||||
|
||||
Renderable::~Renderable() {
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
|
||||
// open space includes
|
||||
#include "renderablebody.h"
|
||||
#include <openspace/rendering/renderablebody.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
/*
|
||||
RenderableBody::RenderableBody(const pss &radius):Renderable(radius) {
|
||||
programObject_ = nullptr;
|
||||
texture_ = nullptr;
|
||||
@@ -70,5 +70,6 @@ void RenderableBody::render(const Camera *camera, const psc &thisPosition) {
|
||||
void RenderableBody::update() {
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
} // namespace openspace
|
||||
@@ -1,23 +1,95 @@
|
||||
|
||||
// open space includes
|
||||
#include "renderableplanet.h"
|
||||
#include <openspace/rendering/renderableplanet.h>
|
||||
|
||||
#include <ghoul/opengl/texturereader.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <sgct.h>
|
||||
|
||||
namespace {
|
||||
std::string _loggerCat = "RenderablePlanet";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
RenderablePlanet::RenderablePlanet(const pss &radius):Renderable(radius) {
|
||||
programObject_ = nullptr;
|
||||
texture_ = nullptr;
|
||||
|
||||
// setup a unit sphere
|
||||
planet_ = new Planet(radius,30);
|
||||
RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary): programObject_(nullptr),
|
||||
_texturePath(""),
|
||||
texture_(nullptr),
|
||||
planet_(nullptr)
|
||||
{
|
||||
double value = 1.0f, exponent= 0.0f;
|
||||
double segments = 20.0;
|
||||
|
||||
if(dictionary.hasKey("Geometry.Radius.1"))
|
||||
dictionary.getValue("Geometry.Radius.1", value);
|
||||
|
||||
if(dictionary.hasKey("Geometry.Radius.2"))
|
||||
dictionary.getValue("Geometry.Radius.2", exponent);
|
||||
|
||||
if(dictionary.hasKey("Geometry.Segments"))
|
||||
dictionary.getValue("Geometry.Segments", segments);
|
||||
|
||||
// create the power scaled scalar
|
||||
pss planetSize(value, exponent);
|
||||
setBoundingSphere(planetSize);
|
||||
|
||||
// get path if available
|
||||
std::string path = "";
|
||||
if(dictionary.hasKey("Path")) {
|
||||
dictionary.getValue("Path", path);
|
||||
path += "/";
|
||||
}
|
||||
|
||||
if(dictionary.hasKey("Textures.Color")) {
|
||||
std::string texturePath;
|
||||
dictionary.getValue("Textures.Color", texturePath);
|
||||
_texturePath = path + texturePath;
|
||||
}
|
||||
|
||||
planet_ = new PowerScaledSphere(pss(value, exponent), static_cast<int>(segments));
|
||||
}
|
||||
|
||||
RenderablePlanet::~RenderablePlanet() {
|
||||
delete planet_;
|
||||
deinitialize();
|
||||
}
|
||||
|
||||
void RenderablePlanet::setProgramObject(ghoul::opengl::ProgramObject *programObject = nullptr) {
|
||||
assert(programObject) ;
|
||||
bool RenderablePlanet::initialize() {
|
||||
|
||||
bool completeSuccess = true;
|
||||
if (programObject_ == nullptr) {
|
||||
completeSuccess = OsEng.ref().configurationManager().getValue("pscShader", programObject_);
|
||||
}
|
||||
|
||||
if(_texturePath != "") {
|
||||
texture_ = ghoul::opengl::loadTexture(_texturePath);
|
||||
if (texture_) {
|
||||
LDEBUG("Loaded texture from '" << _texturePath <<"'");
|
||||
texture_->uploadTexture();
|
||||
} else {
|
||||
completeSuccess = false;
|
||||
}
|
||||
}
|
||||
planet_->initialize();
|
||||
|
||||
return completeSuccess;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool RenderablePlanet::deinitialize() {
|
||||
if(planet_)
|
||||
delete planet_;
|
||||
|
||||
if(texture_)
|
||||
delete texture_;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderablePlanet::setProgramObject(ghoul::opengl::ProgramObject *programObject) {
|
||||
assert(programObject);
|
||||
programObject_ = programObject;
|
||||
}
|
||||
|
||||
@@ -31,7 +103,7 @@ void RenderablePlanet::render(const Camera *camera, const psc &thisPosition) {
|
||||
// check so that the shader is set
|
||||
assert(programObject_);
|
||||
assert(texture_);
|
||||
|
||||
|
||||
// activate shader
|
||||
programObject_->activate();
|
||||
|
||||
@@ -39,9 +111,11 @@ void RenderablePlanet::render(const Camera *camera, const psc &thisPosition) {
|
||||
psc currentPosition = thisPosition;
|
||||
psc campos = camera->getPosition();
|
||||
glm::mat4 camrot = camera->getViewRotationMatrix();
|
||||
pss scaling = camera->getScaling();
|
||||
|
||||
// scale the planet to appropriate size since the planet is a unit sphere
|
||||
glm::mat4 transform = glm::mat4(1);
|
||||
transform = glm::rotate(transform, 4.1f*static_cast<float>(sgct::Engine::instance()->getTime()), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
|
||||
// setup the data to the shader
|
||||
programObject_->setUniform("ViewProjection", camera->getViewProjectionMatrix());
|
||||
@@ -49,9 +123,9 @@ void RenderablePlanet::render(const Camera *camera, const psc &thisPosition) {
|
||||
programObject_->setUniform("campos", campos.getVec4f());
|
||||
programObject_->setUniform("objpos", currentPosition.getVec4f());
|
||||
programObject_->setUniform("camrot", camrot);
|
||||
programObject_->setUniform("scaling", camera->getScaling());
|
||||
programObject_->setUniform("scaling", scaling.getVec2f());
|
||||
|
||||
//// if texture is availible, use it
|
||||
// Bind texture
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
texture_->bind();
|
||||
programObject_->setUniform("texture1", 0);
|
||||
|
||||
+89
-164
@@ -22,90 +22,82 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include "rendering/renderengine.h"
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
|
||||
#include "openspaceengine.h"
|
||||
#include "scenegraph/scenegraph.h"
|
||||
#include "scenegraph/scenegraphloader.h"
|
||||
#include "util/camera.h"
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/scenegraph/scenegraph.h>
|
||||
#include <openspace/util/camera.h>
|
||||
|
||||
#include "sgct.h"
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "RenderEngine";
|
||||
}
|
||||
namespace openspace {
|
||||
|
||||
RenderEngine::RenderEngine()
|
||||
: _mainCamera(nullptr)
|
||||
, _sceneGraph(nullptr)
|
||||
{
|
||||
}
|
||||
RenderEngine::RenderEngine() : _mainCamera(nullptr) , _sceneGraph(nullptr) {}
|
||||
|
||||
RenderEngine::~RenderEngine() {
|
||||
delete _mainCamera;
|
||||
delete _sceneGraph;
|
||||
}
|
||||
|
||||
bool RenderEngine::initialize(const std::string& sceneGraph) {
|
||||
// init camera and set position
|
||||
bool RenderEngine::initialize() {
|
||||
|
||||
// init camera and set temporary position and scaling
|
||||
_mainCamera = new Camera();
|
||||
_mainCamera->setScaling(glm::vec2(1.0, -8.0));
|
||||
_mainCamera->setPosition(psc(0.0,0.0,1.499823,11.0)); // about the distance from the sun to our moon, will be overritten by the scenegraphloader
|
||||
|
||||
_mainCamera->setPosition(psc(0.0,0.0,1.499823,11.0));
|
||||
|
||||
// if master, setup interaction
|
||||
if (sgct::Engine::instance()->isMaster()) {
|
||||
OsEng.interactionHandler().setCamera(_mainCamera);
|
||||
|
||||
// init interactionhandler and mouse interaction
|
||||
//keyboardControl_ = new KeyboardExternalControl(RELATIVE_PATH"pyinput/keyboard.py");
|
||||
//mouseControl_ = new MouseExternalControl(RELATIVE_PATH"pyinput/mouse.py");
|
||||
//InteractionHandler::ref().addExternalControl(mouseControl_); // the interactionhandler is deallocating the object when it terminates
|
||||
//InteractionHandler::ref().addExternalControl(keyboardControl_); // the interactionhandler is deallocating the object when it terminates
|
||||
|
||||
}
|
||||
|
||||
// init scenegraph
|
||||
// initialize scenegraph
|
||||
_sceneGraph = new SceneGraph;
|
||||
_sceneGraph->init();
|
||||
//_sceneGraph = loadSceneGraph(sceneGraph);
|
||||
_sceneGraph->loadFromModulePath(absPath("${SCENEPATH}"));
|
||||
_sceneGraph->initialize();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderEngine::initializeGL() {
|
||||
// GL settings
|
||||
glEnable (GL_DEPTH_TEST);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
// set the close clip plane and the far clip plane to extreme values while in development
|
||||
sgct::Engine::instance()->setNearAndFarClippingPlanes(0.1f,100.0f);
|
||||
//sgct::Engine::setNearAndFarClippingPlanes(0.1f,10000.0f);
|
||||
//sgct::Engine::getPtr()->setNearAndFarClippingPlanes(0.1f,10000.0f);
|
||||
|
||||
// calculating the maximum field of view for the camera, used to determine visibility of objects in the scene graph
|
||||
if(sgct::Engine::instance()->getWindowPtr(0)->isUsingFisheyeRendering()) {
|
||||
#define SGCT_WPTR sgct::Engine::instance()->getWindowPtr(0)
|
||||
using sgct_core::Viewport;
|
||||
|
||||
// TODO: Fix the power scaled coordinates in such a way that these values can be set
|
||||
// to more realistic values
|
||||
|
||||
// set the close clip plane and the far clip plane to extreme values while in development
|
||||
//sgct::Engine::instance()->setNearAndFarClippingPlanes(0.1f,100.0f);
|
||||
sgct::Engine::instance()->setNearAndFarClippingPlanes(0.00001f,100.0f);
|
||||
|
||||
// calculating the maximum field of view for the camera, used to
|
||||
// determine visibility of objects in the scene graph
|
||||
if(SGCT_WPTR->isUsingFisheyeRendering()) {
|
||||
|
||||
// fisheye mode, looking upwards to the "dome"
|
||||
glm::vec4 viewdir(0,1,0,0);
|
||||
|
||||
// get the tilt and rotate the view
|
||||
float tilt = sgct::Engine::instance()->getWindowPtr(0)->getFisheyeTilt();
|
||||
float tilt = SGCT_WPTR->getFisheyeTilt();
|
||||
//tilt = tilt * 0.0174532925; // degrees to radians
|
||||
glm::mat4 tiltMatrix = glm::rotate(glm::mat4(1.0f), tilt, glm::vec3(1.0f,0.0f,0.0f));
|
||||
viewdir = tiltMatrix * viewdir;
|
||||
|
||||
// set the tilted view and the FOV
|
||||
_mainCamera->setCameraDirection(glm::vec3(viewdir[0],viewdir[1],viewdir[2]));
|
||||
//mainCamera_->setMaxFov(sgct_core::SGCTSettings::Instance()->getFisheyeFOV());
|
||||
_mainCamera->setMaxFov(sgct::Engine::instance()->getWindowPtr(0)->getFisheyeFOV());
|
||||
_mainCamera->setMaxFov(SGCT_WPTR->getFisheyeFOV());
|
||||
} else {
|
||||
// get corner positions, calculating the forth to easily calculate center
|
||||
// get corner positions, calculating the forth to easily calculate center
|
||||
glm::vec3 corners[4];
|
||||
corners[0] = sgct::Engine::instance()->getWindowPtr(0)->getCurrentViewport()->getViewPlaneCoords(sgct_core::Viewport::LowerLeft);
|
||||
corners[1] = sgct::Engine::instance()->getWindowPtr(0)->getCurrentViewport()->getViewPlaneCoords(sgct_core::Viewport::UpperLeft);
|
||||
corners[2] = sgct::Engine::instance()->getWindowPtr(0)->getCurrentViewport()->getViewPlaneCoords(sgct_core::Viewport::UpperRight);
|
||||
corners[0] = SGCT_WPTR->getCurrentViewport()->getViewPlaneCoords(Viewport::LowerLeft);
|
||||
corners[1] = SGCT_WPTR->getCurrentViewport()->getViewPlaneCoords(Viewport::UpperLeft);
|
||||
corners[2] = SGCT_WPTR->getCurrentViewport()->getViewPlaneCoords(Viewport::UpperRight);
|
||||
corners[3] = glm::vec3(corners[2][0],corners[0][1],corners[2][2]);
|
||||
glm::vec3 center = (corners[0] + corners[1] + corners[2] + corners[3]) / 4.0f;
|
||||
|
||||
@@ -133,7 +125,7 @@ bool RenderEngine::initializeGL() {
|
||||
}
|
||||
_mainCamera->setMaxFov(maxFov);
|
||||
}
|
||||
|
||||
|
||||
// successful init
|
||||
return true;
|
||||
}
|
||||
@@ -144,52 +136,73 @@ void RenderEngine::postSynchronizationPreDraw() {
|
||||
_mainCamera->compileViewRotationMatrix();
|
||||
|
||||
// update and evaluate the scene starting from the root node
|
||||
//_sceneGraph->update();
|
||||
//_sceneGraph->evaluate(_mainCamera);
|
||||
_sceneGraph->update();
|
||||
_mainCamera->setCameraDirection(glm::vec3(0,0,-1));
|
||||
_sceneGraph->evaluate(_mainCamera);
|
||||
}
|
||||
|
||||
void RenderEngine::render() {
|
||||
|
||||
// preparing the camera can only be done in the render function
|
||||
// since the SGCT get matrix functions is only valid in the render function
|
||||
glm::mat4 projection = sgct::Engine::instance()->getActiveProjectionMatrix();
|
||||
glm::mat4 view = sgct::Engine::instance()->getActiveViewMatrix();
|
||||
const glm::vec3 eyePosition = sgct_core::ClusterManager::instance()->getUserPtr()->getPos();
|
||||
view = glm::translate(view, eyePosition); // make sure the eye is in the center
|
||||
|
||||
// SGCT resets certian settings
|
||||
glEnable (GL_DEPTH_TEST);
|
||||
glEnable(GL_CULL_FACE);
|
||||
|
||||
// setup the camera for the current frame
|
||||
//_mainCamera->setViewProjectionMatrix(projection*view);
|
||||
const glm::vec3 eyePosition = sgct_core::ClusterManager::instance()->getUserPtr()->getPos();
|
||||
glm::mat4 view = glm::translate(glm::mat4(1.0), eyePosition); // make sure the eye is in the center
|
||||
_mainCamera->setViewProjectionMatrix(sgct::Engine::instance()->getActiveModelViewProjectionMatrix()*view);
|
||||
|
||||
// render the scene starting from the root node
|
||||
//_sceneGraph->render(_mainCamera);
|
||||
/*
|
||||
_sceneGraph->render(_mainCamera);
|
||||
|
||||
// Print some useful information on the master viewport
|
||||
if (sgct::Engine::instance()->isMaster()) {
|
||||
|
||||
// Apple usually has retina screens
|
||||
#ifdef __APPLE__
|
||||
#define FONT_SIZE 18
|
||||
#else
|
||||
#define FONT_SIZE 10
|
||||
#endif
|
||||
|
||||
const glm::vec2 scaling = _mainCamera->getScaling();
|
||||
const glm::vec3 viewdirection = _mainCamera->getViewDirection();
|
||||
const psc position = _mainCamera->getPosition();
|
||||
Freetype::print(sgct_text::FontManager::instance()->getFont( "SGCTFont", 10 ), 10, 50,
|
||||
"Position: (%.5f, %.5f, %.5f, %.5f)", position[0], position[1], position[2], position[3]
|
||||
);
|
||||
Freetype::print(sgct_text::FontManager::instance()->getFont( "SGCTFont", 10 ), 10, 35,
|
||||
"View direction: (%.3f, %.3f, %.3f)", viewdirection[0], viewdirection[1], viewdirection[2]
|
||||
);
|
||||
Freetype::print(sgct_text::FontManager::instance()->getFont( "SGCTFont", 10 ), 10, 20,
|
||||
"Scaling: (%.10f, %.2f)", scaling[0], scaling[1]
|
||||
);
|
||||
const psc origin = OsEng.interactionHandler().getOrigin();
|
||||
const pss pssl = (position - origin).length();
|
||||
|
||||
Freetype::print(sgct_text::FontManager::instance()->getFont( "SGCTFont", FONT_SIZE ),
|
||||
FONT_SIZE,
|
||||
FONT_SIZE*10,
|
||||
"Origin: (%.5f, %.5f, %.5f, %.5f)",
|
||||
origin[0], origin[1], origin[2], origin[3]
|
||||
);
|
||||
Freetype::print(sgct_text::FontManager::instance()->getFont( "SGCTFont", FONT_SIZE ),
|
||||
FONT_SIZE,
|
||||
FONT_SIZE*8,
|
||||
"Camera position: (%.5f, %.5f, %.5f, %.5f)",
|
||||
position[0], position[1], position[2], position[3]
|
||||
);
|
||||
Freetype::print(sgct_text::FontManager::instance()->getFont( "SGCTFont", FONT_SIZE ),
|
||||
FONT_SIZE,
|
||||
FONT_SIZE*6,
|
||||
"Distance to origin: (%.15f, %.2f)",
|
||||
pssl[0], pssl[1]
|
||||
);
|
||||
Freetype::print(sgct_text::FontManager::instance()->getFont( "SGCTFont", FONT_SIZE ),
|
||||
FONT_SIZE,
|
||||
FONT_SIZE*4,
|
||||
"View direction: (%.3f, %.3f, %.3f)",
|
||||
viewdirection[0], viewdirection[1], viewdirection[2]
|
||||
);
|
||||
Freetype::print(sgct_text::FontManager::instance()->getFont( "SGCTFont", FONT_SIZE ),
|
||||
FONT_SIZE,
|
||||
FONT_SIZE*2,
|
||||
"Scaling: (%.10f, %.2f)",
|
||||
scaling[0], scaling[1]
|
||||
);
|
||||
|
||||
psc campos = _mainCamera->getPosition();
|
||||
psc origin = OsEng.interactionHandler().getOrigin();
|
||||
//psc campos = InteractionHandler::ref().getCamera()->getPosition();
|
||||
//psc origin = InteractionHandler::ref().getOrigin();
|
||||
psc relative = campos - origin;
|
||||
pss pssl = relative.length();
|
||||
//mainCamera_->setScaling(glm::vec2(pssl[0], -pssl[1]+6));
|
||||
//mainCamera_->setScaling(glm::vec2(3000.0, -11.0f));
|
||||
Freetype::print(sgct_text::FontManager::instance()->getFont( "SGCTFont", 10 ), 10, 65,
|
||||
"Distance to origin: (%.15f, %.2f)", pssl[0], pssl[1]
|
||||
);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
SceneGraph* RenderEngine::sceneGraph() {
|
||||
@@ -199,92 +212,4 @@ SceneGraph* RenderEngine::sceneGraph() {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
void RenderEngine::keyboardCallback(int key, int action) {
|
||||
const double speed = 0.75;
|
||||
if (key == 'S') {
|
||||
double dt = InteractionHandler::ref().getDt();
|
||||
glm::vec3 euler(speed * dt, 0.0, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
InteractionHandler::ref().orbit(rot);
|
||||
}
|
||||
if (key == 'W') {
|
||||
double dt = InteractionHandler::ref().getDt();
|
||||
glm::vec3 euler(-speed * dt, 0.0, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
InteractionHandler::ref().orbit(rot);
|
||||
}
|
||||
if (key == 'A') {
|
||||
double dt = InteractionHandler::ref().getDt();
|
||||
glm::vec3 euler(0.0, -speed * dt, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
InteractionHandler::ref().orbit(rot);
|
||||
}
|
||||
if (key == 'D') {
|
||||
double dt = InteractionHandler::ref().getDt();
|
||||
glm::vec3 euler(0.0, speed * dt, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
InteractionHandler::ref().orbit(rot);
|
||||
}
|
||||
if (key == 262) {
|
||||
double dt = InteractionHandler::ref().getDt();
|
||||
glm::vec3 euler(0.0, speed * dt, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
InteractionHandler::ref().rotate(rot);
|
||||
}
|
||||
if (key == 263) {
|
||||
double dt = InteractionHandler::ref().getDt();
|
||||
glm::vec3 euler(0.0, -speed * dt, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
InteractionHandler::ref().rotate(rot);
|
||||
}
|
||||
if (key == 264) {
|
||||
double dt = InteractionHandler::ref().getDt();
|
||||
glm::vec3 euler(speed * dt, 0.0, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
InteractionHandler::ref().rotate(rot);
|
||||
}
|
||||
if (key == 265) {
|
||||
double dt = InteractionHandler::ref().getDt();
|
||||
glm::vec3 euler(-speed * dt, 0.0, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
InteractionHandler::ref().rotate(rot);
|
||||
}
|
||||
if (key == 'R') {
|
||||
double dt = InteractionHandler::ref().getDt();
|
||||
pss dist(3 * -speed * dt, 8.0);
|
||||
InteractionHandler::ref().distance(dist);
|
||||
}
|
||||
if (key == 'F') {
|
||||
double dt = InteractionHandler::ref().getDt();
|
||||
pss dist(3 * speed * dt, 8.0);
|
||||
InteractionHandler::ref().distance(dist);
|
||||
}
|
||||
if (key == '1') {
|
||||
SceneGraphNode* earth = sceneGraph_->root()->get("sun");
|
||||
|
||||
InteractionHandler::ref().setFocusNode(earth);
|
||||
InteractionHandler::ref().getCamera()->setPosition(earth->getWorldPosition() + psc(0.0, 0.0, 0.5, 10.0));
|
||||
InteractionHandler::ref().getCamera()->setCameraDirection(glm::vec3(0.0, 0.0, -1.0));
|
||||
}
|
||||
|
||||
if (key == '2') {
|
||||
SceneGraphNode* earth = sceneGraph_->root()->get("earth");
|
||||
|
||||
InteractionHandler::ref().setFocusNode(earth);
|
||||
InteractionHandler::ref().getCamera()->setPosition(earth->getWorldPosition() + psc(0.0, 0.0, 1.0, 8.0));
|
||||
InteractionHandler::ref().getCamera()->setCameraDirection(glm::vec3(0.0, 0.0, -1.0));
|
||||
}
|
||||
|
||||
|
||||
if (key == '3') {
|
||||
SceneGraphNode* earth = sceneGraph_->root()->get("moon");
|
||||
|
||||
InteractionHandler::ref().setFocusNode(earth);
|
||||
InteractionHandler::ref().getCamera()->setPosition(earth->getWorldPosition() + psc(0.0, 0.0, 0.5, 8.0));
|
||||
InteractionHandler::ref().getCamera()->setCameraDirection(glm::vec3(0.0, 0.0, -1.0));
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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/scenegraph/constantpositioninformation.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
ConstantPositionInformation::ConstantPositionInformation(const ghoul::Dictionary& dictionary) {
|
||||
double x = 0.0, y = 0.0, z = 0.0, e = 0.0;
|
||||
if (dictionary.hasKey("Position.1")) {
|
||||
dictionary.getValue("Position.1", x);
|
||||
dictionary.getValue("Position.2", y);
|
||||
dictionary.getValue("Position.3", z);
|
||||
dictionary.getValue("Position.4", e);
|
||||
}
|
||||
_position = psc(x, y, z, e);
|
||||
}
|
||||
|
||||
ConstantPositionInformation::~ConstantPositionInformation() {}
|
||||
|
||||
bool ConstantPositionInformation::initialize() {
|
||||
return true;
|
||||
}
|
||||
|
||||
const psc& ConstantPositionInformation::position() const {
|
||||
return _position;
|
||||
}
|
||||
|
||||
void ConstantPositionInformation::update() {
|
||||
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,33 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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/scenegraph/positioninformation.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
PositionInformation::PositionInformation() {}
|
||||
PositionInformation::PositionInformation(const ghoul::Dictionary& dictionary) {}
|
||||
PositionInformation::~PositionInformation() {}
|
||||
|
||||
} // namespace openspace
|
||||
+289
-32
@@ -1,10 +1,33 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
// open space includes
|
||||
#include "scenegraph/scenegraph.h"
|
||||
#include "scenegraph/scenegraphloader.h"
|
||||
#include "rendering/renderablebody.h"
|
||||
#include "interaction/interactionhandler.h"
|
||||
#include "util/spice.h"
|
||||
#include <openspace/scenegraph/scenegraph.h>
|
||||
#include <openspace/rendering/renderableplanet.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/util/spice.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
|
||||
// ghoul includes
|
||||
#include "ghoul/opengl/programobject.h"
|
||||
@@ -12,52 +35,286 @@
|
||||
#include "ghoul/logging/consolelog.h"
|
||||
#include "ghoul/opengl/texturereader.h"
|
||||
#include "ghoul/opengl/texture.h"
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
#include <ghoul/lua/lua_helper.h>
|
||||
#include <ghoul/opengl/shadermanager.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace {
|
||||
std::string _loggerCat = "SceneGraph";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
SceneGraph::SceneGraph() {
|
||||
root_ = nullptr;
|
||||
|
||||
void printTree(SceneGraphNode* node, std::string pre = "") {
|
||||
LDEBUGC("Tree", pre << node->nodeName());
|
||||
auto children = node->children();
|
||||
for(auto child: children) {
|
||||
printTree(child, pre + " ");
|
||||
}
|
||||
}
|
||||
|
||||
SceneGraph::SceneGraph(): _focus("Root"), _position("Root"), _root(nullptr) {}
|
||||
|
||||
SceneGraph::~SceneGraph() {
|
||||
|
||||
// deallocate the scene graph
|
||||
if(root_)
|
||||
delete root_;
|
||||
|
||||
// deallocate shaders, iterate c++11 style
|
||||
for (auto& shaderTuple: shaders_) {
|
||||
|
||||
// the shader is in the maps second position
|
||||
delete shaderTuple.second;
|
||||
}
|
||||
|
||||
deinitialize();
|
||||
}
|
||||
|
||||
void SceneGraph::init() {
|
||||
// logger string
|
||||
std::string _loggerCat = "SceneGraph::init";
|
||||
|
||||
// SceneGraphLoader *loader = new SceneGraphLoader(&nodes_, &shaders_);
|
||||
// root_ = loader->loadSceneGraph(absPath("${BASE_PATH}/modules"));
|
||||
update();
|
||||
//pss bs = root_->calculateBoundingSphere();
|
||||
bool SceneGraph::initialize() {
|
||||
LDEBUG("Initializing SceneGraph");
|
||||
|
||||
using ghoul::opengl::ShaderObject;
|
||||
using ghoul::opengl::ProgramObject;
|
||||
using ghoul::opengl::ShaderManager;
|
||||
|
||||
ProgramObject* po = nullptr;
|
||||
if ( OsEng.ref().configurationManager().hasKey("pscShader") &&
|
||||
OsEng.ref().configurationManager().getValue("pscShader", po)) {
|
||||
LWARNING("pscShader already in ConfigurationManager, deleting.");
|
||||
delete po;
|
||||
po = nullptr;
|
||||
}
|
||||
|
||||
ShaderObject* powerscale_vs = new ShaderObject(ShaderObject::ShaderType::ShaderTypeVertex,
|
||||
absPath("${SHADERS}/pscstandard_vs.glsl"),
|
||||
"PS Vertex"
|
||||
);
|
||||
ShaderObject* powerscale_fs = new ShaderObject(ShaderObject::ShaderType::ShaderTypeFragment,
|
||||
absPath("${SHADERS}/pscstandard_fs.glsl"),
|
||||
"PS Fragment"
|
||||
);
|
||||
|
||||
po = new ProgramObject;
|
||||
po->attachObject(powerscale_vs);
|
||||
po->attachObject(powerscale_fs);
|
||||
|
||||
if( ! po->compileShaderObjects())
|
||||
return false;
|
||||
if( ! po->linkProgramObject())
|
||||
return false;
|
||||
|
||||
OsEng.ref().configurationManager().setValue("pscShader", po);
|
||||
|
||||
// Initialize all nodes
|
||||
for(auto node: _nodes) {
|
||||
bool success = node->initialize();
|
||||
if (success) {
|
||||
LDEBUG(node->nodeName() << " initialized successfully!");
|
||||
} else {
|
||||
LWARNING(node->nodeName() << " not initialized.");
|
||||
}
|
||||
}
|
||||
|
||||
// update the position of all nodes
|
||||
update();
|
||||
|
||||
// Calculate the bounding sphere for the scenegraph
|
||||
_root->calculateBoundingSphere();
|
||||
|
||||
// set the camera position
|
||||
auto focusIterator = _allNodes.find(_focus);
|
||||
auto positionIterator = _allNodes.find(_position);
|
||||
|
||||
if(focusIterator != _allNodes.end() && positionIterator != _allNodes.end()) {
|
||||
LDEBUG("Camera position is '"<< _position <<"', camera focus is '" << _focus << "'");
|
||||
SceneGraphNode* focusNode = focusIterator->second;
|
||||
SceneGraphNode* positionNode = positionIterator->second;
|
||||
Camera* c = OsEng.interactionHandler().getCamera();
|
||||
|
||||
// TODO: Make distance depend on radius
|
||||
// TODO: Set distance and camera direction in some more smart way
|
||||
// TODO: Set scaling dependent on the position and distance
|
||||
// set position for camera
|
||||
psc cameraPosition = positionNode->getPosition();
|
||||
cameraPosition += psc(0.0,0.0,1.0,2.0);
|
||||
c->setPosition(cameraPosition);
|
||||
c->setCameraDirection(glm::vec3(0,0,-1));
|
||||
c->setScaling(glm::vec2(1.0,0.0));
|
||||
|
||||
// Set the focus node for the interactionhandler
|
||||
OsEng.interactionHandler().setFocusNode(focusNode);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SceneGraph::deinitialize() {
|
||||
|
||||
// deallocate the scene graph. Recursive deallocation will occur
|
||||
if(_root)
|
||||
delete _root;
|
||||
_root = nullptr;
|
||||
|
||||
_nodes.erase(_nodes.begin(), _nodes.end());
|
||||
_allNodes.erase(_allNodes.begin(), _allNodes.end());
|
||||
|
||||
_focus = "";
|
||||
_position = "";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SceneGraph::update() {
|
||||
for(int i = 0; i < nodes_.size(); ++i) {
|
||||
nodes_[i]->update();
|
||||
}
|
||||
for(auto node: _nodes) {
|
||||
node->update();
|
||||
}
|
||||
}
|
||||
|
||||
void SceneGraph::evaluate(Camera *camera) {
|
||||
root_->evaluate(camera);
|
||||
_root->evaluate(camera);
|
||||
}
|
||||
|
||||
void SceneGraph::render(Camera *camera) {
|
||||
root_->render(camera);
|
||||
_root->render(camera);
|
||||
}
|
||||
|
||||
bool SceneGraph::loadFromModulePath(const std::string& path) {
|
||||
|
||||
LDEBUG("Loading scenegraph nodes");
|
||||
if(_root != nullptr) {
|
||||
LFATAL("Scenegraph already loaded");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string defaultScene = path + "/default.scene";
|
||||
if( ! FileSys.fileExists(defaultScene)) {
|
||||
LFATAL("Could not find 'default.scene' in '" << path << "'");
|
||||
return false;
|
||||
}
|
||||
|
||||
ghoul::Dictionary dictionary;
|
||||
lua_State* state = luaL_newstate();
|
||||
if (state == nullptr) {
|
||||
LFATAL("Error creating new Lua state: Memory allocation error");
|
||||
return false;
|
||||
}
|
||||
luaL_openlibs(state);
|
||||
|
||||
// initialize the root node
|
||||
_root = new SceneGraphNode(ghoul::Dictionary());
|
||||
_root->setName("Root");
|
||||
_nodes.push_back(_root);
|
||||
_allNodes.insert ( std::make_pair("Root", _root));
|
||||
|
||||
ghoul::lua::lua_loadIntoDictionary(state, &dictionary, defaultScene);
|
||||
|
||||
ghoul::Dictionary moduleDictionary;
|
||||
if(dictionary.getValue("Modules", moduleDictionary)) {
|
||||
auto keys = moduleDictionary.keys();
|
||||
std::sort(keys.begin(), keys.end());
|
||||
for (auto key: keys) {
|
||||
std::string moduleFolder;
|
||||
if(moduleDictionary.getValue(key, moduleFolder)) {
|
||||
loadModulesFromModulePath(path +"/"+moduleFolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Make it less hard-coded and more flexible when nodes are not found
|
||||
ghoul::Dictionary cameraDictionary;
|
||||
if(dictionary.getValue("Camera", cameraDictionary)) {
|
||||
LDEBUG("Cameradictionary found");
|
||||
std::string focus;
|
||||
std::string position;
|
||||
|
||||
if(cameraDictionary.hasKey("Focus") && cameraDictionary.getValue("Focus", focus)) {
|
||||
auto focusIterator = _allNodes.find(focus);
|
||||
if (focusIterator != _allNodes.end()) {
|
||||
_focus = focus;
|
||||
LDEBUG("Setting camera focus to '"<< _focus << "'");
|
||||
}
|
||||
}
|
||||
if(cameraDictionary.hasKey("Position") && cameraDictionary.getValue("Position", position)) {
|
||||
auto positionIterator = _allNodes.find(position);
|
||||
if (positionIterator != _allNodes.end()) {
|
||||
_position = position;
|
||||
LDEBUG("Setting camera position to '"<< _position << "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Close the Lua state
|
||||
lua_close(state);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SceneGraph::loadModulesFromModulePath(const std::string& modulePath) {
|
||||
lua_State* state = luaL_newstate();
|
||||
if (state == nullptr) {
|
||||
LFATAL("Error creating new Lua state: Memory allocation error");
|
||||
return;
|
||||
}
|
||||
luaL_openlibs(state);
|
||||
|
||||
auto pos = modulePath.find_last_of("/");
|
||||
if (pos == modulePath.npos) {
|
||||
LFATAL("Bad format for module path: " << modulePath);
|
||||
return;
|
||||
}
|
||||
|
||||
std::string fullModule = modulePath + modulePath.substr(pos) + ".mod";
|
||||
LDEBUG("Loading modules from: " << fullModule);
|
||||
|
||||
ghoul::Dictionary moduleDictionary;
|
||||
ghoul::lua::lua_loadIntoDictionary(state, &moduleDictionary, fullModule);
|
||||
auto keys = moduleDictionary.keys();
|
||||
for (auto key: keys) {
|
||||
ghoul::Dictionary singleModuleDictionary;
|
||||
if(moduleDictionary.getValue(key, singleModuleDictionary)) {
|
||||
std::string moduleName;
|
||||
if (singleModuleDictionary.getValue("Name", moduleName)) {
|
||||
std::string parentName;
|
||||
if ( ! singleModuleDictionary.getValue("Parent", parentName)) {
|
||||
LWARNING("Could not find 'Parent' key, using 'Root'.");
|
||||
parentName = "Root";
|
||||
}
|
||||
|
||||
auto parentIterator = _allNodes.find(parentName);
|
||||
if (parentIterator == _allNodes.end()) {
|
||||
LFATAL("Could not find parent named '"<< parentName <<
|
||||
"' for '" << moduleName << "'." <<
|
||||
" Check module definition order. Skipping module.");
|
||||
continue;
|
||||
}
|
||||
|
||||
// allocate SceneGraphNode and initialize with Dictionary
|
||||
singleModuleDictionary.setValue("Path", modulePath);
|
||||
SceneGraphNode* node = nullptr;
|
||||
node = new SceneGraphNode(singleModuleDictionary);
|
||||
if(node != nullptr) {
|
||||
// add to internal data structures
|
||||
_allNodes.insert(std::make_pair(moduleName, node));
|
||||
_nodes.push_back(node);
|
||||
|
||||
// set child and parent
|
||||
SceneGraphNode* parentNode = parentIterator->second;
|
||||
parentNode->addNode(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Close the Lua state
|
||||
lua_close(state);
|
||||
|
||||
// Print the tree
|
||||
printTree(_root);
|
||||
}
|
||||
|
||||
void SceneGraph::printChildren() const {
|
||||
_root->print();
|
||||
}
|
||||
|
||||
SceneGraphNode* SceneGraph::root() const {
|
||||
return _root;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
@@ -1,46 +0,0 @@
|
||||
#ifndef SCENEGRAPH_H
|
||||
#define SCENEGRAPH_H
|
||||
|
||||
// open space includes
|
||||
#include "scenegraph/scenegraphnode.h"
|
||||
|
||||
// std includes
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
// ghoul includes
|
||||
#include "ghoul/opengl/programobject.h"
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class SceneGraph {
|
||||
public:
|
||||
|
||||
// constructors & destructor
|
||||
SceneGraph();
|
||||
~SceneGraph();
|
||||
|
||||
void init();
|
||||
|
||||
void update();
|
||||
void evaluate(Camera *camera);
|
||||
void render(Camera *camera);
|
||||
|
||||
void printChildren() const {
|
||||
root_->print();
|
||||
}
|
||||
|
||||
SceneGraphNode* root() const { return root_; }
|
||||
void setRoot(SceneGraphNode* root) { root_ = root; }
|
||||
|
||||
private:
|
||||
|
||||
SceneGraphNode *root_;
|
||||
std::vector<SceneGraphNode*> nodes_;
|
||||
std::map<std::string, ghoul::opengl::ProgramObject*> shaders_;
|
||||
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
@@ -1,439 +0,0 @@
|
||||
|
||||
#include "openspaceengine.h"
|
||||
// open space includes
|
||||
#include "scenegraph/scenegraphloader.h"
|
||||
#include "rendering/renderablebody.h"
|
||||
#include "rendering/renderableplanet.h"
|
||||
#include "interaction/interactionhandler.h"
|
||||
#include "util/spice.h"
|
||||
|
||||
// ghoul includes
|
||||
#include "ghoul/logging/logmanager.h"
|
||||
#include "ghoul/logging/consolelog.h"
|
||||
#include "ghoul/opengl/texturereader.h"
|
||||
#include "ghoul/opengl/texture.h"
|
||||
|
||||
// std includes
|
||||
#include <utility>
|
||||
|
||||
namespace openspace {
|
||||
/*
|
||||
|
||||
SceneGraph* loadSceneGraph(const std::string& sceneGraphPath) {
|
||||
SceneGraph* result = new SceneGraph;
|
||||
//result->setRo
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
SceneGraphLoader::SceneGraphLoader(std::vector<SceneGraphNode*> *nodes, std::map<std::string, ghoul::opengl::ProgramObject*> *commonShaders) {
|
||||
root_ = nullptr;
|
||||
nodes_ = nodes;
|
||||
commonShaders_ = commonShaders;
|
||||
}
|
||||
|
||||
SceneGraphLoader::~SceneGraphLoader() {
|
||||
}
|
||||
|
||||
SceneGraphNode* SceneGraphLoader::loadSceneGraph(const std::string &path) {
|
||||
|
||||
assert(commonShaders_);
|
||||
|
||||
std::string _loggerCat = "SceneGraphLoader::loadSceneGraph";
|
||||
|
||||
// initializes the scene graph
|
||||
root_ = new SceneGraphNode();
|
||||
|
||||
// loading all common stuff
|
||||
tinyxml2::XMLDocument commonXML;
|
||||
std::string commonPath = path + "/common/common.xml";
|
||||
commonXML.LoadFile(commonPath.c_str());
|
||||
|
||||
// loading the shaders
|
||||
tinyxml2::XMLElement* shaders = commonXML.FirstChildElement( "shaders" );
|
||||
if(shaders) {
|
||||
tinyxml2::XMLElement* shader = shaders->FirstChildElement( "shader" );
|
||||
for(;shader; shader = shader->NextSiblingElement( "shader" )) {
|
||||
if(shader->Attribute("identifier")) {
|
||||
std::string identifier = shader->Attribute("identifier");
|
||||
ghoul::opengl::ProgramObject *programObject = nullptr;
|
||||
if(getShader(&programObject,path + "/common/", shader ))
|
||||
commonShaders_->insert( std::make_pair(identifier, programObject) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tinyxml2::XMLDocument scenegraphXML;
|
||||
std::string scenegraphPath = path + "/scenegraph.xml";
|
||||
scenegraphXML.LoadFile(scenegraphPath.c_str());
|
||||
|
||||
// loading the scenegraph
|
||||
tinyxml2::XMLElement* root = scenegraphXML.FirstChildElement( "root" );
|
||||
if(root) {
|
||||
tinyxml2::XMLElement* node = root->FirstChildElement( "node" );
|
||||
loadSceneGraphTree(node, root_, path);
|
||||
}
|
||||
|
||||
return root_;
|
||||
}
|
||||
|
||||
// ugly
|
||||
void SceneGraphLoader::loadSceneGraphTree(tinyxml2::XMLElement* node, SceneGraphNode *current, const std::string &path) {
|
||||
// ghoul logger
|
||||
std::string _loggerCat = "SceneGraphLoader::loadSceneGraphTree";
|
||||
|
||||
for(;node; node = node->NextSiblingElement( "node" )) {
|
||||
SceneGraphNode *thisNode = nullptr;
|
||||
std::string name = "";
|
||||
if(node->Attribute("module")) {
|
||||
name = node->Attribute("module");
|
||||
thisNode = loadSceneGraphNodeFromFile(name, current, path);
|
||||
} else {
|
||||
thisNode = loadSceneGraphNode(node, "", current, path);
|
||||
}
|
||||
|
||||
if(thisNode) {
|
||||
tinyxml2::XMLElement* children = node->FirstChildElement( "node" );
|
||||
if(children) {
|
||||
loadSceneGraphTree(children, thisNode, path);
|
||||
}
|
||||
nodes_->push_back(thisNode);
|
||||
|
||||
// camera stuff
|
||||
tinyxml2::XMLElement* camera = node->FirstChildElement( "camera" );
|
||||
if(camera && camera->Attribute("setting")) {
|
||||
std::string setting = camera->Attribute("setting");
|
||||
if(setting == "focus") {
|
||||
// HACK
|
||||
OsEng.interactionHandler().setFocusNode(thisNode->parent());
|
||||
LINFO("Setting camera focus: " << name);
|
||||
} else if(setting == "position") {
|
||||
OsEng.interactionHandler().getCamera()->setPosition(thisNode->getWorldPosition());
|
||||
LINFO("Setting camera position: " << name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
LERROR("Could not load SceneGraphNode [ " << name << " ], ignoring all children!");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
SceneGraphNode * SceneGraphLoader::loadSceneGraphNodeFromFile(std::string name, SceneGraphNode *parent, const std::string &path) {
|
||||
std::string _loggerCat = "SceneGraphLoader::loadSceneGraphNode";
|
||||
|
||||
// path and name
|
||||
std::string nodePath = path + "/" + name + "/" + name + ".xml";
|
||||
tinyxml2::XMLDocument nodeXML;
|
||||
nodeXML.LoadFile(nodePath.c_str());
|
||||
|
||||
return loadSceneGraphNode(nodeXML.FirstChildElement( "module" ), name, parent, path + "/" + name);
|
||||
}
|
||||
|
||||
SceneGraphNode * SceneGraphLoader::loadSceneGraphNode(tinyxml2::XMLElement *xmlnode, std::string name, SceneGraphNode *parent, const std::string &path) {
|
||||
|
||||
assert(commonShaders_);
|
||||
|
||||
std::string _loggerCat = "SceneGraphLoader::loadSceneGraphNode";
|
||||
|
||||
// the node
|
||||
SceneGraphNode *thisNode = nullptr;
|
||||
|
||||
// load the properties
|
||||
tinyxml2::XMLElement* moduleElement = xmlnode;
|
||||
if(moduleElement) {
|
||||
|
||||
thisNode = new SceneGraphNode();
|
||||
|
||||
// load spice
|
||||
getSpice(thisNode, parent, moduleElement->FirstChildElement( "spice" ));
|
||||
|
||||
tinyxml2::XMLElement* renderableElement = moduleElement->FirstChildElement( "renderable" );
|
||||
if(renderableElement && renderableElement->Attribute("type")) {
|
||||
std::string type = renderableElement->Attribute("type");
|
||||
if(type == "RenderableBody") {
|
||||
|
||||
RenderableBody *renderable = nullptr;
|
||||
|
||||
// load radius
|
||||
pss radius;
|
||||
|
||||
// the radii element takes priority when setting the radius
|
||||
if( getRadii(&radius, renderableElement->FirstChildElement( "radii" )) || thisNode->getSpiceID() > 0) {
|
||||
double radii[3];
|
||||
int n;
|
||||
if(Spice::ref().getRadii(thisNode->getSpiceName(),radii,&n)) {
|
||||
|
||||
// multiply with factor 1000, spice uses km as standard and Open Space uses m
|
||||
radius = pss::CreatePSS(radii[0]*1000.0);
|
||||
} else {
|
||||
LERROR("Tried to use spice raddi but failed for: " << name);
|
||||
delete thisNode;
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
LERROR("Could not find radiiElement or spice id for: " << name << " " << thisNode->getSpiceID() );
|
||||
delete thisNode;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
LINFO("Adding renderable: "<< name);
|
||||
// load texture and shader
|
||||
ghoul::opengl::Texture *texture = nullptr;
|
||||
ghoul::opengl::ProgramObject *program = nullptr;
|
||||
|
||||
tinyxml2::XMLElement* textureElement = renderableElement->FirstChildElement( "texture" );
|
||||
if(textureElement) {
|
||||
if( ! getTexture(&texture, path, textureElement->FirstChildElement( "file" ))) {
|
||||
LERROR("Could not load texture " << name);
|
||||
}
|
||||
} else {
|
||||
LERROR("Could not find texture for: " << name);
|
||||
}
|
||||
|
||||
// load shader
|
||||
if( ! getShader(&program, path, renderableElement->FirstChildElement( "shader" ))) {
|
||||
LERROR("Could not find shader for: " << name);
|
||||
}
|
||||
|
||||
if( ! texture || ! program) {
|
||||
delete thisNode;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// create the renderable
|
||||
renderable = new RenderableBody(radius);
|
||||
renderable->setTexture(texture);
|
||||
renderable->setProgramObject(program);
|
||||
thisNode->setRenderable(renderable);
|
||||
|
||||
} else if(type == "RenderablePlanet") {
|
||||
|
||||
RenderablePlanet *renderable = nullptr;
|
||||
|
||||
// load radius
|
||||
pss radius;
|
||||
|
||||
// the radii element takes priority when setting the radius
|
||||
if( getRadii(&radius, renderableElement->FirstChildElement( "radii" )) || thisNode->getSpiceID() > 0) {
|
||||
double radii[3];
|
||||
int n;
|
||||
if(Spice::ref().getRadii(thisNode->getSpiceName(),radii,&n)) {
|
||||
|
||||
// multiply with factor 1000, spice uses km as standard and Open Space uses m
|
||||
radius = pss::CreatePSS(radii[0]*1000.0);
|
||||
} else {
|
||||
LERROR("Tried to use spice raddi but failed for: " << name);
|
||||
delete thisNode;
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
LERROR("Could not find radiiElement or spice id for: " << name << " " << thisNode->getSpiceID() );
|
||||
delete thisNode;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
LINFO("Adding renderable: "<< name);
|
||||
// load texture and shader
|
||||
ghoul::opengl::Texture *texture = nullptr;
|
||||
ghoul::opengl::ProgramObject *program = nullptr;
|
||||
|
||||
tinyxml2::XMLElement* textureElement = renderableElement->FirstChildElement( "texture" );
|
||||
if(textureElement) {
|
||||
if( ! getTexture(&texture, path, textureElement->FirstChildElement( "file" ))) {
|
||||
LERROR("Could not load texture " << name);
|
||||
}
|
||||
} else {
|
||||
LERROR("Could not find texture for: " << name);
|
||||
}
|
||||
|
||||
// load shader
|
||||
if( ! getShader(&program, path, renderableElement->FirstChildElement( "shader" ))) {
|
||||
LERROR("Could not find shader for: " << name);
|
||||
}
|
||||
|
||||
if( ! texture || ! program) {
|
||||
delete thisNode;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// create the renderable
|
||||
renderable = new RenderablePlanet(radius);
|
||||
renderable->setTexture(texture);
|
||||
renderable->setProgramObject(program);
|
||||
thisNode->setRenderable(renderable);
|
||||
LINFO("Adding renderablePlanet");
|
||||
}
|
||||
}
|
||||
|
||||
// set identifier and add to parent
|
||||
thisNode->setName(name);
|
||||
parent->addNode(thisNode);
|
||||
return thisNode;
|
||||
|
||||
} else {
|
||||
LERROR("Unable to open properties element");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool SceneGraphLoader::getSpice(SceneGraphNode *node, SceneGraphNode *parent, tinyxml2::XMLElement *xmlnode) {
|
||||
std::string _loggerCat = "SceneGraphLoader::getSpice";
|
||||
if(xmlnode && node) {
|
||||
tinyxml2::XMLElement* identifierElement = xmlnode->FirstChildElement( "identifier" );
|
||||
if(identifierElement && identifierElement->Attribute("string")) {
|
||||
std::string identifier = identifierElement->Attribute("string");
|
||||
|
||||
int spiceID;
|
||||
int spiceIDFound;
|
||||
Spice::ref().bod_NameToInt(identifierElement->Attribute("string"), &spiceID, &spiceIDFound);
|
||||
if(spiceIDFound) {
|
||||
|
||||
// The spice id exists, save the identifier
|
||||
node->setSpiceName(identifier);
|
||||
|
||||
int parentSpice = 0; // sun barycenter
|
||||
if(parent) {
|
||||
if( parent->getSpiceID() != 0)
|
||||
parentSpice = parent->getSpiceID();
|
||||
}
|
||||
node->setSpiceID(spiceID,parentSpice);
|
||||
return true;
|
||||
} else {
|
||||
LERROR("Could not find spice ID ");
|
||||
}
|
||||
} else {
|
||||
LERROR("Could not find spice identifier element in xml ");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SceneGraphLoader::getRadii(pss *radii, tinyxml2::XMLElement *xmlnode) {
|
||||
std::string _loggerCat = "SceneGraphLoader::getRadii";
|
||||
if(xmlnode ) {
|
||||
double value = 0.0;
|
||||
double power = 0.0;
|
||||
if(xmlnode->Attribute("value")) {
|
||||
value = xmlnode->DoubleAttribute("value");
|
||||
if(xmlnode->Attribute("power"))
|
||||
power = xmlnode->DoubleAttribute("power");
|
||||
*radii = pss(value, power);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SceneGraphLoader::getTexture(ghoul::opengl::Texture **texture, const std::string &path, tinyxml2::XMLElement *xmlnode) {
|
||||
std::string _loggerCat = "SceneGraphLoader::getTexture";
|
||||
if(xmlnode && xmlnode->Attribute("path")) {
|
||||
std::string texturePath = path + "/" + xmlnode->Attribute("path");
|
||||
*texture = ghoul::opengl::loadTexture(texturePath);
|
||||
|
||||
// if textures where accessed, upload them to the graphics card. This check needs to be done to avoid crash.
|
||||
if(texture) {
|
||||
LINFO("Uploading tetxure: "<< texturePath);
|
||||
(*texture)->uploadTexture();
|
||||
//ghoul::opengl::Texture *tmp = new ghoul::opengl::Texture(*texture);
|
||||
//texture = tmp;
|
||||
return true;
|
||||
} else {
|
||||
LERROR("Could not load texture: "<< texturePath);
|
||||
}
|
||||
} else {
|
||||
LERROR("Could not find file element");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SceneGraphLoader::getShader(ghoul::opengl::ProgramObject **program, const std::string &path, tinyxml2::XMLElement *xmlnode) {
|
||||
std::string _loggerCat = "SceneGraphLoader::getShader";
|
||||
if( ! xmlnode)
|
||||
return false;
|
||||
|
||||
// use a common shader
|
||||
if(xmlnode->IntAttribute("common") && xmlnode->Attribute( "identifier" )) {
|
||||
std::string identifier = xmlnode->Attribute( "identifier" );
|
||||
std::map<std::string, ghoul::opengl::ProgramObject*>::iterator it;
|
||||
it = commonShaders_->find(identifier);
|
||||
if(it != commonShaders_->end()) {
|
||||
*program = it->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
LERROR("Could not find common shader: " << identifier);
|
||||
return false;
|
||||
|
||||
// load and return the shader
|
||||
} else {
|
||||
tinyxml2::XMLElement* glsl_vs = xmlnode->FirstChildElement( "vertex" );
|
||||
tinyxml2::XMLElement* glsl_fs = xmlnode->FirstChildElement( "fragment" );
|
||||
if(glsl_vs && glsl_fs) {
|
||||
if(glsl_vs->Attribute("path") && glsl_fs->Attribute("path")) {
|
||||
std::string vs_path = glsl_vs->Attribute("path");
|
||||
std::string fs_path = glsl_fs->Attribute("path");
|
||||
|
||||
vs_path = path + vs_path;
|
||||
fs_path = path + fs_path;
|
||||
ghoul::opengl::ProgramObject *programObject = new ghoul::opengl::ProgramObject();
|
||||
ghoul::opengl::ShaderObject *vs = new ghoul::opengl::ShaderObject(ghoul::opengl::ShaderObject::ShaderType::ShaderTypeVertex, vs_path);
|
||||
ghoul::opengl::ShaderObject *fs = new ghoul::opengl::ShaderObject(ghoul::opengl::ShaderObject::ShaderType::ShaderTypeFragment, fs_path);
|
||||
programObject->attachObject(vs);
|
||||
programObject->attachObject(fs);
|
||||
|
||||
// check for bindings
|
||||
tinyxml2::XMLElement* bindings = xmlnode->FirstChildElement( "bindings" );
|
||||
if(bindings) {
|
||||
|
||||
tinyxml2::XMLElement* attributes = bindings->FirstChildElement( "attribute" );
|
||||
for(;attributes; attributes = attributes->NextSiblingElement( "attribute" )) {
|
||||
if(attributes->Attribute("name") && attributes->Attribute("position")) {
|
||||
std::string name = attributes->Attribute("name");
|
||||
int position = attributes->IntAttribute("position");
|
||||
programObject->bindAttributeLocation(name,position);
|
||||
}
|
||||
}
|
||||
tinyxml2::XMLElement* fragdata = bindings->FirstChildElement( "fragdata" );
|
||||
for(;fragdata; fragdata = fragdata->NextSiblingElement( "fragdata" )) {
|
||||
if(fragdata->Attribute("name") && fragdata->Attribute("position")) {
|
||||
std::string name = fragdata->Attribute("name");
|
||||
int position = fragdata->IntAttribute("position");
|
||||
programObject->bindFragDataLocation(name,position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(programObject->compileShaderObjects()) {
|
||||
if(programObject->linkProgramObject()) {
|
||||
*program = programObject;
|
||||
LINFO("Common shader successfully loaded!");
|
||||
return true;
|
||||
} else {
|
||||
LERROR("Common shader could not be linked!");
|
||||
}
|
||||
} else {
|
||||
LERROR("Common shader could not be compiled!");
|
||||
}
|
||||
|
||||
if(programObject)
|
||||
delete programObject;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LERROR("Could not load shader");
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
} // namespace openspace
|
||||
@@ -1,56 +0,0 @@
|
||||
#ifndef SCENEGRAPHLOADER_H
|
||||
#define SCENEGRAPHLOADER_H
|
||||
|
||||
// open space includes
|
||||
#include "scenegraph/scenegraphnode.h"
|
||||
|
||||
// std includes
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
// ghoul includes
|
||||
#include "ghoul/opengl/programobject.h"
|
||||
#include "ghoul/opengl/texture.h"
|
||||
|
||||
// sgct includes
|
||||
//#include "ext/tinyxml2.h"
|
||||
|
||||
namespace openspace {
|
||||
/*
|
||||
|
||||
class SceneGraph;
|
||||
|
||||
SceneGraph* loadSceneGraph(const std::string& sceneGraphPath);
|
||||
|
||||
class SceneGraphLoader {
|
||||
public:
|
||||
|
||||
// constructors & destructor
|
||||
SceneGraphLoader(std::vector<SceneGraphNode*> *nodes, std::map<std::string, ghoul::opengl::ProgramObject*> *commonShaders);
|
||||
~SceneGraphLoader();
|
||||
|
||||
SceneGraphNode *loadSceneGraph(const std::string &path);
|
||||
|
||||
private:
|
||||
|
||||
SceneGraphNode *root_;
|
||||
std::map<std::string, ghoul::opengl::ProgramObject*> *commonShaders_;
|
||||
std::vector<SceneGraphNode*> *nodes_;
|
||||
|
||||
// private methods
|
||||
void loadSceneGraphTree(tinyxml2::XMLElement* node, SceneGraphNode *current, const std::string &path);
|
||||
SceneGraphNode * loadSceneGraphNodeFromFile(std::string name, SceneGraphNode *parent, const std::string &path);
|
||||
SceneGraphNode * loadSceneGraphNode(tinyxml2::XMLElement *xmlnode, std::string name, SceneGraphNode *parent, const std::string &path);
|
||||
|
||||
bool getSpice(SceneGraphNode *node,SceneGraphNode *parent, tinyxml2::XMLElement *xmlnode);
|
||||
bool getRadii(pss *radii, tinyxml2::XMLElement *xmlnode);
|
||||
bool getTexture(ghoul::opengl::Texture **texture, const std::string &path, tinyxml2::XMLElement *xmlnode);
|
||||
bool getShader(ghoul::opengl::ProgramObject **program, const std::string &path, tinyxml2::XMLElement *xmlnode);
|
||||
|
||||
};
|
||||
*/
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
+186
-122
@@ -1,125 +1,186 @@
|
||||
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
// open space includes
|
||||
#include "scenegraph/scenegraphnode.h"
|
||||
#include "util/spice.h"
|
||||
#include <openspace/scenegraph/scenegraphnode.h>
|
||||
#include <openspace/util/spice.h>
|
||||
|
||||
// ghoul includes
|
||||
#include "ghoul/logging/logmanager.h"
|
||||
#include "ghoul/logging/consolelog.h"
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/logging/consolelog.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/opengl/shadermanager.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/shaderobject.h>
|
||||
|
||||
#include <openspace/scenegraph/constantpositioninformation.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
|
||||
namespace {
|
||||
std::string _loggerCat = "SceneGraphNode";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
SceneGraphNode::SceneGraphNode() {
|
||||
|
||||
nodeName_ = "";
|
||||
|
||||
// init pointers with nullptr
|
||||
renderable_ = nullptr;
|
||||
parent_ = nullptr;
|
||||
boundingSphereVisible_ = false;
|
||||
renderableVisible_ = false;
|
||||
|
||||
// spice not used when spiceID_ is 0, 0 is the sun barycenter
|
||||
spiceID_ = 0;
|
||||
parentSpiceID_ = 0;
|
||||
SceneGraphNode::SceneGraphNode(const ghoul::Dictionary& dictionary):
|
||||
_parent(nullptr), _nodeName("Unnamed OpenSpace SceneGraphNode"), _position(nullptr),
|
||||
_renderable(nullptr), _renderableVisible(false), _boundingSphereVisible(false)
|
||||
{
|
||||
ghoul::Dictionary localDictionary = dictionary;
|
||||
|
||||
// set the _nodeName if available
|
||||
localDictionary.getValue("Name", _nodeName);
|
||||
|
||||
std::string path = "";
|
||||
localDictionary.getValue("Path", path);
|
||||
|
||||
if(localDictionary.hasKey("Renderable")) {
|
||||
if(safeCreationWithDictionary<Renderable>(&_renderable, "Renderable", &localDictionary, path)) {
|
||||
LDEBUG(_nodeName << ": Successful creation of renderable!");
|
||||
} else {
|
||||
LDEBUG(_nodeName << ": Failed to create renderable!");
|
||||
}
|
||||
}
|
||||
if(localDictionary.hasKey("Position")) {
|
||||
if(safeCreationWithDictionary<PositionInformation>(&_position, "Position", &localDictionary, path)) {
|
||||
LDEBUG(_nodeName << ": Successful creation of position!");
|
||||
} else {
|
||||
LDEBUG(_nodeName << ": Failed to create position!");
|
||||
}
|
||||
}
|
||||
|
||||
if (_position == nullptr) {
|
||||
_position = new ConstantPositionInformation(ghoul::Dictionary());
|
||||
_position->initialize();
|
||||
}
|
||||
}
|
||||
|
||||
SceneGraphNode::~SceneGraphNode() {
|
||||
// logger string
|
||||
std::string _loggerCat = "SceneGraphNode::~SceneGraphNode()";
|
||||
LDEBUG("Deallocating: " << nodeName_);
|
||||
deinitialize();
|
||||
}
|
||||
|
||||
bool SceneGraphNode::initialize() {
|
||||
if(_renderable != nullptr)
|
||||
_renderable->initialize();
|
||||
|
||||
// deallocate position
|
||||
if(_position != nullptr)
|
||||
_position->initialize();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SceneGraphNode::deinitialize() {
|
||||
LDEBUG("Deinitialize: " << _nodeName);
|
||||
|
||||
// deallocate the renderable
|
||||
if(renderable_)
|
||||
delete renderable_;
|
||||
|
||||
if(_renderable != nullptr)
|
||||
delete _renderable;
|
||||
|
||||
// deallocate position
|
||||
if(_position != nullptr)
|
||||
delete _position;
|
||||
|
||||
// deallocate the child nodes and delete them, iterate c++11 style
|
||||
for( auto &child: children_) {
|
||||
for( auto child: _children)
|
||||
delete child;
|
||||
}
|
||||
|
||||
// empty the vector
|
||||
children_.erase (children_.begin(),children_.end());
|
||||
|
||||
// empty the children vector
|
||||
_children.erase(_children.begin(), _children.end());
|
||||
|
||||
// reset variables
|
||||
_parent = nullptr;
|
||||
_renderable = nullptr;
|
||||
_position = nullptr;
|
||||
_nodeName = "Unnamed OpenSpace SceneGraphNode";
|
||||
_renderableVisible = false;
|
||||
_boundingSphereVisible = false;
|
||||
_boundingSphere = pss(0.0,0.0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// essential
|
||||
void SceneGraphNode::update() {
|
||||
|
||||
if(spiceID_ > 0) {
|
||||
double state[3];
|
||||
//double orientation[3][3];
|
||||
Spice::ref().spk_getPosition(spiceID_, parentSpiceID_, state);
|
||||
|
||||
// multiply with factor 1000, spice uses km as standard and Open Space uses m
|
||||
position_ = psc::CreatePSC(state[0]*1000.0,state[1]*1000.0,state[2]*1000.0);
|
||||
|
||||
// update rotation
|
||||
//if(Spice::ref().spk_getOrientation(spiceName_,orientation)) {
|
||||
// printf("%s\n",spiceName_);
|
||||
// printf("%.5f %.5f %.5f \n", orientation[0][0], orientation[0][1], orientation[0][2]);
|
||||
// printf("%.5f %.5f %.5f \n", orientation[1][0], orientation[1][1], orientation[1][2]);
|
||||
// printf("%.5f %.5f %.5f \n", orientation[2][0], orientation[2][1], orientation[2][2]);
|
||||
//}
|
||||
}
|
||||
|
||||
if(renderable_) {
|
||||
renderable_->update();
|
||||
}
|
||||
_position->update();
|
||||
}
|
||||
|
||||
void SceneGraphNode::evaluate(const Camera *camera, const psc & parentPosition) {
|
||||
void SceneGraphNode::evaluate(const Camera *camera, const psc& parentPosition) {
|
||||
|
||||
const psc thisPosition = parentPosition + position_;
|
||||
const psc thisPosition = parentPosition + _position->position();
|
||||
const psc camPos = camera->getPosition();
|
||||
const psc toCamera = thisPosition - camPos;
|
||||
|
||||
|
||||
// init as not visible
|
||||
boundingSphereVisible_ = true;
|
||||
renderableVisible_ = false;
|
||||
|
||||
_boundingSphereVisible = false;
|
||||
_renderableVisible = false;
|
||||
|
||||
// check if camera is outside the node boundingsphere
|
||||
if(toCamera.length() > boundingSphere_) {
|
||||
if(toCamera.length() > _boundingSphere) {
|
||||
|
||||
// check if the boudningsphere is visible before avaluating children
|
||||
if( ! sphereInsideFrustum(thisPosition, boundingSphere_, camera)) {
|
||||
if( ! sphereInsideFrustum(thisPosition, _boundingSphere, camera)) {
|
||||
// the node is completely outside of the camera view, stop evaluating this node
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
boundingSphereVisible_ = true;
|
||||
// inside boudningsphere or parts of the sphere is visible, individual children needs to be evaluated
|
||||
}
|
||||
|
||||
// inside boudningsphere or parts of the sphere is visible, individual
|
||||
// children needs to be evaluated
|
||||
_boundingSphereVisible = true;
|
||||
|
||||
// this node has an renderable
|
||||
if(renderable_) {
|
||||
if(_renderable) {
|
||||
|
||||
// check if the renderable boundingsphere is visible
|
||||
renderableVisible_ = sphereInsideFrustum(thisPosition, renderable_->getBoundingSphere(), camera);
|
||||
_renderableVisible = sphereInsideFrustum(thisPosition, _renderable->getBoundingSphere(), camera);
|
||||
}
|
||||
|
||||
// evaluate all the children, tail-recursive function(?)
|
||||
for(auto &child: children_) {
|
||||
child->evaluate(camera,thisPosition);
|
||||
for(auto &child: _children) {
|
||||
child->evaluate(camera,psc());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void SceneGraphNode::render(const Camera *camera, const psc & parentPosition) {
|
||||
|
||||
const psc thisPosition = parentPosition + position_;
|
||||
const psc thisPosition = parentPosition + _position->position();
|
||||
|
||||
// check if camera is outside the node boundingsphere
|
||||
if( ! boundingSphereVisible_) {
|
||||
if( ! _boundingSphereVisible) {
|
||||
return;
|
||||
}
|
||||
if(renderableVisible_) {
|
||||
if (nodeName_ == "earth")
|
||||
nodeName_ = nodeName_;
|
||||
renderable_->render(camera,thisPosition);
|
||||
}
|
||||
if(_renderableVisible) {
|
||||
//LDEBUG("Render");
|
||||
_renderable->render(camera,thisPosition);
|
||||
}
|
||||
|
||||
// evaluate all the children, tail-recursive function(?)
|
||||
for(auto &child: children_) {
|
||||
|
||||
for(auto &child: _children) {
|
||||
child->render(camera,thisPosition);
|
||||
}
|
||||
|
||||
@@ -127,93 +188,84 @@ void SceneGraphNode::render(const Camera *camera, const psc & parentPosition) {
|
||||
|
||||
// set & get
|
||||
void SceneGraphNode::addNode(SceneGraphNode *child) {
|
||||
|
||||
// add a child node and set this node to be the parent
|
||||
child->setParent(this);
|
||||
children_.push_back(child);
|
||||
|
||||
child->setParent(this);
|
||||
_children.push_back(child);
|
||||
}
|
||||
|
||||
void SceneGraphNode::setName(const std::string &name) {
|
||||
nodeName_ = name;
|
||||
_nodeName = name;
|
||||
}
|
||||
|
||||
void SceneGraphNode::setParent(SceneGraphNode *parent) {
|
||||
parent_ = parent;
|
||||
}
|
||||
|
||||
void SceneGraphNode::setPosition(const psc &position) {
|
||||
position_ = position;
|
||||
}
|
||||
|
||||
void SceneGraphNode::setSpiceID(const int spiceID, const int parentSpiceID) {
|
||||
spiceID_ = spiceID;
|
||||
parentSpiceID_ = parentSpiceID;
|
||||
update();
|
||||
}
|
||||
|
||||
void SceneGraphNode::setSpiceName(const std::string &name) {
|
||||
spiceName_ = name;
|
||||
}
|
||||
|
||||
const int SceneGraphNode::getSpiceID() const {
|
||||
return spiceID_;
|
||||
}
|
||||
|
||||
const std::string & SceneGraphNode::getSpiceName() {
|
||||
return spiceName_;
|
||||
_parent = parent;
|
||||
}
|
||||
|
||||
const psc &SceneGraphNode::getPosition() const {
|
||||
return position_;
|
||||
return _position->position();
|
||||
}
|
||||
|
||||
psc SceneGraphNode::getWorldPosition() const {
|
||||
|
||||
// recursive up the hierarchy if there are parents available
|
||||
if(parent_) {
|
||||
return position_ + parent_->getWorldPosition();
|
||||
if(_parent) {
|
||||
return _position->position() + _parent->getWorldPosition();
|
||||
} else {
|
||||
return position_;
|
||||
return _position->position();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string SceneGraphNode::nodeName() const {
|
||||
return _nodeName;
|
||||
}
|
||||
|
||||
SceneGraphNode* SceneGraphNode::parent() const {
|
||||
return _parent;
|
||||
}
|
||||
const std::vector<SceneGraphNode*>& SceneGraphNode::children() const {
|
||||
return _children;
|
||||
}
|
||||
|
||||
// bounding sphere
|
||||
pss SceneGraphNode::calculateBoundingSphere() {
|
||||
|
||||
// set the vounding sphere to 0.0
|
||||
boundingSphere_ = 0.0;
|
||||
_boundingSphere = 0.0;
|
||||
|
||||
if(children_.size() > 0) { // node
|
||||
if(_children.size() > 0) { // node
|
||||
pss maxChild;
|
||||
|
||||
// loop though all children and find the one furthest away/with the largest bounding sphere
|
||||
for(size_t i = 0; i < children_.size(); ++i) {
|
||||
for(size_t i = 0; i < _children.size(); ++i) {
|
||||
|
||||
// when positions is dynamix, change this part to fins the most distant position
|
||||
pss child = children_.at(i)->getPosition().length() + children_.at(i)->calculateBoundingSphere();
|
||||
pss child = _children.at(i)->getPosition().length() +
|
||||
_children.at(i)->calculateBoundingSphere();
|
||||
if(child > maxChild) {
|
||||
maxChild = child;
|
||||
}
|
||||
}
|
||||
boundingSphere_ += maxChild;
|
||||
_boundingSphere += maxChild;
|
||||
} else { // leaf
|
||||
|
||||
// if has a renderable, use that boundingsphere
|
||||
if(renderable_)
|
||||
boundingSphere_ += renderable_->getBoundingSphere();
|
||||
if(_renderable)
|
||||
_boundingSphere += _renderable->getBoundingSphere();
|
||||
}
|
||||
|
||||
return boundingSphere_;
|
||||
return _boundingSphere;
|
||||
}
|
||||
|
||||
// renderable
|
||||
void SceneGraphNode::setRenderable(Renderable *renderable) {
|
||||
renderable_ = renderable;
|
||||
_renderable = renderable;
|
||||
update();
|
||||
}
|
||||
|
||||
const Renderable * SceneGraphNode::getRenderable() const{
|
||||
return renderable_;
|
||||
return _renderable;
|
||||
}
|
||||
|
||||
// private helper methods
|
||||
@@ -228,13 +280,6 @@ bool SceneGraphNode::sphereInsideFrustum(const psc s_pos, const pss & s_rad, con
|
||||
// the vector to the object from the new position
|
||||
psc D = s_pos - U;
|
||||
|
||||
// check if outside the maximum angle
|
||||
if (nodeName_ == "earth") {
|
||||
//psc tmp = s_pos - camera->getPosition();
|
||||
|
||||
//LINFOC("", "Angle: " << psc_camdir.angle(D));
|
||||
//LINFOC("", "Pos: " << tmp.getVec4f()[0] << " " << tmp.getVec4f()[1] << " " << tmp.getVec4f()[2] << " " << tmp.getVec4f()[3]);
|
||||
}
|
||||
const double a = psc_camdir.angle(D);
|
||||
if ( a < camera->getMaxFov())
|
||||
{
|
||||
@@ -254,5 +299,24 @@ bool SceneGraphNode::sphereInsideFrustum(const psc s_pos, const pss & s_rad, con
|
||||
|
||||
}
|
||||
|
||||
SceneGraphNode* SceneGraphNode::get(const std::string& name) {
|
||||
if (_nodeName == name)
|
||||
return this;
|
||||
else
|
||||
for (auto it : _children) {
|
||||
SceneGraphNode* tmp = it->get(name);
|
||||
if (tmp != nullptr) {
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void SceneGraphNode::print() const {
|
||||
std::cout << _nodeName << std::endl;
|
||||
for (auto it : _children) {
|
||||
it->print();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
@@ -1,93 +0,0 @@
|
||||
#ifndef SCENEGRAPHNODE_H
|
||||
#define SCENEGRAPHNODE_H
|
||||
|
||||
// open space includes
|
||||
#include "rendering/renderable.h"
|
||||
|
||||
// std includes
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class SceneGraphNode {
|
||||
public:
|
||||
|
||||
// constructors & destructor
|
||||
SceneGraphNode();
|
||||
~SceneGraphNode();
|
||||
|
||||
// essential
|
||||
void update();
|
||||
void evaluate(const Camera *camera, const psc &parentPosition = psc());
|
||||
void render(const Camera *camera, const psc &parentPosition = psc());
|
||||
|
||||
// set & get
|
||||
void addNode(SceneGraphNode *child);
|
||||
void setName(const std::string &name);
|
||||
void setParent(SceneGraphNode *parent);
|
||||
void setPosition(const psc &position);
|
||||
void setSpiceID(const int spiceID, const int parentSpiceID);
|
||||
void setSpiceName(const std::string &name);
|
||||
const int getSpiceID() const;
|
||||
const std::string & getSpiceName();
|
||||
const psc& getPosition() const;
|
||||
psc getWorldPosition() const;
|
||||
std::string nodeName() const { return nodeName_; }
|
||||
|
||||
SceneGraphNode* parent() const { return parent_; }
|
||||
const std::vector<SceneGraphNode*>& children() const { return children_; }
|
||||
|
||||
// bounding sphere
|
||||
pss calculateBoundingSphere();
|
||||
|
||||
SceneGraphNode* get(const std::string& name) {
|
||||
if (nodeName_ == name)
|
||||
return this;
|
||||
else
|
||||
for (auto it : children_)
|
||||
return it->get(name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void print() const {
|
||||
std::cout << nodeName_ << std::endl;
|
||||
for (auto it : children_) {
|
||||
it->print();
|
||||
}
|
||||
}
|
||||
|
||||
// renderable
|
||||
void setRenderable(Renderable *renderable);
|
||||
const Renderable * getRenderable() const;
|
||||
|
||||
private:
|
||||
|
||||
// essential
|
||||
std::vector<SceneGraphNode*> children_;
|
||||
SceneGraphNode *parent_;
|
||||
psc position_;
|
||||
std::string nodeName_;
|
||||
|
||||
// renderable
|
||||
Renderable *renderable_;
|
||||
bool renderableVisible_;
|
||||
|
||||
// bounding sphere
|
||||
bool boundingSphereVisible_;
|
||||
pss boundingSphere_;
|
||||
|
||||
// spice
|
||||
std::string spiceName_;
|
||||
int spiceID_;
|
||||
int parentSpiceID_;
|
||||
|
||||
// private helper methods
|
||||
bool sphereInsideFrustum(const psc s_pos, const pss & s_rad, const Camera *camera);
|
||||
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,69 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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/scenegraph/spicepositioninformation.h>
|
||||
|
||||
#include <openspace/util/spice.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
SpicePositionInformation::SpicePositionInformation(const ghoul::Dictionary& dictionary): _targetName(""),
|
||||
_originName(""),
|
||||
_target(0),
|
||||
_origin(0),
|
||||
_position()
|
||||
{
|
||||
dictionary.getValue("Body", _targetName);
|
||||
dictionary.getValue("Observer", _originName);
|
||||
}
|
||||
SpicePositionInformation::~SpicePositionInformation() {}
|
||||
|
||||
bool SpicePositionInformation::initialize() {
|
||||
|
||||
if (_targetName != "" && _originName != "") {
|
||||
int bsuccess = 0;
|
||||
int osuccess = 0;
|
||||
Spice::ref().bod_NameToInt(_targetName, &_target, &bsuccess);
|
||||
Spice::ref().bod_NameToInt(_originName, &_origin, &osuccess);
|
||||
|
||||
if (bsuccess && osuccess) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const psc& SpicePositionInformation::position() const {
|
||||
return _position;
|
||||
}
|
||||
|
||||
void SpicePositionInformation::update() {
|
||||
double state[3];
|
||||
|
||||
Spice::ref().spk_getPosition(_target, _origin, state);
|
||||
_position = psc::CreatePSC(state[0], state[1], state[2]);
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,38 @@
|
||||
#########################################################################################
|
||||
# #
|
||||
# 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. #
|
||||
#########################################################################################
|
||||
|
||||
option(OPENSPACE_HAVE_TESTS "Activate the OpenSpace unit tests" ON)
|
||||
if (OPENSPACE_HAVE_TESTS)
|
||||
add_definitions(-DOPENSPACE_HAVE_TESTS)
|
||||
|
||||
include_directories("${GHOUL_ROOT_DIR}/ext/gtest/include")
|
||||
include_directories("${GHOUL_ROOT_DIR}/include")
|
||||
file(GLOB_RECURSE OPENSPACE_TEST_FILES ${HEADER_ROOT_DIR}/openspace/tests/*.inl)
|
||||
|
||||
source_group(OpenSpaceSource FILES ${OPENSPACE_SOURCE} ${OPENSPACE_HEADER})
|
||||
|
||||
add_executable(OpenSpaceTest ${SOURCE_ROOT_DIR}/tests/main.cpp ${OPENSPACE_TEST_FILES} ${OPENSPACE_HEADER} ${OPENSPACE_SOURCE})
|
||||
target_link_libraries(OpenSpaceTest gtest ${DEPENDENT_LIBS})
|
||||
|
||||
endif (OPENSPACE_HAVE_TESTS)
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
-- Solar System module
|
||||
{
|
||||
Name = "SolarSystem",
|
||||
Parent = "Root",
|
||||
Position = {
|
||||
Type = "static",
|
||||
Position = { 0, 0, 0, 0}
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
|
||||
{
|
||||
Camera = {
|
||||
Focus = "Earth",
|
||||
Position = "Earth"
|
||||
},
|
||||
Modules = {
|
||||
"common",
|
||||
"earth"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
{
|
||||
-- Earth barycenter module
|
||||
{
|
||||
Name = "EarthBarycenter",
|
||||
Parent = "SolarSystem",
|
||||
Static = "true",
|
||||
Position = {
|
||||
Type = "Kepler",
|
||||
Inclination = 0.00041,
|
||||
AscendingNode = 349.2,
|
||||
Perihelion = 102.8517,
|
||||
SemiMajorAxis = 1.00002,
|
||||
DailyMotion = 0.9855796,
|
||||
Eccentricity = 0.0166967,
|
||||
MeanLongitude = 328.40353
|
||||
}
|
||||
},
|
||||
|
||||
-- dummy earth module
|
||||
--[[
|
||||
{
|
||||
Name = "DummyEarth",
|
||||
Parent = "Root",
|
||||
Renderable = {
|
||||
Type = "RenderablePlanet",
|
||||
Geometry = {
|
||||
Type = "SimpleSphere",
|
||||
--Radius = { 1.0, 1 } -- not sure if correct; supposed 6371km in meters in pss
|
||||
Radius = { 1.0, 1} -- not sure if correct; supposed 6371km in meters in pss
|
||||
},
|
||||
Textures = {
|
||||
Type = "simple",
|
||||
Color = "textures/earth_nasa_lowres.png",
|
||||
Depth = "textures/earth_depth.png"
|
||||
},
|
||||
},
|
||||
Position = {
|
||||
Type = "Static",
|
||||
Position = { 0, 0, -1, 1}
|
||||
}
|
||||
},
|
||||
]]--
|
||||
|
||||
-- Earth module
|
||||
{
|
||||
Name = "Earth",
|
||||
Parent = "EarthBarycenter",
|
||||
Renderable = {
|
||||
Type = "RenderablePlanet",
|
||||
Geometry = {
|
||||
Type = "SimpleSphere",
|
||||
--Radius = { 6.371, 6 },
|
||||
Radius = { 1.0, 1},
|
||||
Segments = 10
|
||||
},
|
||||
Textures = {
|
||||
Type = "simple",
|
||||
Color = "textures/earth_nasa_lowres.png",
|
||||
Depth = "textures/earth_depth.png"
|
||||
},
|
||||
Atmosphere = {
|
||||
Type = "Nishita", -- for example, values missing etc etc
|
||||
MieFactor = 1.0,
|
||||
MieColor = {1.0, 1.0, 1.0}
|
||||
}
|
||||
},
|
||||
Position = {
|
||||
Type = "Spice",
|
||||
Body = "EARTH",
|
||||
Reference = "ECLIPJ2000",
|
||||
Observer = "EARTH BARYCENTER",
|
||||
Kernels = {
|
||||
"kernels/earth.bsp"
|
||||
}
|
||||
},
|
||||
Rotation = {
|
||||
Type = "Spice",
|
||||
Frame = "IAU_EARTH",
|
||||
Reference = "ECLIPJ2000"
|
||||
},
|
||||
GuiName = "/Solar/Planets/Earth"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 145 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 734 KiB |
@@ -0,0 +1,59 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* GHOUL *
|
||||
* General Helpful Open Utility Library *
|
||||
* *
|
||||
* Copyright (c) 2012-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 "gtest/gtest.h"
|
||||
|
||||
#include <ghoul/cmdparser/cmdparser>
|
||||
#include <ghoul/filesystem/filesystem>
|
||||
#include <ghoul/logging/logging>
|
||||
|
||||
#include <openspace/tests/test_common.inl>
|
||||
#include <openspace/tests/test_scenegraph.inl>
|
||||
#include <openspace/tests/test_powerscalecoordinates.inl>
|
||||
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
#include <iostream>
|
||||
|
||||
using namespace ghoul::cmdparser;
|
||||
using namespace ghoul::filesystem;
|
||||
using namespace ghoul::logging;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
LogManager::initialize(LogManager::LogLevel::None);
|
||||
LogMgr.addLog(new ConsoleLog);
|
||||
|
||||
FileSystem::initialize();
|
||||
|
||||
openspace::OpenSpaceEngine::registerFilePaths();
|
||||
FileSys.registerPathToken("${TESTDIR}", "${BASE_PATH}/src/tests");
|
||||
|
||||
openspace::Time::init();
|
||||
openspace::Spice::init();
|
||||
openspace::Spice::ref().loadDefaultKernels();
|
||||
openspace::FactoryManager::initialize();
|
||||
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
+2
-5
@@ -1,6 +1,6 @@
|
||||
|
||||
// open space includes
|
||||
#include "camera.h"
|
||||
#include <openspace/util/camera.h>
|
||||
|
||||
// sgct includes
|
||||
#include "sgct.h"
|
||||
@@ -8,11 +8,9 @@
|
||||
namespace openspace {
|
||||
|
||||
Camera::Camera() {
|
||||
//glm::vec3 EulerAngles(90, 45, 0);
|
||||
scaling_ = glm::vec2(1.0,0.0);
|
||||
glm::vec3 EulerAngles(0, 0, 0);
|
||||
viewRotation_ = glm::quat(EulerAngles);
|
||||
//printf("Camera: [%f, %f, %f, %f]\n", viewRotation_[0], viewRotation_[1], viewRotation_[2], viewRotation_[3]);
|
||||
}
|
||||
|
||||
Camera::~Camera() {
|
||||
@@ -20,7 +18,7 @@ Camera::~Camera() {
|
||||
}
|
||||
|
||||
void Camera::setPosition(psc pos) {
|
||||
position_ = pos;
|
||||
position_ = pos;
|
||||
}
|
||||
|
||||
const psc& Camera::getPosition() const {
|
||||
@@ -72,7 +70,6 @@ const glm::vec3 & Camera::getViewDirection() const {
|
||||
return viewDirection_;
|
||||
}
|
||||
|
||||
|
||||
const float & Camera::getMaxFov() const {
|
||||
return maxFov_;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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/util/factorymanager.h>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include <openspace/rendering/renderableplanet.h>
|
||||
#include <openspace/scenegraph/constantpositioninformation.h>
|
||||
#include <openspace/scenegraph/spicepositioninformation.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
// Template specializations for the different factories
|
||||
template<>
|
||||
ghoul::TemplateFactory<Renderable>* FactoryManager::factoryByType() {
|
||||
return &_renderableFactory;
|
||||
}
|
||||
template<>
|
||||
ghoul::TemplateFactory<PositionInformation>* FactoryManager::factoryByType() {
|
||||
return &_positionInformationFactory;
|
||||
}
|
||||
|
||||
FactoryManager* FactoryManager::_manager = nullptr;
|
||||
|
||||
void FactoryManager::initialize() {
|
||||
assert(_manager == nullptr);
|
||||
if (_manager == nullptr)
|
||||
_manager = new FactoryManager;
|
||||
assert(_manager != nullptr);
|
||||
|
||||
// Add Renderables
|
||||
_manager->factoryByType<Renderable>()->
|
||||
registerClass<RenderablePlanet>("RenderablePlanet");
|
||||
|
||||
// Add PositionInformations
|
||||
_manager->factoryByType<PositionInformation>()->
|
||||
registerClass<ConstantPositionInformation>("Static");
|
||||
_manager->factoryByType<PositionInformation>()->
|
||||
registerClass<SpicePositionInformation>("Spice");
|
||||
|
||||
}
|
||||
|
||||
void FactoryManager::deinitialize() {
|
||||
assert(_manager != nullptr);
|
||||
delete _manager;
|
||||
_manager = nullptr;
|
||||
}
|
||||
|
||||
FactoryManager& FactoryManager::ref() {
|
||||
assert(_manager != nullptr);
|
||||
return *_manager;
|
||||
}
|
||||
|
||||
FactoryManager::FactoryManager() {
|
||||
|
||||
}
|
||||
FactoryManager::~FactoryManager() {
|
||||
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
@@ -9,7 +9,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
*/
|
||||
|
||||
// open space includes
|
||||
#include "util/geometry.h"
|
||||
#include <openspace/util/geometry.h>
|
||||
|
||||
gl4::Geometry::Geometry()
|
||||
{
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
*/
|
||||
|
||||
// open space includes
|
||||
#include "util/planet.h"
|
||||
#include <openspace/util/planet.h>
|
||||
|
||||
// sgct includes
|
||||
#include "sgct.h"
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
/**
|
||||
Copyright (C) 2012-2014 Jonas Strandstedt
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
// open space includes
|
||||
#include <openspace/util/powerscaledsphere.h>
|
||||
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
|
||||
namespace {
|
||||
std::string _loggerCat = "PowerScaledSphere";
|
||||
}
|
||||
|
||||
namespace openspace
|
||||
{
|
||||
|
||||
|
||||
PowerScaledSphere::PowerScaledSphere(const pss radius, int segments)
|
||||
{
|
||||
|
||||
static_assert(sizeof(Vertex) == 64 , "The size of the Vertex needs to be 64 for performance");
|
||||
|
||||
_vBufferID = 0;
|
||||
_iBufferID = 0;
|
||||
_vaoID = 0;
|
||||
_isize = 0;
|
||||
_vsize = 0;
|
||||
_varray = nullptr;
|
||||
_iarray = nullptr;
|
||||
_mode = GL_TRIANGLES;
|
||||
|
||||
// calculate and allocate memory for number of vertices and incicies
|
||||
_vsize = (segments +1) * (segments + 1);
|
||||
_isize = 6*segments*segments;
|
||||
_varray = new Vertex[_vsize];
|
||||
_iarray = new int[_isize];
|
||||
|
||||
// define PI
|
||||
const float PI = 3.14159265f;
|
||||
int nr = 0;
|
||||
for (int i = 0; i <= segments; i++)
|
||||
{
|
||||
// define an extra vertex around the y-axis due to texture mapping
|
||||
for (int j = 0; j <= segments; j++)
|
||||
{
|
||||
|
||||
float fi = static_cast<float>(i);
|
||||
float fj = static_cast<float>(j);
|
||||
float fsegments = static_cast<float>(segments);
|
||||
|
||||
float r = static_cast<float>(radius[0]);
|
||||
|
||||
// inclenation angle (north to south)
|
||||
float theta = fi*PI/fsegments; // 0 -> PI
|
||||
|
||||
// azimuth angle (east to west)
|
||||
float phi = fj*PI*2.0f/fsegments; // 0 -> 2*PI
|
||||
|
||||
float x = r*sin(phi)*sin(theta); //
|
||||
float y = r*cos(theta); // up
|
||||
float z = r*cos(phi)*sin(theta); //
|
||||
|
||||
glm::vec3 normal = glm::vec3(x,y,z);
|
||||
if (!(x == 0.f && y == 0.f && z == 0.f))
|
||||
normal = glm::normalize(normal);
|
||||
|
||||
float t1 = fj/fsegments;
|
||||
float t2 = fi/fsegments;
|
||||
|
||||
_varray[nr].location[0] = x;
|
||||
_varray[nr].location[1] = y;
|
||||
_varray[nr].location[2] = z;
|
||||
_varray[nr].location[3] = static_cast<GLfloat>(radius[1]);
|
||||
_varray[nr].normal[0] = normal[0];
|
||||
_varray[nr].normal[1] = normal[1];
|
||||
_varray[nr].normal[2] = normal[2];
|
||||
|
||||
_varray[nr].tex[0] = t1;
|
||||
_varray[nr].tex[1] = t2;
|
||||
//LDEBUG("T: (" << t1 << ", " << t2 << ")");
|
||||
|
||||
nr++;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
nr = 0;
|
||||
// define indicies for all triangles
|
||||
for (int i = 1; i <= segments; ++i)
|
||||
{
|
||||
for (int j = 0; j < segments; ++j)
|
||||
{
|
||||
|
||||
int t = segments+1;
|
||||
_iarray[nr] = (t) * (i-1) + j + 0; nr++;
|
||||
_iarray[nr] = (t) * (i+0) + j + 0; nr++;
|
||||
_iarray[nr] = (t) * (i+0) + j + 1; nr++;
|
||||
|
||||
_iarray[nr] = (t) * (i-1) + j + 0; nr++;
|
||||
_iarray[nr] = (t) * (i+0) + j + 1; nr++;
|
||||
_iarray[nr] = (t) * (i-1) + j + 1; nr++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
PowerScaledSphere::~PowerScaledSphere() {
|
||||
if(_varray)
|
||||
delete[] _varray;
|
||||
|
||||
if(_iarray)
|
||||
delete[] _iarray;
|
||||
|
||||
if(_vBufferID != 0)
|
||||
glDeleteBuffers(1, &_vBufferID);
|
||||
|
||||
if(_iBufferID != 0)
|
||||
glDeleteBuffers(1, &_iBufferID);
|
||||
|
||||
if(_vaoID != 0)
|
||||
glDeleteVertexArrays(1, &_vaoID);
|
||||
}
|
||||
|
||||
bool PowerScaledSphere::initialize() {
|
||||
|
||||
bool completeSuccess = true;
|
||||
|
||||
// Initialize and upload to graphics card
|
||||
GLuint errorID;
|
||||
glGenVertexArrays(1, &_vaoID);
|
||||
|
||||
// First VAO setup
|
||||
glBindVertexArray(_vaoID);
|
||||
|
||||
glGenBuffers(1, &_vBufferID);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vBufferID);
|
||||
glBufferData(GL_ARRAY_BUFFER, _vsize*sizeof(Vertex), _varray, GL_STATIC_DRAW);
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glEnableVertexAttribArray(2);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET( 0));
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(16));
|
||||
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(24));
|
||||
|
||||
glGenBuffers(1, &_iBufferID);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferID);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, _isize*sizeof(int), _iarray, GL_STATIC_DRAW);
|
||||
|
||||
if(_vBufferID == 0)
|
||||
{
|
||||
LERROR("Vertex buffer not initialized");
|
||||
completeSuccess = false;
|
||||
}
|
||||
if(_iBufferID == 0)
|
||||
{
|
||||
LERROR("Index buffer not initialized");
|
||||
completeSuccess = false;
|
||||
}
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
||||
errorID = glGetError();
|
||||
if(errorID != GL_NO_ERROR)
|
||||
{
|
||||
LERROR("OpenGL error: " << glewGetErrorString(errorID));
|
||||
LERROR("Attempting to proceed anyway. Expect rendering errors or a crash.");
|
||||
completeSuccess = false;
|
||||
}
|
||||
return completeSuccess;
|
||||
}
|
||||
|
||||
void PowerScaledSphere::render() {
|
||||
glBindVertexArray(_vaoID); // select first VAO
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferID);
|
||||
glDrawElements(_mode, _isize, GL_UNSIGNED_INT, BUFFER_OFFSET(0));
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
}
|
||||
+12
-2
@@ -1,7 +1,7 @@
|
||||
|
||||
// open space includes
|
||||
#include "util/psc.h"
|
||||
#include "util/pss.h"
|
||||
#include <openspace/util/psc.h>
|
||||
#include <openspace/util/pss.h>
|
||||
|
||||
// std includes
|
||||
#include <cstdio>
|
||||
@@ -240,6 +240,10 @@ const double psc::angle(const psc &rhs) const {
|
||||
bool psc::operator==(const psc &other) const {
|
||||
return vec_ == other.vec_;
|
||||
}
|
||||
|
||||
bool psc::operator!=(const psc &other) const {
|
||||
return vec_ != other.vec_;
|
||||
}
|
||||
|
||||
bool psc::operator<(const psc &other) const {
|
||||
double ds = this->vec_[3] - other.vec_[3];
|
||||
@@ -279,5 +283,11 @@ bool psc::operator>=(const psc &other) const {
|
||||
return *this > other || *this == other;
|
||||
}
|
||||
|
||||
|
||||
std::ostream& operator<<(::std::ostream& os, const psc& rhs) {
|
||||
os << "(" << rhs[0] << ", " << rhs[1] << ", " << rhs[2] << ", " << rhs[3] << ")";
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
+11
-2
@@ -1,6 +1,6 @@
|
||||
|
||||
// open space includes
|
||||
#include "util/pss.h"
|
||||
#include <openspace/util/pss.h>
|
||||
|
||||
// std includes
|
||||
#include <cstdio>
|
||||
@@ -204,7 +204,12 @@ bool pss::operator<(const pss &other) const {
|
||||
double ds = this->vec_[1] - other.vec_[1];
|
||||
if(ds >= 0) {
|
||||
double upscaled = other.vec_[0]*pow(k,-ds);
|
||||
return vec_[0] < upscaled;
|
||||
return vec_[0] < upscaled;
|
||||
/*
|
||||
bool retur =(vec_[0] < upscaled);
|
||||
std::printf("this: %f, upscaled: %f, this<upscaled: %i\n", vec_[0], upscaled, retur);
|
||||
return retur;
|
||||
*/
|
||||
} else {
|
||||
double upscaled = vec_[0]*pow(k,-ds);
|
||||
return other.vec_[0] > upscaled;
|
||||
@@ -271,5 +276,9 @@ bool pss::operator>=(const double &other) const {
|
||||
return *this > other || *this == other;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(::std::ostream& os, const pss& rhs) {
|
||||
os << "(" << rhs[0] << ", " << rhs[1] << ")";
|
||||
return os;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
*/
|
||||
|
||||
// open space includes
|
||||
#include "util/sphere.h"
|
||||
#include <openspace/util/sphere.h>
|
||||
|
||||
gl4::Sphere::Sphere(float radius, int segments, bool tessellation)
|
||||
{
|
||||
|
||||
+4
-4
@@ -1,9 +1,9 @@
|
||||
|
||||
// openspace stuff
|
||||
#include "util/spice.h"
|
||||
#include "util/time.h"
|
||||
#include "util/psc.h"
|
||||
#include "interaction/interactionhandler.h"
|
||||
#include <openspace/util/spice.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/psc.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
|
||||
// spice
|
||||
#include "SpiceUsr.h"
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
|
||||
// open space includes
|
||||
#include "util/time.h"
|
||||
#include "interaction/interactionhandler.h"
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
|
||||
// std includes
|
||||
#include <cassert>
|
||||
@@ -29,7 +29,7 @@ Time::~Time() {
|
||||
}
|
||||
|
||||
void Time::init() {
|
||||
assert( ! this_);
|
||||
assert( this_ == nullptr);
|
||||
this_ = new Time();
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -9,7 +9,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
*/
|
||||
|
||||
// open space includes
|
||||
#include "util/vbo.h"
|
||||
#include <openspace/util/vbo.h>
|
||||
|
||||
// ghoul includes
|
||||
#include "ghoul/logging/logmanager.h"
|
||||
@@ -52,7 +52,7 @@ void gl4::VBO::init()
|
||||
// if arrays not set from sub-class initialize with a colored quad
|
||||
if(_vsize == 0 || _isize == 0 || _varray == NULL || _iarray == NULL) {
|
||||
|
||||
//LOG("VBO: Init color quad\n");
|
||||
LDEBUG("VBO: Init color quad");
|
||||
_mode = GL_TRIANGLES;
|
||||
|
||||
_vsize = 4;
|
||||
@@ -122,7 +122,7 @@ void gl4::VBO::init()
|
||||
|
||||
}
|
||||
|
||||
GLuint errorID = glGetError();
|
||||
GLuint errorID;
|
||||
glGenVertexArrays(1, &_vaoID);
|
||||
|
||||
// First VAO setup
|
||||
|
||||
Reference in New Issue
Block a user