Skip to content

Commit

Permalink
fix GetSpeedDir < 0
Browse files Browse the repository at this point in the history
  • Loading branch information
cryham committed May 3, 2024
1 parent df28d71 commit ca36475
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/game/CarPosInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ void PosInfo::FromCar(CAR* pCar)
speed = pCar->GetSpeed();
fboost = cd->boostVal; //posInfo.steer = cd->steer;
braking = cd->IsBraking(); //percent = outside
reverse = cd->GetTransmission().GetCurrentGearRatio() < 0.0;
reverse = cd->vtype != V_Car ?
pCar->GetSpeedometer() < 0.0 :
cd->GetTransmission().GetCurrentGearRatio() < 0.0;
hov_throttle = cd->hov_throttle;

fHitTime = cd->fHitTime; fParIntens = cd->fParIntens; fParVel = cd->fParVel;
Expand Down
2 changes: 1 addition & 1 deletion src/vdrift/car.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class CAR
float GetSpeedometer() const
{
return dynamics.vtype != V_Car ?
dynamics.GetVelocity().Magnitude() : dynamics.GetSpeedMPS();
dynamics.GetSpeedDir() : dynamics.GetSpeedMPS();
}

std::string GetCarType() const { return cartype; }
Expand Down
5 changes: 3 additions & 2 deletions src/vdrift/cardynamics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "pch.h"
#include "par.h"
#include "cardefs.h"
#include "mathvector.h"
#include "cardynamics.h"
#include "tobullet.h"
#include "Def_Str.h"
Expand Down Expand Up @@ -44,7 +45,7 @@ float CARDYNAMICS::GetMass() const
Dbl CARDYNAMICS::GetSpeed() const
{
return body.GetVelocity().Magnitude();
//return chassis->getLinearVelocity().length();
// const auto& v = chassis->getLinearVelocity();
}

Dbl CARDYNAMICS::GetSpeedDir() const
Expand All @@ -53,7 +54,7 @@ Dbl CARDYNAMICS::GetSpeedDir() const
Orientation().RotateVector(v);

Dbl vel = body.GetVelocity().dot(v); // car body vel in local car direction
return sqrt(vel*vel);
return vel < 0.0 ? -sqrt(vel*vel) : sqrt(vel*vel);
}

MATHVECTOR<Dbl,3> CARDYNAMICS::GetVelocity() const
Expand Down

0 comments on commit ca36475

Please sign in to comment.