88 lines
1.5 KiB
C++
88 lines
1.5 KiB
C++
#include "..\header\Camera.h"
|
|
#include <glm\gtc\matrix_transform.hpp>
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
// constructor/destructor
|
|
|
|
Camera::Camera(int width, int height):
|
|
fFOV(45),
|
|
fMinView(0.1f),
|
|
fMaxView(100.0f),
|
|
iWidth(width),
|
|
iHeight(height),
|
|
dTranslationX(0),
|
|
dTranslationY(0),
|
|
dTranslationZ(5)
|
|
{
|
|
}
|
|
|
|
|
|
Camera::~Camera()
|
|
{
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
// private functions
|
|
|
|
void Camera::updateMatrices()
|
|
{
|
|
m4x4Projection = glm::perspective(fFOV, float(iWidth) / float(iHeight), fMinView, fMaxView);
|
|
m4x4View = glm::lookAt(
|
|
glm::vec3(dTranslationX, dTranslationY, dTranslationZ),
|
|
glm::vec3(dTranslationX, dTranslationY, dTranslationZ - 1),
|
|
glm::vec3(0, 1, 0)
|
|
);
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
// public getter
|
|
|
|
glm::mat4 Camera::getMatrix()
|
|
{
|
|
updateMatrices();
|
|
return m4x4Projection * m4x4View;
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
// public setter
|
|
|
|
void Camera::setFOV(float fov)
|
|
{
|
|
fFOV = fov;
|
|
}
|
|
|
|
void Camera::setMinView(float distance)
|
|
{
|
|
fMinView = distance;
|
|
}
|
|
|
|
void Camera::setMaxView(float distance)
|
|
{
|
|
fMaxView = distance;
|
|
}
|
|
|
|
void Camera::setSize(int width, int height)
|
|
{
|
|
iWidth = width;
|
|
iHeight = height;
|
|
}
|
|
|
|
void Camera::add2x(double value)
|
|
{
|
|
dTranslationX += value;
|
|
}
|
|
|
|
void Camera::add2y(double value)
|
|
{
|
|
dTranslationY += value;
|
|
}
|
|
|
|
void Camera::add2z(double value)
|
|
{
|
|
dTranslationZ += value;
|
|
}
|