0
我最近在我的3D遊戲中附加了一個剛體,以便它可以與環境相撞。現在鼠標移動直接旋轉剛體。剛體的夾角旋轉角度
#include <BULLET/btBulletDynamicsCommon.h>
void Rotate(float Pitch, float Yaw, float Roll, float Speed)
{
// get current rotation
btTransform transform = body->getWorldTransform();
btQuaternion rotation = transform.getRotation();
// create orientation vectors
btVector3 up(0, 1, 0);
btVector3 lookat = quatRotate(rotation, btVector3(0, 0, 1));
btVector3 forward = btVector3(lookat.getX(), 0, lookat.getZ()).normalize();
btVector3 side = btCross(up, forward);
// rotate camera with quaternions created from axis and angle
rotation = btQuaternion(up, Amount.getY()) * rotation;
rotation = btQuaternion(side, Amount.getX()) * rotation;
rotation = btQuaternion(forward, Amount.getZ()) * rotation;
// set new rotation
transform.setRotation(rotation);
body->setWorldTransform(transform);
}
我想夾住攝像機的間距的-80°
至80°
。這有助於玩家保持導向。否則,他將能夠將相機更高地轉動到頭頂上,並將自己背後的世界倒過來看。相反,一個真正的人試圖這會打破他的脖子。
我讓Bullet Physics爲我在四元數存儲旋轉,因此瀝青不直接存儲。我如何夾緊剛體的間距?