88 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			88 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
#include "Camera.h"
 | 
						|
 | 
						|
#include "Math/Matrix.h"
 | 
						|
 | 
						|
#include "GL/glfw.h"
 | 
						|
 | 
						|
namespace BlueCore
 | 
						|
{
 | 
						|
 | 
						|
Camera::Camera() :
 | 
						|
	_LookAt (false), _FoV(45.0), _NearPlane(1.0), _FarPlane(15000.0)
 | 
						|
{
 | 
						|
}
 | 
						|
 | 
						|
Camera::~Camera()
 | 
						|
{
 | 
						|
}
 | 
						|
 | 
						|
void Camera::setFoV(Scalar fov)
 | 
						|
{
 | 
						|
	_FoV = fov;
 | 
						|
}
 | 
						|
 | 
						|
void Camera::setNearPlane(Scalar near)
 | 
						|
{
 | 
						|
	_NearPlane = near;
 | 
						|
}
 | 
						|
 | 
						|
void Camera::setFarPlane(Scalar far)
 | 
						|
{
 | 
						|
	_FarPlane = far;
 | 
						|
}
 | 
						|
 | 
						|
void Camera::setPosition(const Vector3& position)
 | 
						|
{
 | 
						|
	_Position = position;
 | 
						|
 | 
						|
	if (_LookAt)
 | 
						|
		updateLookAtRotation();
 | 
						|
}
 | 
						|
 | 
						|
const Vector3& Camera::getPosition()
 | 
						|
{
 | 
						|
	return _Position;
 | 
						|
}
 | 
						|
 | 
						|
void Camera::setRotation(const Quaternion& rotation)
 | 
						|
{
 | 
						|
	_Rotation = rotation;
 | 
						|
}
 | 
						|
 | 
						|
const Quaternion& Camera::getRotation()
 | 
						|
{
 | 
						|
	return _Rotation;
 | 
						|
}
 | 
						|
 | 
						|
Scalar Camera::getNearPlane() const
 | 
						|
{
 | 
						|
	return _NearPlane;
 | 
						|
}
 | 
						|
 | 
						|
Scalar Camera::getFarPlane() const
 | 
						|
{
 | 
						|
	return _FarPlane;
 | 
						|
}
 | 
						|
 | 
						|
Scalar Camera::getFov() const
 | 
						|
{
 | 
						|
	return _FoV;
 | 
						|
}
 | 
						|
 | 
						|
void Camera::lookAt(const Vector3 &point)
 | 
						|
{
 | 
						|
	_LookAt = true;
 | 
						|
	_LookAtPoint = point;
 | 
						|
	_LookAtUp = Vector3(0.0, 1.0, 0.0);
 | 
						|
 | 
						|
	updateLookAtRotation();
 | 
						|
}
 | 
						|
 | 
						|
void Camera::updateLookAtRotation()
 | 
						|
{
 | 
						|
	Matrix3x3 m (_LookAtPoint - _Position, _LookAtUp);
 | 
						|
	_Rotation = m.toQuaternion().inversed();
 | 
						|
}
 | 
						|
 | 
						|
} // namespace BlueCore
 |