/// <summary>
		/// this btSimpleDynamicsWorld constructor creates dispatcher, broadphase pairCache and constraintSolver
		/// </summary>
		/// <param name="dispatcher"></param>
		/// <param name="pairCache"></param>
		/// <param name="constraintSolver"></param>
		public SimpleDynamicsWorld(IDispatcher dispatcher, OverlappingPairCache pairCache, IConstraintSolver constraintSolver)
			: base(dispatcher, pairCache)
		{
			_constraintSolver = constraintSolver;
			_ownsConstraintSolver = false;
			_gravity = new Vector3(0, 0, -10);
		}
Exemple #2
0
        public void reset()
        {
            foreach (RigidBodyObject rbo in _physics_world.rigid_body_objects)
            {
                rbo.body.ClearForces();
                rbo.body.AngularVelocity = Vector3.Zero;
                rbo.body.LinearVelocity  = Vector3.Zero;

                rbo.body.WorldTransform             = rbo.original_transformation;
                rbo.body.MotionState.WorldTransform = rbo.original_transformation;
                rbo.body.Activate();
            }


            OverlappingPairCache       pair_cache = _physics_world.world.Broadphase.OverlappingPairCache;
            AlignedBroadphasePairArray pair_array = pair_cache.OverlappingPairArray;

            for (int i = 0; i < pair_array.Count; i++)
            {
                pair_cache.CleanOverlappingPair(pair_array[i], _physics_world.world.Dispatcher);
            }

            _solver.Reset();
            _physics_world.world.ClearForces();
            _broadphase.ResetPool(_dispatcher);

            _physics_world.paused = false;
        }
 /// <summary>
 /// this btSimpleDynamicsWorld constructor creates dispatcher, broadphase pairCache and constraintSolver
 /// </summary>
 /// <param name="dispatcher"></param>
 /// <param name="pairCache"></param>
 /// <param name="constraintSolver"></param>
 public SimpleDynamicsWorld(IDispatcher dispatcher, OverlappingPairCache pairCache, IConstraintSolver constraintSolver)
     : base(dispatcher, pairCache)
 {
     _constraintSolver     = constraintSolver;
     _ownsConstraintSolver = false;
     _gravity = new Vector3(0, 0, -10);
 }
Exemple #4
0
 //this btDiscreteDynamicsWorld constructor gets created objects from the user, and will not delete those
 public DiscreteDynamicsWorld(IDispatcher dispatcher, OverlappingPairCache pairCache, IConstraintSolver constraintSolver)
     : base(dispatcher, pairCache)
 {
     _constraintSolver = constraintSolver != null ? constraintSolver : new SequentialImpulseConstraintSolver();
     _debugDrawer = null;
     _gravity = new Vector3(0, -10, 0);
     _localTime = 1f / 60f;
     _profileTimings = 0;
     _islandManager = new SimulationIslandManager();
     _ownsIslandManager = true;
     _ownsConstraintSolver = constraintSolver == null;
 }
 //this btDiscreteDynamicsWorld constructor gets created objects from the user, and will not delete those
 public DiscreteDynamicsWorld(IDispatcher dispatcher, OverlappingPairCache pairCache, IConstraintSolver constraintSolver)
     : base(dispatcher, pairCache)
 {
     _constraintSolver     = constraintSolver != null ? constraintSolver : new SequentialImpulseConstraintSolver();
     _debugDrawer          = null;
     _gravity              = new Vector3(0, -10, 0);
     _localTime            = 1f / 60f;
     _profileTimings       = 0;
     _islandManager        = new SimulationIslandManager();
     _ownsIslandManager    = true;
     _ownsConstraintSolver = constraintSolver == null;
 }
Exemple #6
0
    //GUIHelperInterface m_guiHelper;

    public CommonMultiBodyBase()
    {
        //m_filterCallback = null;
        m_pairCache              = null;
        m_broadphase             = null;
        m_dispatcher             = null;
        m_solver                 = null;
        m_collisionConfiguration = null;
        m_dynamicsWorld          = null;
        //m_pickedBody = null;
        //m_pickedConstraint = null;
        //m_pickingMultiBodyPoint2Point = null;
        m_prevCanSleep = false;
        //m_guiHelper = null;
    }
        public override void UpdateAabbs()
        {
            Vector3 colorvec = new Vector3(1, 0, 0);

            for (int i = 0; i < CollisionObjects.Count; i++)
            {
                CollisionObject colObj = CollisionObjects[i];
                RigidBody       body   = RigidBody.Upcast(colObj);

                if (body != null)
                {
                    //	if (body->IsActive() && (!body->IsStatic()))
                    {
                        Vector3 minAabb, maxAabb;
                        colObj.CollisionShape.GetAabb(colObj.WorldTransform, out minAabb, out maxAabb);
                        OverlappingPairCache bp = BroadphasePairCache;

                        //moving objects should be moderately sized, probably something wrong if not
                        if (colObj.IsStaticObject || ((maxAabb - minAabb).LengthSquared() < 1e12f))
                        {
                            bp.SetAabb(body.Broadphase, minAabb, maxAabb);
                        }
                        else
                        {
                            //something went wrong, investigate
                            //this assert is unwanted in 3D modelers (danger of loosing work)
                            BulletDebug.Assert(false);
                            body.ActivationState = ActivationState.DisableSimulation;

                            if (_reportMe)
                            {
                                _reportMe = false;
                                Console.WriteLine("Overflow in AABB, object removed from simulation \n");
                                Console.WriteLine("If you can reproduce this, please email [email protected]\n");
                                Console.WriteLine("Please include above information, your Platform, version of OS.\n");
                                Console.WriteLine("Thanks.\n");
                            }
                        }
                        if (_debugDrawer != null && (_debugDrawer.DebugMode & DebugDrawModes.DrawAabb) != 0)
                        {
                            DrawAabb(_debugDrawer, minAabb, maxAabb, colorvec);
                        }
                    }
                }
            }
        }
Exemple #8
0
        /// <summary>
        /// Reinitializes physics.
        /// </summary>
        public void ResetPhysics()
        {
            _collisionDispatcher = new CollisionDispatcher();

            if (_useSweepAndPrune)
            {
                Vector3   worldAabbMin = new Vector3(-10000, -10000, -10000);
                Vector3   worldAabbMax = new Vector3(10000, 10000, 10000);
                const int maxProxies   = 32766;
                _broadphase = new AxisSweep3(worldAabbMin, worldAabbMax, maxProxies);
            }
            else
            {
                _broadphase = new SimpleBroadphase();
            }

            _solver = new SequentialImpulseConstraintSolver();
            _world  = new DiscreteDynamicsWorld(_collisionDispatcher, _broadphase, _solver);

            //world.setConstraintSolver(solver);
            _world.Gravity = new Vector3(0, -10, 0);

            _shapePtr    = new CollisionShape[4];
            _shapePtr[0] = new BoxShape(new Vector3(50, 10, 50));
            _shapePtr[1] = new CylinderShape(new Vector3(_cubeHalfExtent - _collisionMargin, _cubeHalfExtent - _collisionMargin, _cubeHalfExtent - _collisionMargin));
            _shapePtr[2] = new SphereShape(_cubeHalfExtent);
            _shapePtr[3] = new BoxShape(new Vector3(_cubeHalfExtent, _cubeHalfExtent, _cubeHalfExtent));

            _shapeIndex = new int[_maxNumObjects];
            Matrix tr = Matrix.Identity;

            for (int i = 0; i < _numObjects; i++)
            {
                if (i > 0)
                {
                    // set shape
                    _shapeIndex[i] = 1;
                }
                else
                {
                    _shapeIndex[i] = 0;
                }
            }

            GC.Collect();
        }
Exemple #9
0
        public virtual void createEmptyDynamicsWorld()
        {
            ///collision configuration contains default setup for memory, collision setup
            CollisionConf = new DefaultCollisionConfiguration();

            ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
            Dispatcher = new CollisionDispatcher(CollisionConf);

            m_pairCache = new HashedOverlappingPairCache();

            Broadphase = new DbvtBroadphase(m_pairCache);

            m_solver = new MultiBodyConstraintSolver();

            World = m_dynamicsWorld = new MultiBodyDynamicsWorld(Dispatcher, Broadphase, m_solver, CollisionConf);

            m_dynamicsWorld.Gravity = (new BulletSharp.Math.Vector3(0, -10, 0));
        }
Exemple #10
0
    public virtual void createEmptyDynamicsWorld()
    {
        ///collision configuration contains default setup for memory, collision setup

        m_collisionConfiguration = new DefaultCollisionConfiguration();
        //m_collisionConfiguration.setConvexConvexMultipointIterations();
        //m_filterCallback = new MyOverlapFilterCallback2();

        ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
        m_dispatcher = new      CollisionDispatcher(m_collisionConfiguration);

        m_pairCache = new HashedOverlappingPairCache();

        //m_pairCache.OverlapFilterCallback = (m_filterCallback);

        m_broadphase = new DbvtBroadphase(m_pairCache);        //btSimpleBroadphase();

        m_solver = new MultiBodyConstraintSolver();

        m_dynamicsWorld = new MultiBodyDynamicsWorld(m_dispatcher, m_broadphase, m_solver, m_collisionConfiguration);

        m_dynamicsWorld.Gravity = (new BulletSharp.Math.Vector3(0, -10, 0));
    }
Exemple #11
0
		public DynamicsWorld(IDispatcher dispatcher, OverlappingPairCache pairCache)
			: base(dispatcher, pairCache) { }
Exemple #12
0
 public DiscreteDynamicsWorld(IDispatcher dispatcher, OverlappingPairCache pairCache)
     : this(dispatcher, pairCache, null)
 {
 }
Exemple #13
0
 public DynamicsWorld(IDispatcher dispatcher, OverlappingPairCache pairCache)
     : base(dispatcher, pairCache)
 {
 }
Exemple #14
0
    public virtual void exitPhysics()
    {
        removePickingConstraint();
        //cleanup in the reverse order of creation/initialization

        //remove the rigidbodies from the dynamics world and delete them

        if (m_dynamicsWorld == null)
        {
            int i;
            for (i = m_dynamicsWorld.NumConstraints - 1; i >= 0; i--)
            {
                m_dynamicsWorld.RemoveConstraint(m_dynamicsWorld.GetConstraint(i));
            }

            for (i = m_dynamicsWorld.NumMultiBodyConstraints - 1; i >= 0; i--)
            {
                MultiBodyConstraint mbc = m_dynamicsWorld.GetMultiBodyConstraint(i);
                m_dynamicsWorld.RemoveMultiBodyConstraint(mbc);
                mbc.Dispose();
            }

            for (i = m_dynamicsWorld.NumMultibodies - 1; i >= 0; i--)
            {
                MultiBody mb = m_dynamicsWorld.GetMultiBody(i);
                m_dynamicsWorld.RemoveMultiBody(mb);
                mb.Dispose();
            }
            for (i = m_dynamicsWorld.NumCollisionObjects - 1; i >= 0; i--)
            {
                CollisionObject obj  = m_dynamicsWorld.CollisionObjectArray[i];
                RigidBody       body = RigidBody.Upcast(obj);
                if (body != null && body.MotionState != null)
                {
                    body.MotionState.Dispose();
                }
                m_dynamicsWorld.RemoveCollisionObject(obj);
                obj.Dispose();
            }
        }
        //delete collision shapes
        for (int j = 0; j < m_collisionShapes.Count; j++)
        {
            CollisionObject shape = m_collisionShapes[j];
            shape.Dispose();
        }
        m_collisionShapes.Clear();

        m_dynamicsWorld.Dispose();
        m_dynamicsWorld = null;

        m_solver.Dispose();
        m_solver = null;

        m_broadphase.Dispose();
        m_broadphase = null;

        m_dispatcher.Dispose();
        m_dispatcher = null;

        m_pairCache.Dispose();
        m_pairCache = null;

        //m_filterCallback.Dispose();
        //m_filterCallback = null;

        m_collisionConfiguration.Dispose();
        m_collisionConfiguration = null;
    }
Exemple #15
0
        public override void ExitPhysics()
        {
            if (m_inverseModel != null)
            {
                Debug.Log("Dispose inverse model " + m_inverseModel.NumBodies);
                m_inverseModel.Dispose();
            }

            Debug.Log("InverseDynamicsExitPhysics");
            //cleanup in the reverse order of creation/initialization

            //remove the rigidbodies from the dynamics world and delete them

            if (m_dynamicsWorld == null)
            {
                int i;
                for (i = m_dynamicsWorld.NumConstraints - 1; i >= 0; i--)
                {
                    TypedConstraint tc = m_dynamicsWorld.GetConstraint(i);
                    m_dynamicsWorld.RemoveConstraint(tc);
                    tc.Dispose();
                }

                for (i = m_dynamicsWorld.NumMultiBodyConstraints - 1; i >= 0; i--)
                {
                    MultiBodyConstraint mbc = m_dynamicsWorld.GetMultiBodyConstraint(i);
                    m_dynamicsWorld.RemoveMultiBodyConstraint(mbc);
                    mbc.Dispose();
                }

                for (i = m_dynamicsWorld.NumMultibodies - 1; i >= 0; i--)
                {
                    MultiBody mb = m_dynamicsWorld.GetMultiBody(i);
                    m_dynamicsWorld.RemoveMultiBody(mb);
                    mb.Dispose();
                }
                for (i = m_dynamicsWorld.NumCollisionObjects - 1; i >= 0; i--)
                {
                    CollisionObject obj  = m_dynamicsWorld.CollisionObjectArray[i];
                    RigidBody       body = RigidBody.Upcast(obj);
                    if (body != null && body.MotionState != null)
                    {
                        body.MotionState.Dispose();
                    }
                    m_dynamicsWorld.RemoveCollisionObject(obj);
                    obj.Dispose();
                }
            }

            if (m_multiBody != null)
            {
                m_multiBody.Dispose();
            }

            //delete collision shapes
            for (int j = 0; j < CollisionShapes.Count; j++)
            {
                CollisionShape shape = CollisionShapes[j];
                shape.Dispose();
            }
            CollisionShapes.Clear();

            m_dynamicsWorld.Dispose();
            m_dynamicsWorld = null;

            m_solver.Dispose();
            m_solver = null;

            Broadphase.Dispose();
            Broadphase = null;

            Dispatcher.Dispose();
            Dispatcher = null;

            m_pairCache.Dispose();
            m_pairCache = null;

            CollisionConf.Dispose();
            CollisionConf = null;
            Debug.Log("After dispose B");
        }
 public DiscreteDynamicsWorld(IDispatcher dispatcher, OverlappingPairCache pairCache)
     : this(dispatcher, pairCache, null)
 {
 }