mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
added more noexcept
This commit is contained in:
@@ -13,5 +13,5 @@ namespace omath::primitives
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
std::array<Triangle<Vector3<float>>, 12> create_box(const Vector3<float>& top, const Vector3<float>& bottom,
|
std::array<Triangle<Vector3<float>>, 12> create_box(const Vector3<float>& top, const Vector3<float>& bottom,
|
||||||
const Vector3<float>& dir_forward, const Vector3<float>& dir_right,
|
const Vector3<float>& dir_forward, const Vector3<float>& dir_right,
|
||||||
float ratio = 4.f);
|
float ratio = 4.f) noexcept;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ namespace omath::collision
|
|||||||
bool infinite_length = false;
|
bool infinite_length = false;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Vector3<float> direction_vector() const;
|
Vector3<float> direction_vector() const noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Vector3<float> direction_vector_normalized() const;
|
Vector3<float> direction_vector_normalized() const noexcept;
|
||||||
};
|
};
|
||||||
class LineTracer
|
class LineTracer
|
||||||
{
|
{
|
||||||
@@ -27,11 +27,11 @@ namespace omath::collision
|
|||||||
LineTracer() = delete;
|
LineTracer() = delete;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static bool can_trace_line(const Ray& ray, const Triangle<Vector3<float>>& triangle);
|
static bool can_trace_line(const Ray& ray, const Triangle<Vector3<float>>& triangle) noexcept;
|
||||||
|
|
||||||
// Realization of Möller–Trumbore intersection algorithm
|
// Realization of Möller–Trumbore intersection algorithm
|
||||||
// https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm
|
// https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static Vector3<float> get_ray_hit_point(const Ray& ray, const Triangle<Vector3<float>>& triangle);
|
static Vector3<float> get_ray_hit_point(const Ray& ray, const Triangle<Vector3<float>>& triangle) noexcept;
|
||||||
};
|
};
|
||||||
} // namespace omath::collision
|
} // namespace omath::collision
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace omath::iw_engine
|
|||||||
void look_at(const Vector3<float>& target) override;
|
void look_at(const Vector3<float>& target) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
[[nodiscard]] Mat4X4 calc_view_matrix() const override;
|
[[nodiscard]] Mat4X4 calc_view_matrix() const noexcept override;
|
||||||
[[nodiscard]] Mat4X4 calc_projection_matrix() const override;
|
[[nodiscard]] Mat4X4 calc_projection_matrix() const noexcept override;
|
||||||
};
|
};
|
||||||
} // namespace omath::iw_engine
|
} // namespace omath::iw_engine
|
||||||
@@ -13,7 +13,7 @@ namespace omath::opengl_engine
|
|||||||
Camera(const Vector3<float>& position, const ViewAngles& view_angles, const projection::ViewPort& view_port,
|
Camera(const Vector3<float>& position, const ViewAngles& view_angles, const projection::ViewPort& view_port,
|
||||||
const Angle<float, 0.f, 180.f, AngleFlags::Clamped>& fov, float near, float far);
|
const Angle<float, 0.f, 180.f, AngleFlags::Clamped>& fov, float near, float far);
|
||||||
void look_at(const Vector3<float>& target) override;
|
void look_at(const Vector3<float>& target) override;
|
||||||
[[nodiscard]] Mat4X4 calc_view_matrix() const override;
|
[[nodiscard]] Mat4X4 calc_view_matrix() const noexcept override;
|
||||||
[[nodiscard]] Mat4X4 calc_projection_matrix() const override;
|
[[nodiscard]] Mat4X4 calc_projection_matrix() const noexcept override;
|
||||||
};
|
};
|
||||||
} // namespace omath::opengl_engine
|
} // namespace omath::opengl_engine
|
||||||
@@ -8,19 +8,19 @@
|
|||||||
namespace omath::opengl_engine
|
namespace omath::opengl_engine
|
||||||
{
|
{
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Vector3<float> forward_vector(const ViewAngles& angles);
|
Vector3<float> forward_vector(const ViewAngles& angles) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Vector3<float> right_vector(const ViewAngles& angles);
|
Vector3<float> right_vector(const ViewAngles& angles) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Vector3<float> up_vector(const ViewAngles& angles);
|
Vector3<float> up_vector(const ViewAngles& angles) noexcept;
|
||||||
|
|
||||||
[[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin);
|
[[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Mat4X4 rotation_matrix(const ViewAngles& angles);
|
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far);
|
Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far) noexcept;
|
||||||
} // namespace omath::opengl_engine
|
} // namespace omath::opengl_engine
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace omath::source_engine
|
|||||||
void look_at(const Vector3<float>& target) override;
|
void look_at(const Vector3<float>& target) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
[[nodiscard]] Mat4X4 calc_view_matrix() const override;
|
[[nodiscard]] Mat4X4 calc_view_matrix() const noexcept override;
|
||||||
[[nodiscard]] Mat4X4 calc_projection_matrix() const override;
|
[[nodiscard]] Mat4X4 calc_projection_matrix() const noexcept override;
|
||||||
};
|
};
|
||||||
} // namespace omath::source_engine
|
} // namespace omath::source_engine
|
||||||
@@ -7,19 +7,19 @@
|
|||||||
namespace omath::source_engine
|
namespace omath::source_engine
|
||||||
{
|
{
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Vector3<float> forward_vector(const ViewAngles& angles);
|
Vector3<float> forward_vector(const ViewAngles& angles) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Mat4X4 rotation_matrix(const ViewAngles& angles);
|
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Vector3<float> right_vector(const ViewAngles& angles);
|
Vector3<float> right_vector(const ViewAngles& angles) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Vector3<float> up_vector(const ViewAngles& angles);
|
Vector3<float> up_vector(const ViewAngles& angles) noexcept;
|
||||||
|
|
||||||
[[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin);
|
[[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far);
|
Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far) noexcept;
|
||||||
} // namespace omath::source_engine
|
} // namespace omath::source_engine
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace omath::unity_engine
|
|||||||
void look_at(const Vector3<float>& target) override;
|
void look_at(const Vector3<float>& target) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
[[nodiscard]] Mat4X4 calc_view_matrix() const override;
|
[[nodiscard]] Mat4X4 calc_view_matrix() const noexcept override;
|
||||||
[[nodiscard]] Mat4X4 calc_projection_matrix() const override;
|
[[nodiscard]] Mat4X4 calc_projection_matrix() const noexcept override;
|
||||||
};
|
};
|
||||||
} // namespace omath::unity_engine
|
} // namespace omath::unity_engine
|
||||||
@@ -8,19 +8,19 @@
|
|||||||
namespace omath::unity_engine
|
namespace omath::unity_engine
|
||||||
{
|
{
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Vector3<float> forward_vector(const ViewAngles& angles);
|
Vector3<float> forward_vector(const ViewAngles& angles) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Vector3<float> right_vector(const ViewAngles& angles);
|
Vector3<float> right_vector(const ViewAngles& angles) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Vector3<float> up_vector(const ViewAngles& angles);
|
Vector3<float> up_vector(const ViewAngles& angles) noexcept;
|
||||||
|
|
||||||
[[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin);
|
[[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Mat4X4 rotation_matrix(const ViewAngles& angles);
|
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far);
|
Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far) noexcept;
|
||||||
} // namespace omath::unity_engine
|
} // namespace omath::unity_engine
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ namespace omath::projectile_prediction
|
|||||||
class ProjPredEngineAvx2 final : public ProjPredEngine
|
class ProjPredEngineAvx2 final : public ProjPredEngine
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
[[nodiscard]] std::optional<Vector3<float>> maybe_calculate_aim_point(const Projectile& projectile,
|
[[nodiscard]] std::optional<Vector3<float>>
|
||||||
const Target& target) const override;
|
maybe_calculate_aim_point(const Projectile& projectile, const Target& target) const override;
|
||||||
|
|
||||||
ProjPredEngineAvx2(float gravity_constant, float simulation_time_step, float maximum_simulation_time);
|
ProjPredEngineAvx2(float gravity_constant, float simulation_time_step, float maximum_simulation_time);
|
||||||
~ProjPredEngineAvx2() override = default;
|
~ProjPredEngineAvx2() override = default;
|
||||||
|
|||||||
@@ -29,11 +29,12 @@ namespace omath::projectile_prediction
|
|||||||
const float m_distance_tolerance;
|
const float m_distance_tolerance;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
std::optional<float> maybe_calculate_projectile_launch_pitch_angle(const Projectile& projectile,
|
std::optional<float>
|
||||||
const Vector3<float>& target_position) const;
|
maybe_calculate_projectile_launch_pitch_angle(const Projectile& projectile,
|
||||||
|
const Vector3<float>& target_position) const noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
bool is_projectile_reached_target(const Vector3<float>& target_position, const Projectile& projectile,
|
bool is_projectile_reached_target(const Vector3<float>& target_position, const Projectile& projectile,
|
||||||
float pitch, float time) const;
|
float pitch, float time) const noexcept;
|
||||||
};
|
};
|
||||||
} // namespace omath::projectile_prediction
|
} // namespace omath::projectile_prediction
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace omath::projectile_prediction
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Vector3<float> predict_position(float pitch, float yaw, float time, float gravity) const;
|
Vector3<float> predict_position(float pitch, float yaw, float time, float gravity) const noexcept;
|
||||||
|
|
||||||
Vector3<float> m_origin;
|
Vector3<float> m_origin;
|
||||||
float m_launch_speed{};
|
float m_launch_speed{};
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace omath::projectile_prediction
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr Vector3<float> predict_position(const float time, const float gravity) const
|
constexpr Vector3<float> predict_position(const float time, const float gravity) const noexcept
|
||||||
{
|
{
|
||||||
auto predicted = m_origin + m_velocity * time;
|
auto predicted = m_origin + m_velocity * time;
|
||||||
|
|
||||||
|
|||||||
@@ -41,9 +41,9 @@ namespace omath::projection
|
|||||||
protected:
|
protected:
|
||||||
virtual void look_at(const Vector3<float>& target) = 0;
|
virtual void look_at(const Vector3<float>& target) = 0;
|
||||||
|
|
||||||
[[nodiscard]] virtual Mat4X4Type calc_view_matrix() const = 0;
|
[[nodiscard]] virtual Mat4X4Type calc_view_matrix() const noexcept = 0;
|
||||||
|
|
||||||
[[nodiscard]] virtual Mat4X4Type calc_projection_matrix() const = 0;
|
[[nodiscard]] virtual Mat4X4Type calc_projection_matrix() const noexcept = 0;
|
||||||
|
|
||||||
[[nodiscard]] Mat4X4Type calc_view_projection_matrix() const noexcept
|
[[nodiscard]] Mat4X4Type calc_view_projection_matrix() const noexcept
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ namespace omath::primitives
|
|||||||
{
|
{
|
||||||
std::array<Triangle<Vector3<float>>, 12> create_box(const Vector3<float>& top, const Vector3<float>& bottom,
|
std::array<Triangle<Vector3<float>>, 12> create_box(const Vector3<float>& top, const Vector3<float>& bottom,
|
||||||
const Vector3<float>& dir_forward,
|
const Vector3<float>& dir_forward,
|
||||||
const Vector3<float>& dir_right, const float ratio)
|
const Vector3<float>& dir_right, const float ratio) noexcept
|
||||||
{
|
{
|
||||||
const auto height = top.distance_to(bottom);
|
const auto height = top.distance_to(bottom);
|
||||||
const auto side_size = height / ratio;
|
const auto side_size = height / ratio;
|
||||||
|
|||||||
@@ -5,21 +5,21 @@
|
|||||||
|
|
||||||
namespace omath::collision
|
namespace omath::collision
|
||||||
{
|
{
|
||||||
bool LineTracer::can_trace_line(const Ray& ray, const Triangle<Vector3<float>>& triangle)
|
bool LineTracer::can_trace_line(const Ray& ray, const Triangle<Vector3<float>>& triangle) noexcept
|
||||||
{
|
{
|
||||||
return get_ray_hit_point(ray, triangle) == ray.end;
|
return get_ray_hit_point(ray, triangle) == ray.end;
|
||||||
}
|
}
|
||||||
Vector3<float> Ray::direction_vector() const
|
Vector3<float> Ray::direction_vector() const noexcept
|
||||||
{
|
{
|
||||||
return end - start;
|
return end - start;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3<float> Ray::direction_vector_normalized() const
|
Vector3<float> Ray::direction_vector_normalized() const noexcept
|
||||||
{
|
{
|
||||||
return direction_vector().normalized();
|
return direction_vector().normalized();
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3<float> LineTracer::get_ray_hit_point(const Ray& ray, const Triangle<Vector3<float>>& triangle)
|
Vector3<float> LineTracer::get_ray_hit_point(const Ray& ray, const Triangle<Vector3<float>>& triangle) noexcept
|
||||||
{
|
{
|
||||||
constexpr float k_epsilon = std::numeric_limits<float>::epsilon();
|
constexpr float k_epsilon = std::numeric_limits<float>::epsilon();
|
||||||
|
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ namespace omath::iw_engine
|
|||||||
m_view_angles.yaw = -YawAngle::from_radians(std::atan2(delta.y, delta.x));
|
m_view_angles.yaw = -YawAngle::from_radians(std::atan2(delta.y, delta.x));
|
||||||
m_view_angles.roll = RollAngle::from_radians(0.f);
|
m_view_angles.roll = RollAngle::from_radians(0.f);
|
||||||
}
|
}
|
||||||
Mat4X4 Camera::calc_view_matrix() const
|
Mat4X4 Camera::calc_view_matrix() const noexcept
|
||||||
{
|
{
|
||||||
return iw_engine::calc_view_matrix(m_view_angles, m_origin);
|
return iw_engine::calc_view_matrix(m_view_angles, m_origin);
|
||||||
}
|
}
|
||||||
Mat4X4 Camera::calc_projection_matrix() const
|
Mat4X4 Camera::calc_projection_matrix() const noexcept
|
||||||
{
|
{
|
||||||
return calc_perspective_projection_matrix(m_field_of_view.as_degrees(), m_view_port.aspect_ratio(),
|
return calc_perspective_projection_matrix(m_field_of_view.as_degrees(), m_view_port.aspect_ratio(),
|
||||||
m_near_plane_distance, m_far_plane_distance);
|
m_near_plane_distance, m_far_plane_distance);
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ namespace omath::opengl_engine
|
|||||||
m_view_angles.yaw = -YawAngle::from_radians(std::atan2(delta.y, delta.x));
|
m_view_angles.yaw = -YawAngle::from_radians(std::atan2(delta.y, delta.x));
|
||||||
m_view_angles.roll = RollAngle::from_radians(0.f);
|
m_view_angles.roll = RollAngle::from_radians(0.f);
|
||||||
}
|
}
|
||||||
Mat4X4 Camera::calc_view_matrix() const
|
Mat4X4 Camera::calc_view_matrix() const noexcept
|
||||||
{
|
{
|
||||||
return opengl_engine::calc_view_matrix(m_view_angles, m_origin);
|
return opengl_engine::calc_view_matrix(m_view_angles, m_origin);
|
||||||
}
|
}
|
||||||
Mat4X4 Camera::calc_projection_matrix() const
|
Mat4X4 Camera::calc_projection_matrix() const noexcept
|
||||||
{
|
{
|
||||||
return calc_perspective_projection_matrix(m_field_of_view.as_degrees(), m_view_port.aspect_ratio(),
|
return calc_perspective_projection_matrix(m_field_of_view.as_degrees(), m_view_port.aspect_ratio(),
|
||||||
m_near_plane_distance, m_far_plane_distance);
|
m_near_plane_distance, m_far_plane_distance);
|
||||||
|
|||||||
@@ -6,39 +6,39 @@
|
|||||||
namespace omath::opengl_engine
|
namespace omath::opengl_engine
|
||||||
{
|
{
|
||||||
|
|
||||||
Vector3<float> forward_vector(const ViewAngles& angles)
|
Vector3<float> forward_vector(const ViewAngles& angles) noexcept
|
||||||
{
|
{
|
||||||
const auto vec
|
const auto vec
|
||||||
= rotation_matrix(angles) * mat_column_from_vector<float, MatStoreType::COLUMN_MAJOR>(k_abs_forward);
|
= rotation_matrix(angles) * mat_column_from_vector<float, MatStoreType::COLUMN_MAJOR>(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)};
|
||||||
}
|
}
|
||||||
Vector3<float> right_vector(const ViewAngles& angles)
|
Vector3<float> right_vector(const ViewAngles& angles) noexcept
|
||||||
{
|
{
|
||||||
const auto vec
|
const auto vec
|
||||||
= rotation_matrix(angles) * mat_column_from_vector<float, MatStoreType::COLUMN_MAJOR>(k_abs_right);
|
= rotation_matrix(angles) * mat_column_from_vector<float, MatStoreType::COLUMN_MAJOR>(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> up_vector(const ViewAngles& angles)
|
Vector3<float> up_vector(const ViewAngles& angles) noexcept
|
||||||
{
|
{
|
||||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector<float, MatStoreType::COLUMN_MAJOR>(k_abs_up);
|
const auto vec = rotation_matrix(angles) * mat_column_from_vector<float, MatStoreType::COLUMN_MAJOR>(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 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin)
|
Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||||
{
|
{
|
||||||
return mat_camera_view<float, MatStoreType::COLUMN_MAJOR>(-forward_vector(angles), right_vector(angles),
|
return mat_camera_view<float, MatStoreType::COLUMN_MAJOR>(-forward_vector(angles), right_vector(angles),
|
||||||
up_vector(angles), cam_origin);
|
up_vector(angles), cam_origin);
|
||||||
}
|
}
|
||||||
Mat4X4 rotation_matrix(const ViewAngles& angles)
|
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||||
{
|
{
|
||||||
return mat_rotation_axis_x<float, MatStoreType::COLUMN_MAJOR>(-angles.pitch)
|
return mat_rotation_axis_x<float, MatStoreType::COLUMN_MAJOR>(-angles.pitch)
|
||||||
* mat_rotation_axis_y<float, MatStoreType::COLUMN_MAJOR>(-angles.yaw)
|
* mat_rotation_axis_y<float, MatStoreType::COLUMN_MAJOR>(-angles.yaw)
|
||||||
* mat_rotation_axis_z<float, MatStoreType::COLUMN_MAJOR>(angles.roll);
|
* mat_rotation_axis_z<float, MatStoreType::COLUMN_MAJOR>(angles.roll);
|
||||||
}
|
}
|
||||||
Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near,
|
Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near,
|
||||||
const float far)
|
const float far) noexcept
|
||||||
{
|
{
|
||||||
const float fov_half_tan = std::tan(angles::degrees_to_radians(field_of_view) / 2.f);
|
const float fov_half_tan = std::tan(angles::degrees_to_radians(field_of_view) / 2.f);
|
||||||
|
|
||||||
|
|||||||
@@ -22,12 +22,12 @@ namespace omath::source_engine
|
|||||||
m_view_angles.roll = RollAngle::from_radians(0.f);
|
m_view_angles.roll = RollAngle::from_radians(0.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mat4X4 Camera::calc_view_matrix() const
|
Mat4X4 Camera::calc_view_matrix() const noexcept
|
||||||
{
|
{
|
||||||
return source_engine::calc_view_matrix(m_view_angles, m_origin);
|
return source_engine::calc_view_matrix(m_view_angles, m_origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mat4X4 Camera::calc_projection_matrix() const
|
Mat4X4 Camera::calc_projection_matrix() const noexcept
|
||||||
{
|
{
|
||||||
return calc_perspective_projection_matrix(m_field_of_view.as_degrees(), m_view_port.aspect_ratio(),
|
return calc_perspective_projection_matrix(m_field_of_view.as_degrees(), m_view_port.aspect_ratio(),
|
||||||
m_near_plane_distance, m_far_plane_distance);
|
m_near_plane_distance, m_far_plane_distance);
|
||||||
|
|||||||
@@ -5,38 +5,38 @@
|
|||||||
|
|
||||||
namespace omath::source_engine
|
namespace omath::source_engine
|
||||||
{
|
{
|
||||||
Vector3<float> forward_vector(const ViewAngles& angles)
|
Vector3<float> forward_vector(const ViewAngles& angles) noexcept
|
||||||
{
|
{
|
||||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
|
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 rotation_matrix(const ViewAngles& angles)
|
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||||
{
|
{
|
||||||
return mat_rotation_axis_z(angles.yaw) * mat_rotation_axis_y(angles.pitch) * mat_rotation_axis_x(angles.roll);
|
return mat_rotation_axis_z(angles.yaw) * mat_rotation_axis_y(angles.pitch) * mat_rotation_axis_x(angles.roll);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3<float> right_vector(const ViewAngles& angles)
|
Vector3<float> right_vector(const ViewAngles& angles) noexcept
|
||||||
{
|
{
|
||||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right);
|
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> up_vector(const ViewAngles& angles)
|
Vector3<float> up_vector(const ViewAngles& angles) noexcept
|
||||||
{
|
{
|
||||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up);
|
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 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin)
|
Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||||
{
|
{
|
||||||
return mat_camera_view(forward_vector(angles), right_vector(angles), up_vector(angles), cam_origin);
|
return mat_camera_view(forward_vector(angles), right_vector(angles), up_vector(angles), cam_origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near,
|
Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near,
|
||||||
const float far)
|
const float far) noexcept
|
||||||
{
|
{
|
||||||
// NOTE: Need magic number to fix fov calculation, since source inherit Quake proj matrix calculation
|
// NOTE: Need magic number to fix fov calculation, since source inherit Quake proj matrix calculation
|
||||||
constexpr auto k_multiply_factor = 0.75f;
|
constexpr auto k_multiply_factor = 0.75f;
|
||||||
|
|||||||
@@ -15,11 +15,11 @@ namespace omath::unity_engine
|
|||||||
{
|
{
|
||||||
throw std::runtime_error("Not implemented");
|
throw std::runtime_error("Not implemented");
|
||||||
}
|
}
|
||||||
Mat4X4 Camera::calc_view_matrix() const
|
Mat4X4 Camera::calc_view_matrix() const noexcept
|
||||||
{
|
{
|
||||||
return unity_engine::calc_view_matrix(m_view_angles, m_origin);
|
return unity_engine::calc_view_matrix(m_view_angles, m_origin);
|
||||||
}
|
}
|
||||||
Mat4X4 Camera::calc_projection_matrix() const
|
Mat4X4 Camera::calc_projection_matrix() const noexcept
|
||||||
{
|
{
|
||||||
return calc_perspective_projection_matrix(m_field_of_view.as_degrees(), m_view_port.aspect_ratio(),
|
return calc_perspective_projection_matrix(m_field_of_view.as_degrees(), m_view_port.aspect_ratio(),
|
||||||
m_near_plane_distance, m_far_plane_distance);
|
m_near_plane_distance, m_far_plane_distance);
|
||||||
|
|||||||
@@ -5,37 +5,37 @@
|
|||||||
|
|
||||||
namespace omath::unity_engine
|
namespace omath::unity_engine
|
||||||
{
|
{
|
||||||
Vector3<float> forward_vector(const ViewAngles& angles)
|
Vector3<float> forward_vector(const ViewAngles& angles) noexcept
|
||||||
{
|
{
|
||||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
|
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)};
|
||||||
}
|
}
|
||||||
Vector3<float> right_vector(const ViewAngles& angles)
|
Vector3<float> right_vector(const ViewAngles& angles) noexcept
|
||||||
{
|
{
|
||||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right);
|
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> up_vector(const ViewAngles& angles)
|
Vector3<float> up_vector(const ViewAngles& angles) noexcept
|
||||||
{
|
{
|
||||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up);
|
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 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin)
|
Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||||
{
|
{
|
||||||
return mat_camera_view<float, MatStoreType::ROW_MAJOR>(forward_vector(angles), -right_vector(angles),
|
return mat_camera_view<float, MatStoreType::ROW_MAJOR>(forward_vector(angles), -right_vector(angles),
|
||||||
up_vector(angles), cam_origin);
|
up_vector(angles), cam_origin);
|
||||||
}
|
}
|
||||||
Mat4X4 rotation_matrix(const ViewAngles& angles)
|
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||||
{
|
{
|
||||||
return mat_rotation_axis_x<float, MatStoreType::ROW_MAJOR>(angles.pitch)
|
return mat_rotation_axis_x<float, MatStoreType::ROW_MAJOR>(angles.pitch)
|
||||||
* mat_rotation_axis_y<float, MatStoreType::ROW_MAJOR>(angles.yaw)
|
* mat_rotation_axis_y<float, MatStoreType::ROW_MAJOR>(angles.yaw)
|
||||||
* mat_rotation_axis_z<float, MatStoreType::ROW_MAJOR>(angles.roll);
|
* mat_rotation_axis_z<float, MatStoreType::ROW_MAJOR>(angles.roll);
|
||||||
}
|
}
|
||||||
Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near,
|
Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near,
|
||||||
const float far)
|
const float far) noexcept
|
||||||
{
|
{
|
||||||
const float fov_half_tan = std::tan(angles::degrees_to_radians(field_of_view) / 2.f);
|
const float fov_half_tan = std::tan(angles::degrees_to_radians(field_of_view) / 2.f);
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ namespace omath::projectile_prediction
|
|||||||
{
|
{
|
||||||
const auto predicted_target_position = target.predict_position(time, m_gravity_constant);
|
const auto predicted_target_position = target.predict_position(time, m_gravity_constant);
|
||||||
|
|
||||||
const auto projectile_pitch
|
const auto projectile_pitch =
|
||||||
= maybe_calculate_projectile_launch_pitch_angle(projectile, predicted_target_position);
|
maybe_calculate_projectile_launch_pitch_angle(projectile, predicted_target_position);
|
||||||
|
|
||||||
if (!projectile_pitch.has_value()) [[unlikely]]
|
if (!projectile_pitch.has_value()) [[unlikely]]
|
||||||
continue;
|
continue;
|
||||||
@@ -35,9 +35,8 @@ namespace omath::projectile_prediction
|
|||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<float>
|
std::optional<float> ProjPredEngineLegacy::maybe_calculate_projectile_launch_pitch_angle(
|
||||||
ProjPredEngineLegacy::maybe_calculate_projectile_launch_pitch_angle(const Projectile& projectile,
|
const Projectile& projectile, const Vector3<float>& target_position) const noexcept
|
||||||
const Vector3<float>& target_position) const
|
|
||||||
{
|
{
|
||||||
const auto bullet_gravity = m_gravity_constant * projectile.m_gravity_scale;
|
const auto bullet_gravity = m_gravity_constant * projectile.m_gravity_scale;
|
||||||
const auto delta = target_position - projectile.m_origin;
|
const auto delta = target_position - projectile.m_origin;
|
||||||
@@ -60,7 +59,7 @@ namespace omath::projectile_prediction
|
|||||||
|
|
||||||
bool ProjPredEngineLegacy::is_projectile_reached_target(const Vector3<float>& target_position,
|
bool ProjPredEngineLegacy::is_projectile_reached_target(const Vector3<float>& target_position,
|
||||||
const Projectile& projectile, const float pitch,
|
const Projectile& projectile, const float pitch,
|
||||||
const float time) const
|
const float time) const noexcept
|
||||||
{
|
{
|
||||||
const auto yaw = projectile.m_origin.view_angle_to(target_position).y;
|
const auto yaw = projectile.m_origin.view_angle_to(target_position).y;
|
||||||
const auto projectile_position = projectile.predict_position(pitch, yaw, time, m_gravity_constant);
|
const auto projectile_position = projectile.predict_position(pitch, yaw, time, m_gravity_constant);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
namespace omath::projectile_prediction
|
namespace omath::projectile_prediction
|
||||||
{
|
{
|
||||||
Vector3<float> Projectile::predict_position(const float pitch, const float yaw, const float time,
|
Vector3<float> Projectile::predict_position(const float pitch, const float yaw, const float time,
|
||||||
const float gravity) const
|
const float gravity) const noexcept
|
||||||
{
|
{
|
||||||
auto current_pos = m_origin
|
auto current_pos = m_origin
|
||||||
+ source_engine::forward_vector({source_engine::PitchAngle::from_degrees(-pitch),
|
+ source_engine::forward_vector({source_engine::PitchAngle::from_degrees(-pitch),
|
||||||
|
|||||||
Reference in New Issue
Block a user