Last change
on this file since 2841 was
2840,
checked in by ldelgass, 13 years ago
|
Use trace macros in image loader. Formatting fixes in libs
|
File size:
1.2 KB
|
Line | |
---|
1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
2 | #include <vrmath/vrRotation.h> |
---|
3 | #include <vrmath/vrVector3f.h> |
---|
4 | #include <vrmath/vrQuaternion.h> |
---|
5 | |
---|
6 | void vrRotation::set(const vrVector3f &vec1, const vrVector3f &vec2) |
---|
7 | { |
---|
8 | if (vec1 == vec2) { |
---|
9 | x = 0.0f; |
---|
10 | y = 0.0f; |
---|
11 | z = 1.0f; |
---|
12 | angle = 0.0f; |
---|
13 | return; |
---|
14 | } |
---|
15 | |
---|
16 | vrVector3f cross; |
---|
17 | cross.cross(vec1, vec2); |
---|
18 | |
---|
19 | float ang = atan2( cross.length(), vec1.dot(vec2) ); |
---|
20 | |
---|
21 | cross.normalize(); |
---|
22 | |
---|
23 | x = cross.x; |
---|
24 | y = cross.y; |
---|
25 | z = cross.z; |
---|
26 | angle = ang; |
---|
27 | } |
---|
28 | |
---|
29 | void vrRotation::set(const vrQuaternion& quat) |
---|
30 | { |
---|
31 | //if (quat.w > 1) quat.normalize(); |
---|
32 | |
---|
33 | angle = acos(quat.w) * 2.0f; |
---|
34 | float scale = sqrt(1 - quat.w * quat.w); |
---|
35 | if (scale < 0.001) { |
---|
36 | x = quat.x; |
---|
37 | y = quat.y; |
---|
38 | z = quat.z; |
---|
39 | } else { |
---|
40 | x = quat.x / scale; |
---|
41 | y = quat.y / scale; |
---|
42 | z = quat.z / scale; |
---|
43 | } |
---|
44 | /* |
---|
45 | // http://gpwiki.org/index.php/OpenGL:Tutorials:Using_Quaternions_to_represent_rotation#Quaternion_to_axis-angle |
---|
46 | 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 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.