mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-19 11:29:08 -06:00
commit to be able to merge
This commit is contained in:
@@ -63,6 +63,7 @@ public:
|
||||
void update(const UpdateData& data);
|
||||
void evaluate(const Camera* camera, const psc& parentPosition = psc());
|
||||
void render(const RenderData& data);
|
||||
void updateCamera(Camera* camera) const;
|
||||
|
||||
void addNode(SceneGraphNode* child);
|
||||
|
||||
|
||||
@@ -115,6 +115,9 @@ public:
|
||||
void setCameraDirection(glm::vec3 cameraDirection);
|
||||
glm::vec3 cameraDirection() const;
|
||||
|
||||
void setFocusPosition(psc pos);
|
||||
const psc& focusPosition() const;
|
||||
|
||||
void setViewRotationMatrix(glm::mat4 m);
|
||||
const glm::mat4& viewRotationMatrix() const;
|
||||
void compileViewRotationMatrix();
|
||||
@@ -149,6 +152,7 @@ private:
|
||||
glm::mat4 _projectionMatrix;
|
||||
glm::vec3 _viewDirection;
|
||||
glm::vec3 _cameraDirection;
|
||||
psc _focusPosition;
|
||||
// glm::quat _viewRotation;
|
||||
|
||||
glm::vec3 _lookUp;
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
@@ -49,6 +50,9 @@ namespace openspace {
|
||||
* advanceTime(double) method is called each frame, the <code>tickTime</code> has to be
|
||||
* equal to the frame time.
|
||||
*/
|
||||
|
||||
class SyncBuffer;
|
||||
|
||||
class Time {
|
||||
public:
|
||||
/**
|
||||
@@ -146,6 +150,14 @@ public:
|
||||
*/
|
||||
double retreatTime(double tickTime);
|
||||
|
||||
void serialize(SyncBuffer* syncBuffer);
|
||||
|
||||
void deserialize(SyncBuffer* syncBuffer);
|
||||
|
||||
void postSynchronizationPreDraw();
|
||||
|
||||
void preSynchronization();
|
||||
|
||||
/**
|
||||
* Returns the Lua library that contains all Lua functions available to change the
|
||||
* current time, retrieve the current time etc. The functions contained are
|
||||
@@ -166,9 +178,25 @@ private:
|
||||
Time& operator=(const Time& rhs) = delete;
|
||||
|
||||
static Time* _instance; ///< The singleton instance
|
||||
double _time; ///< The time stored as the number of seconds past the J2000 epoch
|
||||
|
||||
|
||||
double _deltaTimePerSecond; ///< The delta time that is used to advance the time
|
||||
|
||||
//sync variables
|
||||
|
||||
//local copies
|
||||
double _time; ///< The time stored as the number of seconds past the J2000 epoch
|
||||
double _dt;
|
||||
|
||||
//shared copies
|
||||
double _sharedTime;
|
||||
double _sharedDt;
|
||||
|
||||
//synched copies
|
||||
double _syncedTime;
|
||||
double _syncedDt;
|
||||
|
||||
std::mutex _syncMutex;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -501,13 +501,19 @@ void OpenSpaceEngine::preSynchronization() {
|
||||
|
||||
Time::ref().advanceTime(_dt);
|
||||
|
||||
Time::ref().preSynchronization();
|
||||
|
||||
_renderEngine.preSynchronization();
|
||||
}
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::postSynchronizationPreDraw() {
|
||||
//time must be called first
|
||||
Time::ref().postSynchronizationPreDraw();
|
||||
|
||||
_renderEngine.postSynchronizationPreDraw();
|
||||
|
||||
|
||||
if (sgct::Engine::instance()->isMaster() && _gui.isEnabled()) {
|
||||
double posX, posY;
|
||||
sgct::Engine::instance()->getMousePos(0, &posX, &posY);
|
||||
@@ -613,7 +619,7 @@ void OpenSpaceEngine::mouseScrollWheelCallback(int pos) {
|
||||
void OpenSpaceEngine::encode() {
|
||||
if (_syncBuffer) {
|
||||
_renderEngine.serialize(_syncBuffer);
|
||||
|
||||
Time::ref().serialize(_syncBuffer);
|
||||
_syncBuffer->write();
|
||||
}
|
||||
}
|
||||
@@ -622,6 +628,7 @@ void OpenSpaceEngine::decode() {
|
||||
if (_syncBuffer) {
|
||||
_syncBuffer->read();
|
||||
_renderEngine.deserialize(_syncBuffer);
|
||||
Time::ref().deserialize(_syncBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -480,6 +480,7 @@ void InteractionHandler::update(double deltaTime) {
|
||||
|
||||
void InteractionHandler::setFocusNode(SceneGraphNode* node) {
|
||||
_focusNode = node;
|
||||
_camera->setFocusPosition(node->worldPosition());
|
||||
}
|
||||
|
||||
const SceneGraphNode* const InteractionHandler::focusNode() const {
|
||||
@@ -523,12 +524,6 @@ void InteractionHandler::orbit(const float &dx, const float &dy, const float &dz
|
||||
|
||||
lockControls();
|
||||
|
||||
// should be changed to something more dynamic =)
|
||||
psc origin;
|
||||
if (_focusNode) {
|
||||
origin = _focusNode->worldPosition();
|
||||
}
|
||||
|
||||
glm::vec3 cameraUp = glm::normalize((glm::inverse(_camera->viewRotationMatrix()) * glm::vec4(_camera->lookUpVector(), 0))).xyz;
|
||||
glm::vec3 cameraRight = glm::cross(_camera->viewDirection(), cameraUp);
|
||||
|
||||
@@ -537,6 +532,13 @@ void InteractionHandler::orbit(const float &dx, const float &dy, const float &dz
|
||||
transform = glm::rotate(dy, cameraRight) * transform;
|
||||
transform = glm::rotate(dz, _camera->viewDirection()) * transform;
|
||||
|
||||
// should be changed to something more dynamic =)
|
||||
psc origin;
|
||||
if (_focusNode) {
|
||||
origin = _focusNode->worldPosition();
|
||||
}
|
||||
_camera->setFocusPosition(origin);
|
||||
|
||||
// the camera position
|
||||
psc relative = _camera->position();
|
||||
psc relative_origin_coordinate = relative - origin;
|
||||
|
||||
@@ -222,6 +222,7 @@ void OrbitalMouseController::scrollWheel(int pos) {
|
||||
}
|
||||
|
||||
void OrbitalMouseController::update(const double& dt){
|
||||
|
||||
if (_leftMouseButtonDown || _rightMouseButtonDown || _middleMouseButtonDown){
|
||||
_handler->orbit(
|
||||
static_cast<float>(_leftMouseButtonDown) * static_cast<float>(dt) * _currentCursorDiff[MouseButtons::ButtonLeft].x * _rotationSpeed,
|
||||
|
||||
@@ -334,6 +334,11 @@ void RenderEngine::postSynchronizationPreDraw()
|
||||
|
||||
// clear the abuffer before rendering the scene
|
||||
_abuffer->clear();
|
||||
|
||||
if (const SceneGraphNode* node = OsEng.ref().interactionHandler().focusNode()){
|
||||
node->updateCamera(_mainCamera);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void RenderEngine::render()
|
||||
|
||||
@@ -411,4 +411,23 @@ SceneGraphNode* SceneGraphNode::childNode(const std::string& name)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void SceneGraphNode::updateCamera(Camera* camera) const{
|
||||
|
||||
psc origin = worldPosition();
|
||||
int i = 0;
|
||||
// the camera position
|
||||
|
||||
psc relative = camera->position();
|
||||
psc focus = camera->focusPosition();
|
||||
psc relative_focus = relative - focus;
|
||||
|
||||
psc target = origin + relative_focus;
|
||||
|
||||
camera->setPosition(target);
|
||||
camera->setFocusPosition(origin);
|
||||
|
||||
//printf("target: %f, %f, %f, %f\n", target.vec4().x, target.vec4().y, target.vec4().z, target.vec4().w);
|
||||
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -43,10 +43,10 @@ Camera::Camera()
|
||||
, _modelMatrix()
|
||||
, _viewMatrix()
|
||||
, _projectionMatrix()
|
||||
, _viewDirection()
|
||||
, _viewDirection(0,0,-1)
|
||||
, _cameraDirection(0.f, 0.f, 0.f)
|
||||
, _localScaling(1.f, 0.f)
|
||||
//, _viewRotation(glm::quat(glm::vec3(0.f, 0.f, 0.f)))
|
||||
//, _viewRotation(glm::quat(glm::vec3(0.f, 0.f, 0.f)))
|
||||
, _localViewRotationMatrix(1.f)
|
||||
, _sharedPosition()
|
||||
, _sharedScaling(1.f, 0.f)
|
||||
@@ -54,6 +54,7 @@ Camera::Camera()
|
||||
, _syncedPosition()
|
||||
, _syncedScaling(1.f, 0.f)
|
||||
, _syncedViewRotationMatrix(1.f)
|
||||
, _focusPosition()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -64,11 +65,15 @@ Camera::~Camera()
|
||||
void Camera::setPosition(psc pos)
|
||||
{
|
||||
_localPosition = std::move(pos);
|
||||
_syncedPosition = _localPosition;
|
||||
}
|
||||
|
||||
const psc& Camera::position() const
|
||||
{
|
||||
return _syncedPosition;
|
||||
///* FIXA HÄR!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (litet compileringsfel på slutet också så jag inte ska glömma!)*/ hej här är ett kompileringsfel!
|
||||
|
||||
//return _localPosition;
|
||||
}
|
||||
|
||||
void Camera::setModelMatrix(glm::mat4 modelMatrix){
|
||||
@@ -159,6 +164,15 @@ void Camera::setRotation(glm::mat4 rotation)
|
||||
// return _viewRotation;
|
||||
//}
|
||||
|
||||
void Camera::setFocusPosition(psc pos){
|
||||
_focusPosition = pos;
|
||||
}
|
||||
|
||||
const psc& Camera::focusPosition() const{
|
||||
return _focusPosition;
|
||||
}
|
||||
|
||||
|
||||
const glm::vec3& Camera::viewDirection() const
|
||||
{
|
||||
return _viewDirection;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/util/constants.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/util/syncbuffer.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
|
||||
@@ -144,8 +145,13 @@ int time_currentTimeUTC(lua_State* L) {
|
||||
|
||||
Time* Time::_instance = nullptr;
|
||||
|
||||
Time::Time()
|
||||
Time::Time()
|
||||
: _time(-1.0)
|
||||
, _dt(1.0)
|
||||
, _sharedTime(-1.0)
|
||||
, _sharedDt(1.0)
|
||||
, _syncedTime(-1.0)
|
||||
, _syncedDt(1.0)
|
||||
, _deltaTimePerSecond(1.0)
|
||||
{
|
||||
}
|
||||
@@ -177,23 +183,23 @@ void Time::setTime(double value) {
|
||||
|
||||
double Time::currentTime() const {
|
||||
assert(_instance);
|
||||
return _time;
|
||||
return _syncedTime;
|
||||
}
|
||||
|
||||
double Time::advanceTime(double tickTime) {
|
||||
return _time += _deltaTimePerSecond * tickTime;
|
||||
return _time += _dt * tickTime;
|
||||
}
|
||||
|
||||
double Time::retreatTime(double tickTime) {
|
||||
return _time -= _deltaTimePerSecond * tickTime;
|
||||
return _time -= _dt * tickTime;
|
||||
}
|
||||
|
||||
void Time::setDeltaTime(double deltaT) {
|
||||
_deltaTimePerSecond = std::move(deltaT);
|
||||
_dt = std::move(deltaT);
|
||||
}
|
||||
|
||||
double Time::deltaTime() const {
|
||||
return _deltaTimePerSecond;
|
||||
return _syncedDt;
|
||||
}
|
||||
|
||||
void Time::setTime(std::string time) {
|
||||
@@ -202,10 +208,46 @@ void Time::setTime(std::string time) {
|
||||
|
||||
std::string Time::currentTimeUTC() const {
|
||||
std::string date;
|
||||
SpiceManager::ref().getDateFromET(_time, date);
|
||||
SpiceManager::ref().getDateFromET(_syncedTime, date);
|
||||
return date;
|
||||
}
|
||||
|
||||
void Time::serialize(SyncBuffer* syncBuffer){
|
||||
_syncMutex.lock();
|
||||
|
||||
syncBuffer->encode(_sharedTime);
|
||||
syncBuffer->encode(_sharedDt);
|
||||
|
||||
_syncMutex.unlock();
|
||||
}
|
||||
|
||||
void Time::deserialize(SyncBuffer* syncBuffer){
|
||||
_syncMutex.lock();
|
||||
|
||||
syncBuffer->decode(_sharedTime);
|
||||
syncBuffer->decode(_sharedDt);
|
||||
|
||||
_syncMutex.unlock();
|
||||
}
|
||||
|
||||
void Time::postSynchronizationPreDraw(){
|
||||
_syncMutex.lock();
|
||||
|
||||
_syncedTime = _sharedTime;
|
||||
_syncedDt = _sharedDt;
|
||||
|
||||
_syncMutex.unlock();
|
||||
}
|
||||
|
||||
void Time::preSynchronization(){
|
||||
_syncMutex.lock();
|
||||
|
||||
_sharedTime = _time;
|
||||
_sharedDt = _dt;
|
||||
|
||||
_syncMutex.unlock();
|
||||
}
|
||||
|
||||
scripting::ScriptEngine::LuaLibrary Time::luaLibrary() {
|
||||
scripting::ScriptEngine::LuaLibrary timeLibrary = {
|
||||
"time",
|
||||
|
||||
Reference in New Issue
Block a user