Exemplo n.º 1
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;
        }