Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void CESTestVehicle::CommitInputs(float Interval)
- {
- // Ok, it's time to redo this flying code, and write long comments like this one
- // The main idea behind this is to go for full arcade flight
- // with a bit of a newtonian flare on the "cut engines" key
- // so what we will do is rotate the velocity vector, rather than do all the acceleration shit
- // that will allow us to use realistic accels for translational without compromising turn speed
- // Define a bunch of vectors over here
- Vector localvelocity, accel;
- AngularImpulse angaccel(0,0,0);
- {
- // Speed depends on wether or not turbo is on
- float flSpeedMax = 100.0f;
- VectorIRotate( GetAbsVelocity(), EntityToWorldTransform(), localvelocity );
- // Just regular turning for angles
- VectorMultiply( m_angTurnMax, input_torque, angaccel );
- angaccel -= m_vecEntityAngVelocity.Get(); // "angaccel" and "angular" are angular velocities
- angaccel /= Interval; // "angaccel" now an angular acceleration
- angaccel.x = MIN( m_angAccelMax.x, angaccel.x );
- angaccel.y = MIN( m_angAccelMax.y, angaccel.y );
- angaccel.z = MIN( m_angAccelMax.z, angaccel.z );
- // Poor man's normalization. Basically projects the box to a circle
- // Its not perfect, but it works (problem is being at 0.7 x and 0.7 y is the same as 1 x and 1 y)
- float vel = input_force.LengthSqr();
- if( vel > 1.0f )
- input_force *= FastRSqrt( vel );
- accel = input_force * flSpeedMax - localvelocity; // "accel" now a velocity delta in local space
- // Note: here and in the VectorMultiply following are the only
- // cases in which a specific input parameter is referenced.
- accel /= Interval; // "accel" now an acceleration
- accel.x = MIN( m_vecAccelMax.x, accel.x ); // Clamp to max
- accel.y = MIN( m_vecAccelMax.y, accel.y ); // Clamp to max
- accel.z = MIN( m_vecAccelMax.z, accel.z ); // Clamp to max
- accel *= Interval;
- angaccel *= Interval;
- localvelocity += accel;
- m_vecEntityAngVelocity += angaccel;
- QAngle angvel;
- matrix3x4_t AngVel, output, localToWorld;
- AngularImpulseToQAngle( m_vecEntityAngVelocity, angvel );
- #ifdef CLIENT_DLL
- AngleMatrix( GetNetworkAngles(), localToWorld ); // Nothing lost here, it gets done if you call EntityToWorld too
- #else
- AngleMatrix( GetLocalAngles(), localToWorld ); // Nothing lost here, it gets done if you call EntityToWorld too
- #endif
- AngleMatrix( angvel * Interval, AngVel );
- ConcatTransforms( localToWorld, AngVel, output );
- MatrixAngles( output, angvel );
- #ifdef CLIENT_DLL
- // This should fix pred errors
- angvel[0] = anglemod(angvel[0]);
- angvel[1] = anglemod(angvel[1]);
- angvel[2] = anglemod(angvel[2]);
- #endif
- SetAbsAngles( angvel );
- // NOTE: output is the new angle, this bypasses all the slippage inducing stuff by hard clamping the rotation
- VectorRotate( localvelocity, output, accel );
- SetAbsVelocity( accel );
- }
- //m_iEngineBits = EngineBits( input_force );
- #ifdef CLIENT_DLL
- Vector origin = GetNetworkOrigin() + GetAbsVelocity() * TICK_INTERVAL;
- #else
- Vector origin = GetLocalOrigin() + GetAbsVelocity() * TICK_INTERVAL;
- #endif
- SetAbsOrigin( origin );
- #ifdef GAME_DLL
- if( VPhysicsGetObject() )
- {
- VPhysicsGetObject()->UpdateShadow( GetAbsOrigin(), GetAbsAngles(), false, TICK_INTERVAL );
- }
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment