added orbiting camera
This commit is contained in:
parent
839f5253f5
commit
4dc3079fe8
5 changed files with 88 additions and 28 deletions
39
src/OrbitingCamera.cpp
Normal file
39
src/OrbitingCamera.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include "OrbitingCamera.hpp"
|
||||
|
||||
OrbitingCamera::OrbitingCamera(const glm::vec3& target, float distance, const glm::vec2& pitchRange) :
|
||||
target(target), distance(distance), pitchRange(pitchRange)
|
||||
{
|
||||
pitch = pitchRange.x + (pitchRange.y - pitchRange.x) / 2;
|
||||
yaw = 0.0f;
|
||||
}
|
||||
|
||||
void OrbitingCamera::Pan(float amount)
|
||||
{
|
||||
yaw += amount;
|
||||
if (yaw < 0.0f || yaw >= 360.0f)
|
||||
yaw = 0.0f;
|
||||
|
||||
CalculateMatrix();
|
||||
}
|
||||
|
||||
void OrbitingCamera::Tilt(float amount)
|
||||
{
|
||||
pitch += amount;
|
||||
if (pitch < pitchRange.x)
|
||||
pitch = pitchRange.x;
|
||||
else if (pitch > pitchRange.y)
|
||||
pitch = pitchRange.y;
|
||||
|
||||
CalculateMatrix();
|
||||
}
|
||||
|
||||
void OrbitingCamera::CalculateMatrix()
|
||||
{
|
||||
glm::vec3 position = distance * glm::vec3(
|
||||
cos(glm::radians(yaw)) * sin(glm::radians(pitch)),
|
||||
cos(glm::radians(pitch)),
|
||||
sin(glm::radians(yaw)) * sin(glm::radians(pitch))
|
||||
);
|
||||
|
||||
transformation = glm::lookAt(position, target, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue