示例#1
0
        private void CreateComposite()
        {
            var        compositeRigidBodyDescriptor = new RigidBodyDescriptor(MotionType.Dynamic, Matrices.Translate(0f, 10, 0), true);
            IRigidBody composite     = _simulator.ActorsFactory.CreateRigidBody(compositeRigidBodyDescriptor);
            var        sphereFixture =
                composite.FixtureFactory.CreateSimpleFixture(new FixtureDescriptor(Matrices.I));

            sphereFixture.MaterialFactory.CreateMaterial(new MaterialDescriptor(0.01f, 1.01f));
            var compositeShape =
                sphereFixture.ShapeFactory.CreateComposite(new CompositeShapeDescriptor());
            var shapePositionerCenter =
                compositeShape.ShapePositionerFactory.CreateShapePositioner(
                    new ShapePositionerDescriptor(Matrices.I));

            shapePositionerCenter.ShapeFactory.CreateSphere(new SphereShapeDescriptor(1.5f));
            var shapePositionerLeft =
                compositeShape.ShapePositionerFactory.CreateShapePositioner(
                    new ShapePositionerDescriptor(Matrices.Translate(-2.5f, 0, 0)));

            shapePositionerLeft.ShapeFactory.CreateSphere(new SphereShapeDescriptor(0.5f));
            var shapePositionerRight =
                compositeShape.ShapePositionerFactory.CreateShapePositioner(
                    new ShapePositionerDescriptor(Matrices.Translate(2.5f, 0, 0)));

            shapePositionerRight.ShapeFactory.CreateSphere(new SphereShapeDescriptor(0.5f));
        }
示例#2
0
            IRigidBody IFactoryOf <IRigidBody, RigidBodyDescriptor> .Create(RigidBodyDescriptor descriptor)
            {
                var rigidBody = new RigidBodies.RigidBody(descriptor);

                _simulator._wrappedSimulation.RigidBodies.Add(rigidBody.WrappedRigidBody);
                return(rigidBody);
            }
示例#3
0
        private void CreateChain <TShape, TShapeDescriptor>(MaterialDescriptor materialDescriptor,
                                                            TShapeDescriptor shapeDescriptor,
                                                            DistanceRangeJointDescriptor constraintDescriptor,
                                                            int count, float space, int staticBall, float xOffset, float yOffset, float zOffset)
            where TShapeDescriptor : struct, IDescriptor
            where TShape : IShape, IDescriptible <TShapeDescriptor>
        {
            var bodies = new IRigidBody[count];
            var rigidBodyDescriptor = new RigidBodyDescriptor(MotionType.Static, Matrices.I, true);

            for (int i = 0; i < count; i++)
            {
                rigidBodyDescriptor.Pose = Matrices.Translate(xOffset + (space + i * space - ((count - 1) * space / 2)), yOffset, zOffset);
                bodies[i]          = _simulator.ActorsFactory.Create <IRigidBody, RigidBodyDescriptor>(rigidBodyDescriptor);
                bodies[i].UserData = String.Format("chain {0}", i);
                var fixture = bodies[i].FixtureFactory.Create <ISimpleFixture, FixtureDescriptor>(new FixtureDescriptor(Matrices.I));
                fixture.ShapeFactory.Create <TShape, TShapeDescriptor>(shapeDescriptor);
                fixture.MaterialFactory.Create <IMaterial, MaterialDescriptor>(materialDescriptor);
                if (i > 0)
                {
                    constraintDescriptor.RigidBodyA = bodies[i - 1];
                    constraintDescriptor.RigidBodyB = bodies[i];
                    _simulator.ConstraintsFactory.Create <IDistanceRangeJoint, DistanceRangeJointDescriptor>(
                        constraintDescriptor);
                }
                else
                {
                    rigidBodyDescriptor.MotionType = MotionType.Static;
                }
            }
        }
示例#4
0
        public static void SetSimpleScene(ISimulator simulator)
        {
            #region Create a box

            //create a rigidBody
            var boxRigidBodyDescriptor = new RigidBodyDescriptor(MotionType.Dynamic, Matrices.Translate(0, 10, 0));
            var boxRigidBody           = simulator.ActorsFactory.CreateRigidBody(boxRigidBodyDescriptor);

            //create a simple fixture for the rigidBody
            var fixtureDescriptor = new FixtureDescriptor(Matrices.I);
            var simpleFixture     = boxRigidBody.FixtureFactory.CreateSimpleFixture(fixtureDescriptor);

            //define the shape for the simple fixture
            var boxShapeDescriptor = new BoxShapeDescriptor(3, 3, 3, _motionColor);
            simpleFixture.ShapeFactory.CreateBox(boxShapeDescriptor);

            //define the material for the simple fixture
            var materialDescriptor = new MaterialDescriptor(friction: 0.5f, restitution: 0.6f);
            simpleFixture.MaterialFactory.CreateMaterial(materialDescriptor);
            boxRigidBody.MassFrame.UpdateFromShape();

            #endregion

            #region Create a plane for the ground

            var groundRigidBody =
                simulator.ActorsFactory.CreateRigidBody(new RigidBodyDescriptor(MotionType.Static, Matrices.I));
            var groundSimpleFixture =
                groundRigidBody.FixtureFactory.CreateSimpleFixture(new FixtureDescriptor(Matrices.I));
            groundSimpleFixture.ShapeFactory.CreatePlane(new PlaneShapeDescriptor(Vectors.YAxis, 0, _groundColor));
            groundSimpleFixture.MaterialFactory.CreateMaterial(materialDescriptor);

            #endregion
        }
示例#5
0
        private void CreateGroud(MaterialDescriptor materialDescriptor)
        {
            var groundRigidBodyDescriptor = new RigidBodyDescriptor(MotionType.Static, Matrices.I, true);
            var ground        = _simulator.ActorsFactory.CreateRigidBody(groundRigidBodyDescriptor);
            var groundFixture = ground.FixtureFactory.CreateSimpleFixture(new FixtureDescriptor(Matrices.I));

            groundFixture.ShapeFactory.CreatePlane(new PlaneShapeDescriptor(new Vector3(0, 1, 0), 0));
            groundFixture.MaterialFactory.CreateMaterial(materialDescriptor);
        }
示例#6
0
        private void CreateMassTesting(float xPosition, float side, float mass)
        {
            var        rigidBodyDescriptor = new RigidBodyDescriptor(MotionType.Dynamic, Matrices.Translate(xPosition, 10, 0), true);
            IRigidBody rigidBody           = _simulator.ActorsFactory.Create <IRigidBody, RigidBodyDescriptor>(rigidBodyDescriptor);
            var        fixture             = rigidBody.FixtureFactory.Create <ISimpleFixture, FixtureDescriptor>(new FixtureDescriptor(Matrices.I));

            fixture.MaterialFactory.Create <IMaterial, MaterialDescriptor>(new MaterialDescriptor(0.01f, 1.01f));
            fixture.ShapeFactory.Create <IBoxShape, BoxShapeDescriptor>(new BoxShapeDescriptor(side, side, side));
            rigidBody.MassFrame.Mass = mass;
        }
示例#7
0
 internal RigidBody(RigidBodyDescriptor descriptor, Scene scene)
 {
     WrappedActor   = CreateActor(descriptor, scene);
     Configurator   = new RigidBodyConfigurator(this);
     FixtureFactory = new RigidBodyFixtureFactory(this);
     Forces         = new RigidBodyForces(this);
     Velocity       = new RigidBodyVelocity(this);
     MassFrame      = new RigidBodyMassFrame(this);
     UserData       = descriptor.UserData;
 }
示例#8
0
        public static void SetCompositeScene(ISimulator simulator)
        {
            for (int i = 0; i < 1; i++)
            {
                var rigidBodyDescriptor = new RigidBodyDescriptor(MotionType.Dynamic,
                                                                  GMath.mul(Matrices.RotateZGrad(-20),
                                                                            Matrices.Translate(0, 20 * i + 7, 0)),
                                                                  _motionColor);
                var rigidBody = simulator.ActorsFactory.CreateRigidBody(rigidBodyDescriptor);

                var fixtureDescriptor = new FixtureDescriptor(Matrices.I);
                var compositeFixture  = rigidBody.FixtureFactory.CreateCompositeFixture(fixtureDescriptor);

                var simpleFixture =
                    compositeFixture.FixtureFactory.CreateSimpleFixture(
                        new FixtureDescriptor(Matrices.Translate(0, 2.5f, 0)));
                simpleFixture.ShapeFactory.CreateBox(new BoxShapeDescriptor(1, 5, 1));
                simpleFixture.MaterialFactory.CreateMaterial(new MaterialDescriptor(friction: 0.5f, restitution: 0f));


                simpleFixture =
                    compositeFixture.FixtureFactory.CreateSimpleFixture(
                        new FixtureDescriptor(Matrices.Translate(0, 2.5f, 5)));
                simpleFixture.ShapeFactory.CreateBox(new BoxShapeDescriptor(1, 5, 1));
                simpleFixture.MaterialFactory.CreateMaterial(new MaterialDescriptor(friction: 0.5f, restitution: 0f));

                simpleFixture =
                    compositeFixture.FixtureFactory.CreateSimpleFixture(
                        new FixtureDescriptor(Matrices.Translate(5, 2.5f, 0)));
                simpleFixture.ShapeFactory.CreateBox(new BoxShapeDescriptor(1, 5, 1));
                simpleFixture.MaterialFactory.CreateMaterial(new MaterialDescriptor(friction: 0.5f, restitution: 1f));

                simpleFixture =
                    compositeFixture.FixtureFactory.CreateSimpleFixture(
                        new FixtureDescriptor(Matrices.Translate(5, 2.5f, 5)));
                simpleFixture.ShapeFactory.CreateBox(new BoxShapeDescriptor(1, 5, 1));
                simpleFixture.MaterialFactory.CreateMaterial(new MaterialDescriptor(friction: 0.5f, restitution: 1f));

                simpleFixture =
                    compositeFixture.FixtureFactory.CreateSimpleFixture(
                        new FixtureDescriptor(Matrices.Translate(2.5f, 5.1f, 2.5f)));
                simpleFixture.ShapeFactory.CreateBox(new BoxShapeDescriptor(6, 0.2f, 6));

                simpleFixture =
                    compositeFixture.FixtureFactory.CreateSimpleFixture(
                        new FixtureDescriptor(Matrices.Translate(5.5f, 8f, 2.5f)));
                simpleFixture.ShapeFactory.CreateBox(new BoxShapeDescriptor(0.2f, 6, 6));
                simpleFixture.MaterialFactory.CreateMaterial(new MaterialDescriptor(friction: 0.5f, restitution: 1f));

                rigidBody.MassFrame.UpdateFromShape();
            }
            SetGround(simulator, new MaterialDescriptor(friction: 0.5f, restitution: 1f));
        }
示例#9
0
        internal RigidBody(RigidBodyDescriptor descriptor)
        {
            WrappedRigidBody = new DR.RigidBody {
                AutoUpdateMass = true, MotionType = descriptor.MotionType.ToDigitalRune()
            };

            Configurator   = new RigidBodyConfigurator(this);
            FixtureFactory = new RigidBodyFixtureFactory(this);
            Forces         = new RigidBodyForces(this);
            Velocity       = new RigidBodyVelocity(this);
            MassFrame      = new RigidBodyMassFrame(this);
            Descriptor     = descriptor;
        }
示例#10
0
        private static IRigidBody SetSimpleRigidBody <TShape, TShapeDescriptor>(ISimulator simulator,
                                                                                RigidBodyDescriptor rigidBodyDescriptor,
                                                                                TShapeDescriptor descriptor,
                                                                                MaterialDescriptor materialDescriptor)
            where TShape : IShape, IDescriptible <TShapeDescriptor>
            where TShapeDescriptor : struct, IDescriptor
        {
            var rigidBody = simulator.ActorsFactory.CreateRigidBody(rigidBodyDescriptor);

            var fixtureDescriptor = new FixtureDescriptor(Matrices.I);
            var simpleFixture     = rigidBody.FixtureFactory.CreateSimpleFixture(fixtureDescriptor);

            simpleFixture.ShapeFactory.Create <TShape, TShapeDescriptor>(descriptor);
            simpleFixture.MaterialFactory.CreateMaterial(materialDescriptor);

            rigidBody.MassFrame.UpdateFromShape();
            return(rigidBody);
        }
示例#11
0
        private Actor CreateActor(RigidBodyDescriptor descriptor, Scene scene)
        {
            var materialDesc = new MaterialDescription
            {
                DynamicFriction        = 0.5f,
                StaticFriction         = 0.5f,
                Restitution            = 0.7f,
                FrictionCombineMode    = CombineMode.Average,
                RestitutionCombineMode = CombineMode.Average
            };

            DefaultMaterial = scene.CreateMaterial(materialDesc);
            var boxDesc = new BoxShapeDescription
            {
                Material   = DefaultMaterial,
                Dimensions = new Vector3(1, 1, 1)
            };
            ///////////////////////////////////////////////



            //resolve the motion type
            var rigidBodyDesc = descriptor.MotionType == MotionType.Static
                                    ? null
                                    : new BodyDescription();

            if (descriptor.MotionType == MotionType.Kinematic)
            {
                rigidBodyDesc.BodyFlags = BodyFlag.Kinematic;
            }

            HasDefaultShape = true;
            var actorDesc = new ActorDescription(boxDesc)
            {
                BodyDescription = rigidBodyDesc,
                Density         = 10.0f,
                GlobalPose      = descriptor.Pose.ToPhysX(),
                UserData        = descriptor.UserData
            };

            return(scene.CreateActor(actorDesc));
        }
示例#12
0
        private void CreateTower <TShape, TShapeDescriptor>(MaterialDescriptor materialDescriptor, TShapeDescriptor descriptor, int xCount, int yCount, int zCount, float xSpace, float ySpace, float zSpace, float xOffset, float yOffset, float zOffset)
            where TShapeDescriptor : struct, IDescriptor
            where TShape : IShape, IDescriptible <TShapeDescriptor>
        {
            var rigidBodyDescriptor = new RigidBodyDescriptor(MotionType.Dynamic, Matrices.I, true);

            for (int x = 0; x < xCount; x++)
            {
                for (int y = 0; y < yCount; y++)
                {
                    for (int z = 0; z < zCount; z++)
                    {
                        rigidBodyDescriptor.Pose = Matrices.Translate(xOffset + x * xSpace - ((xCount - 1) * xSpace / 2),
                                                                      yOffset + y * ySpace - ((yCount - 1) * ySpace / 2),
                                                                      zOffset + z * zSpace - ((zCount - 1) * zSpace / 2));
                        var rigidBody = _simulator.ActorsFactory.Create <IRigidBody, RigidBodyDescriptor>(rigidBodyDescriptor);
                        var fixture   =
                            rigidBody.FixtureFactory.Create <ISimpleFixture, FixtureDescriptor>(new FixtureDescriptor(Matrices.I));
                        fixture.ShapeFactory.Create <TShape, TShapeDescriptor>(descriptor);
                        fixture.MaterialFactory.Create <IMaterial, MaterialDescriptor>(materialDescriptor);
                    }
                }
            }
        }
示例#13
0
 CreateRigidBody(this IFactory <IActor> factory,
                 RigidBodyDescriptor descriptor)
 {
     return(factory.Create <IRigidBody, RigidBodyDescriptor>(descriptor));
 }
 IRigidBody IFactoryOf <IRigidBody, RigidBodyDescriptor> .Create(RigidBodyDescriptor descriptor)
 {
     return(new RigidBody(descriptor, _simulator._wrappedScene));
 }