2 #include <boost/test/unit_test.hpp>
3 #include <boost/shared_ptr.hpp>
4 #include <boost/date_time/posix_time/posix_time.hpp>
5 #include <boost/thread/thread.hpp>
7 BOOST_AUTO_TEST_SUITE( Rotation_Suite )
9 bool is_critical( CStdErrorInfo const& ex ) {
return ex.m_lError < 0; }
12 void normalise(
float &x,
float &y,
float &z,
float &w,
float fltTolerance)
15 float mag2 = w * w + x * x + y * y + z * z;
16 if (fabs(mag2) > fltTolerance && fabs(mag2 - 1.0f) > fltTolerance) {
17 float mag = sqrt(mag2);
26 osg::Quat FromEuler(
float pitch,
float yaw,
float roll)
28 float rollOver2 = roll * 0.5f;
29 float sinRollOver2 = (float)sin((
double)rollOver2);
30 float cosRollOver2 = (float)cos((
double)rollOver2);
31 float pitchOver2 = pitch * 0.5f;
32 float sinPitchOver2 = (float)sin((
double)pitchOver2);
33 float cosPitchOver2 = (float)cos((
double)pitchOver2);
34 float yawOver2 = yaw * 0.5f;
35 float sinYawOver2 = (float)sin((
double)yawOver2);
36 float cosYawOver2 = (float)cos((
double)yawOver2);
38 float x = cosYawOver2 * cosPitchOver2 * cosRollOver2 + sinYawOver2 * sinPitchOver2 * sinRollOver2;
39 float y = cosYawOver2 * cosPitchOver2 * sinRollOver2 - sinYawOver2 * sinPitchOver2 * cosRollOver2;
40 float z = cosYawOver2 * sinPitchOver2 * cosRollOver2 + sinYawOver2 * cosPitchOver2 * sinRollOver2;
41 float w = sinYawOver2 * cosPitchOver2 * cosRollOver2 - cosYawOver2 * sinPitchOver2 * sinRollOver2;
43 osg::Quat result(x, y, z, w);
59 osg::Matrix NewSetupMatrix1(CStdFPoint &localPos, osg::Quat qRot)
61 osg::Matrix osgLocalMatrix;
62 osgLocalMatrix.makeIdentity();
65 osg::Vec3 vPos(localPos.x, localPos.y, localPos.z);
68 osgLocalMatrix.makeRotate(qRot);
69 osgLocalMatrix.setTrans(vPos);
71 return osgLocalMatrix;
74 osg::Matrix NewSetupMatrix(CStdFPoint &localPos, CStdFPoint &localRot)
78 osg::Vec3 vPos(localPos.x, localPos.y, localPos.z);
81 m.makeRotate(localRot.z, osg::Vec3d(0, 0, 1), localRot.y, osg::Vec3d(0, 1, 0), localRot.x, osg::Vec3d(1, 0, 0));
88 osg::Matrix OldSetupMatrix(CStdFPoint &localPos, CStdFPoint &localRot)
94 osg::Matrix osgLocalMatrix;
102 return osgLocalMatrix;
106 osg::Quat OldSetupMatrixQuat(CStdFPoint &localPos, CStdFPoint &localRot)
124 CStdFPoint OldEulerRotationFromMatrix(osg::Matrix osgMT)
134 vRot.ClearNearZero();
138 bool QuatEqual(osg::Quat q1, osg::Quat q2)
140 if( (fabs(q1.x()-q2.x()) < 1e-5) && (fabs(q1.y()-q2.y()) < 1e-5) && (fabs(q1.z()-q2.z()) < 1e-5) && (fabs(q1.w()-q2.w()) < 1e-5) )
148 CStdFPoint ExtractEulerXYZ (osg::Matrix osgMT)
152 osg::Matrix3 osgMT3(osgMT(0, 0), osgMT(1, 0), osgMT(2, 0),
153 osgMT(0, 1), osgMT(1, 1), osgMT(2, 1),
154 osgMT(0, 2), osgMT(1, 2), osgMT(2, 2));
161 float xAngle=0, yAngle=0, zAngle=0;
163 if (osgMT3(0, 2) < 1)
165 if (osgMT3(0, 2) > -1)
170 yAngle = (float) asin((
double) osgMT3(0, 2));
171 xAngle = (float) atan2((
double) -osgMT3(1, 2), (double) osgMT3(2, 2));
172 zAngle = (float) atan2((
double) -osgMT3(0, 1), (double) osgMT3(0, 0));
180 yAngle = -(osg::PI/2);
181 xAngle = -atan2((
double) osgMT3(1, 0), (
double) osgMT3(1, 1));
192 xAngle = atan2((
double) osgMT3(1, 0), (
double) osgMT3(1, 1));
197 CStdFPoint vRot(xAngle, yAngle, zAngle);
198 vRot.ClearNearZero();
428 BOOST_AUTO_TEST_CASE( SimulationMgr_CreateModifyShutdownWithWindow )
431 std::string strExecutablePath, strExeFile;
433 std::string strProjFile =
"";
436 strProjFile = strExecutablePath +
"../Tutorials/Examples/StandAloneSimTest/Bullet_Single_x32_debug.asim";
438 strProjFile = strExecutablePath +
"../Tutorials/Examples/StandAloneSimTest/Bullet_Single_x32.asim";
441 SimulationThread *lpThread = SimulationMgr::Instance().CreateSimulation(strProjFile);
443 AnimatBase *lpNeuron = lpThread->Sim()->FindByID(
"0825d6e6-ebc4-4d4e-8c87-1fd06f821916");
445 float fltVth = -0.050;
446 for(
int iIdx=0; iIdx<2; iIdx++)
448 lpNeuron->SetData(
"Vth", fltVth);
450 lpThread->Simulate(2.0);
452 while(lpThread->Sim()->SimRunning())
454 boost::this_thread::sleep(boost::posix_time::milliseconds(100));
460 SimulationMgr::Instance().ShutdownAllSimulations();
463 BOOST_AUTO_TEST_SUITE_END()
void Std_SplitPathAndFile(std::string &strFullPath, std::string &strPath, std::string &strFile)
Splits the path from the actual filename.
std::string Std_ExecutablePath()
Finds the name and path of the current executable.