public void Evaluate(int SpreadMax)
        {
            if (this.FBodies.IsConnected)
            {
                this.FId.SliceCount       = this.FBodies.SliceCount;
                this.FPosition.SliceCount = this.FBodies.SliceCount;
                this.FRadius.SliceCount   = this.FBodies.SliceCount;

                for (int i = 0; i < SpreadMax; i++)
                {
                    RigidBody body = this.FBodies[i];

                    BodyCustomData bd = (BodyCustomData)body.UserObject;

                    this.FId[i] = bd.Id;
                    CollisionShape shape = body.CollisionShape;
                    Vector3        center;
                    float          radius;
                    shape.GetBoundingSphere(out center, out radius);
                    this.FPosition[i] = center.ToVVVVector();
                    this.FRadius[i]   = radius;
                }
            }
            else
            {
                this.FId.SliceCount       = 0;
                this.FPosition.SliceCount = 0;
                this.FRadius.SliceCount   = 0;
            }
        }
Ejemplo n.º 2
0
        public void Evaluate(int SpreadMax)
        {
            if (this.FWorld.PluginIO.IsConnected)
            {
                this.FHit.SliceCount = SpreadMax;

                List <double>    fraction = new List <double>();
                List <Vector3D>  position = new List <Vector3D>();
                List <Vector3D>  normal   = new List <Vector3D>();
                List <RigidBody> body     = new List <RigidBody>();
                List <int>       bodyid   = new List <int>();
                List <int>       qidx     = new List <int>();

                for (int i = 0; i < SpreadMax; i++)
                {
                    Vector3 from = this.FFrom[i].ToBulletVector();
                    Vector3 to   = this.FTo[i].ToBulletVector();
                    CollisionWorld.ClosestRayResultCallback cb =
                        new CollisionWorld.ClosestRayResultCallback(from, to);
                    //cb.CollisionFilterMask =

                    this.FWorld[0].World.RayTest(from, to, cb);

                    if (cb.HasHit)
                    {
                        this.FHit[i] = true;
                        BodyCustomData bd = (BodyCustomData)cb.CollisionObject.UserObject;
                        fraction.Add(cb.ClosestHitFraction);
                        position.Add(cb.HitPointWorld.ToVVVVector());
                        normal.Add(cb.HitNormalWorld.ToVVVVector());
                        body.Add((RigidBody)cb.CollisionObject);
                        bodyid.Add(bd.Id);
                        qidx.Add(i);
                    }
                    else
                    {
                        this.FHit[i] = false;
                    }
                }

                this.FId.AssignFrom(bodyid);
                this.FHitFraction.AssignFrom(fraction);
                this.FHitNormal.AssignFrom(normal);
                this.FHitPosition.AssignFrom(position);
                this.FQueryIndex.AssignFrom(qidx);
                this.FBody.AssignFrom(body);
            }
            else
            {
                this.FHit.SliceCount         = 0;
                this.FId.SliceCount          = 0;
                this.FHitFraction.SliceCount = 0;
                this.FHitPosition.SliceCount = 0;
            }
        }
        public bool Filter(RigidBody body)
        {
            if (IdList == null)
            {
                return(false);
            }

            BodyCustomData data = (BodyCustomData)body.UserObject;

            return(IdList.Contains(data.Id));
        }
        public void Evaluate(int SpreadMax)
        {
            for (int i = 0; i < SpreadMax; i++)
            {
                RigidBody rb = this.FInput[i];

                if (rb != null && FSet[i])
                {
                    BodyCustomData bd = (BodyCustomData)rb.UserObject;
                    bd.Custom = FString[i];
                }
            }
        }
Ejemplo n.º 5
0
        internal void ProcessDelete()
        {
            int cnt = this.RigidBodies.Count;

            for (int i = 0; i < cnt; i++)
            {
                RigidBody      body = this.RigidBodies[i];
                BodyCustomData bd   = (BodyCustomData)body.UserObject;
                bd.Created = false;
                if (bd.MarkedForDeletion)
                {
                    if (this.RigidBodyDeleted != null)
                    {
                        this.RigidBodyDeleted(body, bd.Id);
                    }
                    this.Unregister(body);
                }
            }

            cnt = this.SoftBodies.Count;
            for (int i = 0; i < cnt; i++)
            {
                SoftBody       body = this.SoftBodies[i];
                BodyCustomData bd   = (BodyCustomData)body.UserObject;
                bd.Created = false;
                if (bd.MarkedForDeletion)
                {
                    if (this.SoftBodyDeleted != null)
                    {
                        this.SoftBodyDeleted(body, bd.Id);
                    }
                    this.Unregister(body);
                }
            }

            cnt = this.Constraints.Count;
            for (int i = 0; i < cnt; i++)
            {
                TypedConstraint      cst = this.constraints[i];
                ConstraintCustomData cd  = (ConstraintCustomData)cst.UserObject;
                cd.Created = false;
                if (cd.MarkedForDeletion)
                {
                    if (this.ConstraintDeleted != null)
                    {
                        this.ConstraintDeleted(cst, cd.Id);
                    }
                    this.Unregister(cst);
                }
            }
        }
        public void Evaluate(int SpreadMax)
        {
            if (this.FBodies.IsConnected)
            {
                this.FCustom.SliceCount = this.FBodies.SliceCount;

                for (int i = 0; i < SpreadMax; i++)
                {
                    RigidBody      body = this.FBodies[i];
                    BodyCustomData bd   = (BodyCustomData)body.UserObject;

                    this.FCustom[i] = bd.Custom;
                }
            }
            else
            {
                this.FCustom.SliceCount = 0;
            }
        }
Ejemplo n.º 7
0
        protected override void ProcessObject(RigidBody obj, int slice)
        {
            if (obj.CollisionShape.IsCompound && FWorld.PluginIO.IsConnected)
            {
                CompoundShape  comp = (CompoundShape)obj.CollisionShape;
                BodyCustomData bc   = (BodyCustomData)obj.UserObject;
                bc.MarkedForDeletion = true;


                for (int i = 0; i < comp.ChildList.Count; i++)
                {
                    CollisionShape shape = comp.GetChildShape(i);

                    float mass      = 1.0f / obj.InvMass;
                    float massshape = mass / (float)comp.ChildList.Count;

                    Vector3 inert;
                    shape.CalculateLocalInertia(massshape, out inert);

                    Matrix      m  = obj.MotionState.WorldTransform;
                    MotionState ms = new DefaultMotionState(m);
                    //List<RigidBody> bodies = new List<RigidBody>();

                    RigidBody rb = new RigidBody(new RigidBodyConstructionInfo(mass, ms, shape, inert));
                    rb.LinearVelocity  = obj.LinearVelocity;
                    rb.AngularVelocity = obj.AngularVelocity;
                    rb.Restitution     = obj.Restitution;
                    rb.Friction        = obj.Friction;
                    //rb.CollisionShape = shape;

                    BodyCustomData copy = new BodyCustomData();
                    copy.Id     = this.FWorld[0].GetNewBodyId();
                    copy.Custom = bc.Custom;

                    rb.UserObject = copy;

                    this.FWorld[0].Register(rb);

                    //bodies.Add(rb);
                }
            }
        }
Ejemplo n.º 8
0
        public void Evaluate(int SpreadMax)
        {
            if (this.bodies.IsConnected)
            {
                this.id.SliceCount = this.bodies.SliceCount;

                var ids = this.id.Stream.Buffer;

                for (int i = 0; i < SpreadMax; i++)
                {
                    RigidBody      body = this.bodies[i];
                    BodyCustomData bd   = (BodyCustomData)body.UserObject;
                    ids[i] = bd.Id;
                }
                this.id.Flush(true);
            }
            else
            {
                this.id.SliceCount = 0;
            }
        }
        protected override void ProcessObject(CollisionObject obj, int slice)
        {
            BodyCustomData bd = (BodyCustomData)obj.UserObject;

            bd.MarkedForDeletion = true;
        }
Ejemplo n.º 10
0
        public void Evaluate(int SpreadMax)
        {
            IRigidBulletWorld inputWorld = this.worldInput[0];

            SpreadMax = 1;

            if (inputWorld != null)
            {
                this.persistedList.UpdateWorld(inputWorld);

                if (this.chassisShape.IsConnected)
                {
                    for (int i = 0; i < SpreadMax; i++)
                    {
                        if (this.doCreate[i])
                        {
                            RigidBodyPose       initialPose = this.initialPoseInput.IsConnected ? this.initialPoseInput[i] : RigidBodyPose.Default;
                            RigidBodyProperties properties  = this.initialProperties.IsConnected ? this.initialProperties[i] : RigidBodyProperties.Default;

                            ShapeCustomData            shapeData = new ShapeCustomData();
                            DynamicShapeDefinitionBase chassisShapeDefinition = this.chassisShape[i];

                            CollisionShape chassisShape = chassisShapeDefinition.GetShape(shapeData);
                            shapeData.ShapeDef = chassisShapeDefinition;

                            RaycastVehicle vehicle;
                            CompoundShape  compoundShape = new CompoundShape();

                            Matrix localTrans = Matrix.Translation(Vector3.UnitY);
                            compoundShape.AddChildShape(localTrans, chassisShape);

                            //Build mass for dynamic object
                            Vector3 localInertia = Vector3.Zero;
                            if (chassisShapeDefinition.Mass > 0.0f)
                            {
                                compoundShape.CalculateLocalInertia(chassisShapeDefinition.Mass, out localInertia);
                            }

                            Tuple <RigidBody, int> createBodyResult = inputWorld.CreateRigidBody(chassisShape, ref initialPose, ref properties, ref localInertia, chassisShapeDefinition.Mass, this.customString[i]);
                            RigidBody carChassis = createBodyResult.Item1;

                            RaycastVehicle.VehicleTuning tuning           = new RaycastVehicle.VehicleTuning();
                            DefaultVehicleRaycaster      vehicleRayCaster = new DefaultVehicleRaycaster(inputWorld.World);
                            vehicle = new RaycastVehicle(tuning, carChassis, vehicleRayCaster);
                            vehicle.SetCoordinateSystem(rightIndex, upIndex, forwardIndex);

                            carChassis.ActivationState = ActivationState.DisableDeactivation;
                            inputWorld.World.AddAction(vehicle);

                            int wheelCount = this.wheelConstruction.SliceCount;

                            //Add wheels
                            for (int j = 0; j < this.wheelConstruction[i].SliceCount; j++)
                            {
                                WheelConstructionProperties wcs = this.wheelConstruction[i][j];
                                Vector3   connectionPointCS0    = wcs.localPosition.ToBulletVector();
                                WheelInfo wheel = vehicle.AddWheel(connectionPointCS0, wcs.wheelDirection.ToBulletVector(), wcs.wheelAxis.ToBulletVector(), wcs.SuspensionRestLength, wcs.WheelRadius, tuning, wcs.isFrontWheel);
                            }

                            //Set Wheel Properties
                            WheelProperties wis = this.wheelInfoSettings[i] != null ? this.wheelInfoSettings[i] : new WheelProperties();
                            for (int j = 0; j < vehicle.NumWheels; j++)
                            {
                                WheelInfo wheel = vehicle.GetWheelInfo(j);
                                wheel.SuspensionStiffness      = wis.SuspensionStiffness;
                                wheel.WheelsDampingRelaxation  = wis.WheelsDampingRelaxation;
                                wheel.WheelsDampingCompression = wis.WheelsDampingCompression;
                                wheel.FrictionSlip             = wis.FrictionSlip;
                                wheel.RollInfluence            = wis.RollInfluence;
                            }

                            BodyCustomData bd = (BodyCustomData)carChassis.UserObject;
                            bd.Vehicle = vehicle;

                            this.persistedList.Append(createBodyResult.Item1, createBodyResult.Item2);
                        }
                    }


                    List <RigidBody> bodies = this.persistedList.Bodies;
                    this.vehicleOutput.SliceCount = bodies.Count;
                    this.chassisOutput.SliceCount = bodies.Count;
                    for (int i = 0; i < bodies.Count; i++)
                    {
                        BodyCustomData bd = (BodyCustomData)bodies[i].UserObject;
                        this.vehicleOutput[i] = bd.Vehicle;
                        this.chassisOutput[i] = bodies[i];
                    }
                }
            }
            else
            {
                this.vehicleOutput.SliceCount = 0;
                this.chassisOutput.SliceCount = 0;
            }
        }
Ejemplo n.º 11
0
        internal void ProcessDelete(double dt)
        {
            List <RigidBody> todelete = new List <RigidBody>();
            List <int>       deleteid = new List <int>();

            int cnt = this.RigidBodies.Count;

            for (int i = 0; i < cnt; i++)
            {
                RigidBody      body = this.RigidBodies[i];
                BodyCustomData bd   = (BodyCustomData)body.UserObject;
                if (!bd.Created)
                {
                    bd.LifeTime += dt;
                }
                bd.Created = false;
                if (bd.MarkedForDeletion)
                {
                    todelete.Add(body);
                    deleteid.Add(bd.Id);
                }
            }

            for (int i = 0; i < todelete.Count; i++)
            {
                RigidBody body = todelete[i];
                if (this.RigidBodyDeleted != null)
                {
                    this.RigidBodyDeleted(body, deleteid[i]);
                }
                this.Unregister(body);
            }

            cnt = this.SoftBodies.Count;
            for (int i = 0; i < cnt; i++)
            {
                SoftBody       body = this.SoftBodies[i];
                BodyCustomData bd   = (BodyCustomData)body.UserObject;
                if (!bd.Created)
                {
                    bd.LifeTime += dt;
                }
                bd.Created = false;
                if (bd.MarkedForDeletion)
                {
                    if (this.SoftBodyDeleted != null)
                    {
                        this.SoftBodyDeleted(body, bd.Id);
                    }
                    this.Unregister(body);
                }
            }

            cnt = this.Constraints.Count;
            for (int i = 0; i < cnt; i++)
            {
                TypedConstraint      cst = this.constraints[i];
                ConstraintCustomData cd  = (ConstraintCustomData)cst.UserObject;
                if (!cd.Created)
                {
                    cd.LifeTime += dt;
                }
                cd.Created = false;
                if (cd.MarkedForDeletion)
                {
                    if (this.ConstraintDeleted != null)
                    {
                        this.ConstraintDeleted(cst, cd.Id);
                    }
                    this.Unregister(cst);
                }
                else
                {
                    cd.LifeTime += dt;
                }
            }
        }
Ejemplo n.º 12
0
        public void Evaluate(int dummy)
        {
            if (this.FWorld.IsConnected)
            {
                fraction.Clear();
                position.Clear();
                normal.Clear();
                body.Clear();
                qidx.Clear();

                //Ignore slice count for excluded bodies, as 0 is allowed (means we do a full search)
                int spreadMax = SpreadUtils.SpreadMax(FWorld, FFrom, FTo);

                this.FHit.SliceCount      = spreadMax;
                this.FHitCount.SliceCount = spreadMax;

                for (int i = 0; i < spreadMax; i++)
                {
                    Vector3 from = this.FFrom[i].ToBulletVector();
                    Vector3 to   = this.FTo[i].ToBulletVector();

                    if (cb == null)
                    {
                        cb = new AllHitsRayResultCallback(from, to);
                    }

                    cb.HitFractions.Clear();
                    cb.HitNormalWorld.Clear();
                    cb.HitPointWorld.Clear();
                    cb.CollisionObjects.Clear();

                    this.FWorld[0].World.RayTest(from, to, cb);

                    if (cb.HasHit)
                    {
                        this.FHitCount[i] = cb.HitFractions.Count;

                        float     minfrac = float.MaxValue;
                        RigidBody closest = null;
                        int       minidx  = 0;

                        for (int h = 0; h < cb.HitFractions.Count; h++)
                        {
                            RigidBody rb = (RigidBody)cb.CollisionObjects[h];

                            BodyCustomData bd = (BodyCustomData)rb.UserObject;

                            if (cb.HitFractions[h] < minfrac && !this.FExcludedBody.Contains(rb))
                            {
                                closest = rb;
                                minidx  = h;
                            }
                        }

                        if (closest != null)
                        {
                            this.FHit[i] = true;

                            Vector3 diff  = to - from;
                            Vector3 inter = from + diff * cb.HitFractions[minidx];

                            position.Add(inter.ToVVVVector());
                            fraction.Add(cb.HitFractions[minidx]);
                            normal.Add(cb.HitNormalWorld[minidx].ToVVVVector());
                            body.Add(closest);
                            qidx.Add(i);
                        }
                        else
                        {
                            this.FHit[i] = false;
                        }
                    }
                    else
                    {
                        this.FHit[i]      = false;
                        this.FHitCount[i] = 0;
                    }
                }

                this.FHitFraction.SliceCount = fraction.Count;
                this.FHitNormal.SliceCount   = fraction.Count;
                this.FHitPosition.SliceCount = fraction.Count;
                this.FQueryIndex.SliceCount  = fraction.Count;
                this.FBody.SliceCount        = fraction.Count;

                for (int i = 0; i < fraction.Count; i++)
                {
                    this.FHitFraction[i] = fraction[i];
                    this.FHitNormal[i]   = normal[i];
                    this.FHitPosition[i] = position[i];
                    this.FBody[i]        = body[i];
                    this.FQueryIndex[i]  = qidx[i];
                }
            }
            else
            {
                this.FHit.SliceCount         = 0;
                this.FHitFraction.SliceCount = 0;
                this.FHitPosition.SliceCount = 0;
                this.FHitNormal.SliceCount   = 0;
                this.FHitCount.SliceCount    = 0;
                this.FQueryIndex.SliceCount  = 0;
            }
        }
Ejemplo n.º 13
0
        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;
                }
            }
        }
        public bool Filter(RigidBody body)
        {
            BodyCustomData data = (BodyCustomData)body.UserObject;

            return(Id.HasValue ? data.Id == Id : false);
        }
Ejemplo n.º 15
0
        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;
                }
            }
        }
Ejemplo n.º 16
0
        public void Evaluate(int SpreadMax)
        {
            if (this.FWorld.PluginIO.IsConnected)
            {
                this.FHit.SliceCount      = SpreadMax;
                this.FHitCount.SliceCount = SpreadMax;

                List <double>    fraction = new List <double>();
                List <Vector3D>  position = new List <Vector3D>();
                List <Vector3D>  normal   = new List <Vector3D>();
                List <RigidBody> body     = new List <RigidBody>();
                List <int>       bodyid   = new List <int>();
                List <int>       qidx     = new List <int>();


                for (int i = 0; i < SpreadMax; i++)
                {
                    Vector3 from = this.FFrom[i].ToBulletVector();
                    Vector3 to   = this.FTo[i].ToBulletVector();

                    if (cb == null)
                    {
                        cb = new CollisionWorld.AllHitsRayResultCallback(from, to);
                    }

                    cb.HitFractions.Clear();
                    cb.HitNormalWorld.Clear();
                    cb.HitPointWorld.Clear();
                    cb.CollisionObjects.Clear();

                    this.FWorld[0].World.RayTest(from, to, cb);

                    if (cb.HasHit)
                    {
                        this.FHitCount[i] = cb.HitFractions.Count;

                        float     minfrac = float.MaxValue;
                        RigidBody closest = null;
                        int       minidx  = 0;

                        for (int h = 0; h < cb.HitFractions.Count; h++)
                        {
                            RigidBody rb = (RigidBody)cb.CollisionObjects[h];
                            if (cb.HitFractions[h] < minfrac && !this.FExcludedBody.Contains(rb))
                            {
                                closest = rb;
                                minidx  = h;
                            }
                        }

                        if (closest != null)
                        {
                            this.FHit[i] = true;
                            BodyCustomData bd = (BodyCustomData)closest.UserObject;
                            fraction.Add(cb.HitFractions[minidx]);
                            position.Add(cb.HitPointWorld[minidx].ToVVVVector());
                            normal.Add(cb.HitNormalWorld[minidx].ToVVVVector());
                            body.Add(closest);
                            bodyid.Add(bd.Id);
                            qidx.Add(i);
                        }
                        else
                        {
                            this.FHit[i] = false;
                        }
                    }
                    else
                    {
                        this.FHit[i]      = false;
                        this.FHitCount[i] = 0;
                    }
                }

                this.FId.AssignFrom(bodyid);
                this.FHitFraction.AssignFrom(fraction);
                this.FHitNormal.AssignFrom(normal);
                this.FHitPosition.AssignFrom(position);
                this.FQueryIndex.AssignFrom(qidx);
                this.FBody.AssignFrom(body);
            }
            else
            {
                this.FHit.SliceCount         = 0;
                this.FId.SliceCount          = 0;
                this.FHitFraction.SliceCount = 0;
                this.FHitPosition.SliceCount = 0;
                this.FHitCount.SliceCount    = 0;
            }
        }
        public bool Filter(RigidBody body)
        {
            BodyCustomData data = (BodyCustomData)body.UserObject;

            return(data.LifeTime <= MinimumAge);
        }
Ejemplo n.º 18
0
        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;

            }
        }
        //[Import()]
        //VVVV. FLog;


        public void Evaluate(int SpreadMax)
        {
            if (this.FBodies.PluginIO.IsConnected)
            {
                this.FId.SliceCount              = this.FBodies.SliceCount;
                this.FPosition.SliceCount        = this.FBodies.SliceCount;
                this.FRotation.SliceCount        = this.FBodies.SliceCount;
                this.FShapes.SliceCount          = this.FBodies.SliceCount;
                this.FCustom.SliceCount          = this.FBodies.SliceCount;
                this.FIsNew.SliceCount           = this.FBodies.SliceCount;
                this.FLinVel.SliceCount          = this.FBodies.SliceCount;
                this.FAngVel.SliceCount          = this.FBodies.SliceCount;
                this.FActive.SliceCount          = this.FBodies.SliceCount;
                this.FContactResponse.SliceCount = this.FBodies.SliceCount;
                this.FStatic.SliceCount          = this.FBodies.SliceCount;
                this.FKinematic.SliceCount       = this.FBodies.SliceCount;
                this.FShapeTransform.SliceCount  = this.FBodies.SliceCount;
                this.FHasCustomObj.SliceCount    = this.FBodies.SliceCount;
                this.FCustomObj.SliceCount       = this.FBodies.SliceCount;



                List <Matrix4x4> transforms = new List <Matrix4x4>();

                for (int i = 0; i < SpreadMax; i++)
                {
                    RigidBody body = this.FBodies[i];


                    this.FPosition[i] = new Vector3D(body.MotionState.WorldTransform.M41,
                                                     body.MotionState.WorldTransform.M42, body.MotionState.WorldTransform.M43);

                    Quaternion rot = body.Orientation;
                    this.FRotation[i] = new Vector4D(rot.X, rot.Y, rot.Z, rot.W);

                    this.FLinVel[i] = body.LinearVelocity.ToVVVVector();
                    this.FAngVel[i] = body.AngularVelocity.ToVVVVector();

                    CollisionShape shape = body.CollisionShape;

                    if (shape.IsCompound)
                    {
                        //CompoundShape sp = new CompoundShape(
                        CompoundShape comp = (CompoundShape)shape;
                        this.FShapes[i].SliceCount         = comp.NumChildShapes;
                        this.FShapeTransform[i].SliceCount = comp.NumChildShapes;


                        for (int j = 0; j < comp.NumChildShapes; j++)
                        {
                            CollisionShape child = comp.GetChildShape(j);

                            this.FShapes[i][j] = child;

                            Matrix m = comp.GetChildTransform(j);

                            Matrix4x4 mn = new Matrix4x4(m.M11, m.M12, m.M13, m.M14,
                                                         m.M21, m.M22, m.M23, m.M24, m.M31, m.M32, m.M33, m.M34,
                                                         m.M41, m.M42, m.M43, m.M44);

                            mn *= VMath.Scale(child.LocalScaling.ToVVVVector());
                            this.FShapeTransform[i][j] = mn;
                            //comp.
                            //comp.GetChildTransform(
                            //this.FShapes[i][j].
                        }
                    }
                    else
                    {
                        this.FShapes[i].SliceCount         = 1;
                        this.FShapes[i][0]                 = shape;
                        this.FShapeTransform[i].SliceCount = 1;



                        this.FShapeTransform[i][0] = VMath.Scale(shape.LocalScaling.ToVVVVector());
                        //transforms.Add(VMath.IdentityMatrix);
                    }


                    BodyCustomData bd = (BodyCustomData)body.UserObject;

                    ShapeCustomData sc = (ShapeCustomData)shape.UserObject;

                    this.FActive[i]          = body.IsActive;
                    this.FContactResponse[i] = body.HasContactResponse;
                    this.FStatic[i]          = body.IsStaticObject;
                    this.FKinematic[i]       = body.IsKinematicObject;


                    //this.FShapeCount[i] = sc.ShapeDef.ShapeCount;
                    this.FId[i]     = bd.Id;
                    this.FIsNew[i]  = bd.Created;
                    this.FCustom[i] = bd.Custom;

                    if (bd.CustomObject != null)
                    {
                        this.FHasCustomObj[i] = true;
                        this.FCustomObj[i]    = bd.CustomObject;
                    }
                    else
                    {
                        this.FHasCustomObj[i] = false;
                        this.FCustomObj[i]    = null;
                    }
                }

                //this.FShapeTransform.SliceCount = transforms.Count;
                //this.FShapeTransform.AssignFrom(transforms);
            }
            else
            {
                this.FId.SliceCount             = 0;
                this.FPosition.SliceCount       = 0;
                this.FRotation.SliceCount       = 0;
                this.FShapes.SliceCount         = 0;
                this.FCustom.SliceCount         = 0;
                this.FIsNew.SliceCount          = 0;
                this.FLinVel.SliceCount         = 0;
                this.FAngVel.SliceCount         = 0;
                this.FShapeTransform.SliceCount = 0;
            }
        }
Ejemplo n.º 20
0
        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);
            }
        }