Commit ea1be458 authored by Robert Menzel's avatar Robert Menzel

clean ups in camera

parent b3157152
......@@ -127,31 +127,31 @@ class GenericCamera
* vertical FoV will get (implicitly) changed!
* @param _fovh New horizontal field of view of the camera.
*/
void setHorizontalFieldOfView( double _fovh );
double getHorizontalFieldOfView() const { return mHorizontalFieldOfView; }
void setHorizontalFieldOfView( float _fovh );
float getHorizontalFieldOfView() const { return mHorizontalFieldOfView; }
/**
* Set the vertical field of view of the camera in degree.
* Aspect ratio will get changed!
* @param _fovv New vertical field of view of the camera.
*/
void setVerticalFieldOfView( double _fovv );
double getVerticalFieldOfView() const;
void setVerticalFieldOfView( float _fovv );
float getVerticalFieldOfView() const;
/**
* Set the aspect ratio of the camera. The horizontal FoV stays the same, the
* vertical FoV gets updated.
* @param aspectRatio New aspect ratio (width/height)
*/
void setAspectRatio( double _aspectRatio ) { mAspectRatio = _aspectRatio; }
double getAspectRatio() const { return mAspectRatio; }
void setAspectRatio( float _aspectRatio ) { mAspectRatio = _aspectRatio; }
float getAspectRatio() const { return mAspectRatio; }
/**
* Set the near clipping plane of the camera.
* The plane is defined only by a distance from the camera.
* @param _plane New near clipping plane of the camera.
*/
void setNearClippingPlane( double _plane );
void setNearClippingPlane( float _plane );
/// Gets the near clip distance
float getNearClippingPlane() const { return mNearClippingPlane; }
......@@ -160,7 +160,7 @@ class GenericCamera
* The plane is defined only by a distance from the camera.
* @param _plane New far clipping plane of the camera.
*/
void setFarClippingPlane( double _plane );
void setFarClippingPlane( float _plane );
/// Gets the far clip distance
float getFarClippingPlane() const { return mFarClippingPlane; }
......@@ -169,7 +169,7 @@ class GenericCamera
* Will change the target!
* @param _distance New focal distance of the camera.
*/
void setLookAtDistance( double _distance );
void setLookAtDistance( float _distance );
/// Gets the look-at distance
float getLookAtDistance() const { return mLookAtDistance; }
......@@ -312,12 +312,12 @@ class GenericCamera
/// the Matrix with the camera position/orientation.
/// eyeShift is the half of the eyeDistance (can be 0 if we don't want stereo)
/// toeInValue is the value of how many degrees the camera will be looking to the right/left for toe in
//glm::mat4 getCameraMatrix( double _eyeShift = 0.0f, double _toeInValue = 0.0f );
//glm::mat4 getCameraMatrix( float _eyeShift = 0.0f, float _toeInValue = 0.0f );
/// the projection matrix
/// for non-symetric projections set eyeShift != 0.
/// this is used for off-axis projections (value in meters, negativ for the left eye)
//glm::mat4 getPerspectiveProjectionMatrix( double _eyeShift = 0.0f );
//glm::mat4 getPerspectiveProjectionMatrix( float _eyeShift = 0.0f );
///
......@@ -337,9 +337,9 @@ class GenericCamera
/// Current eye
Eye mCurrentEye;
/// Current camera horizontal field of view
double mHorizontalFieldOfView;
float mHorizontalFieldOfView;
/// Current aspect ratio: width/height.
double mAspectRatio;
float mAspectRatio;
/// Distance of the eyes for stereo projection. In that case, the left eye is 0.5*eyeDistance
/// shifted to the left of position and the right eye is 0.5*eyeDistance to the right shifted.
......@@ -347,12 +347,12 @@ class GenericCamera
float mEyeDistance;
/// Current camera near clipping plane
double mNearClippingPlane;
float mNearClippingPlane;
/// Current camera far clipping plane
double mFarClippingPlane;
float mFarClippingPlane;
/// Current camera focal distance
double mLookAtDistance;
float mLookAtDistance;
/// viewport in pixel:
glm::uvec2 mViewportSize;
......
......@@ -101,20 +101,6 @@ glm::mat4 GenericCamera::getTranslationMatrix4() const
return trans;
}
/*
*
rotMatrix[0][0] = rightVector.x;
rotMatrix[0][1] = upVector.x;
rotMatrix[0][2] = -forwardVector.x;
rotMatrix[1][0] = rightVector.y;
rotMatrix[1][1] = upVector.y;
rotMatrix[1][2] = -forwardVector.y;
rotMatrix[2][0] = rightVector.z;
rotMatrix[2][1] = upVector.z;
rotMatrix[2][2] = -forwardVector.z;
*
*/
glm::vec3 GenericCamera::getUpDirection () const
{
glm::vec3 up(mRotationMatrix[0][1], mRotationMatrix[1][1], mRotationMatrix[2][1]);
......@@ -157,14 +143,14 @@ void GenericCamera::setTarget(const glm::vec3 &_target, const glm::vec3 &_up)
setRotationMatrix( rotMatrix );
}
void GenericCamera::setHorizontalFieldOfView(double _fovh)
void GenericCamera::setHorizontalFieldOfView(float _fovh)
{
assert( _fovh < 180.0f );
assert( _fovh > 0.0f );
mHorizontalFieldOfView = _fovh;
}
void GenericCamera::setVerticalFieldOfView(double _fovv)
void GenericCamera::setVerticalFieldOfView(float _fovv)
{
assert( _fovv < 180.0f );
assert( _fovv > 0.0f );
......@@ -175,24 +161,26 @@ void GenericCamera::setVerticalFieldOfView(double _fovv)
mAspectRatio = tan( calcDegToRad(0.5f * mHorizontalFieldOfView) ) / tan( calcDegToRad(0.5f * _fovv) );
}
double GenericCamera::getVerticalFieldOfView() const
float GenericCamera::getVerticalFieldOfView() const
{
return calcRadToDeg( atan( tan( calcDegToRad(0.5f*mHorizontalFieldOfView) ) / mAspectRatio ) *2.0f );
}
void GenericCamera::setNearClippingPlane(double _plane)
void GenericCamera::setNearClippingPlane(float _plane)
{
assert (_plane > 0.0f);
mNearClippingPlane = _plane;
}
void GenericCamera::setFarClippingPlane(double _plane)
void GenericCamera::setFarClippingPlane(float _plane)
{
assert (_plane > 0.0f);
mFarClippingPlane = _plane;
}
void GenericCamera::setLookAtDistance(double _distance)
void GenericCamera::setLookAtDistance(float _distance)
{
assert (_distance > 0.0f);
mLookAtDistance = _distance;
}
......@@ -248,7 +236,7 @@ glm::mat4 GenericCamera::getProjectionMatrix() const
switch (this->mStereoMode)
{
case MONO: return getMonoProjectionMatrix();
default: assert(0); // not implemented
default: assert( 0 && "unsupported stereo mode" );
return glm::mat4();
}
}
......@@ -258,7 +246,7 @@ glm::mat4 GenericCamera::getViewMatrix() const
switch (this->mStereoMode)
{
case MONO: return getMonoViewMatrix();
default: assert(0); // not implemented
default: assert( 0 && "unsupported stereo mode" );
return glm::mat4();
}
}
......@@ -268,7 +256,7 @@ glm::mat4 GenericCamera::getInverseViewMatrix() const
switch (this->mStereoMode)
{
case MONO: return getMonoInverseViewMatrix();
default: assert(0); // not implemented
default: assert( 0 && "unsupported stereo mode" );
return glm::mat4();
}
}
......@@ -281,10 +269,10 @@ glm::mat4 GenericCamera::getMonoProjectionMatrix() const
{
// we don't set the left/right/top/bottom values explicitly, so we want that
// all object at our focal distance appear the same in perspective and isometric view
double right = tan( calcDegToRad(getHorizontalFieldOfView() * 0.5f) ) * mLookAtDistance;
double left = -right;
double top = tan( calcDegToRad(getVerticalFieldOfView() * 0.5f) ) * mLookAtDistance;
double bottom = -top;
float right = tan( calcDegToRad(getHorizontalFieldOfView() * 0.5f) ) * mLookAtDistance;
float left = -right;
float top = tan( calcDegToRad(getVerticalFieldOfView() * 0.5f) ) * mLookAtDistance;
float bottom = -top;
// we do the same here as a glOrtho call would do.
projectionMatrix[ 0][0] = 2.0f / (right - left);
......@@ -299,47 +287,17 @@ glm::mat4 GenericCamera::getMonoProjectionMatrix() const
{
projectionMatrix = glm::perspective( (float)getHorizontalFieldOfView(), (float)getAspectRatio(), (float)mNearClippingPlane, (float)mFarClippingPlane );
}
else assert(0); // not supported
else assert(0 && "unsupported projection mode");
return projectionMatrix;
}
/*
glm::vec3 FrescoCamera::getUpDirection () const
{
//return glm::gtx::quaternion::rotate( mRotation, glm::vec3(0.0, 0.0, -1.0) );
}
glm::vec3 FrescoCamera::getRightDirection () const
{
//return glm::gtx::quaternion::rotate( mRotation, glm::vec3(1.0, 0.0, 0.0) );
}
glm::vec3 FrescoCamera::getForwardDirection() const
{
//return glm::gtx::quaternion::rotate( mRotation, glm::vec3(0.0, 1.0, 0.0) );
}*/
void GenericCamera::move( const glm::vec3 &_vector )
{
glm::mat3 inverseRotation = getInverseRotationMatrix3();
mPosition += (inverseRotation * _vector);
}
/*
*
rotMatrix[0][0] = rightVector.x;
rotMatrix[0][1] = upVector.x;
rotMatrix[0][2] = -forwardVector.x;
rotMatrix[1][0] = rightVector.y;
rotMatrix[1][1] = upVector.y;
rotMatrix[1][2] = -forwardVector.y;
rotMatrix[2][0] = rightVector.z;
rotMatrix[2][1] = upVector.z;
rotMatrix[2][2] = -forwardVector.z;
*
*/
glm::mat4 GenericCamera::getMonoViewMatrix() const
{
glm::mat4 m(mRotationMatrix);
......@@ -476,12 +434,12 @@ void GenericCamera::setStateFromString( const std::string &_state )
if ( token[pos] == "EYE_RIGHT") mCurrentEye = EYE_RIGHT;
pos++;
mHorizontalFieldOfView = to<double>( token[pos++] );
mAspectRatio = to<double>( token[pos++] );
mHorizontalFieldOfView = to<float>( token[pos++] );
mAspectRatio = to<float>( token[pos++] );
mEyeDistance = to<float>( token[pos++] );
mNearClippingPlane = to<double>( token[pos++] );
mFarClippingPlane = to<double>( token[pos++] );
mLookAtDistance = to<double>( token[pos++] );
mNearClippingPlane = to<float>( token[pos++] );
mFarClippingPlane = to<float>( token[pos++] );
mLookAtDistance = to<float>( token[pos++] );
mViewportSize = toUvec2( token[pos++] );
}
......
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