8 #ifndef CO_MATH_UTILS_H_
9 #define CO_MATH_UTILS_H_
10 #ifndef _USE_MATH_DEFINES
11 #define _USE_MATH_DEFINES
13 #include <util/coExport.h>
19 #define M_PI 3.141592653
24 #define MAKE_EULER_MAT(m, h, p, r) \
26 double sr, sp, sh, cr, cp, ch; \
27 sr = sin(r / 180.0 * M_PI); \
28 sp = sin(p / 180.0 * M_PI); \
29 sh = sin(h / 180.0 * M_PI); \
30 cr = cos(r / 180.0 * M_PI); \
31 cp = cos(p / 180.0 * M_PI); \
32 ch = cos(h / 180.0 * M_PI); \
33 m(0, 0) = ch * cr - sh * sr * sp; \
34 m(0, 1) = cr * sh + ch * sr * sp; \
41 m(2, 0) = sp * cr * sh + sr * ch; \
42 m(2, 1) = sr * sh - sp * cr * ch; \
50 #define MAKE_EULER_MAT_VEC(m, hpr) MAKE_EULER_MAT(m, hpr[0], hpr[1], hpr[2])
54 #define GET_HPR(m, h, p, r) \
57 osg::Vec3 v1(m(0, 0), m(0, 1), m(0, 2)); \
58 osg::Vec3 v2(m(1, 0), m(1, 1), m(1, 2)); \
59 osg::Vec3 v3(m(2, 0), m(2, 1), m(2, 2)); \
74 float d = m(1, 0) / cp; \
85 float diff = cos(h) * cp - m(1, 1); \
86 if (diff < -0.01 || diff > 0.01) \
89 diff = cos(h) * cp - m(1, 1); \
90 if (diff < -0.01 || diff > 0.01) \
105 diff = cos(h) * cp - m(1, 1); \
106 if (diff < -0.01 || diff > 0.01) \
119 diff = -sin(r) * cp - m(0, 2); \
120 if (diff < -0.01 || diff > 0.01) \
122 h = h / M_PI * 180.0; \
123 p = p / M_PI * 180.0; \
124 r = r / M_PI * 180.0; \
127 #define GET_HPR_VEC(mx, hpr) \
131 osg::Vec3 v1(mx(0, 0), mx(0, 1), mx(0, 2)); \
132 osg::Vec3 v2(mx(1, 0), mx(1, 1), mx(1, 2)); \
133 osg::Vec3 v3(mx(2, 0), mx(2, 1), mx(2, 2)); \
146 hpr[1] = asin(m(1, 2)); \
148 hpr[0] = -asin(m(1, 0) / cp); \
149 float diff = cos(hpr[0]) * cp - m(1, 1); \
150 if (diff < -0.01 || diff > 0.01) \
152 hpr[0] = M_PI - hpr[0]; \
153 diff = cos(hpr[0]) * cp - m(1, 1); \
154 if (diff < -0.01 || diff > 0.01) \
156 hpr[1] = M_PI - hpr[1]; \
158 hpr[0] = -asin(m(1, 0) / cp); \
159 diff = cos(hpr[0]) * cp - m(1, 1); \
160 if (diff < -0.01 || diff > 0.01) \
162 hpr[0] = M_PI - hpr[0]; \
166 hpr[2] = acos(m(2, 2) / cp); \
167 diff = -sin(hpr[2]) * cp - m(0, 2); \
168 if (diff < -0.01 || diff > 0.01) \
170 hpr[0] = hpr[0] / M_PI * 180.0; \
171 hpr[1] = hpr[1] / M_PI * 180.0; \
172 hpr[2] = hpr[2] / M_PI * 180.0; \
180 coCoord(
const osg::Matrix &right);
185 coCoord &operator=(
const osg::Matrix &right);
186 void makeMat(osg::Matrix &right);
189 void initFromMatrix(
const osg::Matrix &right);
195 void OSGVRUIEXPORT
snapToDegrees(
float degree, osg::Matrix *mat);
197 double OSGVRUIEXPORT
mod(
double a,
double b);
osg::Vec3 xyz
Definition: mathUtils.h:183
void OSGVRUIEXPORT snapTo45Degrees(osg::Matrix *mat)
double OSGVRUIEXPORT mod(double a, double b)
coCoord()
Definition: mathUtils.h:179
osg::Vec3 hpr
Definition: mathUtils.h:184
void OSGVRUIEXPORT snapToDegrees(float degree, osg::Matrix *mat)
Definition: mathUtils.h:176