mirror of
https://github.com/overte-org/overte.git
synced 2025-04-23 23:33:26 +02:00
Added eulerToOrthonormals function for Brad in Util.cpp, sample execution at start of main.
This commit is contained in:
parent
64eed6dfab
commit
d200936615
3 changed files with 47 additions and 1 deletions
|
@ -11,12 +11,44 @@
|
|||
#include <cstring>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <SharedUtil.h>
|
||||
|
||||
#include "world.h"
|
||||
#include "Util.h"
|
||||
|
||||
|
||||
|
||||
void eulerToOrthonormals(glm::vec3 * angles, glm::vec3 * fwd, glm::vec3 * left, glm::vec3 * up) {
|
||||
//
|
||||
// Converts from three euler angles to the associated orthonormal vectors
|
||||
//
|
||||
// Angles contains (pitch, yaw, roll) in radians
|
||||
//
|
||||
|
||||
// First, create the quaternion associated with these euler angles
|
||||
glm::quat q(glm::vec3(angles->x, angles->y, angles->z));
|
||||
|
||||
// Next, create a rotation matrix from that quaternion
|
||||
glm::mat4 rotation;
|
||||
rotation = glm::mat4_cast(q);
|
||||
|
||||
// Transform the original vectors by the rotation matrix to get the new vectors
|
||||
glm::vec4 u(0,1,0,0);
|
||||
glm::vec4 l(1,0,0,0);
|
||||
glm::vec4 f(0,0,1,0);
|
||||
glm::vec4 uNew = u*rotation;
|
||||
glm::vec4 lNew = l*rotation;
|
||||
glm::vec4 fNew = f*rotation;
|
||||
|
||||
// Copy the answers to output vectors
|
||||
up->x = uNew.x; up->y = uNew.y; up->z = uNew.z;
|
||||
left->x = lNew.x; left->y = lNew.y; left->z = lNew.z;
|
||||
fwd->x = fNew.x; fwd->y = fNew.y; fwd->z = fNew.z;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Return the azimuth angle in degrees between two points.
|
||||
float azimuth_to(glm::vec3 head_pos, glm::vec3 source_pos) {
|
||||
return atan2(head_pos.x - source_pos.x, head_pos.z - source_pos.z) * 180.0f / PIf;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include <Orientation.h>
|
||||
|
||||
void eulerToOrthonormals(glm::vec3 * angles, glm::vec3 * fwd, glm::vec3 * left, glm::vec3 * up);
|
||||
|
||||
float azimuth_to(glm::vec3 head_pos, glm::vec3 source_pos);
|
||||
float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float head_yaw);
|
||||
|
|
|
@ -1510,7 +1510,20 @@ void audioMixerUpdate(in_addr_t newMixerAddress, in_port_t newMixerPort) {
|
|||
int main(int argc, const char * argv[])
|
||||
{
|
||||
// Quick test of the Orientation class on startup!
|
||||
testOrientationClass();
|
||||
//testOrientationClass(); // PER - commented out to test orthonormal code
|
||||
|
||||
//
|
||||
// For Brad: Demo of function to test conversion of euler angles to orthonormals
|
||||
// (Note that the euler angles order is Pitch, Yaw, Roll, and in radians)
|
||||
//
|
||||
glm::vec3 angles(0, PI/4, 0);
|
||||
glm::vec3 fwd, left, up;
|
||||
|
||||
eulerToOrthonormals(&angles, &fwd, &left, &up);
|
||||
|
||||
printf("fwd: %4.2f, %4.2f, %4.2f\n", fwd.x, fwd.y, fwd.z);
|
||||
printf("left: %4.2f, %4.2f, %4.2f\n", left.x, left.y, left.z);
|
||||
printf("up: %4.2f, %4.2f, %4.2f\n", up.x, up.y, up.z);
|
||||
|
||||
AgentList::createInstance(AGENT_TYPE_INTERFACE);
|
||||
|
||||
|
|
Loading…
Reference in a new issue