Changeset 1041 for trunk/src/matrix.cpp
 Timestamp:
 Oct 31, 2011, 9:19:09 AM (9 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/matrix.cpp
r939 r1041 23 23 { 24 24 25 template<> float dot(vec2 v1, vec2 v2) 26 { 27 return v1.x * v2.x + v1.y * v2.y; 28 } 29 30 template<> float dot(vec3 v1, vec3 v2) 31 { 32 return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; 33 } 34 35 template<> float dot(vec4 v1, vec4 v2) 36 { 37 return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w; 38 } 39 40 template<> vec3 cross(vec3 v1, vec3 v2) 41 { 42 return vec3(v1.y * v2.z  v1.z * v2.y, 43 v1.z * v2.x  v1.x * v2.z, 44 v1.x * v2.y  v1.y * v2.x); 45 } 46 47 template<> vec2 normalize(vec2 v) 48 { 49 float norm = v.sqlen(); 50 if (!norm) 51 return vec2(0); 52 return v / norm; 53 } 54 55 template<> vec3 normalize(vec3 v) 56 { 57 float norm = v.sqlen(); 58 if (!norm) 59 return vec3(0); 60 return v / norm; 61 } 62 63 template<> vec4 normalize(vec4 v) 64 { 65 float norm = v.sqlen(); 66 if (!norm) 67 return vec4(0); 68 return v / norm; 69 } 70 25 71 static inline float det3(float a, float b, float c, 26 72 float d, float e, float f, … … 67 113 } 68 114 115 template<> void vec2::printf() const 116 { 117 Log::Debug("[ %6.6f %6.6f ]\n", x, y); 118 } 119 120 template<> void vec3::printf() const 121 { 122 Log::Debug("[ %6.6f %6.6f %6.6f ]\n", x, y, z); 123 } 124 125 template<> void vec4::printf() const 126 { 127 Log::Debug("[ %6.6f %6.6f %6.6f %6.6f ]\n", x, y, z, w); 128 } 129 69 130 template<> void mat4::printf() const 70 131 { … … 164 225 } 165 226 166 template<> mat4 mat4::perspective(float theta, float width,167 float height, float near, float far)168 {169 float t1 = tanf(theta / 2.0f);170 float t2 = t1 * height / width;171 172 return frustum(near * t1, near * t1, near * t2, near * t2, near, far);173 }174 175 227 template<> mat4 mat4::translate(float x, float y, float z) 176 228 { … … 180 232 ret[3][2] = z; 181 233 return ret; 234 } 235 236 template<> mat4 mat4::translate(vec3 v) 237 { 238 return translate(v.x, v.y, v.z); 239 } 240 241 template<> mat4 mat4::lookat(vec3 eye, vec3 center, vec3 up) 242 { 243 vec3 f = normalize(center  eye); 244 vec3 u = normalize(up); 245 vec3 s = normalize(cross(f, u)); 246 u = cross(s, f); 247 248 mat4 ret(1.0f); 249 ret[0][0] = s.x; 250 ret[0][1] = s.y; 251 ret[0][2] = s.z; 252 ret[1][0] = u.x; 253 ret[1][1] = u.y; 254 ret[1][2] = u.z; 255 ret[2][0] =f.x; 256 ret[2][1] =f.y; 257 ret[2][2] =f.z; 258 return ret * mat4::translate(eye); 259 } 260 261 template<> mat4 mat4::perspective(float theta, float width, 262 float height, float near, float far) 263 { 264 float t1 = tanf(theta * 0.5f); 265 float t2 = t1 * height / width; 266 267 return frustum(near * t1, near * t1, near * t2, near * t2, near, far); 182 268 } 183 269 … … 214 300 } 215 301 302 template<> mat4 mat4::rotate(float theta, vec3 v) 303 { 304 return rotate(theta, v.x, v.y, v.z); 305 } 306 216 307 } /* namespace lol */ 217 308
Note: See TracChangeset
for help on using the changeset viewer.