protected override void Draw(GameTime gameTime) { base.Draw(gameTime); _engine.Draw(); // Draw the torus knot { Matrix[] transforms = new Matrix[_torusModel.Bones.Count]; _torusModel.CopyAbsoluteBoneTransformsTo(transforms); foreach (ModelMesh mesh in _torusModel.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); effect.World = Matrix.CreateScale(0.1f, 0.1f, 0.1f) * transforms[mesh.ParentBone.Index] * _torusActor.GlobalPose; effect.View = _engine.Camera.View; effect.Projection = _engine.Camera.Projection; } mesh.Draw(); } } // Display basic info about the vehicle WheelContactData contactData = _basicVehicle.LeftFront.GetContactData(); Vector3 readOut = contactData.LongitudalDirection; this.Window.Title = String.Format("LongitudalDirection: {0:0.00},{1:0.00},{2:0.00}", readOut.X, readOut.Y, readOut.Z); }
private void UpdateMatrices(WheelContactData wcd) { if (wcd.ContactShape == null) { CurrentSuspensionTravel = Shape.SuspensionTravel; } else { CurrentSuspensionTravel = wcd.ContactPosition - Shape.Radius; } if (_handbrake != 1) { if (IsSkiddingLng && Shape.MotorTorque != 0) { _rotationMatrix *= Matrix.CreateRotationX(-0.3f); } else { _rotationMatrix *= Matrix.CreateRotationX(MathHelper.ToRadians(Shape.AxleSpeed)); } } else { } Matrix translation = Matrix.CreateTranslation(_axleOffset, -CurrentSuspensionTravel, 0.0f); _renderMatrix = _rotationMatrix * Matrix.CreateRotationY(Shape.SteeringAngle) * translation; }
public void Update() { WheelContactData wcd = Shape.GetContactData(); UpdateMatrices(wcd); ContactPoint = wcd.ContactPoint; SmokeEmitter.Enabled = false; IsSkiddingLat = IsSkiddingLng = ShouldPlaySkidSound = false; if (wcd.ContactForce != 0) { int materialIndex = (int)wcd.OtherShapeMaterialIndex; MaterialModifier materialModifier = Race.Current.ConfigFile.MaterialModifiers[materialIndex]; materialModifier.UpdateWheelShape(_chassis, this); LatSlip = wcd.LateralSlip; if (_chassis.Speed > 10 && (_handbrake == 1 || Math.Abs(wcd.LateralSlip) > 0.23f)) { IsSkiddingLat = true; SmokeEmitter.Enabled = true; } else if (_chassis.Speed > 3 && Shape.MotorTorque != 0 && CActor.IsDriven && wcd.LongitudalSlip > 0.04f) { IsSkiddingLng = true; SmokeEmitter.Enabled = true; } // Setup tire functions taking into account handbrake and terrain float latExtremum = _defaultLatExtremum; if (IsRear) { latExtremum = MathHelper.Lerp(1.9f, 1.05f, _handbrake); } latExtremum *= materialModifier.TyreRoadFriction; _latTireFn.ExtremumValue = latExtremum; _lngTireFn.ExtremumValue = _defaultLngExtremum * materialModifier.TyreRoadFriction; Shape.LateralTireForceFunction = _latTireFn; Shape.LongitudalTireForceFunction = _lngTireFn; ShouldPlaySkidSound = IsSkiddingLat | IsSkiddingLng && materialIndex == 0; SmokeEmitter.Update(wcd.ContactPoint); } }