15 #include "bullet_utils.h"
17 #include "transformState.h"
23 btVector3 LVecBase3_to_btVector3(
const LVecBase3 &v) {
25 return btVector3((btScalar)v.get_x(),
34 LVecBase3 btVector3_to_LVecBase3(
const btVector3 &v) {
37 (PN_stdfloat)v.getY(),
38 (PN_stdfloat)v.getZ());
45 LVector3 btVector3_to_LVector3(
const btVector3 &v) {
47 return LVector3((PN_stdfloat)v.getX(),
48 (PN_stdfloat)v.getY(),
49 (PN_stdfloat)v.getZ());
56 LPoint3 btVector3_to_LPoint3(
const btVector3 &p) {
58 return LPoint3((PN_stdfloat)p.getX(),
59 (PN_stdfloat)p.getY(),
60 (PN_stdfloat)p.getZ());
67 btMatrix3x3 LMatrix3_to_btMatrix3x3(
const LMatrix3 &m) {
70 result.setFromOpenGLSubMatrix((
const btScalar *)m.
get_data());
78 LMatrix3 btMatrix3x3_to_LMatrix3(
const btMatrix3x3 &m) {
81 m.getOpenGLSubMatrix(cells);
82 return LMatrix3((PN_stdfloat)cells[0], (PN_stdfloat)cells[1], (PN_stdfloat)cells[2],
83 (PN_stdfloat)cells[3], (PN_stdfloat)cells[4], (PN_stdfloat)cells[5],
84 (PN_stdfloat)cells[6], (PN_stdfloat)cells[7], (PN_stdfloat)cells[8]);
91 btQuaternion LQuaternion_to_btQuat(
const LQuaternion &q) {
93 return btQuaternion((btScalar)q.get_i(),
103 LQuaternion btQuat_to_LQuaternion(
const btQuaternion &q) {
106 (PN_stdfloat)q.getX(),
107 (PN_stdfloat)q.getY(),
108 (PN_stdfloat)q.getZ());
115 btTransform LMatrix4_to_btTrans(
const LMatrix4 &m) {
120 btQuaternion btq = LQuaternion_to_btQuat(quat);
121 btVector3 btv = LVecBase3_to_btVector3(m.
get_row3(3));
123 return btTransform(btq, btv);
130 LMatrix4 btTrans_to_LMatrix4(
const btTransform &trans) {
132 return TransformState::make_pos_quat_scale(
133 btVector3_to_LVector3(trans.getOrigin()),
134 btQuat_to_LQuaternion(trans.getRotation()),
135 LVector3(1.0f, 1.0f, 1.0f))->get_mat();
142 CPT(TransformState) btTrans_to_TransformState(const btTransform &trans, const
LVecBase3 &scale) {
144 LVecBase3 pos = btVector3_to_LVector3(trans.getOrigin());
145 LQuaternion quat = btQuat_to_LQuaternion(trans.getRotation());
147 return TransformState::make_pos_quat_scale(pos, quat, scale);
154 btTransform TransformState_to_btTrans(CPT(TransformState) ts) {
156 ts = ts->set_scale(1.0);
163 btQuaternion btq = LQuaternion_to_btQuat(quat);
164 btVector3 btv = LVecBase3_to_btVector3(m.
get_row3(3));
166 return btTransform(btq, btv);
173 BulletUpAxis get_default_up_axis() {
175 switch (get_default_coordinate_system()) {
194 void get_node_transform(btTransform &trans,
PandaNode *node) {
197 CPT(TransformState) ts;
198 if (node->get_num_parents() == 0) {
199 ts = node->get_transform();
203 ts = np.get_net_transform();
215 btQuaternion btq = LQuaternion_to_btQuat(quat);
216 btVector3 btv = LVecBase3_to_btVector3(m.
get_row3(3));
218 trans.setRotation(btq);
219 trans.setOrigin(btv);
226 int get_bullet_version() {
228 return BT_BULLET_VERSION;
LMatrix3f get_upper_3() const
Retrieves the upper 3x3 submatrix.
A basic node of the scene graph or data graph.
This is the base class for all three-component vectors and points.
void set_scale(PN_stdfloat scale)
Sets the scale component of the transform, leaving translation and rotation untouched.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
static NodePath any_path(PandaNode *node, Thread *current_thread=Thread::get_current_thread())
Returns a new NodePath that represents any arbitrary path from the root to the indicated node...
This is a 4-by-4 transform matrix.
This is the base quaternion class.
const float * get_data() const
Returns the address of the first of the nine data elements in the matrix.
void set_from_matrix(const LMatrix3f &m)
Sets the quaternion according to the rotation represented by the matrix.
LVecBase3f get_row3(int row) const
Retrieves the row column of the matrix as a 3-component vector, ignoring the last column...
This is a 3-by-3 transform matrix.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...