Selaa lähdekoodia

camera: const correctness for all getters.

undefined
Sam Hocevar 11 vuotta sitten
vanhempi
commit
b91c177125
2 muutettua tiedostoa jossa 26 lisäystä ja 26 poistoa
  1. +9
    -9
      src/camera.cpp
  2. +17
    -17
      src/camera.h

+ 9
- 9
src/camera.cpp Näytä tiedosto

@@ -82,7 +82,7 @@ void Camera::SetView(vec3 pos, quat rot)
m_position = pos;
}

mat4 Camera::GetView()
mat4 Camera::GetView() const
{
return m_view_matrix;
}
@@ -119,7 +119,7 @@ void Camera::SetProjection(float fov, float near, float far, float screen_size,
SetProjection(screen_scale * mat4::ortho(screen_size, screen_size * screen_ratio, m_near, m_far));
}

mat4 Camera::GetProjection()
mat4 Camera::GetProjection() const
{
return m_proj_matrix;
}
@@ -197,39 +197,39 @@ void Camera::SetRotation(quat rot)
}

//--
vec3 Camera::GetPosition()
vec3 Camera::GetPosition() const
{
return m_position;
}

vec3 Camera::GetTarget()
vec3 Camera::GetTarget() const
{
return m_position + (inverse(m_view_matrix) * vec4(0.f, 0.f, -max(m_target_distance, 1.f), 0.f)).xyz;
}

vec3 Camera::GetUp()
vec3 Camera::GetUp() const
{
return (inverse(m_view_matrix) * vec4(0.f, 1.f, 0.f, 0.f)).xyz;
}

vec3 Camera::GetRotationEuler()
vec3 Camera::GetRotationEuler() const
{
return vec3::toeuler_zyx(GetRotation());
}

quat Camera::GetRotation()
quat Camera::GetRotation() const
{
return quat(inverse(m_view_matrix));
}

// Calculate the frustum height at a given distance from the camera.
float Camera::GetFrustumHeightAtDistance(float distance, float fov)
float Camera::GetFrustumHeightAtDistance(float distance, float fov) const
{
return 2.f * distance * lol::tan(fov * .5f * (F_PI / 180.f));
}

// Calculate the FOV needed to get a given frustum height at a given distance.
float Camera::GetFOVForHeightAndDistance(float distance, float height)
float Camera::GetFOVForHeightAndDistance(float distance, float height) const
{
return 2.f * lol::atan(height * .5f / distance) * (180.f / F_PI);
}


+ 17
- 17
src/camera.h Näytä tiedosto

@@ -35,7 +35,7 @@ public:
void SetView(vec3 pos, vec3 rot);
void SetView(vec3 pos, quat rot);

mat4 GetView();
mat4 GetView() const;

//Projections functions
//private:
@@ -44,7 +44,7 @@ public:
void SetProjection(float fov, float near, float far);
void SetProjection(float fov, float near, float far, float screen_size, float screen_ratio);

mat4 GetProjection();
mat4 GetProjection() const;

//Projections manipulation functions
void SetFov(float fov);
@@ -56,14 +56,14 @@ public:
void UseShift(bool should_shift);
void UseTarget(bool use_target);

float GetFov() { return m_fov; }
float GetScreenSize() { return m_screen_size; }
float GetScreenRatio() { return m_screen_ratio; }
float GetNear() { return m_near; }
float GetFar() { return m_far; }
vec2 GetScreenScale() { return m_screen_scale; }
bool IsShifted() { return m_is_shifted; }
bool IsTargeting() { return (m_target_distance != .0f); }
float GetFov() const { return m_fov; }
float GetScreenSize() const { return m_screen_size; }
float GetScreenRatio() const { return m_screen_ratio; }
float GetNear() const { return m_near; }
float GetFar() const { return m_far; }
vec2 GetScreenScale() const { return m_screen_scale; }
bool IsShifted() const { return m_is_shifted; }
bool IsTargeting() const { return (m_target_distance != .0f); }

//camera manipulation Functions
void SetPosition(vec3 pos, bool keep_target=false);
@@ -71,15 +71,15 @@ public:
void SetRotation(vec3 rot);
void SetRotation(quat rot);

vec3 GetPosition();
vec3 GetTarget();
vec3 GetUp();
vec3 GetRotationEuler();
quat GetRotation();
vec3 GetPosition() const;
vec3 GetTarget() const;
vec3 GetUp() const;
vec3 GetRotationEuler() const;
quat GetRotation() const;

//Convenience functions
float GetFrustumHeightAtDistance(float distance, float fov);
float GetFOVForHeightAndDistance(float distance, float height);
float GetFrustumHeightAtDistance(float distance, float fov) const;
float GetFOVForHeightAndDistance(float distance, float height) const;

protected:
virtual void TickGame(float seconds);


Ladataan…
Peruuta
Tallenna