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

Change Math3D::vector3 to glm::dvec3 in TCamera class

This commit is contained in:
docentYT
2026-04-26 18:12:47 +02:00
parent dcfd34908a
commit aa24c55d2d
6 changed files with 26 additions and 15 deletions

View File

@@ -378,7 +378,7 @@ openal_renderer::update( double const Deltatime ) {
// orientation
glm::dmat4 cameramatrix;
Global.pCamera.SetMatrix( cameramatrix );
auto cameraposition = Global.pCamera.Pos + (Global.viewport_move * glm::mat3(cameramatrix));
auto cameraposition = Global.pCamera.Pos + glm::dvec3((Global.viewport_move * glm::mat3(cameramatrix)));
cameramatrix = glm::dmat4(glm::inverse(Global.viewport_rotate)) * cameramatrix;
auto rotationmatrix { glm::mat3{ cameramatrix } };
glm::vec3 const orientation[] = {

View File

@@ -2277,7 +2277,7 @@ opengl_renderer::Render( scene::shape_node const &Shape, bool const Ignorerange
case rendermode::shadows:
case rendermode::cabshadows: {
// 'camera' for the light pass is the light source, but we need to draw what the 'real' camera sees
distancesquared = Math3D::SquareMagnitude( ( data.area.center - Global.pCamera.Pos ) / Global.ZoomFactor ) / Global.fDistanceFactor;
distancesquared = Math3D::SquareMagnitude( ( data.area.center - Global.pCamera.Pos ) / (double)Global.ZoomFactor ) / Global.fDistanceFactor;
break;
}
case rendermode::reflections: {
@@ -3505,7 +3505,7 @@ opengl_renderer::Render_Alpha( TAnimModel *Instance ) {
switch( m_renderpass.draw_mode ) {
case rendermode::shadows: {
// 'camera' for the light pass is the light source, but we need to draw what the 'real' camera sees
distancesquared = Math3D::SquareMagnitude( ( Instance->location() - Global.pCamera.Pos ) / Global.ZoomFactor ) / Global.fDistanceFactor;
distancesquared = Math3D::SquareMagnitude( ( Instance->location() - Global.pCamera.Pos ) / (double)Global.ZoomFactor ) / Global.fDistanceFactor;
break;
}
default: {

View File

@@ -26,6 +26,15 @@ void vector3::RotateY(double angle)
x = (cos(angle) * x + z * sin(angle));
z = (z * cos(angle) - sin(angle) * tx);
};
glm::vec3 RotateY(glm::vec3 v, float angle)
{
float s = sin(angle);
float c = cos(angle);
return glm::vec3(c * v.x + s * v.z, v.y, c * v.z - s * v.x);
}
void vector3::RotateZ(double angle)
{
double ty = y;

View File

@@ -14,6 +14,8 @@ http://mozilla.org/MPL/2.0/.
namespace Math3D
{
glm::vec3 RotateY(glm::vec3 v, float angle);
// Define this to have Math3D.cp generate a main which tests these classes
//#define TEST_MATH3D

View File

@@ -20,7 +20,8 @@ http://mozilla.org/MPL/2.0/.
//---------------------------------------------------------------------------
void TCamera::Init( Math3D::vector3 const &NPos, Math3D::vector3 const &NAngle/*, TCameraType const NType*/, TDynamicObject *Owner ) {
void TCamera::Init(glm::vec3 const &NPos, glm::vec3 const &NAngle /*, TCameraType const NType*/, TDynamicObject *Owner)
{
vUp = { 0, 1, 0 };
Velocity = { 0, 0, 0 };
@@ -170,7 +171,7 @@ void TCamera::Update()
|| ( true == DebugCameraFlag ) ) {
// free movement position update
auto movement { Velocity };
movement.RotateY( Angle.y );
movement = Math3D::RotateY(movement, Angle.y);
Pos += movement * 5.0 * deltatime;
}
else {
@@ -193,7 +194,7 @@ void TCamera::Update()
movement.y = -movement.y;
}
*/
movement.RotateY( Angle.y );
movement = Math3D::RotateY(movement, Angle.y);
m_owneroffset += movement * deltatime;
}
@@ -221,7 +222,7 @@ bool TCamera::SetMatrix( glm::dmat4 &Matrix ) {
void TCamera::RaLook()
{ // zmiana kierunku patrzenia - przelicza Yaw
Math3D::vector3 where = LookAt - Pos /*+ Math3D::vector3(0, 3, 0)*/; // trochę w górę od szyn
Math3D::vector3 where = glm::dvec3(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

@@ -9,7 +9,6 @@ http://mozilla.org/MPL/2.0/.
#pragma once
#include "utilities/dumb3d.h"
#include "input/command.h"
#include "vehicle/DynObj.h"
@@ -18,7 +17,7 @@ http://mozilla.org/MPL/2.0/.
class TCamera {
public: // McZapkie: potrzebuje do kiwania na boki
void Init( Math3D::vector3 const &Location, Math3D::vector3 const &Angle, TDynamicObject *Owner );
void Init(glm::vec3 const &Location, glm::vec3 const &Angle, TDynamicObject *Owner);
void Reset();
void OnCursorMove(double const x, double const y);
bool OnCommand( command_data const &Command );
@@ -26,14 +25,14 @@ class TCamera {
bool SetMatrix(glm::dmat4 &Matrix);
void RaLook();
Math3D::vector3 Angle; // pitch, yaw, roll
Math3D::vector3 Pos; // współrzędne obserwatora
Math3D::vector3 LookAt; // współrzędne punktu, na który ma patrzeć
Math3D::vector3 vUp;
Math3D::vector3 Velocity;
glm::dvec3 Angle; // pitch, yaw, roll
glm::dvec3 Pos; // współrzędne obserwatora
glm::vec3 LookAt; // współrzędne punktu, na który ma patrzeć
glm::vec3 vUp;
glm::dvec3 Velocity;
TDynamicObject *m_owner { nullptr }; // TODO: change to const when shake calculations are part of vehicles update
Math3D::vector3 m_owneroffset {};
glm::vec3 m_owneroffset{};
private:
glm::dvec3 m_moverate;