Commit fdf55ef4 authored by Robert Menzel's avatar Robert Menzel

added two new rotation modes for the camera class

parent d78eeb58
......@@ -301,6 +301,14 @@ class GenericCamera : public CameraBase, public MoveableObject
*/
void FPSstyleLookAround( float _deltaX, float _deltaY );
// rotate around the target, x,y,z are angles to rotate by IN RADIANCE
// the rotation is around the global goordinate system (1,0,0 / 0,1,0 / 0,0,1)
// "turntable style" rotation if _x is set and _y,_z == 0
void rotateAroundTaget_GlobalAxes( float _x, float _y, float _z );
// rotate around the current coordinate system
void rotateAroundTaget_LocalAxes( float _x, float _y, float _z );
private:
///
/// States: update the storeStateToString() & setStateFromString() functions whenever adding a new state!
......@@ -329,6 +337,9 @@ class GenericCamera : public CameraBase, public MoveableObject
/// viewport in pixel:
glm::uvec2 mViewportSize;
// helper:
void rotateAroundTaget_helper( float _x, float _y, float _z, const glm::mat3 &_rotationAxes );
};
ACGL_SMARTPOINTER_TYPEDEFS(GenericCamera)
......
......@@ -77,6 +77,46 @@ void GenericCamera::FPSstyleLookAround( float _deltaX, float _deltaY )
setRotationMatrix( newRotX * newRotY );
}
void GenericCamera::rotateAroundTaget_GlobalAxes( float _x, float _y, float _z)
{
// move camera so, that the target is the center, then rotate around the
// global coordinate system
glm::mat3 t = glm::mat3( glm::vec3(1.0f, 0.0f, 0.0f),
glm::vec3(0.0f, 1.0f, 0.0f),
glm::vec3(0.0f, 0.0f, 1.0f) );
rotateAroundTaget_helper(_x,_y,_z, t);
}
void GenericCamera::rotateAroundTaget_LocalAxes( float _x, float _y, float _z)
{
glm::mat3 R = getRotationMatrix3();
R = glm::transpose( R );
rotateAroundTaget_helper(_x,_y,_z, R);
}
void GenericCamera::rotateAroundTaget_helper( float _x, float _y, float _z, const glm::mat3 &_rotationAxes )
{
glm::vec4 T = glm::vec4( getTarget(), 1.0f );
glm::vec4 P = glm::vec4( getPosition(), 1.0f );
glm::vec4 tempPos = P - T;
glm::mat4 newRotation = glm::rotate( glm::mat4(), _x, _rotationAxes[0] );
newRotation = glm::rotate( newRotation, _y, _rotationAxes[1] );
newRotation = glm::rotate( newRotation, _z, _rotationAxes[2] );
tempPos = newRotation * tempPos;
P = tempPos + T; // new position
glm::vec4 N = glm::vec4( getUpDirection(), 1.0f );
N = newRotation * N;
setLookAtMatrix( glm::vec3(P), glm::vec3(T), glm::vec3(N) );
}
void GenericCamera::setHorizontalFieldOfView(float _fovh)
{
assert( _fovh < 180.0f );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment