16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-17 23:39:18 +02:00

Use glm::dvec3 for Camera LookAt/init

Update Init(...) parameters to glm::dvec3, change LookAt to glm::dvec3 and adjust Camera.cpp to remove redundant glm::dvec3 casts (lookAt call and vector subtraction). These changes improve precision for camera lookAt vector in world coordinates above 4 digits
This commit is contained in:
docentYT
2026-05-05 23:02:16 +02:00
parent ca839652bf
commit c833b8177b
2 changed files with 5 additions and 5 deletions

View File

@@ -21,7 +21,7 @@ http://mozilla.org/MPL/2.0/.
//---------------------------------------------------------------------------
void TCamera::Init(glm::vec3 const &NPos, glm::vec3 const &NAngle /*, TCameraType const NType*/, TDynamicObject *Owner)
void TCamera::Init(glm::dvec3 const &NPos, glm::dvec3 const &NAngle /*, TCameraType const NType*/, TDynamicObject *Owner)
{
vUp = { 0, 1, 0 };
@@ -209,7 +209,7 @@ bool TCamera::SetMatrix( glm::dmat4 &Matrix ) {
if( ( m_owner != nullptr ) && ( false == DebugCameraFlag ) ) {
Matrix *= glm::lookAt(Pos, glm::dvec3{ LookAt }, glm::dvec3{ vUp } );
Matrix *= glm::lookAt(Pos, LookAt, glm::dvec3{ vUp } );
}
else {
Matrix = glm::translate( Matrix, -Pos ); // nie zmienia kierunku patrzenia
@@ -220,7 +220,7 @@ bool TCamera::SetMatrix( glm::dmat4 &Matrix ) {
void TCamera::RaLook()
{ // zmiana kierunku patrzenia - przelicza Yaw
auto where = glm::dvec3(LookAt )- Pos /*+ Math3D::vector3(0, 3, 0)*/; // trochę w górę od szyn
auto where = LookAt - Pos /*+ Math3D::vector3(0, 3, 0)*/; // trochę w górę od szyn
if( ( where.x != 0.0 ) || ( where.z != 0.0 ) ) {
Angle.y = atan2( -where.x, -where.z ); // kąt horyzontalny
m_rotationoffsets.y = 0.0;

View File

@@ -17,7 +17,7 @@ http://mozilla.org/MPL/2.0/.
class TCamera {
public: // McZapkie: potrzebuje do kiwania na boki
void Init(glm::vec3 const &Location, glm::vec3 const &Angle, TDynamicObject *Owner);
void Init(glm::dvec3 const &Location, glm::dvec3 const &Angle, TDynamicObject *Owner);
void Reset();
void OnCursorMove(double const x, double const y);
bool OnCommand( command_data const &Command );
@@ -27,7 +27,7 @@ class TCamera {
glm::vec3 Angle; // pitch, yaw, roll
glm::dvec3 Pos; // współrzędne obserwatora
glm::vec3 LookAt; // współrzędne punktu, na który ma patrzeć
glm::dvec3 LookAt; // Idealnie gdyby był to znormalizowany kierunek, ale obecnie są to współrzędne punktu, na który ma patrzeć
glm::vec3 vUp;
glm::dvec3 Velocity;