mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 11:45:36 +02:00
Removed remaining Orientation bits (and class itself), enforce limits on
head yaw/pitch/roll.
This commit is contained in:
parent
e2ec8245b0
commit
3f6cf08b97
6 changed files with 10 additions and 344 deletions
|
@ -8,7 +8,6 @@
|
|||
#ifndef __interface__camera__
|
||||
#define __interface__camera__
|
||||
|
||||
#include "Orientation.h"
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
||||
|
|
|
@ -309,9 +309,9 @@ void Head::renderMohawk(glm::vec3 cameraPosition) {
|
|||
|
||||
void Head::setOrientation(const glm::quat& orientation) {
|
||||
glm::vec3 eulerAngles = safeEulerAngles(glm::inverse(glm::quat(glm::radians(_bodyRotation))) * orientation);
|
||||
_pitch = eulerAngles.x;
|
||||
_yaw = eulerAngles.y;
|
||||
_roll = eulerAngles.z;
|
||||
setPitch(eulerAngles.x);
|
||||
setYaw(eulerAngles.y);
|
||||
setRoll(eulerAngles.z);
|
||||
}
|
||||
|
||||
glm::quat Head::getOrientation() const {
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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
|
Loading…
Reference in a new issue