Camera now returns a viewing vector.
This commit is contained in:
parent
38b6d33aec
commit
a19039426c
18
camera.cc
18
camera.cc
@ -19,6 +19,7 @@ float Camera::getDistance() {
|
||||
|
||||
void Camera::setDistance(float distance) {
|
||||
this->distance = distance;
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
glm::vec2 Camera::getRotation() {
|
||||
@ -27,8 +28,23 @@ glm::vec2 Camera::getRotation() {
|
||||
|
||||
void Camera::setRotation(glm::vec2 rotation) {
|
||||
this->rotation = rotation;
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
void Camera::updateRotation(glm::vec2 rotation) {
|
||||
this->rotation += rotation;;
|
||||
this->rotation += rotation;
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -13,9 +13,12 @@ class Camera {
|
||||
glm::vec2 getRotation();
|
||||
void setRotation(glm::vec2 rotation);
|
||||
void updateRotation(glm::vec2 rotation); //adds to current rotation
|
||||
glm::vec3 getVector();
|
||||
private:
|
||||
void updatePosition();
|
||||
float distance;
|
||||
glm::vec2 rotation;
|
||||
glm::vec3 vector;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -161,11 +161,7 @@ glm::mat4 Graphics::buildFrustum( float phiInDegree, float _near, float _far, fl
|
||||
}
|
||||
|
||||
glm::mat4 Graphics::buildViewMatrix(Level* level) {
|
||||
glm::vec4 cameraVector = glm::vec4(0.0f, 0.0f, level->getCamera().getDistance(), 0.0f);
|
||||
// rotate vector
|
||||
glm::mat4 rotationMatrix =
|
||||
glm::rotate<float>(level->getCamera().getRotation()[1], glm::vec3(0.0f, 1.0f, 0.0f)) *glm::rotate<float>(level->getCamera().getRotation()[0], glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
cameraVector = rotationMatrix * cameraVector;
|
||||
//construct lookAt (cameraPosition = cameraCenter + cameraVector
|
||||
return glm::lookAt(level->getCameraCenter()->getPosition() + glm::vec3(cameraVector), level->getCameraCenter()->getPosition(), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
return glm::lookAt((level->getCameraCenter()->getPosition() + level->getCamera()->getVector()),
|
||||
level->getCameraCenter()->getPosition(), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user