Exemplo n.º 1
0
        internal void PreStep(float dt)
        {
            Matrix4f.CreateFromAxisAngle(ref suspension.localDirection, shape.steeringAngle, out shape.steeringTransform);
            Vector3f.TransformNormal(ref localForwardDirection, ref shape.steeringTransform, out worldForwardDirection);
            Vector3f.Transform(ref worldForwardDirection, ref Vehicle.Body.orientationMatrix, out worldForwardDirection);
            if (HasSupport)
            {
                Vector3f.Subtract(ref supportLocation, ref Vehicle.Body.position, out ra);
                if (supportingEntity != null)
                {
                    Vector3f.Subtract(ref supportLocation, ref SupportingEntity.position, out rb);
                }


                //Mind the order of updating!  sliding friction must come before driving force or rolling friction
                //because it computes the sliding direction.

                suspension.isActive = true;
                suspension.numIterationsAtZeroImpulse       = 0;
                suspension.solverSettings.currentIterations = 0;
                slidingFriction.isActive = true;
                slidingFriction.numIterationsAtZeroImpulse       = 0;
                slidingFriction.solverSettings.currentIterations = 0;
                drivingMotor.isActive = true;
                drivingMotor.numIterationsAtZeroImpulse       = 0;
                drivingMotor.solverSettings.currentIterations = 0;
                brake.isActive = true;
                brake.numIterationsAtZeroImpulse       = 0;
                brake.solverSettings.currentIterations = 0;

                suspension.PreStep(dt);
                slidingFriction.PreStep(dt);
                drivingMotor.PreStep(dt);
                brake.PreStep(dt);
            }
            else
            {
                //No support, don't need any solving.
                suspension.isActive      = false;
                slidingFriction.isActive = false;
                drivingMotor.isActive    = false;
                brake.isActive           = false;

                suspension.accumulatedImpulse      = 0;
                slidingFriction.accumulatedImpulse = 0;
                drivingMotor.accumulatedImpulse    = 0;
                brake.accumulatedImpulse           = 0;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates the wheel's world transform for graphics.
        /// Called automatically by the owning wheel at the end of each frame.
        /// If the engine is updating asynchronously, you can call this inside of a space read buffer lock
        /// and update the wheel transforms safely.
        /// </summary>
        public override void UpdateWorldTransform()
        {
#if !WINDOWS
            Vector3f newPosition = new Vector3f();
#else
            Vector3f newPosition;
#endif
            Vector3f worldAttachmentPoint;
            Vector3f localAttach;
            Vector3f.Add(ref wheel.suspension.localAttachmentPoint, ref wheel.vehicle.Body.CollisionInformation.localPosition, out localAttach);
            worldTransform = Matrix3f.ToMatrix4f(wheel.vehicle.Body.BufferedStates.InterpolatedStates.OrientationMatrix);

            Vector3f.TransformNormal(ref localAttach, ref worldTransform, out worldAttachmentPoint);
            worldAttachmentPoint += wheel.vehicle.Body.BufferedStates.InterpolatedStates.Position;

            Vector3f worldDirection;
            Vector3f.Transform(ref wheel.suspension.localDirection, ref worldTransform, out worldDirection);

            float length = wheel.suspension.currentLength - graphicalRadius;
            newPosition.X = worldAttachmentPoint.X + worldDirection.X * length;
            newPosition.Y = worldAttachmentPoint.Y + worldDirection.Y * length;
            newPosition.Z = worldAttachmentPoint.Z + worldDirection.Z * length;

            Matrix4f spinTransform;

            Vector3f localSpinAxis;
            Vector3f.Cross(ref wheel.localForwardDirection, ref wheel.suspension.localDirection, out localSpinAxis);
            Matrix4f.CreateFromAxisAngle(ref localSpinAxis, spinAngle, out spinTransform);


            Matrix4f localTurnTransform;
            Matrix4f.Multiply(ref localGraphicTransform, ref spinTransform, out localTurnTransform);
            Matrix4f.Multiply(ref localTurnTransform, ref steeringTransform, out localTurnTransform);
            //Matrix.Multiply(ref localTurnTransform, ref spinTransform, out localTurnTransform);
            Matrix4f.Multiply(ref localTurnTransform, ref worldTransform, out worldTransform);
            worldTransform.Translation += newPosition;
        }