Changeset 648
- Timestamp:
- Feb 14, 2011, 2:26:40 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Makefile.am
r631 r648 3 3 4 4 liblol_a_SOURCES = \ 5 core.h matrix.h tiler.cpp tiler.h dict.cpp dict.h audio.cpp audio.h \ 6 scene.cpp scene.h font.cpp font.h layer.cpp layer.h map.cpp map.h \ 7 entity.cpp entity.h ticker.cpp ticker.h tileset.cpp tileset.h \ 8 forge.cpp forge.h video.cpp video.h timer.cpp timer.h bitfield.h \ 9 profiler.cpp profiler.h input.h input.cpp world.cpp world.h \ 10 sample.cpp sample.h sampler.cpp sampler.h text.cpp text.h \ 11 emitter.cpp emitter.h numeric.h worldentity.cpp worldentity.h \ 5 core.h matrix.cpp matrix.h tiler.cpp tiler.h dict.cpp dict.h \ 6 audio.cpp audio.h scene.cpp scene.h font.cpp font.h layer.cpp layer.h \ 7 map.cpp map.h entity.cpp entity.h ticker.cpp ticker.h \ 8 tileset.cpp tileset.h forge.cpp forge.h video.cpp video.h \ 9 timer.cpp timer.h bitfield.h profiler.cpp profiler.h input.h input.cpp \ 10 world.cpp world.h sample.cpp sample.h sampler.cpp sampler.h \ 11 text.cpp text.h emitter.cpp emitter.h numeric.h \ 12 worldentity.cpp worldentity.h \ 12 13 \ 13 14 sdlinput.cpp sdlinput.h \ -
trunk/src/matrix.h
r643 r648 176 176 GLOBALS(4) 177 177 178 template <typename T> struct Vec4x4179 { 180 inline Vec4x4() { }181 inline Vec4x4(T val) { v[0] = v[1] = v[2] = v[3] = val; }182 inline Vec4x4(Vec4<T> v0, Vec4<T> v1, Vec4<T> v2, Vec4<T> v3)178 template <typename T> struct Mat4 179 { 180 inline Mat4() { } 181 inline Mat4(T val) { for (int i = 0; i < 4; i++) v[i] = val; } 182 inline Mat4(Vec4<T> v0, Vec4<T> v1, Vec4<T> v2, Vec4<T> v3) 183 183 { v[0] = v0; v[1] = v1; v[2] = v2; v[3] = v3; } 184 184 … … 186 186 inline Vec4<T> const& operator[](int n) const { return v[n]; } 187 187 188 inline Vec4x4<T> operator +(Vec4x4<T> const val) const 189 { 190 Vec4x4<T> ret; 188 static inline Mat4<T> identity() 189 { 190 Mat4<T> ret; 191 for (int j = 0; j < 4; j++) 192 for (int i = 0; i < 4; i++) 193 ret[i][j] = i == j; 194 return ret; 195 } 196 197 T det() const; 198 Mat4<T> invert() const; 199 200 inline Mat4<T> operator +(Mat4<T> const val) const 201 { 202 Mat4<T> ret; 191 203 for (int j = 0; j < 4; j++) 192 204 for (int i = 0; i < 4; i++) … … 195 207 } 196 208 197 inline Vec4x4<T> operator -(Vec4x4<T> const val) const198 { 199 Vec4x4<T> ret;209 inline Mat4<T> operator -(Mat4<T> const val) const 210 { 211 Mat4<T> ret; 200 212 for (int j = 0; j < 4; j++) 201 213 for (int i = 0; i < 4; i++) … … 204 216 } 205 217 206 inline Vec4x4<T> operator *(Vec4x4<T> const val) const207 { 208 Vec4x4<T> ret;218 inline Mat4<T> operator *(Mat4<T> const val) const 219 { 220 Mat4<T> ret; 209 221 for (int j = 0; j < 4; j++) 210 222 for (int i = 0; i < 4; i++) … … 234 246 }; 235 247 236 typedef Vec4x4<float> float4x4;237 typedef Vec4x4<int> int4x4;248 typedef Mat4<float> float4x4; 249 typedef Mat4<int> int4x4; 238 250 239 251 #endif // __DH_MATRIX_H__ -
trunk/test/matrix.cpp
r642 r648 23 23 { 24 24 CPPUNIT_TEST_SUITE(MatrixTest); 25 CPPUNIT_TEST(test_mat_det); 25 26 CPPUNIT_TEST(test_mat_mul); 27 CPPUNIT_TEST(test_mat_inv); 26 28 CPPUNIT_TEST_SUITE_END(); 27 29 … … 29 31 MatrixTest() : CppUnit::TestCase("Matrix Test") {} 30 32 31 void setUp() {} 33 void setUp() 34 { 35 identity = float4x4::identity(); 36 triangular = float4x4(float4(1.0f, 0.0f, 0.0f, 0.0f), 37 float4(7.0f, 2.0f, 0.0f, 0.0f), 38 float4(1.0f, 5.0f, 3.0f, 0.0f), 39 float4(8.0f, 9.0f, 2.0f, 4.0f)); 40 invertible = float4x4(float4( 1.0f, 1.0f, 2.0f, -1.0f), 41 float4(-2.0f, -1.0f, -2.0f, 2.0f), 42 float4( 4.0f, 2.0f, 5.0f, -4.0f), 43 float4( 5.0f, -3.0f, -7.0f, -6.0f)); 44 } 32 45 33 46 void tearDown() {} 34 47 48 void test_mat_det() 49 { 50 float d1 = triangular.det(); 51 CPPUNIT_ASSERT(d1 == 24.0f); 52 float d2 = invertible.det(); 53 CPPUNIT_ASSERT(d2 == -1.0f); 54 } 55 35 56 void test_mat_mul() 36 57 { 37 float4 v0(1.0f, 0.0f, 0.0f, 0.0f); 38 float4 v1(0.0f, 1.0f, 0.0f, 0.0f); 39 float4 v2(0.0f, 0.0f, 1.0f, 0.0f); 40 float4 v3(0.0f, 0.0f, 0.0f, 1.0f); 41 float4x4 m0(v0, v1, v2, v3); 42 float4x4 m1(v0, v1, v2, v3); 58 float4x4 m0 = identity; 59 float4x4 m1 = identity; 43 60 float4x4 m2 = m0 * m1; 44 61 45 62 CPPUNIT_ASSERT(m2[0][0] == 1.0f); 63 CPPUNIT_ASSERT(m2[1][0] == 0.0f); 64 CPPUNIT_ASSERT(m2[2][0] == 0.0f); 65 CPPUNIT_ASSERT(m2[3][0] == 0.0f); 66 67 CPPUNIT_ASSERT(m2[0][1] == 0.0f); 46 68 CPPUNIT_ASSERT(m2[1][1] == 1.0f); 69 CPPUNIT_ASSERT(m2[2][1] == 0.0f); 70 CPPUNIT_ASSERT(m2[3][1] == 0.0f); 71 72 CPPUNIT_ASSERT(m2[0][2] == 0.0f); 73 CPPUNIT_ASSERT(m2[1][2] == 0.0f); 47 74 CPPUNIT_ASSERT(m2[2][2] == 1.0f); 75 CPPUNIT_ASSERT(m2[3][2] == 0.0f); 76 77 CPPUNIT_ASSERT(m2[0][3] == 0.0f); 78 CPPUNIT_ASSERT(m2[1][3] == 0.0f); 79 CPPUNIT_ASSERT(m2[2][3] == 0.0f); 48 80 CPPUNIT_ASSERT(m2[3][3] == 1.0f); 49 81 } 82 83 void test_mat_inv() 84 { 85 float4x4 m0 = invertible; 86 float4x4 m1 = m0.invert(); 87 88 float4x4 m2 = m0 * m1; 89 90 CPPUNIT_ASSERT(m2[0][0] == 1.0f); 91 CPPUNIT_ASSERT(m2[1][0] == 0.0f); 92 CPPUNIT_ASSERT(m2[2][0] == 0.0f); 93 CPPUNIT_ASSERT(m2[3][0] == 0.0f); 94 95 CPPUNIT_ASSERT(m2[0][1] == 0.0f); 96 CPPUNIT_ASSERT(m2[1][1] == 1.0f); 97 CPPUNIT_ASSERT(m2[2][1] == 0.0f); 98 CPPUNIT_ASSERT(m2[3][1] == 0.0f); 99 100 CPPUNIT_ASSERT(m2[0][2] == 0.0f); 101 CPPUNIT_ASSERT(m2[1][2] == 0.0f); 102 CPPUNIT_ASSERT(m2[2][2] == 1.0f); 103 CPPUNIT_ASSERT(m2[3][2] == 0.0f); 104 105 CPPUNIT_ASSERT(m2[0][3] == 0.0f); 106 CPPUNIT_ASSERT(m2[1][3] == 0.0f); 107 CPPUNIT_ASSERT(m2[2][3] == 0.0f); 108 CPPUNIT_ASSERT(m2[3][3] == 1.0f); 109 } 110 111 private: 112 float4x4 triangular, identity, invertible; 50 113 }; 51 114 -
trunk/win32/deushax.vcxproj
r614 r648 62 62 <ClCompile Include="..\src\layer.cpp" /> 63 63 <ClCompile Include="..\src\map.cpp" /> 64 <ClCompile Include="..\src\matrix.cpp" /> 64 65 <ClCompile Include="..\src\profiler.cpp" /> 65 66 <ClCompile Include="..\src\sample.cpp" /> -
trunk/win32/deushax.vcxproj.filters
r312 r648 137 137 <Filter>lolengine</Filter> 138 138 </ClCompile> 139 <ClCompile Include="..\src\matrix.cpp"> 140 <Filter>lolengine</Filter> 141 </ClCompile> 139 142 <ClCompile Include="..\src\profiler.cpp"> 140 143 <Filter>lolengine</Filter> -
trunk/win32/editor.vcxproj
r614 r648 62 62 <ClCompile Include="..\src\layer.cpp" /> 63 63 <ClCompile Include="..\src\map.cpp" /> 64 <ClCompile Include="..\src\matrix.cpp" /> 64 65 <ClCompile Include="..\src\profiler.cpp" /> 65 66 <ClCompile Include="..\src\sample.cpp" /> -
trunk/win32/editor.vcxproj.filters
r327 r648 137 137 <Filter>lolengine</Filter> 138 138 </ClCompile> 139 <ClCompile Include="..\src\matrix.cpp"> 140 <Filter>lolengine</Filter> 141 </ClCompile> 139 142 <ClCompile Include="..\src\profiler.cpp"> 140 143 <Filter>lolengine</Filter> -
trunk/win32/monsterz.vcxproj
r614 r648 71 71 <ClCompile Include="..\src\layer.cpp" /> 72 72 <ClCompile Include="..\src\map.cpp" /> 73 <ClCompile Include="..\src\matrix.cpp" /> 73 74 <ClCompile Include="..\src\profiler.cpp" /> 74 75 <ClCompile Include="..\src\sample.cpp" /> -
trunk/win32/monsterz.vcxproj.filters
r352 r648 142 142 <Filter>lolengine</Filter> 143 143 </ClCompile> 144 <ClCompile Include="..\src\matrix.cpp"> 145 <Filter>lolengine</Filter> 146 </ClCompile> 144 147 <ClCompile Include="..\src\profiler.cpp"> 145 148 <Filter>lolengine</Filter>
Note: See TracChangeset
for help on using the changeset viewer.