Commit 3f055220 authored by Andreas Neu's avatar Andreas Neu
Browse files

-Camera class modified, so that no explicit update calls have to be made.

parent 0a74bba2
......@@ -38,26 +38,26 @@ public:
updateOrientationByLocalCoordinateSystem();
}
Camera(
int_t width,
int_t height,
float fov,
float near,
float far,
const glm::vec3& position,
const glm::vec3& target)
int_t _width,
int_t _height,
float _fov,
float _near,
float _far,
const glm::vec3& _position,
const glm::vec3& _target)
: mRight (),
mUp (),
mForward (),
mWidth (width),
mHeight (height),
mFOV (fov),
mNear (near),
mFar (far),
mWidth (_width),
mHeight (_height),
mFOV (_fov),
mNear (_near),
mFar (_far),
mPitch (0.0f),
mYaw (0.0f),
mRoll (0.0f),
mPosition (position),
mTarget (target)
mPosition (_position),
mTarget (_target)
{
updateLocalCoordinateSystemByTarget();
updateOrientationByLocalCoordinateSystem();
......@@ -80,32 +80,74 @@ public:
}
~Camera(void) {}
inline float getAspectRatio () const { return (float)mWidth / (float)mHeight; }
inline const glm::vec3& getUpDirection () const { return mUp; }
inline const glm::vec3& getRightDirection () const { return mRight; }
inline const glm::vec3& getForwardDirection () const { return mForward; }
inline int_t getWidth () const { return mWidth; }
inline int_t getHeight () const { return mHeight; }
inline float getFOV () const { return mFOV; }
inline float getNear () const { return mNear; }
inline float getFar () const { return mFar; }
inline float getPitch () const { return mPitch; }
inline float getYaw () const { return mYaw; }
inline float getRoll () const { return mRoll; }
inline const glm::vec3& getPosition () const { return mPosition; }
inline const glm::vec3& getTarget () const { return mTarget; }
inline float getAspectRatio () const { return (float)mWidth / (float)mHeight; }
inline const glm::vec3& getUpDirection () const { return mUp; }
inline const glm::vec3& getRightDirection () const { return mRight; }
inline const glm::vec3& getForwardDirection () const { return mForward; }
inline int_t getWidth () const { return mWidth; }
inline int_t getHeight () const { return mHeight; }
inline float getFOV () const { return mFOV; }
inline float getNear () const { return mNear; }
inline float getFar () const { return mFar; }
inline float getPitch () const { return mPitch; }
inline float getYaw () const { return mYaw; }
inline float getRoll () const { return mRoll; }
inline const glm::vec3& getPosition () const { return mPosition; }
inline const glm::vec3& getTarget () const { return mTarget; }
inline void setWidth (int_t width) { mWidth = width; }
inline void setHeight (int_t height) { mHeight = height; }
inline void setFOV (float fov) { mFOV = fov; }
inline void setNear (float near) { mNear = near; }
inline void setFar (float far) { mFar = far; }
inline void setPitch (float pitch) { mPitch = pitch; }
inline void setYaw (float yaw) { mYaw = yaw; }
inline void setRoll (float roll) { mRoll = roll; }
inline void setPosition (const glm::vec3& position, bool moveTarget = true) { if(moveTarget) { mTarget += position - mPosition; } mPosition = position; }
inline void setTarget (const glm::vec3& target, bool movePosition = true) { if(movePosition) { mPosition += target - mTarget; } mTarget = target; }
inline void setWidth (int_t _width) { mWidth = _width; }
inline void setHeight (int_t _height) { mHeight = _height; }
inline void setFOV (float _fov) { mFOV = _fov; }
inline void setNear (float _near) { mNear = _near; }
inline void setFar (float _far) { mFar = _far; }
inline void setPosition(const glm::vec3& _position, bool _moveTarget = true)
{
if(_moveTarget)
mTarget += _position - mPosition;
mPosition = _position;
if(!_moveTarget)
updateLocalCoordinateSystemByTarget(mUp);
}
inline void setPosition(const glm::vec3& _position, const glm::vec3& _up, bool _moveTarget = true)
{
if(_moveTarget)
mTarget += _position - mPosition;
mPosition = _position;
updateLocalCoordinateSystemByTarget(_up);
}
inline void setTarget(const glm::vec3& _target, bool _movePosition = true)
{
if(_movePosition)
mPosition += _target - mTarget;
mTarget = _target;
if(!_movePosition)
updateLocalCoordinateSystemByTarget(mUp);
}
inline void setPitch(float _pitch)
{
mPitch = _pitch;
updateLocalCoordinateSystemByOrientation();
}
inline void setYaw(float _yaw)
{
mYaw = _yaw;
updateLocalCoordinateSystemByOrientation();
}
inline void setRoll(float _roll)
{
mRoll = _roll;
}
inline void setPitchAroundTarget(float pitch)
{
......@@ -119,16 +161,25 @@ public:
updateLocalCoordinateSystemByOrientation();
mPosition = mTarget - glm::length(mTarget - mPosition) * mForward;
}
inline void setOrientation(float _pitch, float _yaw, float _roll)
{
mPitch = _pitch;
mYaw = _yaw;
mRoll = _roll;
updateLocalCoordinateSystemByOrientation();
}
glm::mat4 getProjectionMatrix() const;
glm::mat4 getViewMatrix() const;
glm::mat4 getInverseViewMatrix() const;
void updateLocalCoordinateSystemByTarget(const glm::vec3& up = glm::vec3(0.0f, 1.0f, 0.0f));
void updateLocalCoordinateSystemByOrientation(bool moveTarget = true);
private:
void updateLocalCoordinateSystemByTarget(const glm::vec3& _up = glm::vec3(0.0f, 1.0f, 0.0f));
void updateLocalCoordinateSystemByOrientation(bool _moveTarget = true);
void updateOrientationByLocalCoordinateSystem();
private:
glm::vec3 mRight;
glm::vec3 mUp;
glm::vec3 mForward;
......
......@@ -50,15 +50,15 @@ glm::mat4 Camera::getInverseViewMatrix(void) const
return mView;
}
void Camera::updateLocalCoordinateSystemByTarget(const glm::vec3& up)
void Camera::updateLocalCoordinateSystemByTarget(const glm::vec3& _up)
{
mForward = glm::normalize( mTarget - mPosition );
mRight = glm::normalize( glm::cross( mForward, up) );
mRight = glm::normalize( glm::cross( mForward, _up) );
mUp = glm::normalize( glm::cross( mRight, mForward) );
}
void Camera::updateLocalCoordinateSystemByOrientation(bool moveTarget)
void Camera::updateLocalCoordinateSystemByOrientation(bool _moveTarget)
{
//Calculate the full rotation in the right order:
//rot => 1. mYaw (y) -> 2. mPitch (x) -> 3. mRoll (z)
......@@ -72,7 +72,7 @@ void Camera::updateLocalCoordinateSystemByOrientation(bool moveTarget)
mUp = rotation * glm::vec3(0.0f, 1.0f, 0.0f);
mForward = rotation * glm::vec3(0.0f, 0.0f, -1.0f);
if(moveTarget)
if(_moveTarget)
{
mTarget = mPosition + (rotation * (mTarget - mPosition));
}
......
Supports Markdown
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