float wheelFriction = 1000; //BT_LARGE_FLOAT; #endregion Fields #region Methods public override void Evaluate(int SpreadMax) { for (int i = 0; i < SpreadMax; i++) { if (this.CanCreate(i)) { RaycastVehicle vehicle; AbstractRigidShapeDefinition shapedef = this.FShapes[i]; ShapeCustomData sc = new ShapeCustomData(); sc.ShapeDef = shapedef; CompoundShape compound = new CompoundShape(); //List<AbstractRigidShapeDefinition> children = new List<AbstractRigidShapeDefinition>(); CollisionShape chassisShape = shapedef.GetShape(sc); Matrix localTrans = Matrix.Translation(Vector3.UnitY); compound.AddChildShape(localTrans, chassisShape); float mass = shapedef.Mass; bool isDynamic = (mass != 0.0f); Vector3 localInertia = Vector3.Zero; if (isDynamic) chassisShape.CalculateLocalInertia(mass, out localInertia); Vector3D pos = this.FPosition[i]; Vector4D rot = this.FRotation[i]; DefaultMotionState ms = BulletUtils.CreateMotionState(pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, rot.w); RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, ms, compound, localInertia); RigidBody carChassis = new RigidBody(rbInfo); BodyCustomData bd = new BodyCustomData(); carChassis.UserObject = bd; bd.Id = this.FWorld[0].GetNewBodyId(); bd.Custom = this.FCustom[i]; this.FWorld[0].Register(carChassis); RaycastVehicle.VehicleTuning tuning = new RaycastVehicle.VehicleTuning(); VehicleRaycaster vehicleRayCaster = new DefaultVehicleRaycaster(this.FWorld[0].World); vehicle = new RaycastVehicle(tuning, carChassis, vehicleRayCaster); carChassis.ActivationState = ActivationState.DisableDeactivation; this.FWorld[0].World.AddAction(vehicle); float connectionHeight = 1.2f; bool isFrontWheel = true; // choose coordinate system vehicle.SetCoordinateSystem(rightIndex, upIndex, forwardIndex); Vector3 connectionPointCS0 = new Vector3(CUBE_HALF_EXTENTS - (0.3f * wheelWidth), connectionHeight, 2 * CUBE_HALF_EXTENTS - wheelRadius); WheelInfo a = vehicle.AddWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, suspensionRestLength, wheelRadius, tuning, isFrontWheel); connectionPointCS0 = new Vector3(-CUBE_HALF_EXTENTS + (0.3f * wheelWidth), connectionHeight, 2 * CUBE_HALF_EXTENTS - wheelRadius); vehicle.AddWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, suspensionRestLength, wheelRadius, tuning, isFrontWheel); isFrontWheel = false; connectionPointCS0 = new Vector3(-CUBE_HALF_EXTENTS + (0.3f * wheelWidth), connectionHeight, -2 * CUBE_HALF_EXTENTS + wheelRadius); vehicle.AddWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, suspensionRestLength, wheelRadius, tuning, isFrontWheel); connectionPointCS0 = new Vector3(CUBE_HALF_EXTENTS - (0.3f * wheelWidth), connectionHeight, -2 * CUBE_HALF_EXTENTS + wheelRadius); vehicle.AddWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, suspensionRestLength, wheelRadius, tuning, isFrontWheel); for (i = 0; i < vehicle.NumWheels; i++) { WheelInfo wheel = vehicle.GetWheelInfo(i); wheel.SuspensionStiffness = suspensionStiffness; wheel.WheelsDampingRelaxation = suspensionDamping; wheel.WheelsDampingCompression = suspensionCompression; wheel.FrictionSlip = wheelFriction; wheel.RollInfluence = rollInfluence; } FOutVehicle.SliceCount = 1; FOutVehicle[0] = vehicle; } } }
protected RigidBody CreateBody(int i,out int id) { if (this.CanCreate(i)) { AbstractRigidShapeDefinition shapedef = this.FShapes[i]; ShapeCustomData sc = new ShapeCustomData(); sc.ShapeDef = shapedef; Vector3D pos = this.FPosition[i]; Vector4D rot = this.FRotation[i]; DefaultMotionState ms = BulletUtils.CreateMotionState(pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, rot.w); CollisionShape shape = shapedef.GetShape(sc); Vector3 localinertia = Vector3.Zero; if (!this.FKinematic[i] && !this.FStatic[i]) { if (shapedef.Mass > 0.0f) { shape.CalculateLocalInertia(shapedef.Mass, out localinertia); } } RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(shapedef.Mass, ms, shape, localinertia); rbInfo.Friction = this.FFriction[i]; rbInfo.Restitution = this.FRestitution[i]; RigidBody body = new RigidBody(rbInfo); if (!this.FActive[i]) { body.ActivationState |= ActivationState.DisableSimulation; } if (!this.FAllowSleep[i]) { body.ActivationState = ActivationState.DisableDeactivation; } body.LinearVelocity = this.FLinearVelocity[i].ToBulletVector(); body.AngularVelocity = this.FAngularVelocity[i].ToBulletVector(); body.CollisionFlags = CollisionFlags.None; if (!this.FContactResponse[i]) { body.CollisionFlags |= CollisionFlags.NoContactResponse; } if (this.FKinematic[i]) { body.CollisionFlags |= CollisionFlags.KinematicObject; } if (this.FStatic[i]) { body.CollisionFlags |= CollisionFlags.StaticObject; } BodyCustomData bd = new BodyCustomData(); body.UserObject = bd; bd.Id = this.FWorld[0].GetNewBodyId(); bd.Custom = this.FCustom[i]; if (this.FCustomObj.PluginIO.IsConnected) { bd.CustomObject = (ICloneable)this.FCustomObj[i].Clone(); } else { bd.CustomObject = null; } this.FWorld[0].Register(body); id = bd.Id; return body; } else { id = -1; return null; } }