Skip to content
Snippets Groups Projects
Commit ec856073 authored by Robert Menzel's avatar Robert Menzel
Browse files
parents d3706471 419c57e5
Branches
No related tags found
No related merge requests found
......@@ -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,76 @@ 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 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 float getAspectRatio (void) const { return (float)mWidth / (float)mHeight; }
inline const glm::vec3& getUpDirection (void) const { return mUp; }
inline const glm::vec3& getRightDirection (void) const { return mRight; }
inline const glm::vec3& getForwardDirection (void) const { return mForward; }
inline int_t getWidth (void) const { return mWidth; }
inline int_t getHeight (void) const { return mHeight; }
inline float getFOV (void) const { return mFOV; }
inline float getNear (void) const { return mNear; }
inline float getFar (void) const { return mFar; }
inline float getPitch (void) const { return mPitch; }
inline float getYaw (void) const { return mYaw; }
inline float getRoll (void) const { return mRoll; }
inline const glm::vec3& getPosition (void) const { return mPosition; }
inline const glm::vec3& getTarget (void) 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 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();
mTarget = mPosition + glm::length(mTarget - mPosition) * mForward;
}
inline void setYaw(float _yaw)
{
mYaw = _yaw;
updateLocalCoordinateSystemByOrientation();
mTarget = mPosition + glm::length(mTarget - mPosition) * mForward;
}
inline void setRoll(float _roll)
{
mRoll = _roll;
}
inline void setPitchAroundTarget(float pitch)
{
......@@ -120,15 +164,24 @@ public:
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);
void updateOrientationByLocalCoordinateSystem();
private:
void updateLocalCoordinateSystemByTarget(const glm::vec3& _up = glm::vec3(0.0f, 1.0f, 0.0f));
void updateLocalCoordinateSystemByOrientation(void);
void updateOrientationByLocalCoordinateSystem(void);
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(void)
{
//Calculate the full rotation in the right order:
//rot => 1. mYaw (y) -> 2. mPitch (x) -> 3. mRoll (z)
......@@ -71,11 +71,6 @@ void Camera::updateLocalCoordinateSystemByOrientation(bool moveTarget)
mRight = rotation * glm::vec3(1.0f, 0.0f, 0.0f);
mUp = rotation * glm::vec3(0.0f, 1.0f, 0.0f);
mForward = rotation * glm::vec3(0.0f, 0.0f, -1.0f);
if(moveTarget)
{
mTarget = mPosition + (rotation * (mTarget - mPosition));
}
}
void Camera::updateOrientationByLocalCoordinateSystem(void)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment