当前位置: 首页>>代码示例>>C#>>正文


C# BulletSharp.DiscreteDynamicsWorld类代码示例

本文整理汇总了C#中BulletSharp.DiscreteDynamicsWorld的典型用法代码示例。如果您正苦于以下问题:C# DiscreteDynamicsWorld类的具体用法?C# DiscreteDynamicsWorld怎么用?C# DiscreteDynamicsWorld使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DiscreteDynamicsWorld类属于BulletSharp命名空间,在下文中一共展示了DiscreteDynamicsWorld类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnInitializePhysics

        protected override void OnInitializePhysics()
        {
            // collision configuration contains default setup for memory, collision setup
            CollisionConf = new DefaultCollisionConfiguration();
            Dispatcher = new CollisionDispatcher(CollisionConf);

            Broadphase = new AxisSweep3(new Vector3(-10000, -10000, -10000), new Vector3(10000, 10000, 10000));
            Solver = new SequentialImpulseConstraintSolver();

            World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf);
            World.Gravity = new Vector3(0, -10, 0);

            //World.DispatchInfo.UseConvexConservativeDistanceUtil = true;
            //World.DispatchInfo.ConvexConservativeDistanceThreshold = 0.01f;

            // Setup a big ground box
            CollisionShape groundShape = new BoxShape(100, 10, 100);
            CollisionShapes.Add(groundShape);
            Matrix groundTransform = Matrix.Translation(0, -10, 0);

            RigidBody ground = LocalCreateRigidBody(0, groundTransform, groundShape);
            ground.UserObject = "Ground";

            // Spawn one ragdoll
            SpawnRagdoll(new Vector3(1, 0.5f, 0));
            SpawnRagdoll(new Vector3(-1, 0.5f, 0));
        }
开发者ID:sinkingsugar,项目名称:BulletSharpPInvoke,代码行数:27,代码来源:RagdollDemo.cs

示例2: OnInitializePhysics

        protected override void OnInitializePhysics()
        {
            CollisionConf = new DefaultCollisionConfiguration();
            Dispatcher = new CollisionDispatcher(CollisionConf);

            Broadphase = new DbvtBroadphase();

            World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConf);
            World.Gravity = new Vector3(0, -10, 0);

            // ground
            CollisionShape groundShape = new BoxShape(50, 1, 50);
            CollisionShapes.Add(groundShape);
            CollisionObject ground = LocalCreateRigidBody(0, Matrix.Identity, groundShape);
            ground.UserObject = "Ground";

            // Objects
            //colShape = new BoxShape(1);
            Vector3[] points0 = {
                new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 1)
            };
            Vector3[] points1 = {
                new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 1), new Vector3(0,0,-1), new Vector3(-1,-1,0)
            };
            colShape0 = new ConvexHullShape(points0);
            colShape1 = new ConvexHullShape(points1);
            CollisionShapes.Add(colShape0);
            CollisionShapes.Add(colShape1);

            /*body2 =*/ LocalCreateRigidBody(0, body2Position, colShape1);

            rotBody = LocalCreateRigidBody(0, rotBodyPosition, colShape0);
            rotBody.CollisionFlags |= CollisionFlags.KinematicObject;
            rotBody.ActivationState = ActivationState.DisableDeactivation;
        }
开发者ID:RainsSoft,项目名称:BulletSharpUnity3d,代码行数:35,代码来源:DistanceDemo.cs

示例3: SetUp

        public void SetUp()
        {
            conf = new DefaultCollisionConfiguration();
            dispatcher = new CollisionDispatcher(conf);
            broadphase = new AxisSweep3(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000));
            world = new DiscreteDynamicsWorld(dispatcher, broadphase, null, conf);

            // Initialize TriangleIndexVertexArray with float array
            indexVertexArray = new TriangleIndexVertexArray(TorusMesh.Indices, TorusMesh.Vertices);
            gImpactMeshShape = new GImpactMeshShape(indexVertexArray);
            gImpactMeshShape.CalculateLocalInertia(1.0f);
            gImpactMesh = CreateBody(1.0f, gImpactMeshShape, Vector3.Zero);


            // Initialize TriangleIndexVertexArray with Vector3 array
            Vector3[] torusVertices = new Vector3[TorusMesh.Vertices.Length / 3];
            for (int i = 0; i < torusVertices.Length; i++)
            {
                torusVertices[i] = new Vector3(
                    TorusMesh.Vertices[i * 3],
                    TorusMesh.Vertices[i * 3 + 1],
                    TorusMesh.Vertices[i * 3 + 2]);
            }
            indexVertexArray2 = new TriangleIndexVertexArray(TorusMesh.Indices, torusVertices);
            triangleMeshShape = new BvhTriangleMeshShape(indexVertexArray2, true);
            // CalculateLocalInertia must fail for static shapes (shapes based on TriangleMeshShape)
            //triangleMeshShape.CalculateLocalInertia(1.0f);
            triangleMesh = CreateBody(0.0f, triangleMeshShape, Vector3.Zero);
        }
开发者ID:rhynodegreat,项目名称:BulletSharp,代码行数:29,代码来源:TriangleMeshTest.cs

示例4: OnInitializePhysics

        protected override void OnInitializePhysics()
        {
            // collision configuration contains default setup for memory, collision setup
            CollisionConf = new DefaultCollisionConfiguration();
            Dispatcher = new CollisionDispatcher(CollisionConf);

            Vector3 worldAabbMin = new Vector3(-10000, -10000, -10000);
            Vector3 worldAabbMax = new Vector3(10000, 10000, 10000);
            Broadphase = new AxisSweep3(worldAabbMin, worldAabbMax);

            Solver = new SequentialImpulseConstraintSolver();

            World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf);
            World.Gravity = new Vector3(0, -10, 0);
            World.SetInternalTickCallback(MotorPreTickCallback, this, true);

            // create the ground
            CollisionShape groundShape = new BoxShape(200, 10, 200);
            CollisionShapes.Add(groundShape);
            CollisionObject ground = LocalCreateRigidBody(0, Matrix.Translation(0, -10, 0), groundShape);
            ground.UserObject = "Ground";

            fCyclePeriod = 2000.0f;
            fMuscleStrength = 0.5f;
            m_Time = 0;

            SpawnTestRig(new Vector3(1, 0.5f, 0), false);
            SpawnTestRig(new Vector3(-2, 0.5f, 0), true);
        }
开发者ID:raiker,项目名称:BulletSharp,代码行数:29,代码来源:MotorDemo.cs

示例5: DynamicWorldImp

        internal DynamicWorldImp()
        {
            //Debug.WriteLine("DynamicWorldImp");

            //Default
            // collision configuration contains default setup for memory, collision setup
            BtCollisionConf = new DefaultCollisionConfiguration();
            BtDispatcher = new CollisionDispatcher(BtCollisionConf);
            BtBroadphase = new DbvtBroadphase();
            BtSolver = new SequentialImpulseConstraintSolver();
               // BtCollisionShapes = new AlignedCollisionShapeArray();

            BtWorld = new DiscreteDynamicsWorld(BtDispatcher, BtBroadphase, BtSolver, BtCollisionConf)
            {
                Gravity = new Vector3(0, -9.81f, 0)
            };

            BtWorld.SolverInfo.NumIterations = 5;

            BtWorld.PerformDiscreteCollisionDetection();

            //GImpactCollisionAlgorithm.RegisterAlgorithm(BtDispatcher);
               // BtWorld.SetInternalTickCallback(MyTickCallBack);
            //BtWorld.SetInternalTickCallback(TickTack);

            //ManifoldPoint.ContactAdded += OnContactAdded;
            //PersistentManifold.ContactDestroyed += OnContactDestroyed;
            //PersistentManifold.ContactProcessed += OnContactProcessed;
        }
开发者ID:GameProduction,项目名称:ScharfschiessenGame,代码行数:29,代码来源:DynamicWorldImp.cs

示例6: OnInitializePhysics

        protected override void OnInitializePhysics()
        {
            // collision configuration contains default setup for memory, collision setup
            CollisionConf = new DefaultCollisionConfiguration();
            Dispatcher = new CollisionDispatcher(CollisionConf);

            Broadphase = new DbvtBroadphase();

            World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConf);
            World.Gravity = new Vector3(0, -10, 0);

            // create the ground
            BoxShape groundShape = new BoxShape(50, 1, 50);
            //groundShape.InitializePolyhedralFeatures();
            //CollisionShape groundShape = new StaticPlaneShape(new Vector3(0,1,0), 50);

            CollisionShapes.Add(groundShape);
            CollisionObject ground = LocalCreateRigidBody(0, Matrix.Identity, groundShape);
            ground.UserObject = "Ground";

            // create a few dynamic rigidbodies
            const float mass = 1.0f;

            BoxShape colShape = new BoxShape(1);
            CollisionShapes.Add(colShape);
            Vector3 localInertia = colShape.CalculateLocalInertia(mass);

            const float start_x = StartPosX - ArraySizeX / 2;
            const float start_y = StartPosY;
            const float start_z = StartPosZ - ArraySizeZ / 2;

            int k, i, j;
            for (k = 0; k < ArraySizeY; k++)
            {
                for (i = 0; i < ArraySizeX; i++)
                {
                    for (j = 0; j < ArraySizeZ; j++)
                    {
                        Matrix startTransform = Matrix.Translation(
                            2 * i + start_x,
                            2 * k + start_y,
                            2 * j + start_z
                        );

                        // using motionstate is recommended, it provides interpolation capabilities
                        // and only synchronizes 'active' objects
                        DefaultMotionState myMotionState = new DefaultMotionState(startTransform);
                        RigidBodyConstructionInfo rbInfo =
                            new RigidBodyConstructionInfo(mass, myMotionState, colShape, localInertia);
                        RigidBody body = new RigidBody(rbInfo);
                        rbInfo.Dispose();

                        // make it drop from a height
                        body.Translate(new Vector3(0, 20, 0));

                        World.AddRigidBody(body);
                    }
                }
            }
        }
开发者ID:raiker,项目名称:BulletSharp,代码行数:60,代码来源:BasicDemo.cs

示例7: OnInitializePhysics

        protected override void OnInitializePhysics()
        {
            BoxShape boxA = new BoxShape(new Vector3(1, 1, 1));
            boxA.Margin = 0;

            BoxShape boxB = new BoxShape(new Vector3(0.5f, 0.5f, 0.5f));
            boxB.Margin = 0;

            objects[0] = new CollisionObject();
            objects[1] = new CollisionObject();

            objects[0].CollisionShape = boxA;
            objects[1].CollisionShape = boxB;

            // collision configuration contains default setup for memory, collision setup
            CollisionConf = new DefaultCollisionConfiguration();
            Dispatcher = new CollisionDispatcher(CollisionConf);

            Broadphase = new AxisSweep3(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000));

            World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConf);
            World.Gravity = new Vector3(0, -10, 0);
            IsDebugDrawEnabled = true;

            //World.AddCollisionObject(objects[0]);
            World.AddCollisionObject(objects[1]);

            Quaternion rotA = new Quaternion(0.739f, -0.204f, 0.587f, 0.257f);
            rotA.Normalize();

            objects[0].WorldTransform = Matrix.RotationQuaternion(rotA) * Matrix.Translation(0, 3, 0);
            objects[1].WorldTransform = Matrix.Translation(0, 4.248f, 0);
        }
开发者ID:raiker,项目名称:BulletSharp,代码行数:33,代码来源:CollisionInterfaceDemo.cs

示例8: PreSimulate

        /// <summary>
        /// We can't use constraints because otherwise we wouldn't be able to do loops.
        /// </summary>
        void PreSimulate(DiscreteDynamicsWorld world, FrameEvent evt)
        {
            // if the kart's gone, then we can get rid of this handler too
            if (kart == null || kart.Vehicle.IsDisposed) {
                Detach();
                return;
            }
            // don't self-right if we're paused
            else if (Pauser.IsPaused)
                return;

            // so first we get the kart's orientation
            // then we basically get its local Y axis and average it with the global Y axis to make more of a smooth transition
            Vector3 locY = kart.ActualOrientation.YAxis;

            // first of all, if we're self righted enough, we can get rid of this handler
            if (locY.DirectionEquals(Vector3.UNIT_Y, closeEnoughToUp)) { // 3 degrees
                //Detach();
                return;
            }

            // stop it spinning
            kart.Body.AngularVelocity = Vector3.ZERO;

            // update its rotation to point upwards
            var quat = kart.ActualOrientation;
            // make the x and z factors smaller, so that all that's left at the end is the Y pointing upwards
            quat.x *= 0.92f;
            quat.z *= 0.92f;
            quat.Normalise();

            // then update the body's transform
            kart.Body.SetOrientation(quat);
        }
开发者ID:CisciarpMaster,项目名称:PonyKart,代码行数:37,代码来源:SelfRighter.cs

示例9: MyContactCallback

        /*
        void MyContactCallback(object sender, ContactAddedEventArgs e)
        {
            if (e.CollisionObject0Wrapper.CollisionObject.CollisionShape.ShapeType == BroadphaseNativeType.CompoundShape)
            {
                CompoundShape compound = e.CollisionObject0Wrapper.CollisionObject.CollisionShape as CompoundShape;
                CollisionShape childShape = compound.GetChildShape(e.Index0);
            }

            if (e.CollisionObject1Wrapper.CollisionObject.CollisionShape.ShapeType == BroadphaseNativeType.CompoundShape)
            {
                CompoundShape compound = e.CollisionObject1Wrapper.CollisionObject.CollisionShape as CompoundShape;
                CollisionShape childShape = compound.GetChildShape(e.Index1);
            }

            e.IsContactModified = true;
        }
        */
        public void SetupEmptyDynamicsWorld()
        {
            // collision configuration contains default setup for memory, collision setup
            CollisionConf = new DefaultCollisionConfiguration();
            Dispatcher = new CollisionDispatcher(CollisionConf);

            CompoundCollisionAlgorithm.CompoundChildShapePairCallback = MyCompoundChildShapeCallback;

            convexDecompositionObjectOffset = new Vector3(10, 0, 0);

            Broadphase = new AxisSweep3(new Vector3(-10000, -10000, -10000), new Vector3(10000, 10000, 10000));
            //Broadphase = new SimpleBroadphase();

            Solver = new SequentialImpulseConstraintSolver();
            World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf);

            // create the ground
            CollisionShape groundShape = new BoxShape(30, 2, 30);
            CollisionShapes.Add(groundShape);
            CollisionObject ground = LocalCreateRigidBody(0, Matrix.Translation(0, -4.5f, 0), groundShape);
            ground.UserObject = "Ground";

            // create a few dynamic rigidbodies
            float mass = 1.0f;

            CollisionShape colShape = new BoxShape(1);
            CollisionShapes.Add(colShape);
            Vector3 localInertia = colShape.CalculateLocalInertia(mass);
        }
开发者ID:WebFreak001,项目名称:BulletSharp,代码行数:47,代码来源:ConvexDecompositionDemo.cs

示例10: OnInitializePhysics

        protected override void OnInitializePhysics()
        {
            // collision configuration contains default setup for memory, collision setup
            CollisionConf = new DefaultCollisionConfiguration();
            Dispatcher = new CollisionDispatcher(CollisionConf);

            Broadphase = new DbvtBroadphase();
            Solver = new SequentialImpulseConstraintSolver();

            World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf);
            World.Gravity = Freelook.Up * -10.0f;

            BspLoader bspLoader = new BspLoader();
            //string[] args = Environment.GetCommandLineArgs();
            //if (args.Length == 1)
            //{
            UnityEngine.TextAsset bytes = (UnityEngine.TextAsset)UnityEngine.Resources.Load("BspDemo");
            System.IO.Stream byteStream = new System.IO.MemoryStream(bytes.bytes);
            bspLoader.LoadBspFile(byteStream);
            //}
            //else
            //{
            //    bspLoader.LoadBspFile(args[1]);
            //}
            BspConverter bsp2Bullet = new BspToBulletConverter(this);
            bsp2Bullet.ConvertBsp(bspLoader, 0.1f);
        }
开发者ID:Cyberbanan,项目名称:BulletSharpUnity3d,代码行数:27,代码来源:BspDemo.cs

示例11: OnInitializePhysics

        protected override void OnInitializePhysics()
        {
            // collision configuration contains default setup for memory, collision setup
            CollisionConf = new DefaultCollisionConfiguration();
            Dispatcher = new CollisionDispatcher(CollisionConf);

            Broadphase = new DbvtBroadphase();
            Solver = new SequentialImpulseConstraintSolver();

            World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf);
            World.Gravity = Freelook.Up * -10.0f;

            BspLoader bspLoader = new BspLoader();
            string[] args = Environment.GetCommandLineArgs();
            if (args.Length == 1)
            {
                bspLoader.LoadBspFile("data/BspDemo.bsp");
            }
            else
            {
                bspLoader.LoadBspFile(args[1]);
            }
            BspConverter bsp2Bullet = new BspToBulletConverter(this);
            bsp2Bullet.ConvertBsp(bspLoader, 0.1f);
        }
开发者ID:sinkingsugar,项目名称:BulletSharpPInvoke,代码行数:25,代码来源:BspDemo.cs

示例12: Physics

        public Physics()
        {
            CollisionConfiguration config = new DefaultCollisionConfiguration();
            Dispatcher = new CollisionDispatcher(config);
            World = new DiscreteDynamicsWorld(Dispatcher, new DbvtBroadphase(), null, config);
            World.Gravity = new Vector3(0.0f, -9.81f, 0.0f);

            Props = new List<Prop>();
        }
开发者ID:copygirl,项目名称:Blocky,代码行数:9,代码来源:Physics.cs

示例13: Physics

        public Physics()
        {
            // collision configuration contains default setup for memory, collision setup
            collisionConf = new DefaultCollisionConfiguration();
            dispatcher = new CollisionDispatcher(collisionConf);

            broadphase = new DbvtBroadphase();
            World = new DiscreteDynamicsWorld(dispatcher, broadphase, null, collisionConf);
            World.Gravity = new Vector3(0, -10, 0);

            // create the ground
            CollisionShape groundShape = new BoxShape(50, 50, 50);
            collisionShapes.Add(groundShape);
            CollisionObject ground = LocalCreateRigidBody(0, BulletSharp.Math.Matrix.Translation(0, -50, 0), groundShape);
            ground.UserObject = "Ground";

            // create a few dynamic rigidbodies
            float mass = 1.0f;

            CollisionShape colShape = new BoxShape(1);
            collisionShapes.Add(colShape);
            Vector3 localInertia = colShape.CalculateLocalInertia(mass);

            float start_x = StartPosX - ArraySizeX / 2;
            float start_y = StartPosY;
            float start_z = StartPosZ - ArraySizeZ / 2;

            int k, i, j;
            for (k = 0; k < ArraySizeY; k++)
            {
                for (i = 0; i < ArraySizeX; i++)
                {
                    for (j = 0; j < ArraySizeZ; j++)
                    {
                        BulletSharp.Math.Matrix startTransform = BulletSharp.Math.Matrix.Translation(
                            new Vector3(
                                2*i + start_x,
                                2*k + start_y,
                                2*j + start_z
                                )
                            );

                        // using motionstate is recommended, it provides interpolation capabilities
                        // and only synchronizes 'active' objects
                        DefaultMotionState myMotionState = new DefaultMotionState(startTransform);
                        RigidBodyConstructionInfo rbInfo =
                            new RigidBodyConstructionInfo(mass, myMotionState, colShape, localInertia);
                        RigidBody body = new RigidBody(rbInfo);
                        
                        // make it drop from a height
                        body.Translate(new Vector3(0, 20, 0));

                        World.AddRigidBody(body);
                    }
                }
            }
        }
开发者ID:sinkingsugar,项目名称:BulletSharpPInvoke,代码行数:57,代码来源:Physics.cs

示例14: SetupEmptyDynamicsWorld

 void SetupEmptyDynamicsWorld()
 {
     CollisionConf = new DefaultCollisionConfiguration();
     Dispatcher = new CollisionDispatcher(CollisionConf);
     Broadphase = new DbvtBroadphase();
     Solver = new SequentialImpulseConstraintSolver();
     World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf);
     World.Gravity = new Vector3(0, -10, 0);
 }
开发者ID:sinkingsugar,项目名称:BulletSharpPInvoke,代码行数:9,代码来源:ConstraintDemo.cs

示例15: Setup

		public void Setup(Vector3Df gravity)
		{
			bulletCollisionConfiguration = new DefaultCollisionConfiguration();
			bulletCollisionDispatcher = new CollisionDispatcher(bulletCollisionConfiguration);
			bulletBroadphase = new DbvtBroadphase();

			bulletWorld = new DiscreteDynamicsWorld(bulletCollisionDispatcher, bulletBroadphase, null, bulletCollisionConfiguration);
			bulletWorld.Gravity = new Vector3(gravity.X, gravity.Y, gravity.Z);
		}
开发者ID:Download,项目名称:Irrlicht-Lime,代码行数:9,代码来源:Physics.cs


注:本文中的BulletSharp.DiscreteDynamicsWorld类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。