bluecore/engine/Camera.cpp

88 rindas
1.2 KiB
C++

2008-01-16 12:45:17 +01:00
#include "Camera.h"
#include "Math/Matrix.h"
#include "GL/glfw.h"
namespace BlueCore
{
2008-01-20 11:16:37 +01:00
Camera::Camera() :
_LookAt (false), _FoV(45.0), _NearPlane(1.0), _FarPlane(15000.0)
2008-01-16 12:45:17 +01:00
{
}
Camera::~Camera()
{
}
void Camera::setFoV(Scalar fov)
{
2008-01-17 17:42:24 +01:00
_FoV = fov;
2008-01-16 12:45:17 +01:00
}
void Camera::setNearPlane(Scalar near)
{
2008-01-17 17:42:24 +01:00
_NearPlane = near;
2008-01-16 12:45:17 +01:00
}
void Camera::setFarPlane(Scalar far)
{
2008-01-17 17:42:24 +01:00
_FarPlane = far;
2008-01-16 12:45:17 +01:00
}
void Camera::setPosition(const Vector3& position)
{
2008-01-17 17:42:24 +01:00
_Position = position;
2008-01-20 11:16:37 +01:00
if (_LookAt)
updateLookAtRotation();
2008-01-16 12:45:17 +01:00
}
const Vector3& Camera::getPosition()
{
2008-01-17 17:42:24 +01:00
return _Position;
2008-01-16 12:45:17 +01:00
}
void Camera::setRotation(const Quaternion& rotation)
{
2008-01-17 17:42:24 +01:00
_Rotation = rotation;
}
const Quaternion& Camera::getRotation()
{
return _Rotation;
2008-01-16 12:45:17 +01:00
}
2008-01-17 17:42:24 +01:00
Scalar Camera::getNearPlane() const
{
return _NearPlane;
}
Scalar Camera::getFarPlane() const
{
return _FarPlane;
}
Scalar Camera::getFov() const
{
return _FoV;
2008-01-16 12:45:17 +01:00
}
2008-01-20 11:16:37 +01:00
void Camera::lookAt(const Vector3 &point)
{
_LookAt = true;
_LookAtPoint = point;
_LookAtUp = Vector3(0.0, 1.0, 0.0);
updateLookAtRotation();
}
2008-01-16 12:45:17 +01:00
2008-01-20 11:16:37 +01:00
void Camera::updateLookAtRotation()
{
Matrix3x3 m (_LookAtPoint - _Position, _LookAtUp);
_Rotation = m.toQuaternion().inversed();
}
} // namespace BlueCore