Skip to content

Commit

Permalink
New 6axis freefly mode
Browse files Browse the repository at this point in the history
this new freefly mode supports 6 DoF navigation
shoulderpads can also be used to change navigation speed.
  • Loading branch information
koosha94 authored and febret committed Jul 7, 2015
1 parent 20413ab commit 8acf7e0
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 14 deletions.
7 changes: 6 additions & 1 deletion include/omega/GamepadCameraController.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,15 @@ namespace omega {
float myStrafeMultiplier;
float myYawMultiplier;
float myPitchMultiplier;

float myRollMultiplier;
Vector3f mySpeedVector;
float myYaw;
float myPitch;
float myRoll;
bool goingUp;
bool goingDown;
bool deaccelerate;
bool accelerate;
Quaternion myTorque;
};

Expand Down
62 changes: 49 additions & 13 deletions src/omega/GamepadCameraController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,20 @@
using namespace omega;

///////////////////////////////////////////////////////////////////////////////
GamepadCameraController::GamepadCameraController():
myStrafeMultiplier(1.0f),
myYawMultiplier(-1.0f),
myPitchMultiplier(1.0f),
mySpeedVector(Vector3f::Zero()),
myTorque(Quaternion::Identity()),
myPitch(0),
myYaw(0)
GamepadCameraController::GamepadCameraController() :
myStrafeMultiplier(1.0f),
myYawMultiplier(-1.0f),
myPitchMultiplier(1.0f),
myRollMultiplier(-1.0f),
mySpeedVector(Vector3f::Zero()),
myTorque(Quaternion::Identity()),
myPitch(0),
myYaw(0),
myRoll(0),
goingDown(false),
goingUp(false),
accelerate(false),
deaccelerate(false)
{
}

Expand All @@ -58,29 +64,59 @@ void GamepadCameraController::handleEvent(const Event& evt)
{
float x = evt.getExtraDataFloat(0);
float y = evt.getExtraDataFloat(1);
float z = evt.getExtraDataFloat(4);
float roll = evt.getExtraDataFloat(5) - evt.getExtraDataFloat(4);
float yaw = evt.getExtraDataFloat(2);
float pitch = evt.getExtraDataFloat(3);
if (evt.isButtonDown(omicron::EventBase::ButtonUp))
goingUp = true;
if (evt.isButtonDown(omicron::EventBase::ButtonDown))
goingDown = true;
if (evt.isButtonUp(omicron::EventBase::ButtonUp))
goingUp = false;
if (evt.isButtonUp(omicron::EventBase::ButtonDown))
goingDown = false;
if (evt.isButtonDown(omicron::EventBase::Button8))
accelerate = true;
if (evt.isButtonDown(omicron::EventBase::Button5))
deaccelerate = true;
if (evt.isButtonUp(omicron::EventBase::Button8))
accelerate = false;
if (evt.isButtonUp(omicron::EventBase::Button5))
deaccelerate = false;

float z = 0;
float speedModifier = 1.0f;
float tresh = 0.2f;

if (goingUp)
z += 2 * tresh;
if (goingDown)
z -= 2 * tresh;
if (accelerate)
speedModifier *= 64;
if (deaccelerate)
speedModifier /= 64;
if(abs(x) < tresh) x = 0;
if(abs(y) < tresh) y = 0;
if(abs(z) < tresh) z = 0;
if(abs(yaw) < tresh) yaw = 0;
if(abs(pitch) < tresh) pitch = 0;

if (abs(roll) < tresh) roll = 0;

myYaw = yaw * myYawMultiplier;
if(myFreeFlyEnabled)
{
myPitch = pitch * myPitchMultiplier;
myRoll = roll * myRollMultiplier;
}
else
{
// If freefly is disabled and trigger is pressed, pitch control is
// used to move camera up/down
if(z != 0) z = pitch;
speedModifier = 1;
}
mySpeedVector = Vector3f(x, z, y) * CameraController::mySpeed;
mySpeedVector = Vector3f(x*speedModifier, z*speedModifier, y*speedModifier) * CameraController::mySpeed;
}
}

Expand All @@ -95,7 +131,7 @@ void GamepadCameraController::update(const UpdateContext& context)
Vector3f mv = mySpeedVector * context.dt;
// The movement vector is oriented based on Camera AND Head orientation
// To make it work reasonably well when using an untracked controller
// in a head-tracked environment (we want 'forward' to be the direction
// in a head-trackeAd environment (we want 'forward' to be the direction
// the user is looking at).
Quaternion o = c->getOrientation() * c->getHeadOrientation();
mv = o * mv;
Expand All @@ -106,7 +142,7 @@ void GamepadCameraController::update(const UpdateContext& context)
}

c->translate(mv, Node::TransformWorld);
Vector3f pyr(myPitch * context.dt, myYaw * context.dt, 0);
Vector3f pyr(myPitch * context.dt, myYaw * context.dt, myRoll * context.dt);
c->rotate(Math::quaternionFromEuler(pyr), Node::TransformLocal);
}
}
Expand Down

0 comments on commit 8acf7e0

Please sign in to comment.