Ejemplo n.º 1
0
        protected override void RemoveObjectFromBulletWorld()
        {
            BPhysicsWorld pw = BPhysicsWorld.Get();

            if (pw != null && m_rigidBody != null && isInWorld)
            {
                Debug.Assert(m_rigidBody.NumConstraintRefs == 0, "Removing rigid body that still had constraints. Remove constraints first.");
                //constraints must be removed before rigid body is removed
                pw.RemoveRigidBody((RigidBody)m_collisionObject);
            }
        }
Ejemplo n.º 2
0
        //called by Physics World just before rigid body is added to world.
        //the current rigid body properties are used to rebuild the rigid body.
        internal override bool _BuildCollisionObject()
        {
            BPhysicsWorld world = BPhysicsWorld.Get();

            if (m_rigidBody != null && isInWorld && world != null)
            {
                isInWorld = false;
                world.RemoveRigidBody(m_rigidBody);
            }

            if (transform.localScale != UnityEngine.Vector3.one)
            {
                Debug.LogErrorFormat("The local scale on {0} rigid body is not one. Bullet physics does not support scaling on a rigid body world transform. Instead alter the dimensions of the CollisionShape.", name);
            }

            m_collisionShape = GetComponent <BCollisionShape>();
            if (m_collisionShape == null)
            {
                Debug.LogErrorFormat("There was no collision shape component attached to this BRigidBody. {0}", name);
                return(false);
            }

            CollisionShape cs = m_collisionShape.GetCollisionShape();

            if (m_motionState == null)
            {
                m_motionState = new BGameObjectMotionState(transform);
            }

            BulletSharp.RigidBody rb = (BulletSharp.RigidBody)m_collisionObject;
            CreateOrConfigureRigidBody(ref rb, ref _localInertia, cs, m_motionState);
            m_collisionObject            = rb;
            m_collisionObject.UserObject = this;

            // gRally
            //if (!isDynamic())
            {
                transform.position   = Native.UtoB(transform.position);
                transform.rotation   = Native.UtoB(transform.rotation);
                transform.localScale = Native.UtoB(transform.localScale);
            }

            return(true);
        }
Ejemplo n.º 3
0
        //called by Physics World just before rigid body is added to world.
        //the current rigid body properties are used to rebuild the rigid body.
        internal override bool _BuildCollisionObject()
        {
            BPhysicsWorld world = BPhysicsWorld.Get();

            if (m_rigidBody != null)
            {
                if (isInWorld && world != null)
                {
                    isInWorld = false;
                    world.RemoveRigidBody(m_rigidBody);
                }
            }

            if (transform.localScale != UnityEngine.Vector3.one)
            {
                BDebug.LogError(debugType, "The local scale on this rigid body is not one. Bullet physics does not support scaling on a rigid body world transform. Instead alter the dimensions of the CollisionShape.");
            }

            m_collisionShape = GetComponent <BCollisionShape>();
            if (m_collisionShape == null)
            {
                BDebug.LogError(debugType, "There was no collision shape component attached to this BRigidBody. {0}", name);
                return(false);
            }

            CollisionShape cs = m_collisionShape.GetCollisionShape();

            //rigidbody is dynamic if and only if mass is non zero, otherwise static
            _localInertia = BulletSharp.Math.Vector3.Zero;
            if (isDynamic())
            {
                cs.CalculateLocalInertia(_mass, out _localInertia);
            }

            if (m_rigidBody == null)
            {
                m_motionState = new BGameObjectMotionState(transform);
                RigidBodyConstructionInfo rbInfo;
                if (isDynamic())
                {
                    rbInfo = new RigidBodyConstructionInfo(_mass, m_motionState, cs, _localInertia);
                }
                else
                {
                    rbInfo = new RigidBodyConstructionInfo(0, m_motionState, cs, localInertia);
                }
                m_rigidBody            = new RigidBody(rbInfo);
                m_rigidBody.UserObject = this;
                rbInfo.Dispose();
                m_rigidBody.CollisionFlags = m_collisionFlags;
            }
            else
            {
                float usedMass = 0f;
                if (isDynamic())
                {
                    usedMass = _mass;
                }
                m_rigidBody.SetMassProps(usedMass, localInertia);
                m_rigidBody.CollisionShape = cs;
                m_rigidBody.CollisionFlags = m_collisionFlags;
            }

            //if kinematic then disable deactivation
            if ((m_collisionFlags & BulletSharp.CollisionFlags.KinematicObject) != 0)
            {
                m_rigidBody.ActivationState = ActivationState.DisableDeactivation;
            }
            return(true);
        }
Ejemplo n.º 4
0
        //called by Physics World just before rigid body is added to world.
        //the current rigid body properties are used to rebuild the rigid body.
        internal bool _BuildRigidBody()
        {
            BPhysicsWorld world = BPhysicsWorld.Get();

            if (m_Brigidbody != null)
            {
                if (isInWorld && world != null)
                {
                    isInWorld = false;
                    world.RemoveRigidBody(m_Brigidbody);
                }
            }

            if (transform.localScale != UnityEngine.Vector3.one)
            {
                Debug.LogError("The local scale on this rigid body is not one. Bullet physics does not support scaling on a rigid body world transform. Instead alter the dimensions of the CollisionShape.");
            }

            m_collisionShape = GetComponent <BCollisionShape>();
            if (m_collisionShape == null)
            {
                Debug.LogError("There was no collision shape component attached to this BRigidBody. " + name);
                return(false);
            }

            CollisionShape cs = m_collisionShape.GetCollisionShape();

            //rigidbody is dynamic if and only if mass is non zero, otherwise static
            _localInertia = BulletSharp.Math.Vector3.Zero;
            if (_type == RBType.dynamic)
            {
                cs.CalculateLocalInertia(_mass, out _localInertia);
            }

            if (m_Brigidbody == null)
            {
                m_motionState = new BGameObjectMotionState(transform);
                RigidBodyConstructionInfo rbInfo;
                if (_type == RBType.dynamic)
                {
                    rbInfo = new RigidBodyConstructionInfo(_mass, m_motionState, cs, _localInertia);
                }
                else
                {
                    rbInfo = new RigidBodyConstructionInfo(0, m_motionState, cs, localInertia);
                }
                m_Brigidbody = new RigidBody(rbInfo);
                rbInfo.Dispose();
            }
            else
            {
                m_Brigidbody.SetMassProps(_mass, localInertia);
                m_Brigidbody.CollisionShape = cs;
            }

            if (_type == RBType.kinematic)
            {
                m_Brigidbody.CollisionFlags  = m_Brigidbody.CollisionFlags | BulletSharp.CollisionFlags.KinematicObject;
                m_Brigidbody.ActivationState = ActivationState.DisableDeactivation;
            }
            if (_isTrigger)
            {
                m_Brigidbody.CollisionFlags = m_Brigidbody.CollisionFlags | BulletSharp.CollisionFlags.NoContactResponse;
            }
            return(true);
        }