mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
changed code style
This commit is contained in:
@@ -4,34 +4,32 @@
|
||||
#include "omath/engines/source_engine/camera.hpp"
|
||||
#include "omath/engines/source_engine/formulas.hpp"
|
||||
|
||||
|
||||
namespace omath::source_engine
|
||||
{
|
||||
|
||||
Camera::Camera(const Vector3<float>& position, const ViewAngles& viewAngles, const projection::ViewPort& viewPort,
|
||||
const projection::FieldOfView& fov, const float near, const float far) :
|
||||
projection::Camera<Mat4x4, ViewAngles>(position, viewAngles, viewPort, fov, near, far)
|
||||
Camera::Camera(const Vector3<float>& position, const ViewAngles& view_angles, const projection::ViewPort& view_port,
|
||||
const projection::FieldOfView& fov, const float near, const float far)
|
||||
: projection::Camera<Mat4X4, ViewAngles>(position, view_angles, view_port, fov, near, far)
|
||||
{
|
||||
}
|
||||
void Camera::LookAt(const Vector3<float>& target)
|
||||
void Camera::look_at(const Vector3<float>& target)
|
||||
{
|
||||
const float distance = m_origin.DistTo(target);
|
||||
const float distance = m_origin.distance_to(target);
|
||||
const auto delta = target - m_origin;
|
||||
|
||||
|
||||
m_viewAngles.pitch = PitchAngle::FromRadians(std::asin(delta.z / distance));
|
||||
m_viewAngles.yaw = -YawAngle::FromRadians(std::atan2(delta.y, delta.x));
|
||||
m_viewAngles.roll = RollAngle::FromRadians(0.f);
|
||||
m_view_angles.pitch = PitchAngle::from_radians(std::asin(delta.z / distance));
|
||||
m_view_angles.yaw = -YawAngle::from_radians(std::atan2(delta.y, delta.x));
|
||||
m_view_angles.roll = RollAngle::from_radians(0.f);
|
||||
}
|
||||
|
||||
Mat4x4 Camera::CalcViewMatrix() const
|
||||
Mat4X4 Camera::calc_view_matrix() const
|
||||
{
|
||||
return source_engine::CalcViewMatrix(m_viewAngles, m_origin);
|
||||
return source_engine::calc_view_matrix(m_view_angles, m_origin);
|
||||
}
|
||||
|
||||
Mat4x4 Camera::CalcProjectionMatrix() const
|
||||
Mat4X4 Camera::calc_projection_matrix() const
|
||||
{
|
||||
return CalcPerspectiveProjectionMatrix(m_fieldOfView.AsDegrees(), m_viewPort.AspectRatio(), m_nearPlaneDistance,
|
||||
m_farPlaneDistance);
|
||||
return calc_perspective_projection_matrix(m_field_of_view.as_degrees(), m_view_port.AspectRatio(),
|
||||
m_near_plane_distance, m_far_plane_distance);
|
||||
}
|
||||
} // namespace omath::source
|
||||
} // namespace omath::source_engine
|
||||
|
||||
@@ -3,50 +3,49 @@
|
||||
//
|
||||
#include <omath/engines/source_engine/formulas.hpp>
|
||||
|
||||
|
||||
namespace omath::source_engine
|
||||
{
|
||||
Vector3<float> ForwardVector(const ViewAngles& angles)
|
||||
Vector3<float> forward_vector(const ViewAngles& angles)
|
||||
{
|
||||
const auto vec = RotationMatrix(angles) * MatColumnFromVector(kAbsForward);
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
|
||||
|
||||
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
||||
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
|
||||
}
|
||||
|
||||
Mat4x4 RotationMatrix(const ViewAngles& angles)
|
||||
Mat4X4 rotation_matrix(const ViewAngles& angles)
|
||||
{
|
||||
return MatRotationAxisZ(angles.yaw) * MatRotationAxisY(angles.pitch) * MatRotationAxisX(angles.roll);
|
||||
return mat_rotation_axis_z(angles.yaw) * mat_rotation_axis_y(angles.pitch) * mat_rotation_axis_x(angles.roll);
|
||||
}
|
||||
|
||||
Vector3<float> RightVector(const ViewAngles& angles)
|
||||
Vector3<float> right_vector(const ViewAngles& angles)
|
||||
{
|
||||
const auto vec = RotationMatrix(angles) * MatColumnFromVector(kAbsRight);
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right);
|
||||
|
||||
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
||||
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
|
||||
}
|
||||
Vector3<float> UpVector(const ViewAngles& angles)
|
||||
Vector3<float> up_vector(const ViewAngles& angles)
|
||||
{
|
||||
const auto vec = RotationMatrix(angles) * MatColumnFromVector(kAbsUp);
|
||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up);
|
||||
|
||||
return {vec.At(0, 0), vec.At(1, 0), vec.At(2, 0)};
|
||||
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
|
||||
}
|
||||
|
||||
Mat4x4 CalcViewMatrix(const ViewAngles& angles, const Vector3<float>& cam_origin)
|
||||
Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin)
|
||||
{
|
||||
return MatCameraView(ForwardVector(angles), RightVector(angles), UpVector(angles), cam_origin);
|
||||
return mat_camera_view(forward_vector(angles), right_vector(angles), up_vector(angles), cam_origin);
|
||||
}
|
||||
|
||||
Mat4x4 CalcPerspectiveProjectionMatrix(const float fieldOfView, const float aspectRatio, const float near,
|
||||
const float far)
|
||||
Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near,
|
||||
const float far)
|
||||
{
|
||||
// NOTE: Need magic number to fix fov calculation, since source inherit Quake proj matrix calculation
|
||||
constexpr auto kMultiplyFactor = 0.75f;
|
||||
constexpr auto k_multiply_factor = 0.75f;
|
||||
|
||||
const float fovHalfTan = std::tan(angles::DegreesToRadians(fieldOfView) / 2.f) * kMultiplyFactor;
|
||||
const float fov_half_tan = std::tan(angles::degrees_to_radians(field_of_view) / 2.f) * k_multiply_factor;
|
||||
|
||||
return {
|
||||
{1.f / (aspectRatio * fovHalfTan), 0, 0, 0},
|
||||
{0, 1.f / (fovHalfTan), 0, 0},
|
||||
{1.f / (aspect_ratio * fov_half_tan), 0, 0, 0},
|
||||
{0, 1.f / (fov_half_tan), 0, 0},
|
||||
{0, 0, (far + near) / (far - near), -(2.f * far * near) / (far - near)},
|
||||
{0, 0, 1, 0},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user