protected void SetBaseParams(AbstractRigidShapeDefinition sd, int sliceindex) { sd.Translation = this.FTranslate[sliceindex].ToBulletVector(); sd.Rotation = this.FRotate[sliceindex].ToBulletQuaternion(); sd.Scaling = this.FScaling[sliceindex].Abs().ToBulletVector(); sd.CustomString = this.FCustom[sliceindex]; sd.CustomObject = this.FCustomObj[sliceindex]; }
protected void SetBaseParams(AbstractRigidShapeDefinition sd, int sliceindex) { sd.Translation = this.FTranslate[sliceindex].ToBulletVector(); sd.Rotation = this.FRotate[sliceindex].ToBulletQuaternion(); sd.Scaling = this.FScaling[sliceindex].Abs().ToBulletVector(); sd.CustomString = this.FCustom[sliceindex]; sd.CustomObject = this.FCustomObj[sliceindex]; }
public override void Evaluate(int SpreadMax) { for (int i = 0; i < SpreadMax; i++) { if (this.CanCreate(i)) { wheelRadius = FwheelRadius[0]; wheelWidth = FwheelWidth[0]; CUBE_HALF_EXTENTS = FwheelDistance[0]; RaycastVehicle vehicle; AbstractRigidShapeDefinition shapedef = this.FShapes[i]; ShapeCustomData sc = new ShapeCustomData(); sc.ShapeDef = shapedef; CompoundShape compound = new CompoundShape(); CollisionShape chassisShape = shapedef.GetShape(sc); Matrix localTrans = Matrix.Translation(Vector3.UnitY); compound.AddChildShape(localTrans, chassisShape); float mass = shapedef.Mass; bool isDynamic = (mass != 0.0f); isFrontWheel = true; 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); // choose coordinate system vehicle.SetCoordinateSystem(rightIndex, upIndex, forwardIndex); Vector3 connectionPointCS0 = new Vector3(CUBE_HALF_EXTENTS - (0.3f * wheelWidth), FconnectionHeight[0], 2 * CUBE_HALF_EXTENTS - wheelRadius); WheelInfo a = vehicle.AddWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, FsuspensionRestLength[0], wheelRadius, tuning, isFrontWheel); connectionPointCS0 = new Vector3(-CUBE_HALF_EXTENTS + (0.3f * wheelWidth), FconnectionHeight[0], 2 * CUBE_HALF_EXTENTS - wheelRadius); vehicle.AddWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, FsuspensionRestLength[0], wheelRadius, tuning, isFrontWheel); isFrontWheel = false; connectionPointCS0 = new Vector3(-CUBE_HALF_EXTENTS + (0.3f * wheelWidth), FconnectionHeight[0], -2 * CUBE_HALF_EXTENTS + wheelRadius); vehicle.AddWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, FsuspensionRestLength[0], wheelRadius, tuning, isFrontWheel); connectionPointCS0 = new Vector3(CUBE_HALF_EXTENTS - (0.3f * wheelWidth), FconnectionHeight[0], -2 * CUBE_HALF_EXTENTS + wheelRadius); vehicle.AddWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, FsuspensionRestLength[0], wheelRadius, tuning, isFrontWheel); for (i = 0; i < vehicle.NumWheels; i++) { WheelInfo wheel = vehicle.GetWheelInfo(i); wheel.SuspensionStiffness = FsuspensionStiffness[0]; wheel.WheelDampingRelaxation = FDampingRelaxation[0]; wheel.WheelDampingCompression = FDampingCompression[0]; wheel.FrictionSlip = FwheelFriction[0]; wheel.RollInfluence = FrollInfluence[0]; wheel.MaxSuspensionTravelCm = FmaxSuspensionTravelCm[0]; wheel.MaxSuspensionForce = FmaxSuspensionForce[0]; } 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); } }