File tree Expand file tree Collapse file tree 9 files changed +38
-41
lines changed
Core/Libraries/Source/WWVegas/WWMath
GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw
GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw Expand file tree Collapse file tree 9 files changed +38
-41
lines changed Original file line number Diff line number Diff line change 5252*/
5353#define WWMATH_EPSILON 0 .0001f
5454#define WWMATH_EPSILON2 WWMATH_EPSILON * WWMATH_EPSILON
55- #define WWMATH_PI 3 .141592654f
55+ #define WWMATH_PI 3 .141592654f
56+ #define WWMATH_TWO_PI 6 .283185308f
5657#define WWMATH_FLOAT_MAX (FLT_MAX)
5758#define WWMATH_FLOAT_MIN (FLT_MIN)
5859#define WWMATH_SQRT2 1 .414213562f
@@ -171,6 +172,8 @@ static WWINLINE float Byte_To_Unit_Float(unsigned char byte) { return ((float)
171172static WWINLINE bool Is_Valid_Float (float x);
172173static WWINLINE bool Is_Valid_Double (double x);
173174
175+ static WWINLINE float Normalize_Angle (float angle); // Normalizes the angle to the range -PI..PI
176+
174177};
175178
176179WWINLINE float WWMath::Sign (float val)
@@ -653,5 +656,9 @@ WWINLINE float WWMath::Inv_Sqrt(float val)
653656}
654657#endif
655658
659+ WWINLINE float WWMath::Normalize_Angle (float angle)
660+ {
661+ return angle - (WWMATH_TWO_PI * Floor ((angle + WWMATH_PI) / WWMATH_TWO_PI));
662+ }
656663
657664#endif
Original file line number Diff line number Diff line change @@ -468,6 +468,7 @@ enum WhichTurretType CPP_11(: Int)
468468
469469// ------------------------------------------------------------------------
470470// this normalizes an angle to the range -PI...PI.
471+ // TheSuperHackers @todo DO NOT USE THIS FUNCTION! Use WWMath::Normalize_Angle instead. Delete this.
471472extern Real normalizeAngle (Real angle);
472473
473474// ------------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ const char *TheRelationshipNames[] =
4848};
4949
5050// -------------------------------------------------------------------------------------------------
51+ // TheSuperHackers @todo DO NOT USE THIS FUNCTION! Use WWMath::Normalize_Angle instead. Delete this.
5152Real normalizeAngle (Real angle)
5253{
5354 DEBUG_ASSERTCRASH (!_isnan (angle), (" Angle is NAN in normalizeAngle!" ));
Original file line number Diff line number Diff line change @@ -540,21 +540,17 @@ void W3DTankTruckDraw::doDrawModule(const Matrix3D* transformMtx)
540540 const Coord3D *vel = physics->getVelocity ();
541541 Real speed = physics->getVelocityMagnitude ();
542542
543-
544543 const TWheelInfo *wheelInfo = getDrawable ()->getWheelInfo (); // note, can return null!
545544 if (wheelInfo && (m_frontLeftTireBone || m_rearLeftTireBone))
546545 {
547- static Real rotation = 0 ;
548546 const Real rotationFactor = getW3DTankTruckDrawModuleData ()->m_rotationSpeedMultiplier ;
547+ const Real powerslideRotationAddition = getW3DTankTruckDrawModuleData ()->m_powerslideRotationAddition * m_isPowersliding;
548+
549549 m_frontWheelRotation += rotationFactor*speed;
550- if (m_isPowersliding)
551- {
552- m_rearWheelRotation += rotationFactor*(speed+getW3DTankTruckDrawModuleData ()->m_powerslideRotationAddition );
553- }
554- else
555- {
556- m_rearWheelRotation += rotationFactor*speed;
557- }
550+ m_rearWheelRotation += rotationFactor*(speed+powerslideRotationAddition);
551+ m_frontWheelRotation = WWMath::Normalize_Angle (m_frontWheelRotation);
552+ m_rearWheelRotation = WWMath::Normalize_Angle (m_rearWheelRotation);
553+
558554 Matrix3D wheelXfrm (1 );
559555 if (m_frontLeftTireBone)
560556 {
Original file line number Diff line number Diff line change @@ -463,7 +463,9 @@ void W3DTruckDraw::doDrawModule(const Matrix3D* transformMtx)
463463
464464 if (m_frontLeftTireBone || m_rearLeftTireBone)
465465 {
466- Real powerslideRotationAddition = moduleData->m_powerslideRotationAddition ;
466+ const Real rotationFactor = moduleData->m_rotationSpeedMultiplier ;
467+ Real powerslideRotationAddition = moduleData->m_powerslideRotationAddition * m_isPowersliding;
468+
467469 if (ai) {
468470 Locomotor *loco = ai->getCurLocomotor ();
469471 if (loco) {
@@ -473,16 +475,11 @@ void W3DTruckDraw::doDrawModule(const Matrix3D* transformMtx)
473475 }
474476 }
475477 }
476- const Real rotationFactor = moduleData-> m_rotationSpeedMultiplier ;
478+
477479 m_frontWheelRotation += rotationFactor*speed;
478- if (m_isPowersliding)
479- {
480- m_rearWheelRotation += rotationFactor*(speed + powerslideRotationAddition);
481- }
482- else
483- {
484- m_rearWheelRotation += rotationFactor*speed;
485- }
480+ m_rearWheelRotation += rotationFactor*(speed + powerslideRotationAddition);
481+ m_frontWheelRotation = WWMath::Normalize_Angle (m_frontWheelRotation);
482+ m_rearWheelRotation = WWMath::Normalize_Angle (m_rearWheelRotation);
486483
487484 // For now, just use the same values for mid wheels -- may want to do independent calcs later...
488485 m_midFrontWheelRotation = m_frontWheelRotation;
Original file line number Diff line number Diff line change @@ -487,6 +487,7 @@ enum WhichTurretType CPP_11(: Int)
487487
488488// ------------------------------------------------------------------------
489489// this normalizes an angle to the range -PI...PI.
490+ // TheSuperHackers @todo DO NOT USE THIS FUNCTION! Use WWMath::Normalize_Angle instead. Delete this.
490491extern Real normalizeAngle (Real angle);
491492
492493// ------------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ const char *TheRelationshipNames[] =
4848};
4949
5050// -------------------------------------------------------------------------------------------------
51+ // TheSuperHackers @todo DO NOT USE THIS FUNCTION! Use WWMath::Normalize_Angle instead. Delete this.
5152Real normalizeAngle (Real angle)
5253{
5354 DEBUG_ASSERTCRASH (!_isnan (angle), (" Angle is NAN in normalizeAngle!" ));
Original file line number Diff line number Diff line change @@ -540,21 +540,17 @@ void W3DTankTruckDraw::doDrawModule(const Matrix3D* transformMtx)
540540 const Coord3D *vel = physics->getVelocity ();
541541 Real speed = physics->getVelocityMagnitude ();
542542
543-
544543 const TWheelInfo *wheelInfo = getDrawable ()->getWheelInfo (); // note, can return null!
545544 if (wheelInfo && (m_frontLeftTireBone || m_rearLeftTireBone))
546545 {
547- static Real rotation = 0 ;
548546 const Real rotationFactor = getW3DTankTruckDrawModuleData ()->m_rotationSpeedMultiplier ;
547+ const Real powerslideRotationAddition = getW3DTankTruckDrawModuleData ()->m_powerslideRotationAddition * m_isPowersliding;
548+
549549 m_frontWheelRotation += rotationFactor*speed;
550- if (m_isPowersliding)
551- {
552- m_rearWheelRotation += rotationFactor*(speed+getW3DTankTruckDrawModuleData ()->m_powerslideRotationAddition );
553- }
554- else
555- {
556- m_rearWheelRotation += rotationFactor*speed;
557- }
550+ m_rearWheelRotation += rotationFactor*(speed+powerslideRotationAddition);
551+ m_frontWheelRotation = WWMath::Normalize_Angle (m_frontWheelRotation);
552+ m_rearWheelRotation = WWMath::Normalize_Angle (m_rearWheelRotation);
553+
558554 Matrix3D wheelXfrm (1 );
559555 if (m_frontLeftTireBone)
560556 {
Original file line number Diff line number Diff line change @@ -463,7 +463,9 @@ void W3DTruckDraw::doDrawModule(const Matrix3D* transformMtx)
463463
464464 if (m_frontLeftTireBone || m_rearLeftTireBone)
465465 {
466- Real powerslideRotationAddition = moduleData->m_powerslideRotationAddition ;
466+ const Real rotationFactor = moduleData->m_rotationSpeedMultiplier ;
467+ Real powerslideRotationAddition = moduleData->m_powerslideRotationAddition * m_isPowersliding;
468+
467469 if (ai) {
468470 Locomotor *loco = ai->getCurLocomotor ();
469471 if (loco) {
@@ -473,16 +475,11 @@ void W3DTruckDraw::doDrawModule(const Matrix3D* transformMtx)
473475 }
474476 }
475477 }
476- const Real rotationFactor = moduleData-> m_rotationSpeedMultiplier ;
478+
477479 m_frontWheelRotation += rotationFactor*speed;
478- if (m_isPowersliding)
479- {
480- m_rearWheelRotation += rotationFactor*(speed + powerslideRotationAddition);
481- }
482- else
483- {
484- m_rearWheelRotation += rotationFactor*speed;
485- }
480+ m_rearWheelRotation += rotationFactor*(speed + powerslideRotationAddition);
481+ m_frontWheelRotation = WWMath::Normalize_Angle (m_frontWheelRotation);
482+ m_rearWheelRotation = WWMath::Normalize_Angle (m_rearWheelRotation);
486483
487484 // For now, just use the same values for mid wheels -- may want to do independent calcs later...
488485 m_midFrontWheelRotation = m_frontWheelRotation;
You can’t perform that action at this time.
0 commit comments