Changeset 15 in flair-src for trunk/lib/FlairCore/src/Euler.cpp
- Timestamp:
- Apr 8, 2016, 3:40:57 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairCore/src/Euler.cpp
r2 r15 23 23 #define PI_D ((double)3.14159265358979323846) 24 24 25 namespace flair 26 { 27 namespace core 28 { 25 namespace flair { 26 namespace core { 29 27 30 Euler::Euler(float inRoll, float inPitch,float inYaw): roll(inRoll), pitch(inPitch),yaw(inYaw) {31 }28 Euler::Euler(float inRoll, float inPitch, float inYaw) 29 : roll(inRoll), pitch(inPitch), yaw(inYaw) {} 32 30 33 Euler::~Euler() { 31 Euler::~Euler() {} 34 32 35 } 36 37 Euler& Euler::operator=(const Euler &euler) { 38 roll=euler.roll; 39 pitch=euler.pitch; 40 yaw=euler.yaw; 41 return (*this); 33 Euler &Euler::operator=(const Euler &euler) { 34 roll = euler.roll; 35 pitch = euler.pitch; 36 yaw = euler.yaw; 37 return (*this); 42 38 } 43 39 /* … … 85 81 */ 86 82 void Euler::ToQuaternion(Quaternion &quaternion) const { 87 quaternion.q0=cos(yaw/2)*cos(pitch/2)*cos(roll/2)88 +sin(yaw/2)*sin(pitch/2)*sin(roll/2);83 quaternion.q0 = cos(yaw / 2) * cos(pitch / 2) * cos(roll / 2) + 84 sin(yaw / 2) * sin(pitch / 2) * sin(roll / 2); 89 85 90 quaternion.q1=cos(yaw/2)*cos(pitch/2)*sin(roll/2)91 -sin(yaw/2)*sin(pitch/2)*cos(roll/2);86 quaternion.q1 = cos(yaw / 2) * cos(pitch / 2) * sin(roll / 2) - 87 sin(yaw / 2) * sin(pitch / 2) * cos(roll / 2); 92 88 93 quaternion.q2=cos(yaw/2)*sin(pitch/2)*cos(roll/2)94 +sin(yaw/2)*cos(pitch/2)*sin(roll/2);89 quaternion.q2 = cos(yaw / 2) * sin(pitch / 2) * cos(roll / 2) + 90 sin(yaw / 2) * cos(pitch / 2) * sin(roll / 2); 95 91 96 quaternion.q3=sin(yaw/2)*cos(pitch/2)*cos(roll/2)97 -cos(yaw/2)*sin(pitch/2)*sin(roll/2);92 quaternion.q3 = sin(yaw / 2) * cos(pitch / 2) * cos(roll / 2) - 93 cos(yaw / 2) * sin(pitch / 2) * sin(roll / 2); 98 94 } 99 95 100 96 Quaternion Euler::ToQuaternion(void) const { 101 102 103 97 Quaternion quaternion; 98 ToQuaternion(quaternion); 99 return quaternion; 104 100 } 105 101 106 float Euler::ToDegree(float radianValue) { 107 return radianValue*180.0f/PI; 108 } 102 float Euler::ToDegree(float radianValue) { return radianValue * 180.0f / PI; } 109 103 110 float Euler::ToRadian(float degreeValue) { 111 return degreeValue/180.0f*PI; 112 } 104 float Euler::ToRadian(float degreeValue) { return degreeValue / 180.0f * PI; } 113 105 114 106 float Euler::YawDistanceFrom(float angle) const { 115 float rot1,rot2; 116 if(angle > yaw ) { 117 rot1=angle-yaw; 118 rot2=2*PI-angle+yaw; 119 } else { 120 rot1=2*PI+angle-yaw; 121 rot2=yaw-angle; 122 } 123 if(rot2<rot1) rot1=-rot2; 124 rot1=-rot1;//pour avoir rot1=yaw-angle 107 float rot1, rot2; 108 if (angle > yaw) { 109 rot1 = angle - yaw; 110 rot2 = 2 * PI - angle + yaw; 111 } else { 112 rot1 = 2 * PI + angle - yaw; 113 rot2 = yaw - angle; 114 } 115 if (rot2 < rot1) 116 rot1 = -rot2; 117 rot1 = -rot1; // pour avoir rot1=yaw-angle 125 118 126 119 return rot1; 127 120 } 128 121
Note:
See TracChangeset
for help on using the changeset viewer.