2014-11-13 16:17:46 +00:00
|
|
|
#include "camera.hh"
|
|
|
|
|
2014-11-14 17:31:26 +00:00
|
|
|
Camera::Camera(glm::vec2 rotation, float distance) {
|
2014-11-13 16:17:46 +00:00
|
|
|
this->rotation = rotation;
|
|
|
|
this->distance = distance;
|
2015-02-13 14:46:00 +00:00
|
|
|
this->setIsPhysicsCamera(true);
|
2014-11-13 16:17:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Camera::Camera() {
|
2015-03-24 18:08:49 +00:00
|
|
|
Camera(glm::vec2(0.0f, 0.0f), 5.0f);
|
2014-11-13 16:17:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Camera::~Camera() {
|
|
|
|
}
|
|
|
|
|
|
|
|
float Camera::getDistance() {
|
|
|
|
return distance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Camera::setDistance(float distance) {
|
|
|
|
this->distance = distance;
|
2014-11-17 12:29:41 +00:00
|
|
|
updatePosition();
|
2014-11-13 16:17:46 +00:00
|
|
|
}
|
|
|
|
|
2014-11-14 17:31:26 +00:00
|
|
|
glm::vec2 Camera::getRotation() {
|
2014-11-13 16:17:46 +00:00
|
|
|
return rotation;
|
|
|
|
}
|
|
|
|
|
2014-11-14 17:31:26 +00:00
|
|
|
void Camera::setRotation(glm::vec2 rotation) {
|
2014-11-13 17:17:58 +00:00
|
|
|
this->rotation = rotation;
|
2014-11-17 12:29:41 +00:00
|
|
|
updatePosition();
|
2014-11-13 17:17:58 +00:00
|
|
|
}
|
|
|
|
|
2015-02-13 14:46:00 +00:00
|
|
|
|
|
|
|
bool Camera::getIsPhysicsCamera()
|
|
|
|
{
|
|
|
|
return usePhysicsCamera;
|
|
|
|
}
|
|
|
|
void Camera::setIsPhysicsCamera(bool val)
|
|
|
|
{
|
|
|
|
usePhysicsCamera = val;
|
|
|
|
}
|
2014-11-14 17:31:26 +00:00
|
|
|
void Camera::updateRotation(glm::vec2 rotation) {
|
2014-11-14 21:55:29 +00:00
|
|
|
if((this->rotation.x + rotation.x) >= 1.57f) {
|
|
|
|
this->rotation.x = 1.57;
|
|
|
|
this->rotation.y += rotation.y;
|
|
|
|
}
|
|
|
|
else if ((this->rotation.x + rotation.x) <= -1.57f) {
|
|
|
|
this->rotation.x = -1.57f;
|
|
|
|
this->rotation.y += rotation.y;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this-> rotation += rotation;
|
|
|
|
}
|
2014-11-17 12:31:01 +00:00
|
|
|
updatePosition();
|
2014-11-13 16:17:46 +00:00
|
|
|
}
|
2014-11-15 13:26:17 +00:00
|
|
|
|
|
|
|
void Camera:: updateDistance(float distance) {
|
2015-01-20 07:45:52 +00:00
|
|
|
if (this->distance + distance <= 2.5f) {
|
|
|
|
this->distance = 2.5f;
|
2014-11-15 13:26:17 +00:00
|
|
|
}
|
2015-03-06 16:45:51 +00:00
|
|
|
else if (this->distance + distance >= 15.0f) {
|
|
|
|
this->distance = 15.f;
|
2014-11-15 13:26:17 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
this->distance += distance;
|
|
|
|
}
|
2014-11-17 12:29:41 +00:00
|
|
|
updatePosition();
|
2014-11-13 16:17:46 +00:00
|
|
|
}
|
2014-11-17 12:29:41 +00:00
|
|
|
|
2015-01-19 15:51:35 +00:00
|
|
|
void Camera::setPosition(glm::vec3 pos)
|
|
|
|
{
|
|
|
|
position = pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
glm::vec3 Camera::getPosition()
|
|
|
|
{
|
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Camera::setDirection(glm::vec3 dir)
|
|
|
|
{
|
|
|
|
direction = dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
glm::vec3 Camera::getDirection()
|
|
|
|
{
|
|
|
|
return direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-17 12:29:41 +00:00
|
|
|
void Camera::updatePosition() {
|
|
|
|
glm::vec4 cameraVector = glm::vec4(0.0f, 0.0f, distance, 0.0f);
|
|
|
|
// rotate vector
|
|
|
|
glm::mat4 rotationMatrix =
|
|
|
|
glm::rotate<float>(rotation[1], glm::vec3(0.0f, 1.0f, 0.0f)) * glm::rotate<float>(rotation[0], glm::vec3(1.0f, 0.0f, 0.0f));
|
|
|
|
this->vector = glm::vec3(rotationMatrix * cameraVector);
|
|
|
|
}
|
|
|
|
|
|
|
|
glm::vec3 Camera::getVector() {
|
|
|
|
return vector;
|
|
|
|
}
|
|
|
|
|