Showing the changes to interface/src/Util.cpp (1 of 3 files). Show all
Unified · Split
| @@ -11,12 +11,44 @@ · 10 unmodified lines | |||
| 11 | #include <cstring> | 11 | #include <cstring> |
| 12 | 12 | ||
| 13 | #include <glm/glm.hpp> | 13 | #include <glm/glm.hpp> |
| 14 | #include <glm/gtc/quaternion.hpp> | ||
| 14 | #include <SharedUtil.h> | 15 | #include <SharedUtil.h> |
| 15 | 16 | ||
| 16 | #include "world.h" | 17 | #include "world.h" |
| 17 | #include "Util.h" | 18 | #include "Util.h" |
| 18 | 19 | ||
| 19 | 20 | ||
| 21 | |||
| 22 | void eulerToOrthonormals(glm::vec3 * angles, glm::vec3 * fwd, glm::vec3 * left, glm::vec3 * up) { | ||
| 23 | // | ||
| 24 | // Converts from three euler angles to the associated orthonormal vectors | ||
| 25 | // | ||
| 26 | // Angles contains (pitch, yaw, roll) in radians | ||
| 27 | // | ||
| 28 | |||
| 29 | // First, create the quaternion associated with these euler angles | ||
| 30 | glm::quat q(glm::vec3(angles->x, angles->y, angles->z)); | ||
| 31 | |||
| 32 | // Next, create a rotation matrix from that quaternion | ||
| 33 | glm::mat4 rotation; | ||
| 34 | rotation = glm::mat4_cast(q); | ||
| 35 | |||
| 36 | // Transform the original vectors by the rotation matrix to get the new vectors | ||
| 37 | glm::vec4 u(0,1,0,0); | ||
| 38 | glm::vec4 l(1,0,0,0); | ||
| 39 | glm::vec4 f(0,0,1,0); | ||
| 40 | glm::vec4 uNew = u*rotation; | ||
| 41 | glm::vec4 lNew = l*rotation; | ||
| 42 | glm::vec4 fNew = f*rotation; | ||
| 43 | |||
| 44 | // Copy the answers to output vectors | ||
| 45 | up->x = uNew.x; up->y = uNew.y; up->z = uNew.z; | ||
| 46 | left->x = lNew.x; left->y = lNew.y; left->z = lNew.z; | ||
| 47 | fwd->x = fNew.x; fwd->y = fNew.y; fwd->z = fNew.z; | ||
| 48 | |||
| 49 | } | ||
| 50 | |||
| 51 | |||
| 20 | // Return the azimuth angle in degrees between two points. | 52 | // Return the azimuth angle in degrees between two points. |
| 21 | float azimuth_to(glm::vec3 head_pos, glm::vec3 source_pos) { | 53 | float azimuth_to(glm::vec3 head_pos, glm::vec3 source_pos) { |
| 22 | return atan2(head_pos.x - source_pos.x, head_pos.z - source_pos.z) * 180.0f / PIf; | 54 | return atan2(head_pos.x - source_pos.x, head_pos.z - source_pos.z) * 180.0f / PIf; |