btVector3 btRigidBody::computeGyroscopicForce(btScalar maxGyroscopicForce) const { btVector3 inertiaLocal; inertiaLocal[0] = 1.f/getInvInertiaDiagLocal()[0]; inertiaLocal[1] = 1.f/getInvInertiaDiagLocal()[1]; inertiaLocal[2] = 1.f/getInvInertiaDiagLocal()[2]; btMatrix3x3 inertiaTensorWorld = getWorldTransform().getBasis().scaled(inertiaLocal) * getWorldTransform().getBasis().transpose(); btVector3 tmp = inertiaTensorWorld*getAngularVelocity(); btVector3 gf = getAngularVelocity().cross(tmp); btScalar l2 = gf.length2(); if (l2>maxGyroscopicForce*maxGyroscopicForce) { gf *= btScalar(1.)/btSqrt(l2)*maxGyroscopicForce; } return gf; }
CsRigidBody* CsRigidBody::Clone() { btScalar cloneMass = btScalar(1.0) / getInvMass(); btVector3 cloneInertia(btScalar(1.0)/getInvInertiaDiagLocal().x(), btScalar(1.0)/getInvInertiaDiagLocal().y(), btScalar(1.0) / getInvInertiaDiagLocal().z()); CsMotionState *motionState = NULL; if (getMotionState()) { CsMotionState *oldState = (CsMotionState*) getMotionState(); motionState = new CsMotionState(*oldState); // set this from outer scope motionState->mObj = NULL; } CsRigidBody *cloneBody = new CsRigidBody(cloneMass, motionState, getCollisionShape(), cloneInertia); return cloneBody; // see test CCDphysics project }