//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); }
/// <summary> /// Called by Physics World just before rigid body is added to world. /// The current rigid body properties are used to rebuild the rigid body. /// </summary> internal override bool _BuildCollisionObject() { WorldController world = GetWorld(); if (m_rigidBody != null && isInWorld && world != null) { isInWorld = false; world.RemoveRigidBody(m_rigidBody); } if (transform.localScale != 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(); //MotionState only for no static objects if (m_motionState == null && !isStatic()) { m_motionState = new BGameObjectMotionState(transform); } RigidBody rb = (RigidBody)collisionObject; CreateOrConfigureRigidBody(ref rb, ref _localInertia, cs, m_motionState); collisionObject = rb; collisionObject.UserObject = this; return(true); }
//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); }
//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); }
//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; }
//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) { 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(); 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; return true; }
//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); float bulletMass = _mass; if (!isDynamic()) { bulletMass = 0f; } RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(bulletMass, m_motionState, cs, _localInertia); rbInfo.Friction = _friction; rbInfo.RollingFriction = _rollingFriction; rbInfo.LinearDamping = _linearDamping; rbInfo.AngularDamping = _angularDamping; rbInfo.Restitution = _restitution; rbInfo.LinearSleepingThreshold = _linearSleepingThreshold; rbInfo.AngularSleepingThreshold = _angularSleepingThreshold; rbInfo.AdditionalDamping = _additionalDamping; rbInfo.AdditionalAngularDampingFactor = _additionalAngularDampingFactor; rbInfo.AdditionalAngularDampingThresholdSqr = _additionalAngularDampingThresholdSqr; rbInfo.AdditionalDampingFactor = _additionalDampingFactor; rbInfo.AdditionalLinearDampingThresholdSqr = _additionalLinearDampingThresholdSqr; m_rigidBody = new RigidBody(rbInfo); m_rigidBody.UserObject = this; m_rigidBody.AngularVelocity = _angularVelocity.ToBullet(); m_rigidBody.LinearVelocity = _linearVelocity.ToBullet(); rbInfo.Dispose(); } else { float usedMass = 0f; if (isDynamic()) { usedMass = _mass; } m_rigidBody.SetMassProps(usedMass, _localInertia); m_rigidBody.Friction = _friction; m_rigidBody.RollingFriction = _rollingFriction; m_rigidBody.SetDamping(_linearDamping,_angularDamping); m_rigidBody.Restitution = _restitution; m_rigidBody.SetSleepingThresholds(_linearSleepingThreshold, _angularSleepingThreshold); m_rigidBody.AngularVelocity = _angularVelocity.ToBullet(); m_rigidBody.LinearVelocity = _linearVelocity.ToBullet(); m_rigidBody.CollisionShape = cs; } m_rigidBody.CollisionFlags = m_collisionFlags; m_rigidBody.LinearFactor = _linearFactor.ToBullet(); m_rigidBody.AngularFactor = _angularFactor.ToBullet(); //if kinematic then disable deactivation if ((m_collisionFlags & BulletSharp.CollisionFlags.KinematicObject) != 0) { m_rigidBody.ActivationState = ActivationState.DisableDeactivation; } return true; }