mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
refactored camera
This commit is contained in:
@@ -10,4 +10,5 @@ target_sources(omath PRIVATE
|
||||
add_subdirectory(prediction)
|
||||
add_subdirectory(pathfinding)
|
||||
add_subdirectory(projection)
|
||||
add_subdirectory(collision)
|
||||
add_subdirectory(collision)
|
||||
add_subdirectory(engines)
|
||||
1
source/engines/CMakeLists.txt
Normal file
1
source/engines/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
||||
add_subdirectory(Source)
|
||||
1
source/engines/Source/CMakeLists.txt
Normal file
1
source/engines/Source/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
||||
target_sources(omath PRIVATE Camera.cpp)
|
||||
31
source/engines/Source/Camera.cpp
Normal file
31
source/engines/Source/Camera.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// Created by Orange on 12/4/2024.
|
||||
//
|
||||
#include "omath/engines/Source/Camera.hpp"
|
||||
#include "omath/engines/Source/Formulas.hpp"
|
||||
|
||||
|
||||
namespace omath::source
|
||||
{
|
||||
|
||||
void Camera::LookAt(const Vector3& target)
|
||||
{
|
||||
const float distance = m_origin.DistTo(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);
|
||||
}
|
||||
|
||||
Mat4x4 Camera::GetViewMatrix() const
|
||||
{
|
||||
return ViewMatrix(m_viewAngles, m_origin);
|
||||
}
|
||||
|
||||
Mat4x4 Camera::GetProjectionMatrix() const
|
||||
{
|
||||
return PerspectiveProjectionMatrix(m_fieldOfView.AsDegrees(), m_viewPort.AspectRatio(), m_nearPlaneDistance, m_farPlaneDistance);
|
||||
}
|
||||
} // namespace omath::source
|
||||
@@ -4,13 +4,13 @@
|
||||
|
||||
#include "omath/prediction/Projectile.hpp"
|
||||
#include <cmath>
|
||||
#include <omath/engines/Source.hpp>
|
||||
#include <omath/engines/Source/Formulas.hpp>
|
||||
|
||||
namespace omath::prediction
|
||||
{
|
||||
Vector3 Projectile::PredictPosition(const float pitch, const float yaw, const float time, const float gravity) const
|
||||
{
|
||||
auto currentPos = m_origin + omath::source::ForwardVector({source::PitchAngle::FromDegrees(pitch), source::YawAngle::FromDegrees(yaw), source::RollAngle::FromDegrees(0)}) * m_launchSpeed * time;
|
||||
auto currentPos = m_origin + omath::source::ForwardVector({source::PitchAngle::FromDegrees(-pitch), source::YawAngle::FromDegrees(yaw), source::RollAngle::FromDegrees(0)}) * m_launchSpeed * time;
|
||||
currentPos.z -= (gravity * m_gravityScale) * std::pow(time, 2.f) * 0.5f;
|
||||
|
||||
return currentPos;
|
||||
|
||||
Reference in New Issue
Block a user