History

Added eulerToOrthonormals function for Brad in Util.cpp, sample execution at start of main.

Philip Rosedale committed 13 years ago

Commit d2009361 parent 64eed6d3 files · +47 −1Browse files

Showing the changes to interface/src/Util.cpp (1 of 3 files). Show all

Unified · Split

interface/src/Util.cpp+32−0
@@ -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
22void 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.
21float azimuth_to(glm::vec3 head_pos, glm::vec3 source_pos) {53float 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;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t