Changeset 2842 for trunk/packages/vizservers/nanovis
- Timestamp:
- Mar 11, 2012 8:43:18 PM (12 years ago)
- Location:
- trunk/packages/vizservers/nanovis/vrmath
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrMatrix4x4f.h
r2841 r2842 11 11 { 12 12 public: 13 vrMatrix4x4f() 14 { 15 makeIdentity(); 16 } 17 13 18 /** 14 19 * @brief make a identity matrix -
trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrQuaternion.h
r2841 r2842 17 17 public: 18 18 vrQuaternion(); 19 19 20 explicit vrQuaternion(const vrRotation& rot); 21 20 22 vrQuaternion(float x, float y = 0, float z = 0, float w = 0); 21 23 22 24 void set(float x1, float y1, float z1, float w1); 25 23 26 const vrQuaternion& set(const vrRotation& rot); 27 28 vrQuaternion conjugate() const 29 { 30 vrQuaternion result; 31 result.w = w; 32 result.x = -x; 33 result.y = -y; 34 result.z = -z; 35 return result; 36 } 37 38 vrQuaternion reciprocal() const 39 { 40 double denom = w*w + x*x + y*y + z*z; 41 vrQuaternion result = conjugate(); 42 result.x /= denom; 43 result.y /= denom; 44 result.z /= denom; 45 result.w /= denom; 46 return result; 47 } 24 48 25 49 void slerp(const vrRotation &a,const vrRotation &b, const float t); … … 28 52 29 53 const vrQuaternion& normalize(); 54 55 vrQuaternion operator*(const vrQuaternion& q2) const 56 { 57 vrQuaternion result; 58 result.w = (w * q2.w) - (x * q2.x) - (y * q2.y) - (z * q2.z); 59 result.x = (w * q2.x) + (x * q2.w) + (y * q2.z) - (z * q2.y); 60 result.y = (w * q2.y) + (y * q2.w) + (z * q2.x) - (x * q2.z); 61 result.z = (w * q2.z) + (z * q2.w) + (x * q2.y) - (y * q2.x); 62 return result; 63 } 30 64 31 65 friend bool operator==(const vrQuaternion& q1, const vrQuaternion& q2); -
trunk/packages/vizservers/nanovis/vrmath/include/vrmath/vrRotation.h
r2841 r2842 8 8 class vrQuaternion; 9 9 10 /** 11 * Represents an axis/angle rotation 12 */ 10 13 class vrRotation 11 14 { … … 28 31 float getAngle() const; 29 32 33 vrQuaternion getQuaternion() const; 34 30 35 void set(float x, float y, float z, float angle); 31 void set(const vrVector3f &vec1, const vrVector3f &vec2);36 void set(const vrVector3f& vec1, const vrVector3f& vec2); 32 37 void set(const vrQuaternion& quat); 33 38 void set(const vrRotation& rot); 34 39 void setAxis(float x, float y, float z); 35 40 void setAngle(float angle); 36 41 37 42 friend bool operator!=(const vrRotation& rot1, const vrRotation& rot2); 38 43 friend bool operator==(const vrRotation& rot1, const vrRotation& rot2); -
trunk/packages/vizservers/nanovis/vrmath/vrMatrix4x4f.cpp
r2840 r2842 7 7 { 8 8 _data[1] = _data[2] = _data[3] = _data[4] = 9 10 9 _data[6] = _data[7] = _data[8] = _data[9] = 10 _data[11] = _data[12] = _data[13] = _data[14] = 0.0f; 11 11 _data[0] = _data[5] = _data[10] = _data[15] = 1.0f; 12 12 } … … 15 15 { 16 16 _data[1] = _data[2] = _data[3] = _data[4] = 17 18 17 _data[6] = _data[7] = _data[8] = _data[9] = 18 _data[11] = 0.0f; 19 19 _data[0] = _data[5] = _data[10] = _data[15] = 1.0f; 20 20 _data[12] = translation.x; … … 26 26 { 27 27 _data[1] = _data[2] = _data[3] = _data[4] = 28 29 28 _data[6] = _data[7] = _data[8] = _data[9] = 29 _data[11] = 0.0f; 30 30 _data[0] = _data[5] = _data[10] = _data[15] = 1.0f; 31 31 _data[12] = x; … … 36 36 void vrMatrix4x4f::makeRotation(const vrRotation& rotation) 37 37 { 38 if (rotation.getX() == 0.0f && rotation.getY() == 0.0f && rotation.getZ() == 0.0f) { 38 if (rotation.getAngle() == 0.0f || 39 (rotation.getX() == 0.0f && 40 rotation.getY() == 0.0f && 41 rotation.getZ() == 0.0f)) { 39 42 makeIdentity(); 40 43 return; … … 42 45 43 46 float xAxis = rotation.getX(), yAxis = rotation.getY(), zAxis = rotation.getZ(); 44 float invLen = 1.0f / sqrt( 47 float invLen = 1.0f / sqrt(xAxis * xAxis + yAxis * yAxis + zAxis * zAxis); 45 48 float cosine = cos(rotation.getAngle()); 46 49 float sine = sin(rotation.getAngle()); … … 70 73 void vrMatrix4x4f::makeRotation(float xAxis, float yAxis, float zAxis, float angle) 71 74 { 72 if (xAxis == 0.0f && yAxis == 0.0f && zAxis == 0.0f) { 75 if (angle == 0.0f || 76 (xAxis == 0.0f && 77 yAxis == 0.0f && 78 zAxis == 0.0f)) { 73 79 makeIdentity(); 74 80 return; 75 81 } 76 82 77 float invLen = 1.0f / sqrt( 83 float invLen = 1.0f / sqrt(xAxis * xAxis + yAxis * yAxis + zAxis * zAxis); 78 84 float cosine = cos(angle); 79 85 float sine = sin(angle); … … 101 107 } 102 108 103 104 109 void vrMatrix4x4f::makeScale(const vrVector3f& scale) 105 110 { 106 111 _data[1] = _data[2] = _data[3] = _data[4] = 107 108 112 _data[6] = _data[7] = _data[8] = _data[9] = 113 _data[11] = 0.0f; 109 114 110 115 _data[0] = scale.x; … … 119 124 { 120 125 float mat[16]; 121 float * mat1 = (float*)m1._data;126 float *mat1 = (float *)m1._data; 122 127 123 128 // 1 row … … 169 174 { 170 175 float mat[16]; 171 float * mat1 = (float*)m1._data;172 float * mat2 = (float*)m2._data;176 float *mat1 = (float *)m1._data; 177 float *mat2 = (float *)m2._data; 173 178 174 179 // 1 row … … 218 223 void vrMatrix4x4f::multiplyFast(const vrMatrix4x4f& m1, const vrMatrix4x4f& m2) 219 224 { 220 float * mat1 = (float*)m1._data;221 float * mat2 = (float*)m2._data;225 float *mat1 = (float *)m1._data; 226 float *mat2 = (float *)m2._data; 222 227 223 228 // 1 row … … 284 289 285 290 void vrMatrix4x4f::invert() 286 287 291 { 288 292 float det = … … 432 436 } 433 437 434 435 436 438 void vrMatrix4x4f::invert(const vrMatrix4x4f& mat) 437 439 { 438 float * data = (float*)mat._data;440 float *data = (float *)mat._data; 439 441 440 442 float det = … … 586 588 void vrMatrix4x4f::invertFast(const vrMatrix4x4f& mat) 587 589 { 588 float * srcData = (float*)mat._data;590 float *srcData = (float *)mat._data; 589 591 590 592 float det = … … 810 812 { 811 813 for (int i = 0; i < 16; ++i) { 812 _data[i] = (float) 814 _data[i] = (float)m[i]; 813 815 } 814 816 } -
trunk/packages/vizservers/nanovis/vrmath/vrRotation.cpp
r2840 r2842 1 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 #include <math.h> 3 2 4 #include <vrmath/vrRotation.h> 3 5 #include <vrmath/vrVector3f.h> … … 17 19 cross.cross(vec1, vec2); 18 20 19 float ang = atan2( cross.length(), vec1.dot(vec2));21 float ang = atan2(cross.length(), vec1.dot(vec2)); 20 22 21 23 cross.normalize(); … … 33 35 angle = acos(quat.w) * 2.0f; 34 36 float scale = sqrt(1 - quat.w * quat.w); 35 if (scale < 0.001) { 37 if (angle < 1.0e-6f) { 38 x = 1; 39 y = 0; 40 z = 0; 41 } else if (scale < 1.0e-6f) { 36 42 x = quat.x; 37 43 y = quat.y; … … 42 48 z = quat.z / scale; 43 49 } 44 /*45 // http://gpwiki.org/index.php/OpenGL:Tutorials:Using_Quaternions_to_represent_rotation#Quaternion_to_axis-angle46 float scale = sqrt(quat.x * quat.x + quat.y * quat.y + quat.z * quat.z);47 x = quat.x / scale;48 y = quat.y / scale;49 z = quat.z / scale;50 */51 50 } 51 52 vrQuaternion vrRotation::getQuaternion() const 53 { 54 vrQuaternion result; 55 56 result.w = cos(angle / 2.0); 57 double sinHalfAngle = sin(angle / 2.0); 58 result.x = x * sinHalfAngle; 59 result.y = y * sinHalfAngle; 60 result.z = z * sinHalfAngle; 61 62 return result; 63 }
Note: See TracChangeset
for help on using the changeset viewer.