Exemplo n.º 1
0
        static void Main(string[] args)
        {
            {
                var world = new DiscreteDynamicsWorld();
                world.Gravity = new Vector3(0.0f, -10.0f, 0.0f);

                var info0 = new RigidBodyConstructionInfo();
                info0.Mass = 1.0f;
                info0.CollisionShape = new BulletDotNet.Shapes.BoxShape(Vector3.One);
                info0.CenterOfMass = Vector3.Zero;
                var rb0 = new RigidBody(info0, OnGetTransform0, OnSetTransform0);

                var info1 = new RigidBodyConstructionInfo();
                info1.Mass = 0.0f;
                info1.CollisionShape = new BulletDotNet.Shapes.BoxShape(Vector3.One);
                info1.CenterOfMass = Vector3.Zero;
                var rb1 = new RigidBody(info1, OnGetTransform1, OnSetTransform1);

                world.AddRigidBody(rb0);
                world.AddRigidBody(rb1);

                for (int i = 0; i < 100; i++)
                {
                    rb0.Activate();
                    world.StepSimulation(1.0f / 60.0f);
                }

                world.RemoveRigidBody(rb0);
                world.RemoveRigidBody(rb1);
            }

            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
Exemplo n.º 2
0
    void Start()
    {
        var boxCollider = GetComponent<BoxCollider>();
        var boxSize = UnityEngine.Vector3.Scale(boxCollider.size, transform.lossyScale);
        var boxHalfExtents = new BulletDotNet.Vector3 {
            X = boxSize.x * 0.5f,
            Y = boxSize.y * 0.5f,
            Z = boxSize.z * 0.5f
        };

        var info = new RigidBodyConstructionInfo();
        info.Mass = mass;
        info.CollisionShape = new BulletDotNet.Shapes.BoxShape(boxHalfExtents);
        info.CenterOfMass = new BulletDotNet.Vector3 { X = centerOfMass.x, Y = centerOfMass.y, Z = centerOfMass.z };
        info.Friction = friction;
        info.LinearDamping = 0.1f;
        info.LinearSleepingThreshold = 0.01f;
        m_rigidBody = new RigidBody(info, OnGetTransform, OnSetTransform);

        AddRigidBody();
    }
Exemplo n.º 3
0
        public RigidBody(RigidBodyConstructionInfo info, RigidBody.GetTransformDelegate get, RigidBody.SetTransformDelegate set)
        {
            m_info = info;
            OnGetTransform = get;
            OnSetTransform = set;

            var biInfo = new Imports.biRigidBodyConstructionInfo();
            biInfo.m_mass = m_info.Mass;
            biInfo.m_collisionShape = m_info.CollisionShape.m_handle;
            biInfo.m_linearDamping = m_info.LinearDamping;
            biInfo.m_angularDamping = m_info.AngularDamping;
            biInfo.m_friction = m_info.Friction;
            biInfo.m_rollingFriction = m_info.RollingFriction;
            biInfo.m_restitution = m_info.Restitution;
            biInfo.m_linearSleepingThreshold = m_info.LinearSleepingThreshold;
            biInfo.m_angularSleepingThreshold = m_info.AngularSleepingThreshold;

            m_getDelegate = MotionStateGetTransform;
            m_setDelegate = MotionStateSetTransform;

            m_handle = Imports.biCreateRigidBody(ref biInfo, IntPtr.Zero, Marshal.GetFunctionPointerForDelegate(m_getDelegate), Marshal.GetFunctionPointerForDelegate(m_setDelegate));
        }
Exemplo n.º 4
0
        public RigidBody(RigidBodyConstructionInfo info, RigidBody.GetTransformDelegate get, RigidBody.SetTransformDelegate set)
        {
            m_info         = info;
            OnGetTransform = get;
            OnSetTransform = set;

            var biInfo = new Imports.biRigidBodyConstructionInfo();

            biInfo.m_mass                     = m_info.Mass;
            biInfo.m_collisionShape           = m_info.CollisionShape.m_handle;
            biInfo.m_linearDamping            = m_info.LinearDamping;
            biInfo.m_angularDamping           = m_info.AngularDamping;
            biInfo.m_friction                 = m_info.Friction;
            biInfo.m_rollingFriction          = m_info.RollingFriction;
            biInfo.m_restitution              = m_info.Restitution;
            biInfo.m_linearSleepingThreshold  = m_info.LinearSleepingThreshold;
            biInfo.m_angularSleepingThreshold = m_info.AngularSleepingThreshold;

            m_getDelegate = MotionStateGetTransform;
            m_setDelegate = MotionStateSetTransform;

            m_handle = Imports.biCreateRigidBody(ref biInfo, IntPtr.Zero, Marshal.GetFunctionPointerForDelegate(m_getDelegate), Marshal.GetFunctionPointerForDelegate(m_setDelegate));
        }