public bool OnBulletCreate() { if( rigidBodyObj != null ) // have created! { return true; } if( CollisionShapeObject == null ) // if user not give a collision, search it on itself first! CollisionShapeObject = GetComponent<BCollisionShape>(); if( CollisionShapeObject == null ) { Debug.LogError("Bullet RigidBody need a collision shape!"); return false; } bool cResult = CollisionShapeObject.OnBulletCreate(); if( cResult == false ) { Debug.LogError("Collision Shape Create Error!"); return false; } btTransform trans = new btTransform(); trans.setIdentity(); btVector3 pos = new btVector3(transform.position.x,transform.position.y,transform.position.z); trans.setOrigin(pos); trans.setRotation(new btQuaternion(transform.rotation.x,transform.rotation.y,transform.rotation.z,transform.rotation.w)); //rigidbody is dynamic if and only if mass is non zero, otherwise static bool isDynamic = (Mass != 0.0f); btVector3 localInertia = new btVector3(0,0,0); if (isDynamic) { CollisionShapeObject.CalculateLocalInertia(Mass,localInertia); } //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects myMotionState = new btDefaultMotionState(trans); rbInfo = new btRigidBodyConstructionInfo(Mass,myMotionState.GetSwigPtr(),CollisionShapeObject.GetCollisionShapePtr(),localInertia.GetSwigPtr()); rigidBodyObj = new btRigidBody(rbInfo); collisionObject = btCollisionObject.GetObjectFromSwigPtr(rigidBodyObj.GetCollisionObject()); collisionObject.setFriction(Friction); return true; }
internal static HandleRef getCPtr(btDefaultMotionState obj) { return((obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr); }
internal static HandleRef getCPtr(btDefaultMotionState obj) { return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr; }