mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 15:09:19 +02:00
state_manager: Optimize/unify track curve derivative computation (#147)
In TSegment there were two different formulas for a derivative. Most places called GetFirstDerivative() that used the direct formula from the curve points. However RaPositionGet() had its own calculation based on pre-computed cubic polynomial coefficients. This latter method is faster and simpler, so change GetFirstDerivative() to use it and change RaPositionGet() to just call GetFirstDerivative().
This commit is contained in:
@@ -163,21 +163,8 @@ void TSegment::InitTFromSInterpolateData()
|
|||||||
|
|
||||||
glm::dvec3 TSegment::GetFirstDerivative(double const fTime) const
|
glm::dvec3 TSegment::GetFirstDerivative(double const fTime) const
|
||||||
{
|
{
|
||||||
|
// derivative is 3*A*t^2 + 2*B*t + C
|
||||||
double fOmTime = 1.0 - fTime;
|
return fTime * ( fTime * 3.0 * vA + vB + vB ) + vC;
|
||||||
double fPowTime = fTime;
|
|
||||||
glm::dvec3 kResult = fOmTime * (CPointOut - Point1);
|
|
||||||
|
|
||||||
// int iDegreeM1 = 3 - 1;
|
|
||||||
|
|
||||||
double fCoeff = 2 * fPowTime;
|
|
||||||
kResult = (kResult + fCoeff * (CPointIn - CPointOut)) * fOmTime;
|
|
||||||
fPowTime *= fTime;
|
|
||||||
|
|
||||||
kResult += fPowTime * (Point2 - CPointIn);
|
|
||||||
kResult *= 3;
|
|
||||||
|
|
||||||
return kResult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double TSegment::RombergIntegral(double const fA, double const fB) const
|
double TSegment::RombergIntegral(double const fA, double const fB) const
|
||||||
@@ -385,8 +372,8 @@ void TSegment::RaPositionGet(double const fDistance, glm::dvec3 &position, glm::
|
|||||||
position = FastGetPoint( t );
|
position = FastGetPoint( t );
|
||||||
// przechyłka w danym miejscu (zmienia się liniowo)
|
// przechyłka w danym miejscu (zmienia się liniowo)
|
||||||
rotation.x = std::lerp( fRoll1, fRoll2, t );
|
rotation.x = std::lerp( fRoll1, fRoll2, t );
|
||||||
// pochodna jest 3*A*t^2+2*B*t+C
|
// pochodna
|
||||||
auto const tangent = t * ( t * 3.0 * vA + vB + vB ) + vC;
|
auto const tangent = GetFirstDerivative( t );
|
||||||
// pochylenie krzywej (w pionie)
|
// pochylenie krzywej (w pionie)
|
||||||
rotation.y = std::atan( tangent.y );
|
rotation.y = std::atan( tangent.y );
|
||||||
// kierunek krzywej w planie
|
// kierunek krzywej w planie
|
||||||
|
|||||||
Reference in New Issue
Block a user