从变换矩阵得到右向量

问题描述 投票:0回答:1

如何从转换矩阵中获得前向,右向和向上矢量?

我想以这些向量为基础,向不同方向的刚体施加力。

btTransform Trans = _RigidBody->getWorldTransform();

btVector3 Forward;  // ???
btVector3 Right;    // ???
btVector3 Up;       // ???

_RigidBody->activate(true);
//
//  Move forward/backward
_RigidBody->applyCentralForce(Forward * 5);
_RigidBody->applyCentralForce(-Forward * 5);
//
//  Jump
_RigidBody->applyCentralForce(Up * 5);
//
//  Move left/right
_RigidBody->applyCentralForce(Right * 5);
_RigidBody->applyCentralForce(-Right * 5);

我也有一个GLM模型矩阵,该矩阵本质上是glm::mat4内的子弹变换矩阵的副本,我可以在这里使用它代替,并将结果向量转换为子弹,但宁愿留在子弹头上这部分。

c++ glm-math bulletphysics bullet
1个回答
0
投票

您应始终明确地说出您正在使用哪个库。我假设您使用this

operator()为您提供了变换后的矢量图像,因此我认为,以下内容可以满足您的要求:

btVector3 Forward = Trans(btVector3{1,0,0});

© www.soinside.com 2019 - 2024. All rights reserved.