Merge pull request #470 from ey6es/master

Removed Orientation class, removed duplicate code in avatar-mixer.
This commit is contained in:
Andrzej Kapolka 2013-05-30 15:53:20 -07:00
commit 97343edfca
9 changed files with 12 additions and 358 deletions

View file

@ -51,19 +51,8 @@ void attachAvatarDataToAgent(Agent* newAgent) {
}
}
bool wantLocalDomain = false;
int main(int argc, const char* argv[]) {
// Handle Local Domain testing with the --local command line
const char* local = "--local";
::wantLocalDomain = cmdOptionExists(argc, argv,local);
if (::wantLocalDomain) {
printf("Local Domain MODE!\n");
int ip = getLocalAddress();
sprintf(DOMAIN_IP,"%d.%d.%d.%d", (ip & 0xFF), ((ip >> 8) & 0xFF),((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF));
}
AgentList* agentList = AgentList::createInstance(AGENT_TYPE_AVATAR_MIXER, AVATAR_LISTEN_PORT);
setvbuf(stdout, NULL, _IOLBF, 0);

View file

@ -1274,7 +1274,7 @@ void Application::init() {
void Application::updateAvatar(float deltaTime) {
// Update my avatar's head position from gyros
_myAvatar.updateHeadFromGyros(deltaTime, &_serialPort, &_gravity);
_myAvatar.updateHeadFromGyros(deltaTime, &_serialPort);
// Grab latest readings from the gyros
float measuredPitchRate = _serialPort.getLastPitchRate();

View file

@ -124,7 +124,7 @@ void Avatar::reset() {
}
// Update avatar head rotation with sensor data
void Avatar::updateHeadFromGyros(float deltaTime, SerialInterface* serialInterface, glm::vec3* gravity) {
void Avatar::updateHeadFromGyros(float deltaTime, SerialInterface* serialInterface) {
const float AMPLIFY_PITCH = 2.f;
const float AMPLIFY_YAW = 2.f;
const float AMPLIFY_ROLL = 2.f;
@ -134,10 +134,9 @@ void Avatar::updateHeadFromGyros(float deltaTime, SerialInterface* serialInterfa
float measuredRollRate = serialInterface->getLastRollRate();
// Update avatar head position based on measured gyro rates
_head.addPitch(measuredPitchRate * AMPLIFY_PITCH * deltaTime);
_head.addYaw (measuredYawRate * AMPLIFY_YAW * deltaTime);
_head.addRoll (measuredRollRate * AMPLIFY_ROLL * deltaTime);
_head.addYaw(measuredYawRate * AMPLIFY_YAW * deltaTime);
_head.addRoll(measuredRollRate * AMPLIFY_ROLL * deltaTime);
// Update head lean distance based on accelerometer data
glm::vec3 headRotationRates(_head.getPitch(), _head.getYaw(), _head.getRoll());

View file

@ -48,7 +48,7 @@ public:
void reset();
void simulate(float deltaTime, Transmitter* transmitter);
void updateHeadFromGyros(float frametime, SerialInterface * serialInterface, glm::vec3 * gravity);
void updateHeadFromGyros(float frametime, SerialInterface * serialInterface);
void updateFromMouse(int mouseX, int mouseY, int screenWidth, int screenHeight);
void addBodyYaw(float y) {_bodyYaw += y;};
void render(bool lookingInMirror);

View file

@ -8,7 +8,6 @@
#ifndef __interface__camera__
#define __interface__camera__
#include "Orientation.h"
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>

View file

@ -12,8 +12,8 @@
#include <glm/glm.hpp>
#include <glm/gtc/noise.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/quaternion.hpp>
#include <AvatarData.h>
#include <SharedUtil.h>
#include "Log.h"
@ -393,10 +393,10 @@ void renderCircle(glm::vec3 position, float radius, glm::vec3 surfaceNormal, int
}
void renderOrientationDirections(glm::vec3 position, Orientation orientation, float size) {
glm::vec3 pRight = position + orientation.getRight() * size;
glm::vec3 pUp = position + orientation.getUp () * size;
glm::vec3 pFront = position + orientation.getFront() * size;
void renderOrientationDirections(glm::vec3 position, const glm::quat& orientation, float size) {
glm::vec3 pRight = position + orientation * AVATAR_RIGHT * size;
glm::vec3 pUp = position + orientation * AVATAR_UP * size;
glm::vec3 pFront = position + orientation * AVATAR_FRONT * size;
glColor3f(1.0f, 0.0f, 0.0f);
glBegin(GL_LINE_STRIP);
@ -424,126 +424,5 @@ bool closeEnoughForGovernmentWork(float a, float b) {
}
void testOrientationClass() {
printLog("\n----------\ntestOrientationClass()\n----------\n\n");
oTestCase tests[] = {
// - inputs ------------, outputs -------------------- ------------------- ----------------------------
// -- front -------------------, -- up -------------, -- right -------------------
// ( yaw , pitch, roll , front.x , front.y , front.z , up.x , up.y , up.z , right.x , right.y , right.z )
// simple yaw tests
oTestCase( 0.f , 0.f , 0.f , 0.f , 0.f , 1.0f , 0.f , 1.0f , 0.f , -1.0f , 0.f , 0.f ),
oTestCase(45.0f , 0.f , 0.f , 0.707107f , 0.f , 0.707107f , 0.f , 1.0f , 0.f , -0.707107f, 0.f , 0.707107f),
oTestCase( 90.0f, 0.f , 0.f , 1.0f , 0.f , 0.f , 0.f , 1.0f , 0.f , 0.0f , 0.f , 1.0f ),
oTestCase(135.0f, 0.f , 0.f , 0.707107f , 0.f ,-0.707107f , 0.f , 1.0f , 0.f , 0.707107f, 0.f , 0.707107f),
oTestCase(180.0f, 0.f , 0.f , 0.f , 0.f , -1.0f , 0.f , 1.0f , 0.f , 1.0f , 0.f , 0.f ),
oTestCase(225.0f, 0.f , 0.f , -0.707107f , 0.f ,-0.707107f , 0.f , 1.0f , 0.f , 0.707107f, 0.f , -0.707107f),
oTestCase(270.0f, 0.f , 0.f , -1.0f , 0.f , 0.f , 0.f , 1.0f , 0.f , 0.0f , 0.f , -1.0f ),
oTestCase(315.0f, 0.f , 0.f , -0.707107f , 0.f , 0.707107f , 0.f , 1.0f , 0.f , -0.707107f, 0.f , -0.707107f),
oTestCase(-45.0f, 0.f , 0.f , -0.707107f , 0.f , 0.707107f , 0.f , 1.0f , 0.f , -0.707107f, 0.f , -0.707107f),
oTestCase(-90.0f, 0.f , 0.f , -1.0f , 0.f , 0.f , 0.f , 1.0f , 0.f , 0.0f , 0.f , -1.0f ),
oTestCase(-135.0f,0.f , 0.f , -0.707107f , 0.f ,-0.707107f , 0.f , 1.0f , 0.f , 0.707107f, 0.f , -0.707107f),
oTestCase(-180.0f,0.f , 0.f , 0.f , 0.f , -1.0f , 0.f , 1.0f , 0.f , 1.0f , 0.f , 0.f ),
oTestCase(-225.0f,0.f , 0.f , 0.707107f , 0.f ,-0.707107f , 0.f , 1.0f , 0.f , 0.707107f, 0.f , 0.707107f),
oTestCase(-270.0f,0.f , 0.f , 1.0f , 0.f , 0.f , 0.f , 1.0f , 0.f , 0.0f , 0.f , 1.0f ),
oTestCase(-315.0f,0.f , 0.f , 0.707107f , 0.f , 0.707107f , 0.f , 1.0f , 0.f , -0.707107f, 0.f , 0.707107f),
// simple pitch tests
oTestCase( 0.f , 0.f , 0.f , 0.f, 0.f , 1.0f , 0.f , 1.0f , 0.f , -1.0f , 0.f , 0.f ),
oTestCase( 0.f ,45.0f , 0.f , 0.f, 0.707107f , 0.707107f, 0.f ,0.707107f, -0.707107f, -1.0f , 0.f , 0.f ),
oTestCase( 0.f ,90.f , 0.f , 0.f, 1.0f , 0.0f , 0.f ,0.0f , -1.0f , -1.0f , 0.f , 0.f ),
oTestCase( 0.f ,135.0f, 0.f , 0.f, 0.707107f , -0.707107f, 0.f ,-0.707107f, -0.707107f, -1.0f , 0.f , 0.f ),
oTestCase( 0.f ,180.f , 0.f , 0.f, 0.0f ,-1.0f , 0.f ,-1.0f , 0.f , -1.0f , 0.f , 0.f ),
oTestCase( 0.f ,225.0f, 0.f , 0.f,-0.707107f , -0.707107f, 0.f ,-0.707107f, 0.707107f, -1.0f , 0.f , 0.f ),
oTestCase( 0.f ,270.f , 0.f , 0.f,-1.0f , 0.0f , 0.f ,0.0f , 1.0f , -1.0f , 0.f , 0.f ),
oTestCase( 0.f ,315.0f, 0.f , 0.f,-0.707107f , 0.707107f, 0.f , 0.707107f, 0.707107f, -1.0f , 0.f , 0.f ),
// simple roll tests
oTestCase( 0.f , 0.f , 0.f , 0.f , 0.f , 1.0f , 0.f , 1.0f ,0.0f , -1.0f , 0.f , 0.0f ),
oTestCase( 0.f , 0.f ,45.0f , 0.f , 0.f , 1.0f , 0.707107f , 0.707107f ,0.0f , -0.707107f, 0.707107f, 0.0f ),
oTestCase( 0.f , 0.f ,90.f , 0.f , 0.f , 1.0f , 1.0f , 0.0f ,0.0f , 0.0f , 1.0f , 0.0f ),
oTestCase( 0.f , 0.f ,135.0f , 0.f , 0.f , 1.0f , 0.707107f , -0.707107f,0.0f , 0.707107f , 0.707107f, 0.0f ),
oTestCase( 0.f , 0.f ,180.f , 0.f , 0.f , 1.0f , 0.0f , -1.0f ,0.0f , 1.0f , 0.0f , 0.0f ),
oTestCase( 0.f , 0.f ,225.0f , 0.f , 0.f , 1.0f , -0.707107f, -0.707107f,0.0f , 0.707107f ,-0.707107f, 0.0f ),
oTestCase( 0.f , 0.f ,270.f , 0.f , 0.f , 1.0f , -1.0f , 0.0f ,0.0f , 0.0f , -1.0f , 0.0f ),
oTestCase( 0.f , 0.f ,315.0f , 0.f , 0.f , 1.0f , -0.707107f, 0.707107f ,0.0f , -0.707107f,-0.707107f, 0.0f ),
// yaw combo tests
oTestCase( 90.f , 90.f , 0.f , 0.f , 1.0f , 0.0f , -1.0f , 0.0f , 0.f , 0.0f , 0.f , 1.0f ),
oTestCase( 90.f , 0.f , 90.f , 1.0f , 0.0f, 0.f , 0.0f , 0.0f , -1.f , 0.0f , 1.0f , 0.0f ),
};
int failedCount = 0;
int totalTests = sizeof(tests)/sizeof(oTestCase);
for (int i=0; i < totalTests; i++) {
bool passed = true; // I'm an optimist!
float yaw = tests[i].yaw;
float pitch = tests[i].pitch;
float roll = tests[i].roll;
Orientation o1;
o1.setToIdentity();
o1.yaw(yaw);
o1.pitch(pitch);
o1.roll(roll);
glm::vec3 front = o1.getFront();
glm::vec3 up = o1.getUp();
glm::vec3 right = o1.getRight();
printLog("\n-----\nTest: %d - yaw=%f , pitch=%f , roll=%f \n",i+1,yaw,pitch,roll);
printLog("\nFRONT\n");
printLog(" + received: front.x=%f, front.y=%f, front.z=%f\n",front.x,front.y,front.z);
if (closeEnoughForGovernmentWork(front.x, tests[i].frontX)
&& closeEnoughForGovernmentWork(front.y, tests[i].frontY)
&& closeEnoughForGovernmentWork(front.z, tests[i].frontZ)) {
printLog(" front vector PASSES!\n");
} else {
printLog(" expected: front.x=%f, front.y=%f, front.z=%f\n",tests[i].frontX,tests[i].frontY,tests[i].frontZ);
printLog(" front vector FAILED! \n");
passed = false;
}
printLog("\nUP\n");
printLog(" + received: up.x=%f, up.y=%f, up.z=%f\n",up.x,up.y,up.z);
if (closeEnoughForGovernmentWork(up.x, tests[i].upX)
&& closeEnoughForGovernmentWork(up.y, tests[i].upY)
&& closeEnoughForGovernmentWork(up.z, tests[i].upZ)) {
printLog(" up vector PASSES!\n");
} else {
printLog(" expected: up.x=%f, up.y=%f, up.z=%f\n",tests[i].upX,tests[i].upY,tests[i].upZ);
printLog(" up vector FAILED!\n");
passed = false;
}
printLog("\nRIGHT\n");
printLog(" + received: right.x=%f, right.y=%f, right.z=%f\n",right.x,right.y,right.z);
if (closeEnoughForGovernmentWork(right.x, tests[i].rightX)
&& closeEnoughForGovernmentWork(right.y, tests[i].rightY)
&& closeEnoughForGovernmentWork(right.z, tests[i].rightZ)) {
printLog(" right vector PASSES!\n");
} else {
printLog(" expected: right.x=%f, right.y=%f, right.z=%f\n",tests[i].rightX,tests[i].rightY,tests[i].rightZ);
printLog(" right vector FAILED!\n");
passed = false;
}
if (!passed) {
printLog("\n-----\nTest: %d - FAILED! \n----------\n\n",i+1);
failedCount++;
}
}
printLog("\n-----\nTotal Failed: %d out of %d \n----------\n\n",failedCount,totalTests);
printLog("\n----------DONE----------\n\n");
}

View file

@ -16,8 +16,7 @@
#endif
#include <glm/glm.hpp>
#include <Orientation.h>
#include <glm/gtc/quaternion.hpp>
// the standard sans serif font family
#define SANS_FONT_FAMILY "Helvetica"
@ -56,44 +55,9 @@ void drawGroundPlaneGrid(float size);
void renderDiskShadow(glm::vec3 position, glm::vec3 upDirection, float radius, float darkness);
void renderOrientationDirections( glm::vec3 position, Orientation orientation, float size );
void renderOrientationDirections( glm::vec3 position, const glm::quat& orientation, float size );
void renderSphereOutline(glm::vec3 position, float radius, int numSides, glm::vec3 cameraPosition);
void renderCircle(glm::vec3 position, float radius, glm::vec3 surfaceNormal, int numSides );
class oTestCase {
public:
float yaw;
float pitch;
float roll;
float frontX;
float frontY;
float frontZ;
float upX;
float upY;
float upZ;
float rightX;
float rightY;
float rightZ;
oTestCase(
float yaw, float pitch, float roll,
float frontX, float frontY, float frontZ,
float upX, float upY, float upZ,
float rightX, float rightY, float rightZ
) :
yaw(yaw),pitch(pitch),roll(roll),
frontX(frontX),frontY(frontY),frontZ(frontZ),
upX(upX),upY(upY),upZ(upZ),
rightX(rightX),rightY(rightY),rightZ(rightZ)
{};
};
void testOrientationClass();
#endif

View file

@ -1,121 +0,0 @@
//-----------------------------------------------------------
//
// Created by Jeffrey Ventrella
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
//
//-----------------------------------------------------------
#include "Orientation.h"
#include "SharedUtil.h"
static const bool USING_QUATERNIONS = true;
Orientation::Orientation() {
setToIdentity();
}
void Orientation::setToIdentity() {
quat = glm::quat();
right = glm::vec3(IDENTITY_RIGHT);
up = glm::vec3(IDENTITY_UP );
front = glm::vec3(IDENTITY_FRONT);
}
void Orientation::set(Orientation o) {
quat = o.quat;
right = o.right;
up = o.up;
front = o.front;
}
void Orientation::yaw(float angle) {
float radian = angle * PI_OVER_180;
if (USING_QUATERNIONS) {
rotateAndGenerateDirections(glm::quat(glm::vec3(0.0f, -radian, 0.0f)));
} else {
float s = sin(radian);
float c = cos(radian);
glm::vec3 cosineFront = front * c;
glm::vec3 cosineRight = right * c;
glm::vec3 sineFront = front * s;
glm::vec3 sineRight = right * s;
front = cosineFront - sineRight;
right = cosineRight + sineFront;
}
}
void Orientation::pitch(float angle) {
float radian = angle * PI_OVER_180;
if (USING_QUATERNIONS) {
rotateAndGenerateDirections(glm::quat(glm::vec3(radian, 0.0f, 0.0f)));
} else {
float s = sin(radian);
float c = cos(radian);
glm::vec3 cosineUp = up * c;
glm::vec3 cosineFront = front * c;
glm::vec3 sineUp = up * s;
glm::vec3 sineFront = front * s;
up = cosineUp - sineFront;
front = cosineFront + sineUp;
}
}
void Orientation::roll(float angle) {
float radian = angle * PI_OVER_180;
if (USING_QUATERNIONS) {
rotateAndGenerateDirections(glm::quat(glm::vec3(0.0f, 0.0f, radian)));
} else {
float s = sin(radian);
float c = cos(radian);
glm::vec3 cosineUp = up * c;
glm::vec3 cosineRight = right * c;
glm::vec3 sineUp = up * s;
glm::vec3 sineRight = right * s;
up = cosineUp - sineRight;
right = cosineRight + sineUp;
}
}
void Orientation::rotate(float pitch_change, float yaw_change, float roll_change) {
pitch(pitch_change);
yaw (yaw_change);
roll (roll_change);
}
void Orientation::rotate(glm::vec3 eulerAngles) {
//this needs to be optimized!
pitch(eulerAngles.x);
yaw (eulerAngles.y);
roll (eulerAngles.z);
}
void Orientation::rotate( glm::quat rotation ) {
rotateAndGenerateDirections(rotation);
}
void Orientation::rotateAndGenerateDirections(glm::quat rotation) {
quat = quat * rotation;
glm::mat4 rotationMatrix = glm::mat4_cast(quat);
right = glm::vec3(glm::vec4(IDENTITY_RIGHT, 0.0f) * rotationMatrix);
up = glm::vec3(glm::vec4(IDENTITY_UP, 0.0f) * rotationMatrix);
front = glm::vec3(glm::vec4(IDENTITY_FRONT, 0.0f) * rotationMatrix);
}

View file

@ -1,55 +0,0 @@
//-----------------------------------------------------------
//
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
//
//-----------------------------------------------------------
#ifndef __interface__orientation__
#define __interface__orientation__
#include <cmath>
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
// this is where the coordinate system is represented
const glm::vec3 IDENTITY_RIGHT = glm::vec3(-1.0f, 0.0f, 0.0f);
const glm::vec3 IDENTITY_UP = glm::vec3( 0.0f, 1.0f, 0.0f);
const glm::vec3 IDENTITY_FRONT = glm::vec3( 0.0f, 0.0f, 1.0f);
class Orientation
{
public:
Orientation();
void set(Orientation);
void setToIdentity();
void pitch(float pitch_change);
void yaw (float yaw_change);
void roll (float roll_change);
void rotate(float pitch, float yaw, float roll);
void rotate(glm::vec3 EulerAngles);
void rotate(glm::quat quaternion);
const glm::quat& getQuat() const {return quat;}
const glm::vec3& getRight() const {return right;}
const glm::vec3& getUp () const {return up; }
const glm::vec3& getFront() const {return front;}
const glm::vec3& getIdentityRight() const {return IDENTITY_RIGHT;}
const glm::vec3& getIdentityUp () const {return IDENTITY_UP;}
const glm::vec3& getIdentityFront() const {return IDENTITY_FRONT;}
private:
glm::quat quat;
glm::vec3 right;
glm::vec3 up;
glm::vec3 front;
void rotateAndGenerateDirections(glm::quat rotation);
};
#endif