CVector PhysicObject::getPhysPosition() { if (!rigidBody) return initialPosition; btTransform trans; if (getIsKinematic()) { rigidBody->getMotionState()->getWorldTransform(trans); } else { trans = rigidBody->getWorldTransform(); } CVector res = CVector(trans.getOrigin().getX() * 100.0f, trans.getOrigin().getY() * 100.0f, trans.getOrigin().getZ() * 100.0f); return res; }
void PhysXRigidbody::rotate(const Quaternion& rotation) { if (getIsKinematic()) { PxTransform target; if (!mInternal->getKinematicTarget(target)) target = PxTransform(PxIdentity); target.q = toPxQuaternion(rotation); mInternal->setKinematicTarget(target); } else { setTransform(getPosition(), rotation); } }
void PhysXRigidbody::move(const Vector3& position) { if (getIsKinematic()) { PxTransform target; if (!mInternal->getKinematicTarget(target)) target = PxTransform(PxIdentity); target.p = toPxVector(position); mInternal->setKinematicTarget(target); } else { setTransform(position, getRotation()); } }
void PhysicObject::setPhysPosition(CVector pos) { if (rigidBody) { btTransform trans; if (getIsKinematic()) { rigidBody->getMotionState()->getWorldTransform(trans); trans.setOrigin(btVector3(pos.x / 100.0f, pos.y / 100.0f, pos.z / 100.0f)); rigidBody->getMotionState()->setWorldTransform(trans); } else { trans = rigidBody->getWorldTransform(); trans.setOrigin(btVector3(pos.x / 100.0f, pos.y / 100.0f, pos.z / 100.0f)); rigidBody->setWorldTransform(trans); } return; } initialPosition = pos / 100.0f; }