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

use glm instead of Math3D in AnimModel

This commit is contained in:
docentYT
2026-04-26 23:14:07 +02:00
parent 1553f82c49
commit 9fef303ec0
2 changed files with 18 additions and 19 deletions

View File

@@ -29,11 +29,11 @@ std::list<std::weak_ptr<TAnimContainer>> TAnimModel::acAnimList;
TAnimContainer::TAnimContainer()
{
vRotateAngles = Math3D::vector3(0.0f, 0.0f, 0.0f); // aktualne kąty obrotu
vDesiredAngles = Math3D::vector3(0.0f, 0.0f, 0.0f); // docelowe kąty obrotu
vRotateAngles = glm::dvec3(0.0f, 0.0f, 0.0f); // aktualne kąty obrotu
vDesiredAngles = glm::dvec3(0.0f, 0.0f, 0.0f); // docelowe kąty obrotu
fRotateSpeed = 0.0;
vTranslation = Math3D::vector3(0.0f, 0.0f, 0.0f); // aktualne przesunięcie
vTranslateTo = Math3D::vector3(0.0f, 0.0f, 0.0f); // docelowe przesunięcie
vTranslation = glm::dvec3(0.0f, 0.0f, 0.0f); // aktualne przesunięcie
vTranslateTo = glm::dvec3(0.0f, 0.0f, 0.0f); // docelowe przesunięcie
fTranslateSpeed = 0.0;
fAngleSpeed = 0.0;
pSubModel = NULL;
@@ -48,7 +48,7 @@ bool TAnimContainer::Init(TSubModel *pNewSubModel)
return (pSubModel != NULL);
}
void TAnimContainer::SetRotateAnim( Math3D::vector3 vNewRotateAngles, double fNewRotateSpeed)
void TAnimContainer::SetRotateAnim(glm::dvec3 vNewRotateAngles, double fNewRotateSpeed)
{
vDesiredAngles = vNewRotateAngles;
fRotateSpeed = fNewRotateSpeed;
@@ -68,7 +68,7 @@ void TAnimContainer::SetRotateAnim( Math3D::vector3 vNewRotateAngles, double fNe
}
}
void TAnimContainer::SetTranslateAnim( Math3D::vector3 vNewTranslate, double fNewSpeed)
void TAnimContainer::SetTranslateAnim(glm::dvec3 vNewTranslate, double fNewSpeed)
{
vTranslateTo = vNewTranslate;
fTranslateSpeed = fNewSpeed;
@@ -96,14 +96,14 @@ void TAnimContainer::UpdateModel() {
if (fTranslateSpeed != 0.0)
{
auto dif = vTranslateTo - vTranslation; // wektor w kierunku docelowym
double l = LengthSquared3(dif); // długość wektora potrzebnego przemieszczenia
double l = glm::length(dif); // długość wektora potrzebnego przemieszczenia
if (l >= 0.0001)
{ // jeśli do przemieszczenia jest ponad 1cm
auto s = Math3D::SafeNormalize(dif); // jednostkowy wektor kierunku
auto s = glm::normalize(dif); // jednostkowy wektor kierunku // Długość wektora nie jest równa 0, sprawdzane wcześniej więc wektor normalny będzie zawsze prawidłowy.
s = s *
(fTranslateSpeed *
Timer::GetDeltaTime()); // przemieszczenie w podanym czasie z daną prędkością
if (LengthSquared3(s) < l) //żeby nie jechało na drugą stronę
if (glm::length(s) < l) //żeby nie jechało na drugą stronę
vTranslation += s;
else
vTranslation = vTranslateTo; // koniec animacji, "koniec animowania" uruchomi
@@ -113,7 +113,7 @@ void TAnimContainer::UpdateModel() {
{ // koniec animowania
vTranslation = vTranslateTo;
fTranslateSpeed = 0.0; // wyłączenie przeliczania wektora
if (LengthSquared3(vTranslation) <= 0.0001) // jeśli jest w punkcie początkowym
if (glm::length(vTranslation) <= 0.0001) // jeśli jest w punkcie początkowym
iAnim &= ~2; // wyłączyć zmianę pozycji submodelu
if( evDone ) {
// wykonanie eventu informującego o zakończeniu

View File

@@ -15,7 +15,6 @@ http://mozilla.org/MPL/2.0/.
#pragma once
#include "utilities/Classes.h"
#include "utilities/dumb3d.h"
#include "utilities/Float3d.h"
#include "model/Model3d.h"
#include "vehicle/DynObj.h"
@@ -52,11 +51,11 @@ class TAnimContainer : std::enable_shared_from_this<TAnimContainer>
friend TAnimModel;
private:
Math3D::vector3 vRotateAngles; // dla obrotów Eulera
Math3D::vector3 vDesiredAngles;
glm::dvec3 vRotateAngles; // dla obrotów Eulera
glm::dvec3 vDesiredAngles;
double fRotateSpeed;
Math3D::vector3 vTranslation;
Math3D::vector3 vTranslateTo;
glm::dvec3 vTranslation;
glm::dvec3 vTranslateTo;
double fTranslateSpeed; // może tu dać wektor?
float4 qCurrent; // aktualny interpolowany
float4 qStart; // pozycja początkowa (0 dla interpolacji)
@@ -82,8 +81,8 @@ class TAnimContainer : std::enable_shared_from_this<TAnimContainer>
inline
std::string NameGet() {
return (pSubModel ? pSubModel->pName : ""); };
void SetRotateAnim( Math3D::vector3 vNewRotateAngles, double fNewRotateSpeed);
void SetTranslateAnim( Math3D::vector3 vNewTranslate, double fNewSpeed);
void SetRotateAnim( glm::dvec3 vNewRotateAngles, double fNewRotateSpeed);
void SetTranslateAnim( glm::dvec3 vNewTranslate, double fNewSpeed);
void AnimSetVMD(double fNewSpeed);
void PrepareModel();
void UpdateModel();
@@ -93,8 +92,8 @@ class TAnimContainer : std::enable_shared_from_this<TAnimContainer>
double AngleGet() {
return vRotateAngles.z; }; // jednak ostatnia, T3D ma inny układ
inline
Math3D::vector3 TransGet() {
return Math3D::vector3(-vTranslation.x, vTranslation.z, vTranslation.y); }; // zmiana, bo T3D ma inny układ
glm::dvec3 TransGet() {
return glm::dvec3(-vTranslation.x, vTranslation.z, vTranslation.y); }; // zmiana, bo T3D ma inny układ
inline
void WillBeAnimated() {
if (pSubModel)