Changeset 1305
 Timestamp:
 Apr 29, 2012, 4:01:00 PM (9 years ago)
 Location:
 trunk
 Files:

 3 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/lol/math/vector.h
r1272 r1305 910 910 { 911 911 inline Quat() {} 912 inline Quat(T X) : x(0), y(0), z(0), w(X) {}913 inline Quat(T X, T Y, T Z, T W) : x(X), y(Y), z(Z), w(W) {}912 inline Quat(T W) : x(0), y(0), z(0), w(W) {} 913 inline Quat(T W, T X, T Y, T Z) : x(X), y(Y), z(Z), w(W) {} 914 914 915 915 Quat(Mat3<T> const &m); … … 917 917 918 918 DECLARE_MEMBER_OPS(Quat) 919 920 static Quat<T> rotate(T angle, T x, T y, T z); 921 static Quat<T> rotate(T angle, Vec3<T> const &v); 919 922 920 923 inline Quat<T> operator *(Quat<T> const &val) const … … 924 927 Vec3<T> v2(val.x, val.y, val.z); 925 928 Vec3<T> v3 = cross(v1, v2) + w * v2 + val.w * v1; 926 return Quat<T>( v3.x, v3.y, v3.z, w * val.w  dot(v1, v2));929 return Quat<T>(w * val.w  dot(v1, v2), v3.x, v3.y, v3.z); 927 930 } 928 931 … … 934 937 inline Quat<T> operator ~() const 935 938 { 936 return Quat<T>( x, y, z, w);939 return Quat<T>(w, x, y, z); 937 940 } 938 941 … … 942 945 #endif 943 946 947 /* Storage order is still xyzw because operator[] uses &this>x */ 944 948 T x, y, z, w; 945 949 }; 
trunk/src/math/vector.cpp
r1272 r1305 204 204 template<> void quat::printf() const 205 205 { 206 Log::Debug("[ %6.6f %6.6f %6.6f %6.6f ]\n", x, y, z, w);206 Log::Debug("[ %6.6f %6.6f %6.6f %6.6f ]\n", w, x, y, z); 207 207 } 208 208 … … 341 341 angle *= (M_PI / 180.0f); 342 342 343 float st = s inf(angle);344 float ct = cosf(angle);343 float st = std::sin(angle); 344 float ct = std::cos(angle); 345 345 346 346 mat2 ret; … … 359 359 angle *= (M_PI / 180.0f); 360 360 361 float st = s inf(angle);362 float ct = cosf(angle);361 float st = std::sin(angle); 362 float ct = std::cos(angle); 363 363 364 364 float len = sqrtf(x * x + y * y + z * z); … … 455 455 w = s * (m[1][0]  m[0][1]); 456 456 } 457 } 458 459 template<> quat quat::rotate(float angle, vec3 const &v) 460 { 461 angle *= (M_PI / 360.0f); 462 463 vec3 tmp = normalize(v) * std::sin(angle); 464 465 return quat(tmp.x, tmp.y, tmp.z, std::cos(angle)); 466 } 467 468 template<> quat quat::rotate(float angle, float x, float y, float z) 469 { 470 return quat::rotate(angle, vec3(x, y, z)); 457 471 } 458 472 
trunk/test/unit/quat.cpp
r1135 r1305 58 58 { 59 59 quat a(1.0f, 3.0f, 2.0f, 4.0f); 60 quat b( 1.0f, 3.0f, 2.0f,4.0f);60 quat b(1.0f, 3.0f, 2.0f, 4.0f); 61 61 62 62 LOLUNIT_ASSERT_EQUAL(a, ~b); … … 71 71 72 72 quat b = a * ~a; 73 quat c( 0.0f, 0.0f, 0.0f, norm(a));73 quat c(norm(a), 0.0f, 0.0f, 0.0f); 74 74 75 75 LOLUNIT_ASSERT_EQUAL(b, c); … … 82 82 LOLUNIT_TEST(Base) 83 83 { 84 quat i( 1.0f, 0.0f, 0.0f, 0.0f);85 quat j(0.0f, 1.0f, 0.0f, 0.0f);86 quat k(0.0f, 0.0f, 1.0f, 0.0f);87 quat one( 0.0f, 0.0f, 0.0f, 1.0f);84 quat i(0.0f, 1.0f, 0.0f, 0.0f); 85 quat j(0.0f, 0.0f, 1.0f, 0.0f); 86 quat k(0.0f, 0.0f, 0.0f, 1.0f); 87 quat one(1.0f, 0.0f, 0.0f, 0.0f); 88 88 89 89 LOLUNIT_ASSERT_EQUAL(norm(i), 1.0f); … … 130 130 LOLUNIT_ASSERT_DOUBLES_EQUAL(m1.w, 1.0, 1e8); 131 131 } 132 133 LOLUNIT_TEST(Rotation) 134 { 135 quat a = quat::rotate(10.0f, vec3(1, 0, 0)); 136 quat b = quat::rotate(20.0f, vec3(1, 0, 0)); 137 quat c = a * a; 138 139 LOLUNIT_ASSERT_DOUBLES_EQUAL(a.w, a.w, 1e8); 140 LOLUNIT_ASSERT_DOUBLES_EQUAL(a.x, a.x, 1e8); 141 LOLUNIT_ASSERT_DOUBLES_EQUAL(a.y, a.y, 1e8); 142 LOLUNIT_ASSERT_DOUBLES_EQUAL(a.z, a.z, 1e8); 143 } 132 144 }; 133 145
Note: See TracChangeset
for help on using the changeset viewer.