Merge remote-tracking branch 'origin'

This commit is contained in:
Philip Rosedale 2013-04-08 19:04:10 -07:00
commit 032fff9d57
11 changed files with 1514 additions and 66 deletions

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

@ -0,0 +1,37 @@
//-----------------------------------------------------------
//
// Created by Jeffrey Ventrella and added as a utility
// class for High Fidelity Code base, April 2013
//
//-----------------------------------------------------------
#include "Camera.h"
#include "Util.h"
//------------------------
Camera::Camera()
{
yaw = 0.0;
pitch = 0.0;
roll = 0.0;
up = 0.0;
distance = 0.0;
targetPosition = glm::dvec3( 0.0, 0.0, 0.0 );
position = glm::dvec3( 0.0, 0.0, 0.0 );
orientation.setToIdentity();
}
//------------------------
void Camera::update()
{
double radian = ( yaw / 180.0 ) * PIE;
double x = distance * sin( radian );
double z = distance * -cos( radian );
double y = -up;
position = glm::dvec3( targetPosition );
position += glm::dvec3( x, y, z );
}

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

@ -0,0 +1,49 @@
//-----------------------------------------------------------
//
// 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 update();
void setYaw ( double y ) { yaw = y; }
void setPitch ( double p ) { pitch = p; }
void setRoll ( double r ) { roll = r; }
void setUp ( double u ) { up = u; }
void setDistance ( double d ) { distance = d; }
void setTargetPosition ( glm::dvec3 t ) { targetPosition = t; };
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;
glm::dvec3 targetPosition;
double yaw;
double pitch;
double roll;
double up;
double distance;
Orientation orientation;
};
#endif

View file

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

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

@ -3,6 +3,7 @@
// interface
//
// Created by Philip Rosedale on 9/11/12.
// adapted by Jeffrey Ventrella, starting on April 2, 2013
// Copyright (c) 2012 Physical, Inc.. All rights reserved.
//
@ -38,11 +39,16 @@ vector<unsigned char> iris_texture;
unsigned int iris_texture_width = 512;
unsigned int iris_texture_height = 256;
//---------------------------------------------------
Head::Head()
{
position = glm::vec3(0,0,0);
velocity = glm::vec3(0,0,0);
thrust = glm::vec3(0,0,0);
initializeAvatar();
position = glm::vec3(0,0,0);
velocity = glm::vec3(0,0,0);
thrust = glm::vec3(0,0,0);
for (int i = 0; i < MAX_DRIVE_KEYS; i++) driveKeys[i] = false;
@ -77,6 +83,8 @@ Head::Head()
lastLoudness = 0.0;
browAudioLift = 0.0;
noise = 0;
handOffset = glm::vec3( 0.0, 0.0, 0.0 );
sphere = NULL;
@ -91,7 +99,14 @@ Head::Head()
}
}
Head::Head(const Head &otherHead) {
//---------------------------------------------------
Head::Head(const Head &otherHead)
{
initializeAvatar();
position = otherHead.position;
velocity = otherHead.velocity;
thrust = otherHead.thrust;
@ -141,26 +156,45 @@ 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
{
const float PITCH_ACCEL_COUPLING = 0.5;
const float ROLL_ACCEL_COUPLING = -1.0;
float measured_pitch_rate = serialInterface->getRelativeValue(PITCH_RATE);
@ -201,64 +235,201 @@ void Head::UpdatePos(float frametime, SerialInterface * serialInterface, int hea
}
}
//---------------------------------------------------
void Head::setAvatarPosition( double x, double y, double z )
{
avatar.position = glm::dvec3( 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)
{
updateAvatarSkeleton();
/*
glm::vec3 forward
(
-sin( avatar.yaw * PI_OVER_180 ),
sin( avatar.pitch * PI_OVER_180 ),
cos( avatar.roll * PI_OVER_180 )
);
*/
/*
glm::vec3 forward(-sinf(getRenderYaw()*PI/180),
sinf(getRenderPitch()*PI/180),
cosf(getRenderYaw()*PI/180));
thrust = glm::vec3(0);
*/
const float THRUST_MAG = 10.0;
const float THRUST_LATERAL_MAG = 10.0;
const float THRUST_VERTICAL_MAG = 10.0;
if (driveKeys[FWD]) {
thrust += THRUST_MAG*forward;
/*
const float THRUST_LATERAL_MAG = 10.0;
const float THRUST_VERTICAL_MAG = 10.0;
*/
avatar.thrust = glm::dvec3( 0.0, 0.0, 0.0 );
if (driveKeys[FWD])
{
//position.x += avatar.orientation.getFront().getX() * 0.01;
//position.y += avatar.orientation.getFront().getY() * 0.01;
//position.z -= avatar.orientation.getFront().getZ() * 0.01;
avatar.thrust.x += avatar.orientation.getFront().getX() * THRUST_MAG;
avatar.thrust.y += avatar.orientation.getFront().getY() * THRUST_MAG;
avatar.thrust.z -= avatar.orientation.getFront().getZ() * THRUST_MAG;
//thrust += THRUST_MAG*forward;
}
if (driveKeys[BACK]) {
thrust += -THRUST_MAG*forward;
}
if (driveKeys[RIGHT]) {
thrust.x += forward.z*-THRUST_LATERAL_MAG;
thrust.z += forward.x*THRUST_LATERAL_MAG;
}
if (driveKeys[LEFT]) {
thrust.x += forward.z*THRUST_LATERAL_MAG;
thrust.z += forward.x*-THRUST_LATERAL_MAG;
}
if (driveKeys[UP]) {
thrust.y += -THRUST_VERTICAL_MAG;
}
if (driveKeys[DOWN]) {
thrust.y += THRUST_VERTICAL_MAG;
if (driveKeys[BACK])
{
//position.x -= avatar.orientation.getFront().getX() * 0.01;
//position.y -= avatar.orientation.getFront().getY() * 0.01;
//position.z += avatar.orientation.getFront().getZ() * 0.01;
avatar.thrust.x -= avatar.orientation.getFront().getX() * THRUST_MAG;
avatar.thrust.y -= avatar.orientation.getFront().getY() * THRUST_MAG;
avatar.thrust.z += avatar.orientation.getFront().getZ() * THRUST_MAG;
//thrust += -THRUST_MAG*forward;
}
if (driveKeys[RIGHT])
{
//position.x += avatar.orientation.getRight().getX() * 0.01;
//position.y += avatar.orientation.getRight().getY() * 0.01;
//position.z -= avatar.orientation.getRight().getZ() * 0.01;
avatar.thrust.x += avatar.orientation.getRight().getX() * THRUST_MAG;
avatar.thrust.y += avatar.orientation.getRight().getY() * THRUST_MAG;
avatar.thrust.z -= avatar.orientation.getRight().getZ() * THRUST_MAG;
//thrust.x += forward.z*-THRUST_LATERAL_MAG;
//thrust.z += forward.x*THRUST_LATERAL_MAG;
}
if (driveKeys[LEFT])
{
//position.x -= avatar.orientation.getRight().getX() * 0.01;
//position.y -= avatar.orientation.getRight().getY() * 0.01;
//position.z += avatar.orientation.getRight().getZ() * 0.01;
avatar.thrust.x -= avatar.orientation.getRight().getX() * THRUST_MAG;
avatar.thrust.y -= avatar.orientation.getRight().getY() * THRUST_MAG;
avatar.thrust.z += avatar.orientation.getRight().getZ() * THRUST_MAG;
//thrust.x += forward.z*THRUST_LATERAL_MAG;
//thrust.z += forward.x*-THRUST_LATERAL_MAG;
}
if (driveKeys[UP])
{
//position.x -= avatar.orientation.getUp().getX() * 0.01;
//position.y -= avatar.orientation.getUp().getY() * 0.01;
//position.z += avatar.orientation.getUp().getZ() * 0.01;
avatar.thrust.x -= avatar.orientation.getUp().getX() * THRUST_MAG;
avatar.thrust.y -= avatar.orientation.getUp().getY() * THRUST_MAG;
avatar.thrust.z += avatar.orientation.getUp().getZ() * THRUST_MAG;
//thrust.y += -THRUST_VERTICAL_MAG;
}
if (driveKeys[DOWN])
{
//position.x += avatar.orientation.getUp().getX() * 0.01;
//position.y += avatar.orientation.getUp().getY() * 0.01;
//position.z -= avatar.orientation.getUp().getZ() * 0.01;
avatar.thrust.x += avatar.orientation.getUp().getX() * THRUST_MAG;
avatar.thrust.y += avatar.orientation.getUp().getY() * THRUST_MAG;
avatar.thrust.z -= avatar.orientation.getUp().getZ() * THRUST_MAG;
//thrust.y += THRUST_VERTICAL_MAG;
}
if (driveKeys[ROT_RIGHT])
{
avatar.yawDelta -= 300.0 * deltaTime;
}
if (driveKeys[ROT_LEFT])
{
avatar.yawDelta += 300.0 * deltaTime;
}
avatar.yaw += avatar.yawDelta * deltaTime;
Yaw = avatar.yaw;
const float TEST_YAW_DECAY = 5.0;
avatar.yawDelta *= ( 1.0 - TEST_YAW_DECAY * deltaTime );
//avatar.yawDelta *= 0.99;
avatar.velocity += avatar.thrust * (double)deltaTime;
position += avatar.velocity * (double)deltaTime;
//avatar.velocity *= 0.9;
const float LIN_VEL_DECAY = 5.0;
avatar.velocity *= ( 1.0 - LIN_VEL_DECAY * deltaTime );
/*
// Increment velocity as time
velocity += thrust * deltaTime;
// Increment position as a function of velocity
position += velocity * deltaTime;
*/
/*
// Decay velocity
const float LIN_VEL_DECAY = 5.0;
velocity *= (1.0 - LIN_VEL_DECAY*deltaTime);
*/
if (!noise)
{
// Decay back toward center
@ -276,6 +447,8 @@ void Head::simulate(float deltaTime)
leanForward *= (1.f - DECAY*30.f*deltaTime);
leanSideways *= (1.f - DECAY*30.f*deltaTime);
// Update where the avatar's eyes are
//
// First, decide if we are making eye contact or not
@ -292,6 +465,8 @@ void Head::simulate(float deltaTime)
}
}
const float DEGREES_BETWEEN_VIEWER_EYES = 3;
const float DEGREES_TO_VIEWER_MOUTH = 7;
@ -315,8 +490,8 @@ void Head::simulate(float deltaTime)
EyeballPitch[0] = EyeballPitch[1] = -Pitch + eye_target_pitch_adjust;
EyeballYaw[0] = EyeballYaw[1] = -Yaw + eye_target_yaw_adjust;
}
if (noise)
{
Pitch += (randFloat() - 0.5)*0.2*NoiseEnvelope;
@ -350,12 +525,26 @@ void Head::simulate(float deltaTime)
}
}
hand->simulate(deltaTime);
//hand->simulate(deltaTime);
}
//---------------------------------------------------
void Head::render(int faceToFace, int isMine)
{
renderBody();
renderHead( faceToFace, isMine );
}
//---------------------------------------------------
void Head::renderHead( int faceToFace, int isMine )
{
int side = 0;
@ -363,23 +552,37 @@ void Head::render(int faceToFace, int isMine)
glEnable(GL_DEPTH_TEST);
glPushMatrix();
glScalef(scale, scale, scale);
glTranslatef(leanSideways, 0.f, leanForward);
//glScalef(scale, scale, scale);
glTranslatef
(
avatar.bone[ AVATAR_BONE_HEAD ].worldPosition.x,
avatar.bone[ AVATAR_BONE_HEAD ].worldPosition.y,
avatar.bone[ AVATAR_BONE_HEAD ].worldPosition.z
);
glScalef( 0.03, 0.03, 0.03 );
//glTranslatef(leanSideways, 0.f, leanForward);
glRotatef(Yaw, 0, 1, 0);
//glRotatef(Yaw, 0, 1, 0);
glRotatef( avatar.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);
// 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 +603,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 +711,320 @@ void Head::render(int faceToFace, int isMine)
}
glPopMatrix();
}
//---------------------------------------------------------
void Head::setHandMovement( glm::dvec3 movement )
{
handOffset = glm::dvec3( movement.x, -movement.y, movement.z );
}
//-----------------------------------------
void Head::initializeAvatar()
{
avatar.position = glm::dvec3( 0.0, 0.0, 0.0 );
avatar.velocity = glm::dvec3( 0.0, 0.0, 0.0 );
avatar.thrust = glm::dvec3( 0.0, 0.0, 0.0 );
avatar.orientation.setToIdentity();
avatar.yaw = 0.0;
avatar.pitch = 0.0;
avatar.roll = 0.0;
avatar.yawDelta = 0.0;
for (int b=0; b<NUM_AVATAR_BONES; b++)
{
avatar.bone[b].worldPosition = glm::dvec3( 0.0, 0.0, 0.0 );
//avatar.bone[b].offsetPosition = glm::dvec3( 0.0, 0.0, 0.0 );
avatar.bone[b].velocity = glm::dvec3( 0.0, 0.0, 0.0 );
avatar.bone[b].worldOrientation.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;
//----------------------------------------------------------
// specify the default pose position
//----------------------------------------------------------
avatar.bone[ AVATAR_BONE_PELVIS_SPINE ].defaultPosePosition = glm::dvec3( 0.0, 0.1, 0.0 );
avatar.bone[ AVATAR_BONE_MID_SPINE ].defaultPosePosition = glm::dvec3( 0.0, 0.1, 0.0 );
avatar.bone[ AVATAR_BONE_CHEST_SPINE ].defaultPosePosition = glm::dvec3( 0.0, 0.1, 0.0 );
avatar.bone[ AVATAR_BONE_NECK ].defaultPosePosition = glm::dvec3( 0.0, 0.06, 0.0 );
avatar.bone[ AVATAR_BONE_HEAD ].defaultPosePosition = glm::dvec3( 0.0, 0.06, 0.0 );
avatar.bone[ AVATAR_BONE_LEFT_CHEST ].defaultPosePosition = glm::dvec3( -0.06, 0.06, 0.0 );
avatar.bone[ AVATAR_BONE_LEFT_SHOULDER ].defaultPosePosition = glm::dvec3( -0.03, 0.0, 0.0 );
avatar.bone[ AVATAR_BONE_LEFT_UPPER_ARM ].defaultPosePosition = glm::dvec3( 0.0, -0.12, 0.0 );
avatar.bone[ AVATAR_BONE_LEFT_FOREARM ].defaultPosePosition = glm::dvec3( 0.0, -0.1, 0.0 );
avatar.bone[ AVATAR_BONE_LEFT_HAND ].defaultPosePosition = glm::dvec3( 0.0, -0.05, 0.0 );
avatar.bone[ AVATAR_BONE_RIGHT_CHEST ].defaultPosePosition = glm::dvec3( 0.06, 0.06, 0.0 );
avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].defaultPosePosition = glm::dvec3( 0.03, 0.0, 0.0 );
avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].defaultPosePosition = glm::dvec3( 0.0, -0.12, 0.0 );
avatar.bone[ AVATAR_BONE_RIGHT_FOREARM ].defaultPosePosition = glm::dvec3( 0.0, -0.1, 0.0 );
avatar.bone[ AVATAR_BONE_RIGHT_HAND ].defaultPosePosition = glm::dvec3( 0.0, -0.05, 0.0 );
avatar.bone[ AVATAR_BONE_LEFT_PELVIS ].defaultPosePosition = glm::dvec3( -0.05, 0.0, 0.0 );
avatar.bone[ AVATAR_BONE_LEFT_THIGH ].defaultPosePosition = glm::dvec3( 0.0, -0.15, 0.0 );
avatar.bone[ AVATAR_BONE_LEFT_SHIN ].defaultPosePosition = glm::dvec3( 0.0, -0.15, 0.0 );
avatar.bone[ AVATAR_BONE_LEFT_FOOT ].defaultPosePosition = glm::dvec3( 0.0, 0.0, 0.04 );
avatar.bone[ AVATAR_BONE_RIGHT_PELVIS ].defaultPosePosition = glm::dvec3( 0.05, 0.0, 0.0 );
avatar.bone[ AVATAR_BONE_RIGHT_THIGH ].defaultPosePosition = glm::dvec3( 0.0, -0.15, 0.0 );
avatar.bone[ AVATAR_BONE_RIGHT_SHIN ].defaultPosePosition = glm::dvec3( 0.0, -0.15, 0.0 );
avatar.bone[ AVATAR_BONE_RIGHT_FOOT ].defaultPosePosition = glm::dvec3( 0.0, 0.0, 0.04 );
//----------------------------------------------------------------------------
// calculate bone length
//----------------------------------------------------------------------------
calculateBoneLengths();
//----------------------------------------------------------------------------
// generate world positions
//----------------------------------------------------------------------------
updateAvatarSkeleton();
//----------------------------------------------------------------------------
// set offset positions = world positions
//----------------------------------------------------------------------------
for (int b=0; b<NUM_AVATAR_BONES; b++)
{
//avatar.bone[b].offsetPosition = avatar.bone[b].worldPosition;
}
}
//-----------------------------------------
void Head::calculateBoneLengths()
{
for (int b=0; b<NUM_AVATAR_BONES; b++)
{
avatar.bone[b].length = glm::length( avatar.bone[b].defaultPosePosition );
}
avatar.maxArmLength
= avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].length
+ avatar.bone[ AVATAR_BONE_RIGHT_FOREARM ].length
+ avatar.bone[ AVATAR_BONE_RIGHT_HAND ].length;
}
//-----------------------------------------
void Head::updateAvatarSkeleton()
{
//rotate the body...
avatar.orientation.setToIdentity();
avatar.orientation.yaw( -avatar.yaw );
//------------------------------------------------------------------------
// calculate positions of all bones by traversing the skeleton tree:
//------------------------------------------------------------------------
for (int b=0; b<NUM_AVATAR_BONES; b++)
{
if ( avatar.bone[b].parent == AVATAR_BONE_NULL )
{
avatar.bone[b].worldOrientation.set( avatar.orientation );
avatar.bone[b].worldPosition = avatar.position;
}
else
{
avatar.bone[b].worldOrientation.set( avatar.bone[ avatar.bone[b].parent ].worldOrientation );
avatar.bone[b].worldPosition = avatar.bone[ avatar.bone[b].parent ].worldPosition;
}
double xx = glm::dot( avatar.bone[b].defaultPosePosition.x, avatar.bone[b].worldOrientation.getRight ().x )
+ glm::dot( avatar.bone[b].defaultPosePosition.y, avatar.bone[b].worldOrientation.getRight ().y )
+ glm::dot( avatar.bone[b].defaultPosePosition.z, avatar.bone[b].worldOrientation.getRight ().z );
double yy = glm::dot( avatar.bone[b].defaultPosePosition.x, avatar.bone[b].worldOrientation.getUp ().x )
+ glm::dot( avatar.bone[b].defaultPosePosition.y, avatar.bone[b].worldOrientation.getUp ().y )
+ glm::dot( avatar.bone[b].defaultPosePosition.z, avatar.bone[b].worldOrientation.getUp ().z );
double zz = glm::dot( avatar.bone[b].defaultPosePosition.x, avatar.bone[b].worldOrientation.getFront ().x )
+ glm::dot( avatar.bone[b].defaultPosePosition.y, avatar.bone[b].worldOrientation.getFront ().y )
+ glm::dot( avatar.bone[b].defaultPosePosition.z, avatar.bone[b].worldOrientation.getFront ().z );
glm::dvec3 rotatedBoneVector( xx, yy, zz );
//rotatedBonePosition.x = avatar.bone[b].defaultPosePosition.x;// * avatar.bone[b].worldOrientation.getFront().x;
//rotatedBonePosition.y = avatar.bone[b].defaultPosePosition.y;// * avatar.bone[b].worldOrientation.getFront().y;
//rotatedBonePosition.z = avatar.bone[b].defaultPosePosition.z;// * avatar.bone[b].worldOrientation.getFront().z;
//glm::dvec3 rotatedBoneVector( avatar.bone[b].defaultPosePosition );
//glm::dmat3x3 rotationMatrix ( glm::dvec3( 1.0, 0.0, 0.0 ), glm::dvec3( 0.0, 1.0, 0.0 ), glm::dvec3( 0.0, 0.0, 1.0 ) );
//glm::dmat3x3 rotationMatrix;
//glm::dmat3x3 rotationMatrix = glm::eulerAngleYXZ( 0.0, 0.0, 0.0 );
avatar.bone[b].worldPosition += rotatedBoneVector;
}
//------------------------------------------------------------------------
// reset hand and elbow position according to hand movement
//------------------------------------------------------------------------
updateHandMovement();
/*
glm::dvec3 v( avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition );
v -= avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].worldPosition;
double distance = glm::length(v);
if ( distance > avatar.maxArmLength )
{
avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].worldPosition += v * 0.2;
}
*/
/*
//------------------------------------------------------------------------
// update offset position
//------------------------------------------------------------------------
for (int b=0; b<NUM_AVATAR_BONES; b++)
{
glm::dvec3 diff( avatar.bone[b].worldPosition );
diff -= avatar.bone[b].offsetPosition;
avatar.bone[b].offsetPosition += diff * 0.1;
}
*/
}
//-------------------------------
double Head::getAvatarYaw()
{
return avatar.yaw;
}
//-------------------------------
void Head::updateHandMovement()
{
//----------------------------------------------------------------
// adjust right hand and elbow according to hand offset
//----------------------------------------------------------------
avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition += handOffset;
glm::dvec3 armVector = avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition;
armVector -= avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].worldPosition;
//-------------------------------------------------------------------------------
// test to see if right hand is being dragged beyond maximum arm length
//-------------------------------------------------------------------------------
double distance = glm::length( armVector );
//-------------------------------------------------------------------------------
// if right hand is being dragged beyond maximum arm length...
//-------------------------------------------------------------------------------
if ( distance > avatar.maxArmLength )
{
//-------------------------------------------------------------------------------
// reset right hand to be constrained to maximum arm length
//-------------------------------------------------------------------------------
avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].worldPosition;
glm::dvec3 armNormal = armVector / distance;
armVector = armNormal * avatar.maxArmLength;
distance = avatar.maxArmLength;
glm::dvec3 constrainedPosition = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].worldPosition;
constrainedPosition += armVector;
avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition = constrainedPosition;
}
//-----------------------------------------------------------------------------
// set elbow position
//-----------------------------------------------------------------------------
glm::dvec3 newElbowPosition = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].worldPosition;
newElbowPosition += armVector * ONE_HALF;
glm::dvec3 perpendicular = glm::dvec3( -armVector.y, armVector.x, armVector.z );
newElbowPosition += perpendicular * ( 1.0 - ( avatar.maxArmLength / distance ) ) * ONE_HALF;
avatar.bone[ AVATAR_BONE_RIGHT_FOREARM ].worldPosition = newElbowPosition;
}
//-----------------------------------------
void Head::renderBody()
{
glColor3fv(skinColor);
for (int b=0; b<NUM_AVATAR_BONES; b++)
{
glPushMatrix();
glTranslatef( avatar.bone[b].worldPosition.x, avatar.bone[b].worldPosition.y, avatar.bone[b].worldPosition.z );
glScalef( 0.02, 0.02, 0.02 );
glutSolidSphere( 1, 10, 5 );
glPopMatrix();
}
}
// Transmit data to agents requesting it
//called on me just prior to sending data to others (continuasly called)
//---------------------------------------------------
int Head::getBroadcastData(char* data)
{
// Copy data for transmission to the buffer, return length of data
@ -519,21 +1032,36 @@ int Head::getBroadcastData(char* data)
getRenderPitch() + Pitch, -getRenderYaw() + 180 -Yaw, Roll,
position.x + leanSideways, position.y, position.z + leanForward,
loudness, averageLoudness,
hand->getPos().x, hand->getPos().y, hand->getPos().z);
//hand->getPos().x, hand->getPos().y, hand->getPos().z); //previous to Ventrella change
avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition.x,
avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition.y,
avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition.z ); // Ventrella change
return strlen(data);
}
void Head::parseData(void *data, int size) {
//called on the other agents - assigns it to my views of the others
//---------------------------------------------------
void Head::parseData(void *data, int size)
{
//glm::vec3 pos;//( (glm::vec3)avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition );
// parse head data for this agent
glm::vec3 handPos(0,0,0);
sscanf((char *)data, "H%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f",
&Pitch, &Yaw, &Roll,
&position.x, &position.y, &position.z,
&loudness, &averageLoudness,
&handPos.x, &handPos.y, &handPos.z);
glm::vec3 handPos( 0,0,0 );
sscanf
(
(char *)data, "H%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f",
&Pitch, &Yaw, &Roll,
&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,103 @@ 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 (not supposed to be rotated)
AVATAR_BONE_MID_SPINE, // connects torso joint with chest joint
AVATAR_BONE_CHEST_SPINE, // connects chest joint with neckBase joint (not supposed to 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 (not supposed to 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 (not supposed to 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 (not supposed to 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 (not supposed to 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;
glm::dvec3 worldPosition;
glm::dvec3 defaultPosePosition;
glm::dvec3 velocity;
double yaw;
double pitch;
double roll;
Orientation worldOrientation;
double length;
};
struct Avatar
{
glm::dvec3 position;
glm::dvec3 velocity;
glm::dvec3 thrust;
double yaw;
double pitch;
double roll;
double yawDelta;
double maxArmLength;
Orientation orientation;
AvatarBone bone[ NUM_AVATAR_BONES ];
};
class Head : public AgentData {
public:
Head();
@ -58,9 +156,19 @@ class Head : public AgentData {
float getRoll() {return Roll;}
float getYaw() {return Yaw;}
float getLastMeasuredYaw() {return YawRate;}
double getAvatarYaw();
void render(int faceToFace, int isMine);
void setAvatarPosition( double, double, double );
void renderBody();
void renderHead( int faceToFace, int isMine );
void simulate(float);
void setHandMovement( glm::dvec3 movement );
void updateHandMovement();
// Send and receive network data
int getBroadcastData(char * data);
@ -124,6 +232,8 @@ class Head : public AgentData {
glm::vec3 position;
glm::vec3 velocity;
glm::vec3 thrust;
glm::dvec3 handOffset;
int driveKeys[MAX_DRIVE_KEYS];
@ -131,10 +241,15 @@ class Head : public AgentData {
eyeContactTargets eyeContactTarget;
GLUquadric *sphere;
Avatar avatar;
void initializeAvatar();
void updateAvatarSkeleton();
void calculateBoneLengths();
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 + CENTIMETER );
assert( right.getMagnitude () > 1.0 - CENTIMETER );
assert( up.getMagnitude () < 1.0 + CENTIMETER );
assert( up.getMagnitude () > 1.0 - CENTIMETER );
assert( front.getMagnitude () < 1.0 + CENTIMETER );
assert( front.getMagnitude () > 1.0 - CENTIMETER );
if ( right.getMagnitude() > 1.0 + CENTIMETER )
{
printf( "oops: the magnitude of the 'right' part of the orientation is %f!\n", right.getMagnitude() );
}
else if ( right.getMagnitude() < 1.0 - CENTIMETER )
{
printf( "oops: the magnitude of the 'right' part of the orientation is %f!\n", right.getMagnitude() );
}
if ( up.getMagnitude() > 1.0 + CENTIMETER )
{
printf( "oops: the magnitude of the 'up' part of the orientation is %f!\n", up.getMagnitude() );
}
else if ( up.getMagnitude() < 1.0 - CENTIMETER )
{
printf( "oops: the magnitude of the 'up' part of the orientation is %f!\n", up.getMagnitude() );
}
if ( front.getMagnitude() > 1.0 + CENTIMETER )
{
printf( "oops: the magnitude of the 'front' part of the orientation is %f!\n", front.getMagnitude() );
}
else if ( front.getMagnitude() < 1.0 - CENTIMETER )
{
printf( "oops: the magnitude of the 'front' part of the orientation is %f!\n", front.getMagnitude() );
}
if (( right.dotWith ( up ) > CENTIMETER )
|| ( right.dotWith ( up ) < -CENTIMETER )) { 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 ) > CENTIMETER )
|| ( right.dotWith ( front ) < -CENTIMETER )) { 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 ) > CENTIMETER )
|| ( up.dotWith ( front ) < -CENTIMETER )) { 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,24 @@
#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 PIE = 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; //smallish number - used as margin of error for some values
static const double SQUARE_ROOT_OF_2 = sqrt(2);
static const double SQUARE_ROOT_OF_3 = sqrt(3);
static const double METER = 1.0;
static const double DECIMETER = 0.1;
static const double CENTIMETER = 0.01;
static const double MILLIIMETER = 0.001;
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,7 @@
using namespace std;
int audio_on = 0; // Whether to turn on the audio support
int audio_on = 1; // Whether to turn on the audio support
int simulate_on = 1;
AgentList agentList('I');
@ -95,6 +96,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;
@ -193,7 +195,6 @@ char texture_filename[] = "images/int-texture256-v4.png";
unsigned int texture_width = 256;
unsigned int texture_height = 256;
float particle_attenuation_quadratic[] = { 0.0f, 0.0f, 2.0f }; // larger Z = smaller particles
float pointer_attenuation_quadratic[] = { 1.0f, 0.0f, 0.0f }; // for 2D view
@ -250,6 +251,9 @@ void Timer(int extra)
}
}
void display_stats(void)
{
// bitmap chars are about 10 pels high
@ -354,6 +358,9 @@ void initDisplay(void)
if (fullscreen) glutFullScreen();
}
void init(void)
{
voxels.init();
@ -374,8 +381,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);
@ -388,7 +397,6 @@ void init(void)
}
#endif
gettimeofday(&timer_start, NULL);
gettimeofday(&last_frame, NULL);
}
@ -454,7 +462,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,6 +564,9 @@ void simulateHead(float frametime)
int render_test_spot = WIDTH/2;
int render_test_direction = 1;
void display(void)
{
PerfStat("display");
@ -577,14 +593,48 @@ 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)) );
glLoadMatrixf( glm::value_ptr(fov.getWorldViewerXform()) );
//-------------------------------------------------------------------------------------
// set the camera to third-person view
//-------------------------------------------------------------------------------------
myCamera.setTargetPosition( (glm::dvec3)myHead.getPos() );
myCamera.setPitch ( 0.0 );
myCamera.setRoll ( 0.0 );
if ( display_head )
//-------------------------------------------------------------------------------------
// set the camera to looking at my face
//-------------------------------------------------------------------------------------
{
myCamera.setYaw ( - myHead.getAvatarYaw() );
myCamera.setUp ( 0.4 );
myCamera.setDistance( 0.08 );
myCamera.update();
}
else
//-------------------------------------------------------------------------------------
// set the camera to third-person view
//-------------------------------------------------------------------------------------
{
myCamera.setYaw ( 180.0 - myHead.getAvatarYaw() );
myCamera.setUp ( 0.15 );
myCamera.setDistance( 0.08 );
myCamera.update();
}
//-------------------------------------------------------------------------------------
// transform to camera view
//-------------------------------------------------------------------------------------
glRotatef ( myCamera.getPitch(), 1, 0, 0 );
glRotatef ( myCamera.getYaw(), 0, 1, 0 );
glRotatef ( myCamera.getRoll(), 0, 0, 1 );
//printf( "myCamera position = %f, %f, %f\n", myCamera.getPosition().x, myCamera.getPosition().y, myCamera.getPosition().z );
glTranslatef( myCamera.getPosition().x, myCamera.getPosition().y, myCamera.getPosition().z );
// fixed view
//glTranslatef( 6.18, -0.15, 1.4 );
if (::starsOn) {
// should be the first rendering pass - w/o depth buffer / lighting
@ -603,7 +653,7 @@ void display(void)
// if (!display_head) cloud.render();
// Draw voxels
voxels.render();
voxels.render();
// Draw field vectors
if (display_field) field.render();
@ -625,12 +675,20 @@ void display(void)
// Render the world box
if (!display_head && stats_on) render_world_box();
//---------------------------------
// Render my own head
//---------------------------------
myHead.render( true, 1 );
/*
glPushMatrix();
glLoadIdentity();
glTranslatef(0.f, 0.f, -7.f);
myHead.render(display_head, 1);
glPopMatrix();
*/
}
glPopMatrix();
@ -721,6 +779,10 @@ void display(void)
framecount++;
}
void testPointToVoxel()
{
float y=0;
@ -965,6 +1027,23 @@ void idle(void)
if (diffclock(&last_frame, &check) > RENDER_FRAME_MSECS)
{
steps_per_frame++;
//----------------------------------------------------------------
// If mouse is being dragged, update hand movement in the avatar
//----------------------------------------------------------------
if ( mouse_pressed == 1 )
{
double xOffset = ( mouse_x - mouse_start_x ) / (double)WIDTH;
double yOffset = ( mouse_y - mouse_start_y ) / (double)HEIGHT;
double leftRight = xOffset;
double downUp = yOffset;
double backFront = 0.0;
glm::dvec3 handMovement( leftRight, downUp, backFront );
myHead.setHandMovement( handMovement );
}
// Simulation
simulateHead(1.f/FPS);
simulateHand(1.f/FPS);
@ -989,6 +1068,8 @@ void idle(void)
}
}
void reshape(int width, int height)
{
WIDTH = width;
@ -1006,6 +1087,8 @@ void reshape(int width, int height)
glViewport(0, 0, width, height);
}
void mouseFunc( int button, int state, int x, int y )
{
if( button == GLUT_LEFT_BUTTON && state == GLUT_DOWN )