adding Camera and some utility classes and start of prototype avatar

This commit is contained in:
Jeffrey Ventrella 2013-04-04 18:04:32 -07:00
parent f859d8ed9c
commit d3f6c19e83
11 changed files with 1141 additions and 29 deletions

19
interface/src/Camera.cpp Executable file
View file

@ -0,0 +1,19 @@
//-----------------------------------------------------------
//
// Created by Jeffrey Ventrella and added as a utility
// class for High Fidelity Code base, April 2013
//
//-----------------------------------------------------------
#include "Camera.h"
//------------------------
Camera::Camera()
{
yaw = 0.0;
pitch = 0.0;
roll = 0.0;
position = glm::dvec3( 0.0, 0.0, 0.0 );
orientation.setToIdentity();
}

41
interface/src/Camera.h Executable file
View file

@ -0,0 +1,41 @@
//-----------------------------------------------------------
//
// Created by Jeffrey Ventrella and added as a utility
// class for High Fidelity Code base, April 2013
//
//-----------------------------------------------------------
#ifndef __interface__camera__
#define __interface__camera__
#include "Vector3D.h"
#include "Orientation.h"
#include <glm/glm.hpp>
class Camera
{
public:
Camera();
void setYaw ( double y ) { yaw = y; }
void setPitch ( double p ) { pitch = p; }
void setRoll ( double r ) { roll = r; }
void setPosition ( glm::dvec3 p ) { position = p; };
void setOrientation ( Orientation o ) { orientation.set(o); }
double getYaw () { return yaw; }
double getPitch () { return pitch; }
double getRoll () { return roll; }
glm::dvec3 getPosition () { return position; }
Orientation getOrientation () { return orientation; }
private:
glm::dvec3 position;
double yaw;
double pitch;
double roll;
Orientation orientation;
};
#endif

View file

@ -40,6 +40,7 @@ private:
float transmitterHz;
int transmitterPackets;
bool renderPointer;
};

302
interface/src/Head.cpp Normal file → Executable file
View file

@ -38,8 +38,13 @@ vector<unsigned char> iris_texture;
unsigned int iris_texture_width = 512;
unsigned int iris_texture_height = 256;
//---------------------------------------------------
Head::Head()
{
initializeAvatar();
position = glm::vec3(0,0,0);
velocity = glm::vec3(0,0,0);
thrust = glm::vec3(0,0,0);
@ -77,6 +82,8 @@ Head::Head()
lastLoudness = 0.0;
browAudioLift = 0.0;
noise = 0;
handOffset.clear();
sphere = NULL;
@ -91,7 +98,14 @@ Head::Head()
}
}
Head::Head(const Head &otherHead) {
//---------------------------------------------------
Head::Head(const Head &otherHead)
{
initializeAvatar();
position = otherHead.position;
velocity = otherHead.velocity;
thrust = otherHead.thrust;
@ -141,22 +155,42 @@ Head::Head(const Head &otherHead) {
hand = &newHand;
}
Head::~Head() {
if (sphere != NULL) {
//---------------------------------------------------
Head::~Head()
{
if (sphere != NULL)
{
gluDeleteQuadric(sphere);
}
}
Head* Head::clone() const {
//---------------------------------------------------
Head* Head::clone() const
{
return new Head(*this);
}
//---------------------------------------------------
void Head::reset()
{
Pitch = Yaw = Roll = 0;
leanForward = leanSideways = 0;
}
//---------------------------------------------------
void Head::UpdatePos(float frametime, SerialInterface * serialInterface, int head_mirror, glm::vec3 * gravity)
// Using serial data, update avatar/render position and angles
{
@ -201,24 +235,49 @@ void Head::UpdatePos(float frametime, SerialInterface * serialInterface, int hea
}
}
//---------------------------------------------------
void Head::setAvatarPosition( double x, double y, double z )
{
avatar.position.setXYZ( x, y, z );
}
//---------------------------------------------------
void Head::addLean(float x, float z) {
// Add Body lean as impulse
leanSideways += x;
leanForward += z;
}
//---------------------------------------------------
void Head::setLeanForward(float dist){
leanForward = dist;
}
//---------------------------------------------------
void Head::setLeanSideways(float dist){
leanSideways = dist;
}
// Simulate the head over time
//---------------------------------------------------
void Head::simulate(float deltaTime)
{
simulateAvatar( deltaTime );
glm::vec3 forward(-sinf(getRenderYaw()*PI/180),
sinf(getRenderPitch()*PI/180),
cosf(getRenderYaw()*PI/180));
@ -350,28 +409,48 @@ void Head::simulate(float deltaTime)
}
}
hand->simulate(deltaTime);
//hand->simulate(deltaTime);
}
//---------------------------------------------------
void Head::render(int faceToFace, int isMine)
{
// render avatar
renderAvatar();
int side = 0;
// Always render own hand, but don't render head unless showing face2face
glEnable(GL_DEPTH_TEST);
glPushMatrix();
glScalef(scale, scale, scale);
glTranslatef(leanSideways, 0.f, leanForward);
//glScalef(scale, scale, scale);
glTranslatef
(
avatar.bone[ AVATAR_BONE_HEAD ].position.x,
avatar.bone[ AVATAR_BONE_HEAD ].position.y,
avatar.bone[ AVATAR_BONE_HEAD ].position.z
);
glScalef( 0.03, 0.03, 0.03 );
glTranslatef(leanSideways, 0.f, leanForward);
glRotatef(Yaw, 0, 1, 0);
hand->render(1);
//hand->render(1);
// Don't render a head if it is really close to your location, because that is your own head!
if (!isMine || faceToFace) {
//if (!isMine || faceToFace)
{
glRotatef(Pitch, 1, 0, 0);
glRotatef(Roll, 0, 0, 1);
@ -380,6 +459,7 @@ void Head::render(int faceToFace, int isMine)
// Overall scale of head
if (faceToFace) glScalef(1.5, 2.0, 2.0);
else glScalef(0.75, 1.0, 1.0);
glColor3fv(skinColor);
@ -400,7 +480,6 @@ void Head::render(int faceToFace, int isMine)
glTranslatef(-2.0, 0, 0);
}
glPopMatrix();
// Eyebrows
audioAttack = 0.9*audioAttack + 0.1*fabs(loudness - lastLoudness);
@ -509,9 +588,201 @@ void Head::render(int faceToFace, int isMine)
}
glPopMatrix();
}
//---------------------------------------------------------
void Head::setHandMovement( glm::dvec3 movement )
{
handOffset.setXYZ( movement.x, movement.y, movement.z );
}
//-----------------------------------------
void Head::initializeAvatar()
{
//printf( "initializeAvatar\n" );
avatar.position.clear();
//avatar.position.setXYZ( -3.0, 0.0, 0.0 );
avatar.velocity.clear();
avatar.orientation.setToIdentity();
for (int b=0; b<NUM_AVATAR_BONES; b++)
{
avatar.bone[b].position.clear();
avatar.bone[b].velocity.clear();
avatar.bone[b].orientation.setToIdentity();
}
//----------------------------------------------------------------------------
// parental hierarchy
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// spine and head
//----------------------------------------------------------------------------
avatar.bone[ AVATAR_BONE_PELVIS_SPINE ].parent = AVATAR_BONE_NULL;
avatar.bone[ AVATAR_BONE_MID_SPINE ].parent = AVATAR_BONE_PELVIS_SPINE;
avatar.bone[ AVATAR_BONE_CHEST_SPINE ].parent = AVATAR_BONE_MID_SPINE;
avatar.bone[ AVATAR_BONE_NECK ].parent = AVATAR_BONE_CHEST_SPINE;
avatar.bone[ AVATAR_BONE_HEAD ].parent = AVATAR_BONE_NECK;
//----------------------------------------------------------------------------
// left chest and arm
//----------------------------------------------------------------------------
avatar.bone[ AVATAR_BONE_LEFT_CHEST ].parent = AVATAR_BONE_MID_SPINE;
avatar.bone[ AVATAR_BONE_LEFT_SHOULDER ].parent = AVATAR_BONE_LEFT_CHEST;
avatar.bone[ AVATAR_BONE_LEFT_UPPER_ARM ].parent = AVATAR_BONE_LEFT_SHOULDER;
avatar.bone[ AVATAR_BONE_LEFT_FOREARM ].parent = AVATAR_BONE_LEFT_UPPER_ARM;
avatar.bone[ AVATAR_BONE_LEFT_HAND ].parent = AVATAR_BONE_LEFT_FOREARM;
//----------------------------------------------------------------------------
// right chest and arm
//----------------------------------------------------------------------------
avatar.bone[ AVATAR_BONE_RIGHT_CHEST ].parent = AVATAR_BONE_MID_SPINE;
avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].parent = AVATAR_BONE_RIGHT_CHEST;
avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].parent = AVATAR_BONE_RIGHT_SHOULDER;
avatar.bone[ AVATAR_BONE_RIGHT_FOREARM ].parent = AVATAR_BONE_RIGHT_UPPER_ARM;
avatar.bone[ AVATAR_BONE_RIGHT_HAND ].parent = AVATAR_BONE_RIGHT_FOREARM;
//----------------------------------------------------------------------------
// left pelvis and leg
//----------------------------------------------------------------------------
avatar.bone[ AVATAR_BONE_LEFT_PELVIS ].parent = AVATAR_BONE_NULL;
avatar.bone[ AVATAR_BONE_LEFT_THIGH ].parent = AVATAR_BONE_LEFT_PELVIS;
avatar.bone[ AVATAR_BONE_LEFT_SHIN ].parent = AVATAR_BONE_LEFT_THIGH;
avatar.bone[ AVATAR_BONE_LEFT_FOOT ].parent = AVATAR_BONE_LEFT_SHIN;
//----------------------------------------------------------------------------
// right pelvis and leg
//----------------------------------------------------------------------------
avatar.bone[ AVATAR_BONE_RIGHT_PELVIS ].parent = AVATAR_BONE_NULL;
avatar.bone[ AVATAR_BONE_RIGHT_THIGH ].parent = AVATAR_BONE_RIGHT_PELVIS;
avatar.bone[ AVATAR_BONE_RIGHT_SHIN ].parent = AVATAR_BONE_RIGHT_THIGH;
avatar.bone[ AVATAR_BONE_RIGHT_FOOT ].parent = AVATAR_BONE_RIGHT_SHIN;
//----------------------------------------------------------
// default pose position
//----------------------------------------------------------
avatar.bone[ AVATAR_BONE_PELVIS_SPINE ].defaultPosePosition.setXYZ( 0.0, 0.1, 0.0 );
avatar.bone[ AVATAR_BONE_MID_SPINE ].defaultPosePosition.setXYZ( 0.0, 0.1, 0.0 );
avatar.bone[ AVATAR_BONE_CHEST_SPINE ].defaultPosePosition.setXYZ( 0.0, 0.1, 0.0 );
avatar.bone[ AVATAR_BONE_NECK ].defaultPosePosition.setXYZ( 0.0, 0.06, 0.0 );
avatar.bone[ AVATAR_BONE_HEAD ].defaultPosePosition.setXYZ( 0.0, 0.06, 0.0 );
avatar.bone[ AVATAR_BONE_LEFT_CHEST ].defaultPosePosition.setXYZ( -0.06, 0.06, 0.0 );
avatar.bone[ AVATAR_BONE_LEFT_SHOULDER ].defaultPosePosition.setXYZ( -0.03, 0.0, 0.0 );
avatar.bone[ AVATAR_BONE_LEFT_UPPER_ARM ].defaultPosePosition.setXYZ( 0.0, -0.12, 0.0 );
avatar.bone[ AVATAR_BONE_LEFT_FOREARM ].defaultPosePosition.setXYZ( 0.0, -0.1, 0.0 );
avatar.bone[ AVATAR_BONE_LEFT_HAND ].defaultPosePosition.setXYZ( 0.0, -0.05, 0.0 );
avatar.bone[ AVATAR_BONE_RIGHT_CHEST ].defaultPosePosition.setXYZ( 0.06, 0.06, 0.0 );
avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].defaultPosePosition.setXYZ( 0.03, 0.0, 0.0 );
avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].defaultPosePosition.setXYZ( 0.0, -0.12, 0.0 );
avatar.bone[ AVATAR_BONE_RIGHT_FOREARM ].defaultPosePosition.setXYZ( 0.0, -0.1, 0.0 );
avatar.bone[ AVATAR_BONE_RIGHT_HAND ].defaultPosePosition.setXYZ( 0.0, -0.05, 0.0 );
avatar.bone[ AVATAR_BONE_LEFT_PELVIS ].defaultPosePosition.setXYZ( -0.05, 0.0, 0.0 );
avatar.bone[ AVATAR_BONE_LEFT_THIGH ].defaultPosePosition.setXYZ( 0.0, -0.15, 0.0 );
avatar.bone[ AVATAR_BONE_LEFT_SHIN ].defaultPosePosition.setXYZ( 0.0, -0.15, 0.0 );
avatar.bone[ AVATAR_BONE_LEFT_FOOT ].defaultPosePosition.setXYZ( 0.0, 0.0, 0.04 );
avatar.bone[ AVATAR_BONE_RIGHT_PELVIS ].defaultPosePosition.setXYZ( 0.05, 0.0, 0.0 );
avatar.bone[ AVATAR_BONE_RIGHT_THIGH ].defaultPosePosition.setXYZ( 0.0, -0.15, 0.0 );
avatar.bone[ AVATAR_BONE_RIGHT_SHIN ].defaultPosePosition.setXYZ( 0.0, -0.15, 0.0 );
avatar.bone[ AVATAR_BONE_RIGHT_FOOT ].defaultPosePosition.setXYZ( 0.0, 0.0, 0.04 );
//----------------------------------------------------------------------------
// length
//----------------------------------------------------------------------------
avatar.bone[ AVATAR_BONE_PELVIS_SPINE ].length = 0.1;
avatar.bone[ AVATAR_BONE_MID_SPINE ].length = 0.1;
avatar.bone[ AVATAR_BONE_CHEST_SPINE ].length = 0.1;
avatar.bone[ AVATAR_BONE_NECK ].length = 0.1;
avatar.bone[ AVATAR_BONE_HEAD ].length = 0.1;
avatar.bone[ AVATAR_BONE_LEFT_CHEST ].length = 0.1;
avatar.bone[ AVATAR_BONE_LEFT_SHOULDER ].length = 0.1;
avatar.bone[ AVATAR_BONE_LEFT_UPPER_ARM ].length = 0.1;
avatar.bone[ AVATAR_BONE_LEFT_FOREARM ].length = 0.1;
avatar.bone[ AVATAR_BONE_LEFT_HAND ].length = 0.1;
avatar.bone[ AVATAR_BONE_RIGHT_CHEST ].length = 0.1;
avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].length = 0.1;
avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].length = 0.1;
avatar.bone[ AVATAR_BONE_RIGHT_FOREARM ].length = 0.1;
avatar.bone[ AVATAR_BONE_RIGHT_HAND ].length = 0.1;
avatar.bone[ AVATAR_BONE_LEFT_PELVIS ].length = 0.1;
avatar.bone[ AVATAR_BONE_LEFT_THIGH ].length = 0.1;
avatar.bone[ AVATAR_BONE_LEFT_SHIN ].length = 0.1;
avatar.bone[ AVATAR_BONE_LEFT_FOOT ].length = 0.1;
avatar.bone[ AVATAR_BONE_RIGHT_PELVIS ].length = 0.1;
avatar.bone[ AVATAR_BONE_RIGHT_THIGH ].length = 0.1;
avatar.bone[ AVATAR_BONE_RIGHT_SHIN ].length = 0.1;
avatar.bone[ AVATAR_BONE_RIGHT_FOOT ].length = 0.1;
updateAvatarSkeleton();
}
//-----------------------------------------
void Head::simulateAvatar( float deltaTime )
{
updateAvatarSkeleton();
}
//-----------------------------------------
void Head::updateAvatarSkeleton()
{
for (int b=0; b<NUM_AVATAR_BONES; b++)
{
if ( avatar.bone[b].parent == AVATAR_BONE_NULL )
{
avatar.bone[b].position.set( avatar.position );
}
else
{
avatar.bone[b].position.set( avatar.bone[ avatar.bone[b].parent ].position );
}
avatar.bone[b].position.add( avatar.bone[b].defaultPosePosition );
}
avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position.add( handOffset );
}
//-----------------------------------------
void Head::renderAvatar()
{
glColor3fv(skinColor);
for (int b=0; b<NUM_AVATAR_BONES; b++)
{
glPushMatrix();
glTranslatef( avatar.bone[b].position.x, avatar.bone[b].position.y, avatar.bone[b].position.z );
glScalef( 0.02, 0.02, 0.02 );
glutSolidSphere( 1, 6, 3 );
glPopMatrix();
}
}
// Transmit data to agents requesting it
//---------------------------------------------------
int Head::getBroadcastData(char* data)
{
// Copy data for transmission to the buffer, return length of data
@ -523,6 +794,7 @@ int Head::getBroadcastData(char* data)
return strlen(data);
}
//---------------------------------------------------
void Head::parseData(void *data, int size) {
// parse head data for this agent
glm::vec3 handPos(0,0,0);
@ -531,9 +803,11 @@ void Head::parseData(void *data, int size) {
&position.x, &position.y, &position.z,
&loudness, &averageLoudness,
&handPos.x, &handPos.y, &handPos.z);
if (glm::length(handPos) > 0.0) hand->setPos(handPos);
}
//---------------------------------------------------
void Head::SetNewHeadTarget(float pitch, float yaw)
{
PitchTarget = pitch;

View file

@ -13,8 +13,9 @@
#include "AgentData.h"
#include "Field.h"
#include "world.h"
#include "Head.h"
#include "Hand.h"
#include "Vector3D.h" // added by Ventrella as a utility
#include "Orientation.h" // added by Ventrella as a utility
#include "InterfaceConfig.h"
#include "SerialInterface.h"
@ -30,6 +31,101 @@ enum eyeContactTargets {LEFT_EYE, RIGHT_EYE, MOUTH};
#define ROT_RIGHT 7
#define MAX_DRIVE_KEYS 8
/*
enum AvatarJoints
{
AVATAR_JOINT_NULL = -1,
AVATAR_JOINT_PELVIS,
AVATAR_JOINT_TORSO,
AVATAR_JOINT_CHEST,
AVATAR_JOINT_NECK_BASE,
AVATAR_JOINT_HEAD_BASE,
AVATAR_JOINT_HEAD_TOP,
AVATAR_JOINT_LEFT_CLAVICLE,
AVATAR_JOINT_LEFT_SHOULDER,
AVATAR_JOINT_LEFT_ELBOW,
AVATAR_JOINT_LEFT_WRIST,
AVATAR_JOINT_LEFT_FINGERTIPS,
AVATAR_JOINT_RIGHT_CLAVICLE,
AVATAR_JOINT_RIGHT_SHOULDER,
AVATAR_JOINT_RIGHT_ELBOW,
AVATAR_JOINT_RIGHT_WRIST,
AVATAR_JOINT_RIGHT_FINGERTIPS,
AVATAR_JOINT_LEFT_HIP,
AVATAR_JOINT_LEFT_KNEE,
AVATAR_JOINT_LEFT_HEEL,
AVATAR_JOINT_LEFT_TOES,
AVATAR_JOINT_RIGHT_HIP,
AVATAR_JOINT_RIGHT_KNEE,
AVATAR_JOINT_RIGHT_HEEL,
AVATAR_JOINT_RIGHT_TOES,
NUM_AVATAR_JOINTS
};
*/
enum AvatarBones
{
AVATAR_BONE_NULL = -1,
AVATAR_BONE_PELVIS_SPINE, // connects pelvis joint with torso joint (cannot be rotated)
AVATAR_BONE_MID_SPINE, // connects torso joint with chest joint
AVATAR_BONE_CHEST_SPINE, // connects chest joint with neckBase joint (cannot be rotated)
AVATAR_BONE_NECK, // connects neckBase joint with headBase joint
AVATAR_BONE_HEAD, // connects headBase joint with headTop joint
AVATAR_BONE_LEFT_CHEST, // connects chest joint with left clavicle joint (cannot be rotated)
AVATAR_BONE_LEFT_SHOULDER, // connects left clavicle joint with left shoulder joint
AVATAR_BONE_LEFT_UPPER_ARM, // connects left shoulder joint with left elbow joint
AVATAR_BONE_LEFT_FOREARM, // connects left elbow joint with left wrist joint
AVATAR_BONE_LEFT_HAND, // connects left wrist joint with left fingertips joint
AVATAR_BONE_RIGHT_CHEST, // connects chest joint with right clavicle joint (cannot be rotated)
AVATAR_BONE_RIGHT_SHOULDER, // connects right clavicle joint with right shoulder joint
AVATAR_BONE_RIGHT_UPPER_ARM, // connects right shoulder joint with right elbow joint
AVATAR_BONE_RIGHT_FOREARM, // connects right elbow joint with right wrist joint
AVATAR_BONE_RIGHT_HAND, // connects right wrist joint with right fingertips joint
AVATAR_BONE_LEFT_PELVIS, // connects pelvis joint with left hip joint (cannot be rotated)
AVATAR_BONE_LEFT_THIGH, // connects left hip joint with left knee joint
AVATAR_BONE_LEFT_SHIN, // connects left knee joint with left heel joint
AVATAR_BONE_LEFT_FOOT, // connects left heel joint with left toes joint
AVATAR_BONE_RIGHT_PELVIS, // connects pelvis joint with right hip joint (cannot be rotated)
AVATAR_BONE_RIGHT_THIGH, // connects right hip joint with right knee joint
AVATAR_BONE_RIGHT_SHIN, // connects right knee joint with right heel joint
AVATAR_BONE_RIGHT_FOOT, // connects right heel joint with right toes joint
NUM_AVATAR_BONES
};
struct AvatarBone
{
AvatarBones parent;
Vector3D position;
Vector3D defaultPosePosition;
Vector3D velocity;
double yaw;
double pitch;
double roll;
Orientation orientation;
double length;
};
struct Avatar
{
Vector3D position;
Vector3D velocity;
Orientation orientation;
AvatarBone bone[ NUM_AVATAR_BONES ];
};
class Head : public AgentData {
public:
Head();
@ -60,7 +156,12 @@ class Head : public AgentData {
float getLastMeasuredYaw() {return YawRate;}
void render(int faceToFace, int isMine);
void setAvatarPosition( double, double, double );
void simulate(float);
void setHandMovement( glm::dvec3 movement );
// Send and receive network data
int getBroadcastData(char * data);
@ -124,6 +225,8 @@ class Head : public AgentData {
glm::vec3 position;
glm::vec3 velocity;
glm::vec3 thrust;
Vector3D handOffset;
int driveKeys[MAX_DRIVE_KEYS];
@ -131,10 +234,16 @@ class Head : public AgentData {
eyeContactTargets eyeContactTarget;
GLUquadric *sphere;
Avatar avatar;
void initializeAvatar();
void simulateAvatar( float deltaTime );
void updateAvatarSkeleton();
void renderAvatar();
void readSensors();
float renderYaw, renderPitch; // Pitch from view frustum when this is own head.
};
#endif
#endif

232
interface/src/Orientation.cpp Executable file
View file

@ -0,0 +1,232 @@
//-----------------------------------------------------------
//
// Created by Jeffrey Ventrella and added as a utility
// class for High Fidelity Code base, April 2013
//
//-----------------------------------------------------------
#include "Orientation.h"
#include "Vector3D.h"
#include "Util.h"
//------------------------
Orientation::Orientation()
{
right.setXYZ ( 1.0, 0.0, 0.0 );
up.setXYZ ( 0.0, 1.0, 0.0 );
front.setXYZ ( 0.0, 0.0, 1.0 );
}
//--------------------------------
void Orientation::setToIdentity()
{
right.setXYZ ( 1.0, 0.0, 0.0 );
up.setXYZ ( 0.0, 1.0, 0.0 );
front.setXYZ ( 0.0, 0.0, 1.0 );
}
//------------------------------------
void Orientation::set( Orientation o )
{
right.set ( o.getRight() );
up.set ( o.getUp () );
front.set ( o.getFront() );
}
//-----------------------------------------------------------------------------------------
void Orientation::forceAxisInDirection( int whichAxis, const Vector3D &direction, double forceAmount )
{
Vector3D diff;
if ( whichAxis == ORIENTATION_RIGHT_AXIS )
{
diff.setToDifference( direction, right );
right.addScaled( diff, forceAmount );
right.normalize();
up.setToCross( front, right );
up.normalize();
front.setToCross( right, up );
}
else if ( whichAxis == ORIENTATION_UP_AXIS )
{
diff.setToDifference( direction, up );
up.addScaled( diff, forceAmount );
up.normalize();
front.setToCross( right, up );
front.normalize();
right.setToCross( up, front );
}
else if ( whichAxis == ORIENTATION_FRONT_AXIS )
{
diff.setToDifference( direction, front );
front.addScaled( diff, forceAmount );
front.normalize();
right.setToCross( up, front );
right.normalize();
up.setToCross( front, right );
}
}
//------------------------------------------------------------------------------------------------------
void Orientation::forceFrontInDirection( const Vector3D &direction, const Vector3D &upDirection, double forceAmount )
{
Vector3D diff;
diff.setToDifference( direction, front );
front.addScaled( diff, forceAmount );
front.normalize();
right.setToCross( upDirection, front );
right.normalize();
up.setToCross( front, right );
}
//---------------------------------------
void Orientation::yaw( double angle )
{
double r = angle * PI_OVER_180;
double s = sin( r );
double c = cos( r );
Vector3D cosineFront;
Vector3D cosineRight;
Vector3D sineFront;
Vector3D sineRight;
cosineFront.setToScaled ( front, c );
cosineRight.setToScaled ( right, c );
sineFront.setToScaled ( front, s );
sineRight.setToScaled ( right, s );
front.set( cosineFront );
front.add( sineRight );
right.set( cosineRight );
right.subtract( sineFront );
}
//---------------------------------------
void Orientation::pitch( double angle )
{
double r = angle * PI_OVER_180;
double s = sin( r );
double c = cos( r );
Vector3D cosineUp;
Vector3D cosineFront;
Vector3D sineUp;
Vector3D sineFront;
cosineUp.setToScaled ( up, c );
cosineFront.setToScaled ( front, c );
sineUp.setToScaled ( up, s );
sineFront.setToScaled ( front, s );
up.set( cosineUp );
up.add( sineFront );
front.set( cosineFront );
front.subtract( sineUp );
}
//---------------------------------------
void Orientation::roll( double angle )
{
double r = angle * PI_OVER_180;
double s = sin( r );
double c = cos( r );
Vector3D cosineUp;
Vector3D cosineRight;
Vector3D sineUp;
Vector3D sineRight;
cosineUp.setToScaled ( up, c );
cosineRight.setToScaled ( right, c );
sineUp.setToScaled ( up, s );
sineRight.setToScaled ( right, s );
up.set( cosineUp );
up.add( sineRight );
right.set( cosineRight );
right.subtract( sineUp );
}
Vector3D Orientation::getRight () { return right; }
Vector3D Orientation::getUp () { return up; }
Vector3D Orientation::getFront () { return front; }
//-----------------------------------------------------------------------------
void Orientation::setRightUpFront( const Vector3D &r, const Vector3D &u, const Vector3D &f )
{
//verifyValidOrientation();
right.set (r);
up.set (u);
front.set (f);
}
//-----------------------------------------------------------------------------
void Orientation::verifyValidOrientation()
{
assert( right.getMagnitude () < 1.0 + BIG_EPSILON );
assert( right.getMagnitude () > 1.0 - BIG_EPSILON );
assert( up.getMagnitude () < 1.0 + BIG_EPSILON );
assert( up.getMagnitude () > 1.0 - BIG_EPSILON );
assert( front.getMagnitude () < 1.0 + BIG_EPSILON );
assert( front.getMagnitude () > 1.0 - BIG_EPSILON );
if ( right.getMagnitude() > 1.0 + BIG_EPSILON )
{
printf( "oops: the magnitude of the 'right' part of the orientation is %f!\n", right.getMagnitude() );
}
else if ( right.getMagnitude() < 1.0 - BIG_EPSILON )
{
printf( "oops: the magnitude of the 'right' part of the orientation is %f!\n", right.getMagnitude() );
}
if ( up.getMagnitude() > 1.0 + BIG_EPSILON )
{
printf( "oops: the magnitude of the 'up' part of the orientation is %f!\n", up.getMagnitude() );
}
else if ( up.getMagnitude() < 1.0 - BIG_EPSILON )
{
printf( "oops: the magnitude of the 'up' part of the orientation is %f!\n", up.getMagnitude() );
}
if ( front.getMagnitude() > 1.0 + BIG_EPSILON )
{
printf( "oops: the magnitude of the 'front' part of the orientation is %f!\n", front.getMagnitude() );
}
else if ( front.getMagnitude() < 1.0 - BIG_EPSILON )
{
printf( "oops: the magnitude of the 'front' part of the orientation is %f!\n", front.getMagnitude() );
}
if (( right.dotWith ( up ) > BIG_EPSILON )
|| ( right.dotWith ( up ) < -BIG_EPSILON )) { printf( "oops: the 'right' and 'up' parts of the orientation are not perpendicular! The dot is: %f\n", right.dotWith ( up ) ); }
if (( right.dotWith ( front ) > BIG_EPSILON )
|| ( right.dotWith ( front ) < -BIG_EPSILON )) { printf( "oops: the 'right' and 'front' parts of the orientation are not perpendicular! The dot is: %f\n", right.dotWith ( front ) ); }
if (( up.dotWith ( front ) > BIG_EPSILON )
|| ( up.dotWith ( front ) < -BIG_EPSILON )) { printf( "oops: the 'up' and 'front' parts of the orientation are not perpendicular! The dot is: %f\n", up.dotWith ( front ) ); }
}

52
interface/src/Orientation.h Executable file
View file

@ -0,0 +1,52 @@
//-----------------------------------------------------------
//
// Created by Jeffrey Ventrella and added as a utility
// class for High Fidelity Code base, April 2013
//
//-----------------------------------------------------------
#ifndef __interface__orientation__
#define __interface__orientation__
#include "Math.h"
#include "Vector3D.h"
enum Axis
{
ORIENTATION_RIGHT_AXIS,
ORIENTATION_UP_AXIS,
ORIENTATION_FRONT_AXIS
};
class Orientation
{
private:
Vector3D right;
Vector3D up;
Vector3D front;
void verifyValidOrientation();
public:
Orientation();
void yaw ( double );
void pitch ( double );
void roll ( double );
void set( Orientation );
void setToIdentity();
void forceFrontInDirection( const Vector3D &, const Vector3D &, double );
void forceAxisInDirection( int, const Vector3D &, double );
Vector3D getRight();
Vector3D getUp();
Vector3D getFront();
void setRightUpFront( const Vector3D &, const Vector3D &, const Vector3D & );
};
#endif

View file

@ -17,6 +17,20 @@
#include <glm/glm.hpp>
// added by Ventrella for utility purposes
static const double ZERO = 0.0;
static const double ONE = 1.0;
static const double ONE_HALF = 0.5;
static const double ONE_THIRD = 0.3333333;
//static const double PI = 3.14159265359;
static const double PI_TIMES_TWO = 3.14159265359 * 2.0;
static const double PI_OVER_180 = 3.14159265359 / 180.0;
static const double EPSILON = 0.00001; // a smallish number meant to be used as a margin of error for some normalized values
static const double BIG_EPSILON = 0.01; // not as smallish as EPSILON
static const double SQUARE_ROOT_OF_3 = sqrt(3);
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);

267
interface/src/Vector3D.cpp Executable file
View file

@ -0,0 +1,267 @@
//-----------------------------------------------------------
//
// Created by Jeffrey Ventrella and added as a utility
// class for High Fidelity Code base, April 2013
//
//-----------------------------------------------------------
#include "Vector3D.h"
#include "Math.h"
//---------------------------------------
Vector3D::Vector3D()
{
x = 0.0;
y = 0.0;
z = 0.0;
}
//---------------------------------------
Vector3D::Vector3D( double x_, double y_, double z_ )
{
x = x_;
y = y_;
z = z_;
}
//---------------------------------------
Vector3D::Vector3D( const Vector3D & v )
{
x = v.x;
y = v.y;
z = v.z;
}
//-----------------------------------------------------
void Vector3D::setXYZ( double x_, double y_, double z_ )
{
x = x_;
y = y_;
z = z_;
}
//---------------------
void Vector3D::clear()
{
x = 0.0;
y = 0.0;
z = 0.0;
}
//-----------------------------------------------------
void Vector3D::addXYZ( double x_, double y_, double z_ )
{
x += x_;
y += y_;
z += z_;
}
//---------------------------------------
void Vector3D::set( const Vector3D &v )
{
x = v.x;
y = v.y;
z = v.z;
}
//-------------------------------------
void Vector3D::add( const Vector3D &v )
{
x += v.x;
y += v.y;
z += v.z;
}
//--------------------------------------------
void Vector3D::subtract ( const Vector3D &v )
{
x -= v.x;
y -= v.y;
z -= v.z;
}
//-----------------------------------------------------
void Vector3D::addScaled( const Vector3D &v, double s )
{
x += v.x * s;
y += v.y * s;
z += v.z * s;
}
//-----------------------------------------------------
void Vector3D::subtractScaled( const Vector3D &v, double s )
{
x -= v.x * s;
y -= v.y * s;
z -= v.z * s;
}
//-------------------------
void Vector3D::normalize()
{
double d = sqrt( x * x + y * y + z * z );
if ( d > 0.0 )
{
x /= d;
y /= d;
z /= d;
}
}
//--------------------------------------------
void Vector3D::setX ( double x_ ) { x = x_; }
void Vector3D::setY ( double y_ ) { y = y_; }
void Vector3D::setZ ( double z_ ) { z = z_; }
void Vector3D::addX ( double x_ ) { x += x_; }
void Vector3D::addY ( double y_ ) { y += y_; }
void Vector3D::addZ ( double z_ ) { z += z_; }
double Vector3D::getX () { return x; }
double Vector3D::getY () { return y; }
double Vector3D::getZ () { return z; }
void Vector3D::scaleX ( double s ) { x *= s; }
void Vector3D::scaleY ( double s ) { y *= s; }
void Vector3D::scaleZ ( double s ) { z *= s; }
//-----------------------------------------------------
void Vector3D::setToScaled( const Vector3D &v, double s )
{
Vector3D c;
x = v.x * s;
y = v.y * s;
z = v.z * s;
}
//--------------------------------------------------------------------
void Vector3D::setToAverage( const Vector3D &v1, const Vector3D &v2 )
{
x = v1.x + ( v2.x - v1.x ) * 0.5;
y = v1.y + ( v2.y - v1.y ) * 0.5;
z = v1.z + ( v2.z - v1.z ) * 0.5;
}
//-----------------------------------------------------
void Vector3D::setToDifference( const Vector3D &v1, const Vector3D &v2 )
{
x = v1.x - v2.x;
y = v1.y - v2.y;
z = v1.z - v2.z;
}
//-----------------------------------------------------
void Vector3D::scale( double s )
{
x *= s;
y *= s;
z *= s;
}
//-----------------------------------------------------
double Vector3D::getMagnitude()
{
return sqrt( x * x + y * y + z * z );
}
//-----------------------------------------------------
double Vector3D::getMagnitudeSquared()
{
return x * x + y * y + z * z ;
}
//-----------------------------------------------------
double Vector3D::getDistanceTo( const Vector3D &v )
{
double xx = v.x - x;
double yy = v.y - y;
double zz = v.z - z;
return sqrt( xx * xx + yy * yy + zz * zz );
}
//-----------------------------------------------------
double Vector3D::getDistanceSquaredTo( const Vector3D &v )
{
double xx = v.x - x;
double yy = v.y - y;
double zz = v.z - z;
return xx * xx + yy * yy + zz * zz;
}
//-------------------------------------------------------------------
double Vector3D::getDistance( const Vector3D &v1, const Vector3D &v2 )
{
double xx = v2.x - v1.x;
double yy = v2.y - v1.y;
double zz = v2.z - v1.z;
return sqrt( xx * xx + yy * yy + zz * zz );
}
//---------------------------------------------------------------------------
double Vector3D::getDistanceSquared( const Vector3D &v1, const Vector3D &v2 )
{
double xx = v2.x - v1.x;
double yy = v2.y - v1.y;
double zz = v2.z - v1.z;
return xx * xx + yy * yy + zz * zz;
}
//-----------------------------------------------------
double Vector3D::dotWith( const Vector3D &v )
{
return
x * v.x +
y * v.y +
z * v.z;
}
//-----------------------------------------------------------------
void Vector3D::setToCross( const Vector3D &v1, const Vector3D &v2 )
{
x = v1.z * v2.y - v1.y * v2.z;
y = v1.x * v2.z - v1.z * v2.x;
z = v1.y * v2.x - v1.x * v2.y;
}
//---------------------------------------------------------------
void Vector3D::setToSum( const Vector3D &v1, const Vector3D &v2 )
{
x = v1.x + v2.x;
y = v1.y + v2.y;
z = v1.z + v2.z;
}
//-----------------------------------------------------
void Vector3D::halve()
{
x *= 0.5;
y *= 0.5;
z *= 0.5;
}

66
interface/src/Vector3D.h Executable file
View file

@ -0,0 +1,66 @@
//-----------------------------------------------------------
//
// Created by Jeffrey Ventrella and added as a utility
// class for High Fidelity Code base, April 2013
//
//-----------------------------------------------------------
#ifndef __interface__vector3D__
#define __interface__vector3D__
class Vector3D
{
public:
//------------------
// members
//------------------
double x;
double y;
double z;
//------------------
// methods
//------------------
Vector3D();
Vector3D( double, double, double );
Vector3D( const Vector3D & );
void clear();
void set ( const Vector3D & );
void setToScaled ( const Vector3D &, double );
void add ( const Vector3D & );
void subtract ( const Vector3D & );
void addScaled ( const Vector3D &, double );
void subtractScaled ( const Vector3D &, double );
void normalize ();
void setToCross ( const Vector3D &, const Vector3D & );
void setToAverage ( const Vector3D &, const Vector3D & );
void setToSum ( const Vector3D &, const Vector3D & );
void setXYZ ( double, double, double );
void addXYZ ( double, double, double );
void setX ( double );
void setY ( double );
void setZ ( double );
void addX ( double );
void addY ( double );
void addZ ( double );
void scaleX ( double );
void scaleY ( double );
void scaleZ ( double );
void halve ();
double getX ();
double getY ();
double getZ ();
double getMagnitude ();
double getMagnitudeSquared ();
double getDistance ( const Vector3D &, const Vector3D & );
double getDistanceSquared ( const Vector3D &, const Vector3D & );
double getDistanceTo ( const Vector3D & );
double getDistanceSquaredTo( const Vector3D & );
double dotWith ( const Vector3D & );
void scale ( double );
void setToDifference ( const Vector3D &, const Vector3D & );
};
#endif

View file

@ -50,6 +50,7 @@
#include "Head.h"
#include "Hand.h"
#include "Camera.h"
#include "Particle.h"
#include "Texture.h"
#include "Cloud.h"
@ -65,7 +66,10 @@
using namespace std;
int audio_on = 0; // Whether to turn on the audio support
double testThingy = 0.0;
int audio_on = 1; // Whether to turn on the audio support
int simulate_on = 1;
AgentList agentList('I');
@ -95,6 +99,7 @@ Oscilloscope audioScope(256,200,true);
#define HAND_RADIUS 0.25 // Radius of in-world 'hand' of you
Head myHead; // The rendered head of oneself
Camera myCamera; // My view onto the world (sometimes on myself :)
char starFile[] = "https://s3-us-west-1.amazonaws.com/highfidelity/stars.txt";
FieldOfView fov;
@ -342,8 +347,10 @@ void init(void)
if (noise_on) {
myHead.setNoise(noise);
}
myHead.setPos(start_location);
myHead.setPos(start_location );
myCamera.setPosition( glm::dvec3( start_location ) );
#ifdef MARKER_CAPTURE
if(marker_capture_enabled){
marker_capturer.position_updated(&position_updated);
@ -406,6 +413,12 @@ void simulateHand(float deltaTime) {
float dy = mouse_y - mouse_start_y;
glm::vec3 vel(dx*MOUSE_HAND_FORCE, -dy*MOUSE_HAND_FORCE*(WIDTH/HEIGHT), 0);
myHead.hand->addVelocity(vel*deltaTime);
double leftRight = dx * 0.001;
double downUp = dy * 0.001;
double backFront = 0.0;
glm::dvec3 handMovement( leftRight, downUp, backFront );
myHead.setHandMovement( handMovement );
}
}
@ -422,7 +435,12 @@ void simulateHead(float frametime)
//float measured_fwd_accel = serialPort.getRelativeValue(ACCEL_Z);
myHead.UpdatePos(frametime, &serialPort, head_mirror, &gravity);
//-------------------------------------------------------------------------------------
// set the position of the avatar
//-------------------------------------------------------------------------------------
myHead.setAvatarPosition( -myHead.getPos().x, -myHead.getPos().y, -myHead.getPos().z );
// Update head_mouse model
const float MIN_MOUSE_RATE = 30.0;
const float MOUSE_SENSITIVITY = 0.1f;
@ -551,16 +569,29 @@ void display(void)
glMaterialfv(GL_FRONT, GL_SPECULAR, specular_color);
glMateriali(GL_FRONT, GL_SHININESS, 96);
// Rotate, translate to camera location
fov.setOrientation(
glm::rotate(glm::rotate(glm::translate(glm::mat4(1.0f), -myHead.getPos()),
-myHead.getRenderYaw(), glm::vec3(0.0f,1.0f,0.0f)),
-myHead.getRenderPitch(), glm::vec3(1.0f,0.0f,0.0f)) );
//-------------------------------------------------------------------------------------
// set the caemra to third-person view
//-------------------------------------------------------------------------------------
myCamera.setYaw ( myHead.getRenderYaw() );
myCamera.setPitch ( 0.0 );
myCamera.setRoll ( 0.0 );
glm::dvec3 offset( 0.7, -0.2, 0.7 );
glLoadMatrixf( glm::value_ptr(fov.getWorldViewerXform()) );
glRotatef(myHead.getRenderPitch(), 1, 0, 0);
glRotatef(myHead.getRenderYaw(), 0, 1, 0);
glm::dvec3 positionWithOffset( myHead.getPos() );
positionWithOffset += offset;
myCamera.setPosition( positionWithOffset );
//-------------------------------------------------------------------------------------
// transform to camera view
//-------------------------------------------------------------------------------------
glRotatef ( myCamera.getPitch(), 1, 0, 0 );
glRotatef ( myCamera.getYaw(), 0, 1, 0 );
glRotatef ( myCamera.getRoll(), 0, 0, 1 );
glTranslatef( myCamera.getPosition().x, myCamera.getPosition().y, myCamera.getPosition().z );
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
@ -601,12 +632,18 @@ void display(void)
// Render the world box
if (!display_head && stats_on) render_world_box();
myHead.render( true, 1 );
/*
// Render my own head
glPushMatrix();
glLoadIdentity();
glTranslatef(0.f, 0.f, -7.f);
myHead.render(display_head, 1);
glPopMatrix();
*/
}
glPopMatrix();