Untabify InteractionHandler files

This commit is contained in:
Alexander Bock
2016-04-08 15:13:21 +02:00
parent 3de5fb3b55
commit 8d3c667ada
3 changed files with 332 additions and 332 deletions

View File

@@ -94,44 +94,44 @@ class InteractionHandler : public properties::PropertyOwner {
public:
InteractionHandler();
~InteractionHandler();
~InteractionHandler();
void setKeyboardController(KeyboardController* controller);
void setMouseController(MouseController* controller);
void addController(Controller* controller);
void setKeyboardController(KeyboardController* controller);
void setMouseController(MouseController* controller);
void addController(Controller* controller);
void lockControls();
void unlockControls();
void lockControls();
void unlockControls();
void update(double deltaTime);
void update(double deltaTime);
void setFocusNode(SceneGraphNode* node);
const SceneGraphNode* const focusNode() const;
void setCamera(Camera* camera);
const Camera* const camera() const;
void setFocusNode(SceneGraphNode* node);
const SceneGraphNode* const focusNode() const;
void setCamera(Camera* camera);
const Camera* const camera() const;
void keyboardCallback(Key key, KeyModifier modifier, KeyAction action);
void mouseButtonCallback(MouseButton button, MouseAction action);
void mousePositionCallback(double x, double y);
void mouseScrollWheelCallback(double pos);
void mouseButtonCallback(MouseButton button, MouseAction action);
void mousePositionCallback(double x, double y);
void mouseScrollWheelCallback(double pos);
double deltaTime() const;
double deltaTime() const;
void orbitDelta(const glm::quat& rotation);
void orbitDelta(const glm::quat& rotation);
void orbit(const float &dx, const float &dy, const float &dz, const float &dist);
void orbit(const float &dx, const float &dy, const float &dz, const float &dist);
//void distance(const float &d);
//void distance(const float &d);
void rotateDelta(const glm::quat& rotation);
void rotateDelta(const glm::quat& rotation);
void distanceDelta(const PowerScaledScalar& distance, size_t iterations = 0);
void distanceDelta(const PowerScaledScalar& distance, size_t iterations = 0);
void lookAt(const glm::quat& rotation);
void lookAt(const glm::quat& rotation);
void setRotation(const glm::quat& rotation);
void setRotation(const glm::quat& rotation);
void resetKeyBindings();
void resetKeyBindings();
void bindKey(Key key, std::string lua);
void setInteractionSensitivity(float sensitivity);
@@ -143,51 +143,51 @@ public:
void setInvertRotation(bool invert);
bool invertRotation() const;
void addKeyframe(const network::datamessagestructures::PositionKeyframe &kf);
void addKeyframe(const network::datamessagestructures::PositionKeyframe &kf);
void clearKeyframes();
/**
* Returns the Lua library that contains all Lua functions available to affect the
* interaction. The functions contained are
* - openspace::luascriptfunctions::setOrigin
* \return The Lua library that contains all Lua functions available to affect the
* interaction
*/
static scripting::ScriptEngine::LuaLibrary luaLibrary();
/**
* Returns the Lua library that contains all Lua functions available to affect the
* interaction. The functions contained are
* - openspace::luascriptfunctions::setOrigin
* \return The Lua library that contains all Lua functions available to affect the
* interaction
*/
static scripting::ScriptEngine::LuaLibrary luaLibrary();
private:
friend class Controller;
friend class Controller;
InteractionHandler(const InteractionHandler&) = delete;
InteractionHandler& operator=(const InteractionHandler&) = delete;
InteractionHandler(InteractionHandler&&) = delete;
InteractionHandler& operator=(InteractionHandler&&) = delete;
InteractionHandler(InteractionHandler&&) = delete;
InteractionHandler& operator=(InteractionHandler&&) = delete;
Camera* _camera;
SceneGraphNode* _focusNode;
Camera* _camera;
SceneGraphNode* _focusNode;
double _deltaTime;
std::mutex _mutex;
double _deltaTime;
std::mutex _mutex;
bool _validKeyLua;
std::multimap<Key, std::string > _keyLua;
bool _validKeyLua;
std::multimap<Key, std::string > _keyLua;
float _controllerSensitivity;
bool _invertRoll;
bool _invertRotation;
KeyboardController* _keyboardController;
MouseController* _mouseController;
std::vector<Controller*> _controllers;
KeyboardController* _keyboardController;
MouseController* _mouseController;
std::vector<Controller*> _controllers;
properties::StringProperty _origin;
properties::StringProperty _coordinateSystem;
//remote controller
std::vector<network::datamessagestructures::PositionKeyframe> _keyframes;
double _currentKeyframeTime;
std::mutex _keyframeMutex;
//remote controller
std::vector<network::datamessagestructures::PositionKeyframe> _keyframes;
double _currentKeyframeTime;
std::mutex _keyframeMutex;
};
} // namespace interaction

View File

@@ -35,19 +35,19 @@
#include <ghoul/misc/interpolator.h>
namespace {
const std::string _loggerCat = "InteractionHandler";
const std::string _loggerCat = "InteractionHandler";
openspace::Key stringToKey(std::string s) {
// key only uppercase
std::transform(s.begin(), s.end(), s.begin(), ::toupper);
// key only uppercase
std::transform(s.begin(), s.end(), s.begin(), ::toupper);
// default is unknown
// default is unknown
auto it = openspace::KeyMapping.find(s);
if (it != openspace::KeyMapping.end())
return it->second;
else
return openspace::Key::Unknown;
}
}
}
#include "interactionhandler_lua.inl"
@@ -113,18 +113,18 @@ namespace interaction {
InteractionHandler::InteractionHandler()
: properties::PropertyOwner()
, _camera(nullptr)
, _focusNode(nullptr)
, _camera(nullptr)
, _focusNode(nullptr)
, _deltaTime(0.0)
, _validKeyLua(false)
, _controllerSensitivity(1.f)
, _invertRoll(false)
, _invertRotation(false)
, _keyboardController(nullptr)
, _mouseController(nullptr)
, _keyboardController(nullptr)
, _mouseController(nullptr)
, _origin("origin", "Origin", "")
, _coordinateSystem("coordinateSystem", "Coordinate System", "")
, _currentKeyframeTime(-1.0)
, _currentKeyframeTime(-1.0)
{
setName("Interaction");
@@ -145,38 +145,38 @@ InteractionHandler::InteractionHandler()
}
InteractionHandler::~InteractionHandler() {
delete _keyboardController;
delete _mouseController;
for (size_t i = 0; i < _controllers.size(); ++i)
delete _controllers[i];
delete _keyboardController;
delete _mouseController;
for (size_t i = 0; i < _controllers.size(); ++i)
delete _controllers[i];
}
void InteractionHandler::setKeyboardController(KeyboardController* controller) {
assert(controller);
delete _keyboardController;
_keyboardController = controller;
_keyboardController->setHandler(this);
assert(controller);
delete _keyboardController;
_keyboardController = controller;
_keyboardController->setHandler(this);
}
void InteractionHandler::setMouseController(MouseController* controller) {
assert(controller);
delete _mouseController;
_mouseController = controller;
_mouseController->setHandler(this);
assert(controller);
delete _mouseController;
_mouseController = controller;
_mouseController->setHandler(this);
}
void InteractionHandler::addController(Controller* controller) {
assert(controller);
_controllers.push_back(controller);
controller->setHandler(this);
assert(controller);
_controllers.push_back(controller);
controller->setHandler(this);
}
void InteractionHandler::lockControls() {
_mutex.lock();
_mutex.lock();
}
void InteractionHandler::unlockControls() {
_mutex.unlock();
_mutex.unlock();
}
//<<<<<<< HEAD
@@ -233,16 +233,16 @@ void InteractionHandler::unlockControls() {
// unlockControls();
//=======
void InteractionHandler::update(double deltaTime) {
_deltaTime = deltaTime;
_mouseController->update(deltaTime);
_deltaTime = deltaTime;
_mouseController->update(deltaTime);
bool hasKeys = false;
psc pos;
glm::quat q;
_keyframeMutex.lock();
_keyframeMutex.lock();
if (_keyframes.size() > 4){ //wait until enough samples are buffered
if (_keyframes.size() > 4){ //wait until enough samples are buffered
hasKeys = true;
openspace::network::datamessagestructures::PositionKeyframe p0, p1, p2, p3;
@@ -252,20 +252,20 @@ void InteractionHandler::update(double deltaTime) {
p2 = _keyframes[2];
p3 = _keyframes[3];
//interval check
if (_currentKeyframeTime < p1._timeStamp){
_currentKeyframeTime = p1._timeStamp;
}
//interval check
if (_currentKeyframeTime < p1._timeStamp){
_currentKeyframeTime = p1._timeStamp;
}
double t0 = p1._timeStamp;
double t1 = p2._timeStamp;
double fact = (_currentKeyframeTime - t0) / (t1 - t0);
double t0 = p1._timeStamp;
double t1 = p2._timeStamp;
double fact = (_currentKeyframeTime - t0) / (t1 - t0);
//glm::dvec4 v = positionInterpCR.interpolate(fact, _keyframes[0]._position.dvec4(), _keyframes[1]._position.dvec4(), _keyframes[2]._position.dvec4(), _keyframes[3]._position.dvec4());
//glm::dvec4 v = positionInterpCR.interpolate(fact, _keyframes[0]._position.dvec4(), _keyframes[1]._position.dvec4(), _keyframes[2]._position.dvec4(), _keyframes[3]._position.dvec4());
glm::dvec4 v = ghoul::interpolateLinear(fact, p1._position.dvec4(), p2._position.dvec4());
pos = psc(v.x, v.y, v.z, v.w);
q = ghoul::interpolateLinear(fact, p1._viewRotationQuat, p2._viewRotationQuat);
@@ -282,29 +282,29 @@ void InteractionHandler::update(double deltaTime) {
_keyframeMutex.unlock();
if(hasKeys){
_camera->setPosition(pos);
_camera->setViewRotationMatrix(glm::mat4_cast(q));
_camera->setPosition(pos);
_camera->setViewRotationMatrix(glm::mat4_cast(q));
}
}
void InteractionHandler::setFocusNode(SceneGraphNode* node) {
if (_focusNode == node){
return;
}
if (_focusNode == node){
return;
}
_focusNode = node;
_focusNode = node;
//orient the camera to the new node
psc focusPos = node->worldPosition();
psc camToFocus = focusPos - _camera->position();
glm::vec3 viewDir = glm::normalize(camToFocus.vec3());
glm::vec3 cameraView = glm::normalize(_camera->viewDirection());
//orient the camera to the new node
psc focusPos = node->worldPosition();
psc camToFocus = focusPos - _camera->position();
glm::vec3 viewDir = glm::normalize(camToFocus.vec3());
glm::vec3 cameraView = glm::normalize(_camera->viewDirection());
//set new focus position
_camera->setFocusPosition(node->worldPosition());
float dot = glm::dot(viewDir, cameraView);
@@ -313,25 +313,25 @@ void InteractionHandler::setFocusNode(SceneGraphNode* node) {
if (dot < 1.f && dot > -1.f) {
//if (glm::length(viewDir - cameraView) < 0.001) {
//if (viewDir != cameraView) {
glm::vec3 rotAxis = glm::normalize(glm::cross(viewDir, cameraView));
float angle = glm::angle(viewDir, cameraView);
glm::quat q = glm::angleAxis(angle, rotAxis);
glm::vec3 rotAxis = glm::normalize(glm::cross(viewDir, cameraView));
float angle = glm::angle(viewDir, cameraView);
glm::quat q = glm::angleAxis(angle, rotAxis);
//rotate view to target new focus
_camera->rotate(q);
//rotate view to target new focus
_camera->rotate(q);
}
}
const SceneGraphNode* const InteractionHandler::focusNode() const {
return _focusNode;
return _focusNode;
}
void InteractionHandler::setCamera(Camera* camera) {
assert(camera);
_camera = camera;
assert(camera);
_camera = camera;
}
const Camera* const InteractionHandler::camera() const {
return _camera;
return _camera;
}
//void InteractionHandler::keyboardCallback(int key, int action) {
@@ -344,71 +344,71 @@ const Camera* const InteractionHandler::camera() const {
//}
void InteractionHandler::mouseButtonCallback(MouseButton button, MouseAction action) {
if (_mouseController)
_mouseController->button(button, action);
if (_mouseController)
_mouseController->button(button, action);
}
void InteractionHandler::mousePositionCallback(double x, double y) {
if (_mouseController)
// TODO Remap screen coordinates to [0,1]
_mouseController->move(static_cast<float>(x), static_cast<float>(y));
if (_mouseController)
// TODO Remap screen coordinates to [0,1]
_mouseController->move(static_cast<float>(x), static_cast<float>(y));
}
void InteractionHandler::mouseScrollWheelCallback(double pos) {
if (_mouseController)
_mouseController->scrollWheel(static_cast<int>(pos));
if (_mouseController)
_mouseController->scrollWheel(static_cast<int>(pos));
}
void InteractionHandler::orbit(const float &dx, const float &dy, const float &dz, const float &dist){
lockControls();
glm::vec3 cameraUp = glm::normalize((glm::inverse(_camera->viewRotationMatrix()) * glm::vec4(_camera->lookUpVector(), 0))).xyz();
glm::vec3 cameraRight = glm::cross(_camera->viewDirection(), cameraUp);
lockControls();
glm::vec3 cameraUp = glm::normalize((glm::inverse(_camera->viewRotationMatrix()) * glm::vec4(_camera->lookUpVector(), 0))).xyz();
glm::vec3 cameraRight = glm::cross(_camera->viewDirection(), cameraUp);
glm::mat4 transform;
transform = glm::rotate(glm::radians(dx * 100.f), cameraUp) * transform;
transform = glm::rotate(glm::radians(dy * 100.f), cameraRight) * transform;
transform = glm::rotate(glm::radians(dz * 100.f), _camera->viewDirection()) * transform;
glm::mat4 transform;
transform = glm::rotate(glm::radians(dx * 100.f), cameraUp) * transform;
transform = glm::rotate(glm::radians(dy * 100.f), cameraRight) * transform;
transform = glm::rotate(glm::radians(dz * 100.f), _camera->viewDirection()) * transform;
//get "old" focus position
psc focus = _camera->focusPosition();
//// get camera position
//psc relative = _camera->position();
//get "old" focus position
psc focus = _camera->focusPosition();
//// get camera position
//psc relative = _camera->position();
// get camera position (UNSYNCHRONIZED)
psc relative = _camera->unsynchedPosition();
// get camera position (UNSYNCHRONIZED)
psc relative = _camera->unsynchedPosition();
//get relative vector
psc relative_focus_coordinate = relative - focus;
//rotate relative vector
relative_focus_coordinate = glm::inverse(transform) * relative_focus_coordinate.vec4();
//get new new position of focus node
psc origin;
if (_focusNode) {
origin = _focusNode->worldPosition();
}
//get relative vector
psc relative_focus_coordinate = relative - focus;
//rotate relative vector
relative_focus_coordinate = glm::inverse(transform) * relative_focus_coordinate.vec4();
//get new new position of focus node
psc origin;
if (_focusNode) {
origin = _focusNode->worldPosition();
}
//new camera position
relative = origin + relative_focus_coordinate;
//new camera position
relative = origin + relative_focus_coordinate;
float bounds = 2.f * (_focusNode ? _focusNode->boundingSphere().lengthf() : 0.f) / 10.f;
float bounds = 2.f * (_focusNode ? _focusNode->boundingSphere().lengthf() : 0.f) / 10.f;
psc target = relative + relative_focus_coordinate * dist;
//don't fly into objects
if ((target - origin).length() < bounds){
target = relative;
}
psc target = relative + relative_focus_coordinate * dist;
//don't fly into objects
if ((target - origin).length() < bounds){
target = relative;
}
unlockControls();
unlockControls();
_camera->setFocusPosition(origin);
_camera->setPosition(target);
_camera->rotate(glm::quat_cast(transform));
_camera->setPosition(target);
_camera->rotate(glm::quat_cast(transform));
}
//void InteractionHandler::distance(const float &d){
@@ -433,35 +433,35 @@ void InteractionHandler::orbit(const float &dx, const float &dy, const float &dz
void InteractionHandler::orbitDelta(const glm::quat& rotation)
{
lockControls();
lockControls();
// the camera position
psc relative = _camera->position();
// the camera position
psc relative = _camera->position();
// should be changed to something more dynamic =)
psc origin;
if (_focusNode) {
origin = _focusNode->worldPosition();
}
// should be changed to something more dynamic =)
psc origin;
if (_focusNode) {
origin = _focusNode->worldPosition();
}
psc relative_origin_coordinate = relative - origin;
//glm::mat4 rotation_matrix = glm::mat4_cast(glm::inverse(rotation));
//relative_origin_coordinate = relative_origin_coordinate.vec4() * glm::inverse(rotation);
relative_origin_coordinate = glm::inverse(rotation) * relative_origin_coordinate.vec4();
relative = relative_origin_coordinate + origin;
psc relative_origin_coordinate = relative - origin;
//glm::mat4 rotation_matrix = glm::mat4_cast(glm::inverse(rotation));
//relative_origin_coordinate = relative_origin_coordinate.vec4() * glm::inverse(rotation);
relative_origin_coordinate = glm::inverse(rotation) * relative_origin_coordinate.vec4();
relative = relative_origin_coordinate + origin;
glm::mat4 la = glm::lookAt(_camera->position().vec3(), origin.vec3(), glm::rotate(rotation, _camera->lookUpVector()));
unlockControls();
_camera->setPosition(relative);
//camera_->rotate(rotation);
//camera_->setRotation(glm::mat4_cast(rotation));
_camera->setPosition(relative);
//camera_->rotate(rotation);
//camera_->setRotation(glm::mat4_cast(rotation));
_camera->setRotation(la);
//camera_->setLookUpVector();
_camera->setRotation(la);
//camera_->setLookUpVector();
}
//<<<<<<< HEAD
@@ -480,46 +480,46 @@ void InteractionHandler::orbitDelta(const glm::quat& rotation)
//=======
void InteractionHandler::rotateDelta(const glm::quat& rotation)
{
_camera->rotate(rotation);
_camera->rotate(rotation);
}
void InteractionHandler::distanceDelta(const PowerScaledScalar& distance, size_t iterations)
{
if (iterations > 5)
return;
//assert(this_);
lockControls();
psc relative = _camera->position();
const psc origin = (_focusNode) ? _focusNode->worldPosition() : psc();
if (iterations > 5)
return;
//assert(this_);
lockControls();
psc relative = _camera->position();
const psc origin = (_focusNode) ? _focusNode->worldPosition() : psc();
unlockControls();
psc relative_origin_coordinate = relative - origin;
const glm::vec3 dir(relative_origin_coordinate.direction());
glm::vec3 newdir = dir * distance[0];
const glm::vec3 dir(relative_origin_coordinate.direction());
glm::vec3 newdir = dir * distance[0];
relative_origin_coordinate = newdir;
relative_origin_coordinate[3] = distance[1];
relative = relative + relative_origin_coordinate;
relative_origin_coordinate = newdir;
relative_origin_coordinate[3] = distance[1];
relative = relative + relative_origin_coordinate;
relative_origin_coordinate = relative - origin;
if (relative_origin_coordinate.vec4().x == 0.f && relative_origin_coordinate.vec4().y == 0.f && relative_origin_coordinate.vec4().z == 0.f)
// TODO: this shouldn't be allowed to happen; a mechanism to prevent the camera to coincide with the origin is necessary (ab)
return;
relative_origin_coordinate = relative - origin;
if (relative_origin_coordinate.vec4().x == 0.f && relative_origin_coordinate.vec4().y == 0.f && relative_origin_coordinate.vec4().z == 0.f)
// TODO: this shouldn't be allowed to happen; a mechanism to prevent the camera to coincide with the origin is necessary (ab)
return;
newdir = relative_origin_coordinate.direction();
newdir = relative_origin_coordinate.direction();
// update only if on the same side of the origin
if (glm::angle(newdir, dir) < 90.0f) {
_camera->setPosition(relative);
}
else {
PowerScaledScalar d2 = distance;
d2[0] *= 0.75f;
d2[1] *= 0.85f;
distanceDelta(d2, iterations + 1);
}
// update only if on the same side of the origin
if (glm::angle(newdir, dir) < 90.0f) {
_camera->setPosition(relative);
}
else {
PowerScaledScalar d2 = distance;
d2[0] *= 0.75f;
d2[1] *= 0.85f;
distanceDelta(d2, iterations + 1);
}
}
void InteractionHandler::lookAt(const glm::quat& rotation)
@@ -529,50 +529,50 @@ void InteractionHandler::lookAt(const glm::quat& rotation)
void InteractionHandler::keyboardCallback(Key key, KeyModifier modifier, KeyAction action) {
// TODO package in script
const float speed = _controllerSensitivity;
const float dt = static_cast<float>(_deltaTime);
const float dt = static_cast<float>(_deltaTime);
if (action == KeyAction::Press || action == KeyAction::Repeat) {
if ((key == Key::Right) && (modifier == KeyModifier::NoModifier)) {
glm::vec3 euler(0.0, speed * dt*0.4, 0.0);
glm::quat rot = glm::quat(euler);
rotateDelta(rot);
}
glm::vec3 euler(0.0, speed * dt*0.4, 0.0);
glm::quat rot = glm::quat(euler);
rotateDelta(rot);
}
if ((key == Key::Left) && (modifier == KeyModifier::NoModifier)) {
glm::vec3 euler(0.0, -speed * dt*0.4, 0.0);
glm::quat rot = glm::quat(euler);
rotateDelta(rot);
}
glm::vec3 euler(0.0, -speed * dt*0.4, 0.0);
glm::quat rot = glm::quat(euler);
rotateDelta(rot);
}
if ((key == Key::Down) && (modifier == KeyModifier::NoModifier)) {
glm::vec3 euler(speed * dt*0.4, 0.0, 0.0);
glm::quat rot = glm::quat(euler);
rotateDelta(rot);
}
glm::vec3 euler(speed * dt*0.4, 0.0, 0.0);
glm::quat rot = glm::quat(euler);
rotateDelta(rot);
}
if ((key == Key::Up) && (modifier == KeyModifier::NoModifier)) {
glm::vec3 euler(-speed * dt*0.4, 0.0, 0.0);
glm::quat rot = glm::quat(euler);
rotateDelta(rot);
}
glm::vec3 euler(-speed * dt*0.4, 0.0, 0.0);
glm::quat rot = glm::quat(euler);
rotateDelta(rot);
}
if ((key == Key::KeypadSubtract) && (modifier == KeyModifier::NoModifier)) {
glm::vec2 s = OsEng.renderEngine().camera()->scaling();
s[1] -= 0.5f;
OsEng.renderEngine().camera()->setScaling(s);
}
glm::vec2 s = OsEng.renderEngine().camera()->scaling();
s[1] -= 0.5f;
OsEng.renderEngine().camera()->setScaling(s);
}
if ((key == Key::KeypadAdd) && (modifier == KeyModifier::NoModifier)) {
glm::vec2 s = OsEng.renderEngine().camera()->scaling();
s[1] += 0.5f;
OsEng.renderEngine().camera()->setScaling(s);
}
glm::vec2 s = OsEng.renderEngine().camera()->scaling();
s[1] += 0.5f;
OsEng.renderEngine().camera()->setScaling(s);
}
// iterate over key bindings
_validKeyLua = true;
auto ret = _keyLua.equal_range(key);
for (auto it = ret.first; it != ret.second; ++it) {
//OsEng.scriptEngine()->runScript(it->second);
OsEng.scriptEngine().queueScript(it->second);
if (!_validKeyLua) {
break;
}
}
}
// iterate over key bindings
_validKeyLua = true;
auto ret = _keyLua.equal_range(key);
for (auto it = ret.first; it != ret.second; ++it) {
//OsEng.scriptEngine()->runScript(it->second);
OsEng.scriptEngine().queueScript(it->second);
if (!_validKeyLua) {
break;
}
}
}
}
//
//void InteractionHandler::mouseButtonCallback(int key, int action) {
@@ -613,43 +613,43 @@ void InteractionHandler::keyboardCallback(Key key, KeyModifier modifier, KeyActi
//
//
void InteractionHandler::resetKeyBindings() {
_keyLua.clear();
_validKeyLua = false;
_keyLua.clear();
_validKeyLua = false;
}
void InteractionHandler::bindKey(Key key, std::string lua) {
_keyLua.insert(std::make_pair(key, lua));
_keyLua.insert(std::make_pair(key, lua));
}
scripting::ScriptEngine::LuaLibrary InteractionHandler::luaLibrary() {
return {
"",
{
{
"clearKeys",
&luascriptfunctions::clearKeys,
"",
"Clear all key bindings"
},
{
"bindKey",
&luascriptfunctions::bindKey,
"string, string",
"Binds a key by name to a lua string command"
},
{
"dt",
&luascriptfunctions::dt,
"",
"Get current frame time"
},
{
"distance",
&luascriptfunctions::distance,
"number",
"Change distance to origin",
return {
"",
{
{
"clearKeys",
&luascriptfunctions::clearKeys,
"",
"Clear all key bindings"
},
{
"bindKey",
&luascriptfunctions::bindKey,
"string, string",
"Binds a key by name to a lua string command"
},
{
"dt",
&luascriptfunctions::dt,
"",
"Get current frame time"
},
{
"distance",
&luascriptfunctions::distance,
"number",
"Change distance to origin",
true
},
},
{
"setInteractionSensitivity",
&luascriptfunctions::setInteractionSensitivity,
@@ -687,18 +687,18 @@ scripting::ScriptEngine::LuaLibrary InteractionHandler::luaLibrary() {
"Returns the status of rotation movement inversion"
}
}
};
}
};
}
//=======
void InteractionHandler::setRotation(const glm::quat& rotation)
{
_camera->setRotation(rotation);
_camera->setRotation(rotation);
}
double InteractionHandler::deltaTime() const {
return _deltaTime;
return _deltaTime;
}
void InteractionHandler::setInteractionSensitivity(float sensitivity) {
@@ -726,15 +726,15 @@ bool InteractionHandler::invertRotation() const {
}
void InteractionHandler::addKeyframe(const network::datamessagestructures::PositionKeyframe &kf){
_keyframeMutex.lock();
_keyframeMutex.lock();
//save a maximum of 10 samples (1 seconds of buffer)
if (_keyframes.size() >= 10){
_keyframes.erase(_keyframes.begin());
}
//save a maximum of 10 samples (1 seconds of buffer)
if (_keyframes.size() >= 10){
_keyframes.erase(_keyframes.begin());
}
_keyframes.push_back(kf);
_keyframeMutex.unlock();
_keyframeMutex.unlock();
}
void InteractionHandler::clearKeyframes(){

View File

@@ -32,28 +32,28 @@ namespace luascriptfunctions {
* Set the origin of the camera
*/
int setOrigin(lua_State* L) {
using ghoul::lua::luaTypeToString;
const std::string _loggerCat = "lua.setOrigin";
using ghoul::lua::luaTypeToString;
const std::string _loggerCat = "lua.setOrigin";
int nArguments = lua_gettop(L);
if (nArguments != 1)
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
int nArguments = lua_gettop(L);
if (nArguments != 1)
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
const int type = lua_type(L, -1);
if (type != LUA_TSTRING)
return luaL_error(L, "Expected string, got %i", type);
const int type = lua_type(L, -1);
if (type != LUA_TSTRING)
return luaL_error(L, "Expected string, got %i", type);
std::string s = luaL_checkstring(L, -1);
std::string s = luaL_checkstring(L, -1);
SceneGraphNode* node = sceneGraphNode(s);
if (!node) {
LWARNING("Could not find a node in scenegraph called '" << s <<"'");
return 0;
}
SceneGraphNode* node = sceneGraphNode(s);
if (!node) {
LWARNING("Could not find a node in scenegraph called '" << s <<"'");
return 0;
}
OsEng.interactionHandler().setFocusNode(node);
OsEng.interactionHandler().setFocusNode(node);
return 0;
return 0;
}
/**
@@ -62,31 +62,31 @@ int setOrigin(lua_State* L) {
* Binds a key to Lua command
*/
int bindKey(lua_State* L) {
using ghoul::lua::luaTypeToString;
const std::string _loggerCat = "lua.bindKey";
using ghoul::lua::luaTypeToString;
const std::string _loggerCat = "lua.bindKey";
int nArguments = lua_gettop(L);
if (nArguments != 2)
return luaL_error(L, "Expected %i arguments, got %i", 2, nArguments);
int nArguments = lua_gettop(L);
if (nArguments != 2)
return luaL_error(L, "Expected %i arguments, got %i", 2, nArguments);
std::string key = luaL_checkstring(L, -2);
std::string command = luaL_checkstring(L, -1);
std::string key = luaL_checkstring(L, -2);
std::string command = luaL_checkstring(L, -1);
if (command.empty())
return luaL_error(L, "Command string is empty");
if (command.empty())
return luaL_error(L, "Command string is empty");
openspace::Key iKey = stringToKey(key);
if (iKey == openspace::Key::Unknown) {
LERROR("Could not find key '"<< key <<"'");
return 0;
}
LERROR("Could not find key '"<< key <<"'");
return 0;
}
OsEng.interactionHandler().bindKey(iKey, command);
OsEng.interactionHandler().bindKey(iKey, command);
return 0;
return 0;
}
/**
@@ -95,16 +95,16 @@ int bindKey(lua_State* L) {
* Clears all key bindings
*/
int clearKeys(lua_State* L) {
using ghoul::lua::luaTypeToString;
const std::string _loggerCat = "lua.clearKeys";
using ghoul::lua::luaTypeToString;
const std::string _loggerCat = "lua.clearKeys";
int nArguments = lua_gettop(L);
if (nArguments != 0)
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
int nArguments = lua_gettop(L);
if (nArguments != 0)
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
OsEng.interactionHandler().resetKeyBindings();
OsEng.interactionHandler().resetKeyBindings();
return 0;
return 0;
}
/**
@@ -113,12 +113,12 @@ int clearKeys(lua_State* L) {
* Get current frame time
*/
int dt(lua_State* L) {
int nArguments = lua_gettop(L);
if (nArguments != 0)
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
int nArguments = lua_gettop(L);
if (nArguments != 0)
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
lua_pushnumber(L,OsEng.interactionHandler().deltaTime());
return 1;
lua_pushnumber(L,OsEng.interactionHandler().deltaTime());
return 1;
}
/**
@@ -127,15 +127,15 @@ int dt(lua_State* L) {
* Change distance to origin
*/
int distance(lua_State* L) {
int nArguments = lua_gettop(L);
if (nArguments != 2)
return luaL_error(L, "Expected %i arguments, got %i", 2, nArguments);
int nArguments = lua_gettop(L);
if (nArguments != 2)
return luaL_error(L, "Expected %i arguments, got %i", 2, nArguments);
double d1 = luaL_checknumber(L, -2);
double d2 = luaL_checknumber(L, -1);
PowerScaledScalar dist(static_cast<float>(d1), static_cast<float>(d2));
OsEng.interactionHandler().distanceDelta(dist);
return 0;
double d1 = luaL_checknumber(L, -2);
double d2 = luaL_checknumber(L, -1);
PowerScaledScalar dist(static_cast<float>(d1), static_cast<float>(d2));
OsEng.interactionHandler().distanceDelta(dist);
return 0;
}
/**