Merge pull request #79 from PhilipRosedale/master

Created eulerToOrthonormals function to (hopefully) help Brad
This commit is contained in:
ZappoMan 2013-04-17 21:14:16 -07:00
commit de102d1799
4 changed files with 50 additions and 1 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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);

View file

@ -82,7 +82,10 @@ void AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
memcpy(&_handPosition, sourceBuffer, sizeof(float) * 3);
sourceBuffer += sizeof(float) * 3;
//printf( "_bodyYaw = %f", _bodyYaw );
//std::cout << _handPosition.x << ", " << _handPosition.y << ", " << _handPosition.z << "\n";
//std::cout << _bodyPosition.x << ", " << _bodyPosition.y << ", " << _bodyPosition.z << "\n";