-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbulletvector.cpp
executable file
·78 lines (57 loc) · 1.84 KB
/
bulletvector.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// irrbullet.h inspired by blindside
#ifndef IRR_BULLET_H
#define IRR_BULLET_H
#include <irrlicht.h>
#include <btBulletDynamicsCommon.h>
namespace irr {
// convert bullet vector to irrlicht vector
core::vector3df toIrrVec(const btVector3& v);
// convert
btVector3 toBtVec(const core::vector3df& v);
// get Euler angles in YXZ-order from bullet quaternion
core::vector3df quaternionToEuler(const btQuaternion& q);
// get bullet quaternion from angles in YXZ-order
btQuaternion eulerToQuaternion(const core::vector3df& euler);
// transform irrlicht matrix to bullet transform
btTransform toBtTransform(const core::matrix4& m);
// choose coordinates from vector
core::vector3df vecAxes(const core::vector3df& v, bool x, bool y, bool z);
// null vector
const btVector3 NullVector(0.0f, 0.0f, 0.0f);
} // end namespace irr
#endif
// irrbullet.cpp
#include "irrbullet.h"
using namespace irr;
using namespace core;
vector3df toIrrVec(const btVector3& v)
{
return (vector3df&)v;
}
btVector3 toBtVec(const vector3df& v)
{
// btVector requires special byte alignment so better not take my chances.
return btVector3(v.X, v.Y, v.Z);
}
vector3df quaternionToEuler(const btQuaternion& q) {
vector3df euler;
quaternion(q.getX(), q.getY(), q.getZ(), q.getW()).toEuler(euler);
return euler;
}
btQuaternion eulerToQuaternion(const vector3df& euler) {
return btQuaternion(euler.Y, euler.X, euler.Z);
}
btTransform toBtTransform(const matrix4& m) {
btScalar* p = (btScalar*)m.pointer();
return btTransform(
btMatrix3x3(p[0], p[1], p[2], p[4], p[5], p[6], p[8], p[9], p[10]),
btVector3(p[12], p[13], p[14])
);
}
core::vector3df vecAxes(const core::vector3df& v, bool x, bool y, bool z) {
vector3df c;
if(x) c.X = v.X;
if(y) c.Y = v.Y;
if(z) c.Z = v.Z;
return c;
}