From d3f6c19e83c8b9e84030aa65768e2ea911a4ae52 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Thu, 4 Apr 2013 18:04:32 -0700 Subject: [PATCH 01/33] adding Camera and some utility classes and start of prototype avatar --- interface/src/Camera.cpp | 19 +++ interface/src/Camera.h | 41 +++++ interface/src/Hand.h | 1 + interface/src/Head.cpp | 302 ++++++++++++++++++++++++++++++++-- interface/src/Head.h | 113 ++++++++++++- interface/src/Orientation.cpp | 232 ++++++++++++++++++++++++++ interface/src/Orientation.h | 52 ++++++ interface/src/Util.h | 14 ++ interface/src/Vector3D.cpp | 267 ++++++++++++++++++++++++++++++ interface/src/Vector3D.h | 66 ++++++++ interface/src/main.cpp | 63 +++++-- 11 files changed, 1141 insertions(+), 29 deletions(-) create mode 100755 interface/src/Camera.cpp create mode 100755 interface/src/Camera.h mode change 100644 => 100755 interface/src/Head.cpp create mode 100755 interface/src/Orientation.cpp create mode 100755 interface/src/Orientation.h create mode 100755 interface/src/Vector3D.cpp create mode 100755 interface/src/Vector3D.h diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp new file mode 100755 index 0000000000..b0c5a2c0dd --- /dev/null +++ b/interface/src/Camera.cpp @@ -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(); +} + diff --git a/interface/src/Camera.h b/interface/src/Camera.h new file mode 100755 index 0000000000..b0bf9373cd --- /dev/null +++ b/interface/src/Camera.h @@ -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 + +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 diff --git a/interface/src/Hand.h b/interface/src/Hand.h index bda0fb2145..cf887a897f 100644 --- a/interface/src/Hand.h +++ b/interface/src/Hand.h @@ -40,6 +40,7 @@ private: float transmitterHz; int transmitterPackets; bool renderPointer; + }; diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp old mode 100644 new mode 100755 index 8cf831d426..18b5d60690 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -38,8 +38,13 @@ vector 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 0.0) hand->setPos(handPos); } +//--------------------------------------------------- void Head::SetNewHeadTarget(float pitch, float yaw) { PitchTarget = pitch; diff --git a/interface/src/Head.h b/interface/src/Head.h index abde89deea..618bdcc16b 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -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 \ No newline at end of file +#endif diff --git a/interface/src/Orientation.cpp b/interface/src/Orientation.cpp new file mode 100755 index 0000000000..16176e736d --- /dev/null +++ b/interface/src/Orientation.cpp @@ -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 ) ); } + +} + + + + diff --git a/interface/src/Orientation.h b/interface/src/Orientation.h new file mode 100755 index 0000000000..217366f8ef --- /dev/null +++ b/interface/src/Orientation.h @@ -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 diff --git a/interface/src/Util.h b/interface/src/Util.h index e2cd566b6e..ea74aafde1 100644 --- a/interface/src/Util.h +++ b/interface/src/Util.h @@ -17,6 +17,20 @@ #include + +// 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); diff --git a/interface/src/Vector3D.cpp b/interface/src/Vector3D.cpp new file mode 100755 index 0000000000..792d55c16a --- /dev/null +++ b/interface/src/Vector3D.cpp @@ -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; +} + + + + + diff --git a/interface/src/Vector3D.h b/interface/src/Vector3D.h new file mode 100755 index 0000000000..9b2bc9744c --- /dev/null +++ b/interface/src/Vector3D.h @@ -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 diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 2cba377d8f..91cae9f4c9 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -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(); From e57e2bdf38ebf9aafefa9a3e0b3a73f32d7f4499 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 5 Apr 2013 10:48:08 -0700 Subject: [PATCH 02/33] thingy2 --- interface/src/main.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 91cae9f4c9..acfb7c8424 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -67,7 +67,7 @@ using namespace std; -double testThingy = 0.0; +double testThingy = 90.0; int audio_on = 1; // Whether to turn on the audio support int simulate_on = 1; @@ -573,11 +573,20 @@ void display(void) //------------------------------------------------------------------------------------- // set the caemra to third-person view //------------------------------------------------------------------------------------- - myCamera.setYaw ( myHead.getRenderYaw() ); + + testThingy += 1.0; + + //myCamera.setYaw ( myHead.getRenderYaw() ); + myCamera.setYaw ( testThingy ); myCamera.setPitch ( 0.0 ); myCamera.setRoll ( 0.0 ); - glm::dvec3 offset( 0.7, -0.2, 0.7 ); + double radian = ( testThingy / 180.0 ) * PI; + double x = 0.7 * sin( radian ); + double z = 0.7 * cos( radian ); + double y = -0.2; + + glm::dvec3 offset( x, y, z ); glm::dvec3 positionWithOffset( myHead.getPos() ); From a0f09b597ad832dd6a9ab63bb648a6e8186cedb0 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 5 Apr 2013 16:19:23 -0700 Subject: [PATCH 03/33] got a basic avatar skeleton with a simpler starter user interaction for moving the right hand --- interface/src/Camera.cpp | 26 +++++++++-- interface/src/Camera.h | 18 ++++++-- interface/src/Head.cpp | 59 ++++++++++++++++++++++-- interface/src/Head.h | 2 +- interface/src/Orientation.cpp | 36 +++++++-------- interface/src/Util.h | 10 ++-- interface/src/main.cpp | 86 +++++++++++++++++------------------ 7 files changed, 158 insertions(+), 79 deletions(-) diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index b0c5a2c0dd..e7bf3d751b 100755 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -6,14 +6,32 @@ //----------------------------------------------------------- #include "Camera.h" +#include "Util.h" //------------------------ Camera::Camera() { - yaw = 0.0; - pitch = 0.0; - roll = 0.0; - position = glm::dvec3( 0.0, 0.0, 0.0 ); + 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 ); +} + diff --git a/interface/src/Camera.h b/interface/src/Camera.h index b0bf9373cd..eed70c1c92 100755 --- a/interface/src/Camera.h +++ b/interface/src/Camera.h @@ -17,11 +17,16 @@ 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); } + 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; } @@ -32,9 +37,12 @@ public: private: glm::dvec3 position; + glm::dvec3 targetPosition; double yaw; double pitch; double roll; + double up; + double distance; Orientation orientation; }; diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 18b5d60690..91cb91bcec 100755 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -595,7 +595,7 @@ glScalef( 0.03, 0.03, 0.03 ); //--------------------------------------------------------- void Head::setHandMovement( glm::dvec3 movement ) { - handOffset.setXYZ( movement.x, movement.y, movement.z ); + handOffset.setXYZ( movement.x, -movement.y, movement.z ); } @@ -744,6 +744,9 @@ void Head::simulateAvatar( float deltaTime ) //----------------------------------------- void Head::updateAvatarSkeleton() { + //------------------------------------------------------------------------ + // calculate positions of all bones by traversing the skeleton tree: + //------------------------------------------------------------------------ for (int b=0; b maxArmLength ) + { + //------------------------------------------------------------------------------- + // reset right hand to be constrained to maximum arm length + //------------------------------------------------------------------------------- + avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position.set( avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position ); + + glm::dvec3 armNormal = armVector / distance; + armVector = armNormal * maxArmLength; + distance = maxArmLength; + + glm::dvec3 constrainedPosition = glm::dvec3( avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position.x, avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position.y, avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position.z ); + + constrainedPosition += armVector; + + avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position.setXYZ( constrainedPosition.x, constrainedPosition.y, constrainedPosition.z ); + } + + + //----------------------------------------------------------------------------- + // set elbow position + //----------------------------------------------------------------------------- + glm::dvec3 newElbowPosition = glm::dvec3( avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position.x, avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position.y, avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position.z ); + + newElbowPosition += armVector * ONE_HALF; + + glm::dvec3 perpendicular = glm::dvec3( -armVector.y, armVector.x, armVector.z ); + + newElbowPosition += perpendicular * ( 1.0 - ( maxArmLength / distance ) ) * ONE_HALF; + + avatar.bone[ AVATAR_BONE_RIGHT_FOREARM ].position.setXYZ( newElbowPosition.x, newElbowPosition.y, newElbowPosition.z ); } + //----------------------------------------- void Head::renderAvatar() { @@ -772,7 +825,7 @@ void Head::renderAvatar() 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 ); + glutSolidSphere( 1, 8, 4 ); glPopMatrix(); } } diff --git a/interface/src/Head.h b/interface/src/Head.h index 618bdcc16b..b5ae162c80 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -158,6 +158,7 @@ class Head : public AgentData { void render(int faceToFace, int isMine); void setAvatarPosition( double, double, double ); + void renderAvatar(); void simulate(float); @@ -239,7 +240,6 @@ class Head : public AgentData { void initializeAvatar(); void simulateAvatar( float deltaTime ); void updateAvatarSkeleton(); - void renderAvatar(); void readSensors(); float renderYaw, renderPitch; // Pitch from view frustum when this is own head. diff --git a/interface/src/Orientation.cpp b/interface/src/Orientation.cpp index 16176e736d..63ea77f4dd 100755 --- a/interface/src/Orientation.cpp +++ b/interface/src/Orientation.cpp @@ -180,50 +180,50 @@ void Orientation::setRightUpFront( const Vector3D &r, const Vector3D &u, const V //----------------------------------------------------------------------------- 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 ); + 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 + BIG_EPSILON ) + 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 - BIG_EPSILON ) + 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 + BIG_EPSILON ) + 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 - BIG_EPSILON ) + 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 + BIG_EPSILON ) + 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 - BIG_EPSILON ) + 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 ) > 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 ( 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 ) > 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 (( 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 ) > 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 ) ); } + 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 ) ); } } diff --git a/interface/src/Util.h b/interface/src/Util.h index 8537f9c769..c5a02df5aa 100644 --- a/interface/src/Util.h +++ b/interface/src/Util.h @@ -23,13 +23,17 @@ 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 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; // 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 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); diff --git a/interface/src/main.cpp b/interface/src/main.cpp index bacd25e3d8..4ae10b94d3 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -66,9 +66,6 @@ using namespace std; - -double testThingy = 90.0; - int audio_on = 1; // Whether to turn on the audio support int simulate_on = 1; @@ -196,7 +193,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 @@ -253,6 +249,9 @@ void Timer(int extra) } } + + + void display_stats(void) { // bitmap chars are about 10 pels high @@ -330,6 +329,9 @@ void initDisplay(void) if (fullscreen) glutFullScreen(); } + + + void init(void) { voxels.init(); @@ -366,7 +368,6 @@ void init(void) } #endif - gettimeofday(&timer_start, NULL); gettimeofday(&last_frame, NULL); } @@ -416,12 +417,6 @@ 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 ); } } @@ -544,6 +539,9 @@ void simulateHead(float frametime) int render_test_spot = WIDTH/2; int render_test_direction = 1; + + + void display(void) { PerfStat("display"); @@ -571,30 +569,16 @@ void display(void) glMaterialfv(GL_FRONT, GL_SPECULAR, specular_color); glMateriali(GL_FRONT, GL_SHININESS, 96); - //------------------------------------------------------------------------------------- // set the caemra to third-person view - //------------------------------------------------------------------------------------- - - testThingy += 1.0; - - //myCamera.setYaw ( myHead.getRenderYaw() ); - myCamera.setYaw ( testThingy ); - myCamera.setPitch ( 0.0 ); - myCamera.setRoll ( 0.0 ); - - double radian = ( testThingy / 180.0 ) * PI; - double x = 0.7 * sin( radian ); - double z = 0.7 * cos( radian ); - double y = -0.2; - - glm::dvec3 offset( x, y, z ); - - glm::dvec3 positionWithOffset( myHead.getPos() ); - - positionWithOffset += offset; - - myCamera.setPosition( positionWithOffset ); + //------------------------------------------------------------------------------------- + myCamera.setTargetPosition ( (glm::dvec3)myHead.getPos() ); + myCamera.setYaw ( 0.0 ); + myCamera.setPitch ( 0.0 ); + myCamera.setRoll ( 0.0 ); + myCamera.setUp ( 0.15 ); + myCamera.setDistance ( 0.08 ); + myCamera.update(); //------------------------------------------------------------------------------------- // transform to camera view @@ -604,16 +588,6 @@ void display(void) glRotatef ( myCamera.getRoll(), 0, 0, 1 ); glTranslatef( myCamera.getPosition().x, myCamera.getPosition().y, myCamera.getPosition().z ); - /* - // 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()) ); - */ - if (::starsOn) { // should be the first rendering pass - w/o depth buffer / lighting stars.render(fov); @@ -631,7 +605,7 @@ void display(void) // if (!display_head) cloud.render(); // Draw voxels - voxels.render(); +//voxels.render(); // Draw field vectors if (display_field) field.render(); @@ -654,7 +628,8 @@ void display(void) if (!display_head && stats_on) render_world_box(); -myHead.render( true, 1 ); + myHead.render( true, 1 ); + //myHead.renderAvatar(); /* // Render my own head @@ -750,6 +725,10 @@ myHead.render( true, 1 ); framecount++; } + + + + void testPointToVoxel() { float y=0; @@ -953,6 +932,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)WIDTH; + + 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); From 87fe21f835a5854c277609a0992e57500b09843f Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 5 Apr 2013 16:21:13 -0700 Subject: [PATCH 04/33] got a basic avatar skeleton with a simpler starter user interaction for moving the right hand --- interface/src/main.cpp | 58 +++++++++++++++++++++++++++++----------- shared/src/VoxelNode.cpp | 25 +++++++---------- shared/src/VoxelNode.h | 2 +- shared/src/VoxelTree.cpp | 9 +------ voxel/src/main.cpp | 24 +++++++---------- 5 files changed, 65 insertions(+), 53 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 4ae10b94d3..0c1fb05ebf 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -147,7 +147,8 @@ glm::vec3 start_location(6.1f, 0, 1.4f); int stats_on = 0; // Whether to show onscreen text overlay with stats bool starsOn = true; // Whether to display the stars bool paintOn = false; // Whether to paint voxels as you fly around - +VoxelDetail paintingVoxel; // The voxel we're painting if we're painting +unsigned char dominantColor = 0; // The dominant color of the voxel we're painting int noise_on = 0; // Whether to add random noise float noise = 1.0; // Overall magnitude scaling for random noise levels @@ -512,23 +513,18 @@ void simulateHead(float frametime) glm::vec3 headPos = myHead.getPos(); - VoxelDetail paintingVoxel; - paintingVoxel.x = headPos.z/10.0; // voxel space x is positive z head space - paintingVoxel.y = headPos.y/-10.0; // voxel space y is negative y head space - paintingVoxel.z = headPos.x/-10.0; // voxel space z is negative x head space - paintingVoxel.s = 1.0/256; - paintingVoxel.red = 0; - paintingVoxel.green = 255; - paintingVoxel.blue = 0; + ::paintingVoxel.x = headPos.z/-10.0; // voxel space x is negative z head space + ::paintingVoxel.y = headPos.y/-10.0; // voxel space y is negative y head space + ::paintingVoxel.z = headPos.x/-10.0; // voxel space z is negative x head space unsigned char* bufferOut; int sizeOut; - if (paintingVoxel.x >= 0.0 && paintingVoxel.x <= 1.0 && - paintingVoxel.y >= 0.0 && paintingVoxel.y <= 1.0 && - paintingVoxel.z >= 0.0 && paintingVoxel.z <= 1.0) { + if (::paintingVoxel.x >= 0.0 && ::paintingVoxel.x <= 1.0 && + ::paintingVoxel.y >= 0.0 && ::paintingVoxel.y <= 1.0 && + ::paintingVoxel.z >= 0.0 && ::paintingVoxel.z <= 1.0) { - if (createVoxelEditMessage('I',0,1,&paintingVoxel,bufferOut,sizeOut)){ + if (createVoxelEditMessage('I',0,1,&::paintingVoxel,bufferOut,sizeOut)){ agentList.broadcastToAgents((char*)bufferOut, sizeOut,AgentList::AGENTS_OF_TYPE_VOXEL); delete bufferOut; } @@ -715,7 +711,12 @@ void display(void) drawtext(WIDTH-200,20, 0.10, 0, 1.0, 0, agents, 1, 1, 0); if (::paintOn) { - drawtext(WIDTH-200,40, 0.10, 0, 1.0, 0, "Paint ON", 1, 1, 0); + + char paintMessage[100]; + sprintf(paintMessage,"Painting (%.3f,%.3f,%.3f/%.3f/%d,%d,%d)", + ::paintingVoxel.x,::paintingVoxel.y,::paintingVoxel.z,::paintingVoxel.s, + (unsigned int)::paintingVoxel.red,(unsigned int)::paintingVoxel.green,(unsigned int)::paintingVoxel.blue); + drawtext(WIDTH-350,40, 0.10, 0, 1.0, 0, paintMessage, 1, 1, 0); } glPopMatrix(); @@ -749,6 +750,27 @@ void testPointToVoxel() } } +void shiftPaintingColor() +{ + // About the color of the paintbrush... first determine the dominant color + ::dominantColor = (::dominantColor+1)%3; // 0=red,1=green,2=blue + ::paintingVoxel.red = (::dominantColor==0)?randIntInRange(200,255):randIntInRange(40,100); + ::paintingVoxel.green = (::dominantColor==1)?randIntInRange(200,255):randIntInRange(40,100); + ::paintingVoxel.blue = (::dominantColor==2)?randIntInRange(200,255):randIntInRange(40,100); +} + +void setupPaintingVoxel() +{ + glm::vec3 headPos = myHead.getPos(); + + ::paintingVoxel.x = headPos.z/-10.0; // voxel space x is negative z head space + ::paintingVoxel.y = headPos.y/-10.0; // voxel space y is negative y head space + ::paintingVoxel.z = headPos.x/-10.0; // voxel space z is negative x head space + ::paintingVoxel.s = 1.0/256; + + shiftPaintingColor(); +} + void addRandomSphere(bool wantColorRandomizer) { float r = randFloatInRange(0.05,0.1); @@ -835,7 +857,13 @@ void key(unsigned char k, int x, int y) if (k == 'q') ::terminate(); if (k == '/') stats_on = !stats_on; // toggle stats if (k == '*') ::starsOn = !::starsOn; // toggle stars - if (k == '&') ::paintOn = !::paintOn; // toggle paint + if (k == '&') { + ::paintOn = !::paintOn; // toggle paint + setupPaintingVoxel(); // also randomizes colors + } + if (k == '^') { + shiftPaintingColor(); // shifts randomize color between R,G,B dominant + } if (k == 'n') { noise_on = !noise_on; // Toggle noise diff --git a/shared/src/VoxelNode.cpp b/shared/src/VoxelNode.cpp index 8b71a04893..7300af814a 100644 --- a/shared/src/VoxelNode.cpp +++ b/shared/src/VoxelNode.cpp @@ -37,25 +37,20 @@ void VoxelNode::addChildAtIndex(int childIndex) { } // will average the child colors... -void VoxelNode::setColorFromAverageOfChildren(int * colorArray) { - if (colorArray == NULL) { - colorArray = new int[4]; - memset(colorArray, 0, 4*sizeof(int)); - - for (int i = 0; i < 8; i++) { - if (children[i] != NULL && children[i]->color[3] == 1) { - for (int j = 0; j < 3; j++) { - colorArray[j] += children[i]->color[j]; - } - colorArray[3]++; - } - } - } +void VoxelNode::setColorFromAverageOfChildren() { + int colorArray[4] = {0,0,0,0}; + for (int i = 0; i < 8; i++) { + if (children[i] != NULL && children[i]->color[3] == 1) { + for (int j = 0; j < 3; j++) { + colorArray[j] += children[i]->color[j]; + } + colorArray[3]++; + } + } if (colorArray[3] > 4) { // we need at least 4 colored children to have an average color value // or if we have none we generate random values - for (int c = 0; c < 3; c++) { // set the average color value color[c] = colorArray[c] / colorArray[3]; diff --git a/shared/src/VoxelNode.h b/shared/src/VoxelNode.h index 9be1b64c70..e97689aa9b 100644 --- a/shared/src/VoxelNode.h +++ b/shared/src/VoxelNode.h @@ -17,7 +17,7 @@ public: ~VoxelNode(); void addChildAtIndex(int childIndex); - void setColorFromAverageOfChildren(int * colorArray = NULL); + void setColorFromAverageOfChildren(); void setRandomColor(int minimumBrightness); bool collapseIdenticalLeaves(); diff --git a/shared/src/VoxelTree.cpp b/shared/src/VoxelTree.cpp index a00fb48cf5..a7390dd06f 100644 --- a/shared/src/VoxelTree.cpp +++ b/shared/src/VoxelTree.cpp @@ -100,8 +100,6 @@ int VoxelTree::readNodeData(VoxelNode *destinationNode, // instantiate variable for bytes already read int bytesRead = 1; - int colorArray[4] = {}; - for (int i = 0; i < 8; i++) { // check the colors mask to see if we have a child to color in if (oneAtBit(*nodeData, i)) { @@ -115,17 +113,12 @@ int VoxelTree::readNodeData(VoxelNode *destinationNode, memcpy(destinationNode->children[i]->color, nodeData + bytesRead, 3); destinationNode->children[i]->color[3] = 1; - for (int j = 0; j < 3; j++) { - colorArray[j] += destinationNode->children[i]->color[j]; - } - bytesRead += 3; - colorArray[3]++; } } // average node's color based on color of children - destinationNode->setColorFromAverageOfChildren(colorArray); + destinationNode->setColorFromAverageOfChildren(); // give this destination node the child mask from the packet unsigned char childMask = *(nodeData + bytesRead); diff --git a/voxel/src/main.cpp b/voxel/src/main.cpp index 914411db64..0a2ae0c584 100644 --- a/voxel/src/main.cpp +++ b/voxel/src/main.cpp @@ -85,8 +85,6 @@ void randomlyFillVoxelTree(int levelsToGo, VoxelNode *currentRootNode) { if (levelsToGo > 0) { bool createdChildren = false; - int colorArray[4] = {}; - createdChildren = false; for (int i = 0; i < 8; i++) { @@ -96,17 +94,8 @@ void randomlyFillVoxelTree(int levelsToGo, VoxelNode *currentRootNode) { // give this child it's octal code currentRootNode->children[i]->octalCode = childOctalCode(currentRootNode->octalCode, i); - - randomlyFillVoxelTree(levelsToGo - 1, currentRootNode->children[i]); - if (currentRootNode->children[i]->color[3] == 1) { - for (int c = 0; c < 3; c++) { - colorArray[c] += currentRootNode->children[i]->color[c]; - } - - colorArray[3]++; - } - + randomlyFillVoxelTree(levelsToGo - 1, currentRootNode->children[i]); createdChildren = true; } } @@ -117,7 +106,7 @@ void randomlyFillVoxelTree(int levelsToGo, VoxelNode *currentRootNode) { currentRootNode->setRandomColor(MIN_BRIGHTNESS); } else { // set the color value for this node - currentRootNode->setColorFromAverageOfChildren(colorArray); + currentRootNode->setColorFromAverageOfChildren(); } } else { // this is a leaf node, just give it a color @@ -171,7 +160,12 @@ void *distributeVoxelsToListeners(void *args) { packetCount++; totalBytesSent += voxelPacketEnd - voxelPacket; - if (agentData->rootMarkerNode->childrenVisitedMask == 255) { + // XXXBHG Hack Attack: This is temporary code to help debug an issue. + // Normally we use this break to prevent resending voxels that an agent has + // already visited. But since we might be modifying the voxel tree we might + // want to always send. This is a hack to test the behavior + bool alwaysSend = true; + if (!alwaysSend && agentData->rootMarkerNode->childrenVisitedMask == 255) { break; } } @@ -311,6 +305,8 @@ int main(int argc, const char * argv[]) pVoxelData+=voxelDataSize; atByte+=voxelDataSize; } + // after done inserting all these voxels, then reaverage colors + randomTree.reaverageVoxelColors(randomTree.rootNode); } if (packetData[0] == 'R') { From cd1533dc7c02407cf5c335e5daecd8d3c12051d9 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Mon, 8 Apr 2013 18:46:00 -0700 Subject: [PATCH 05/33] Lots of small changes in the head (evolving into "avatar") to include skeleton. Also, added camera behaviors for navigation --- interface/src/Head.cpp | 520 ++++++++++++++++++++++++++++------------- interface/src/Head.h | 44 ++-- interface/src/main.cpp | 52 ++++- 3 files changed, 425 insertions(+), 191 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 91cb91bcec..efd07bf8d6 100755 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -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. // @@ -45,9 +46,9 @@ Head::Head() { initializeAvatar(); - position = glm::vec3(0,0,0); - velocity = glm::vec3(0,0,0); - thrust = glm::vec3(0,0,0); + 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; @@ -83,7 +84,7 @@ Head::Head() browAudioLift = 0.0; noise = 0; - handOffset.clear(); + handOffset = glm::vec3( 0.0, 0.0, 0.0 ); sphere = NULL; @@ -194,7 +195,6 @@ void Head::reset() 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); @@ -241,7 +241,7 @@ void Head::UpdatePos(float frametime, SerialInterface * serialInterface, int hea //--------------------------------------------------- void Head::setAvatarPosition( double x, double y, double z ) { - avatar.position.setXYZ( x, y, z ); + avatar.position = glm::dvec3( x, y, z ); } @@ -276,48 +276,159 @@ void Head::setLeanSideways(float dist){ //--------------------------------------------------- void Head::simulate(float deltaTime) { - simulateAvatar( 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; + + + 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 @@ -335,6 +446,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 @@ -351,6 +464,8 @@ void Head::simulate(float deltaTime) } } + + const float DEGREES_BETWEEN_VIEWER_EYES = 3; const float DEGREES_TO_VIEWER_MOUTH = 7; @@ -374,8 +489,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; @@ -409,7 +524,8 @@ void Head::simulate(float deltaTime) } } -//hand->simulate(deltaTime); + + //hand->simulate(deltaTime); } @@ -419,43 +535,49 @@ void Head::simulate(float deltaTime) //--------------------------------------------------- void Head::render(int faceToFace, int isMine) { - // render avatar - renderAvatar(); + renderBody(); + renderHead( faceToFace, isMine ); +} + + + +//--------------------------------------------------- +void Head::renderHead( int faceToFace, int isMine ) +{ int side = 0; // Always render own hand, but don't render head unless showing face2face glEnable(GL_DEPTH_TEST); glPushMatrix(); -//glScalef(scale, scale, scale); + //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 -( - 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); + //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); @@ -595,7 +717,7 @@ glScalef( 0.03, 0.03, 0.03 ); //--------------------------------------------------------- void Head::setHandMovement( glm::dvec3 movement ) { - handOffset.setXYZ( movement.x, -movement.y, movement.z ); + handOffset = glm::dvec3( movement.x, -movement.y, movement.z ); } @@ -603,19 +725,23 @@ void Head::setHandMovement( glm::dvec3 movement ) //----------------------------------------- void Head::initializeAvatar() { - //printf( "initializeAvatar\n" ); - - avatar.position.clear(); - //avatar.position.setXYZ( -3.0, 0.0, 0.0 ); - - avatar.velocity.clear(); + 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 avatar.maxArmLength ) + { + avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].worldPosition += v * 0.2; + } + */ + + + + /* + //------------------------------------------------------------------------ + // update offset position + //------------------------------------------------------------------------ + for (int b=0; b maxArmLength ) + if ( distance > avatar.maxArmLength ) { //------------------------------------------------------------------------------- // reset right hand to be constrained to maximum arm length //------------------------------------------------------------------------------- - avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position.set( avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position ); - + avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].worldPosition; glm::dvec3 armNormal = armVector / distance; - armVector = armNormal * maxArmLength; - distance = maxArmLength; - - glm::dvec3 constrainedPosition = glm::dvec3( avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position.x, avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position.y, avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position.z ); - + 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 ].position.setXYZ( constrainedPosition.x, constrainedPosition.y, constrainedPosition.z ); + avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition = constrainedPosition; } - //----------------------------------------------------------------------------- - // set elbow position + // set elbow position //----------------------------------------------------------------------------- - glm::dvec3 newElbowPosition = glm::dvec3( avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position.x, avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position.y, avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position.z ); - + 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 - ( maxArmLength / distance ) ) * ONE_HALF; - - avatar.bone[ AVATAR_BONE_RIGHT_FOREARM ].position.setXYZ( newElbowPosition.x, newElbowPosition.y, newElbowPosition.z ); + newElbowPosition += perpendicular * ( 1.0 - ( avatar.maxArmLength / distance ) ) * ONE_HALF; + avatar.bone[ AVATAR_BONE_RIGHT_FOREARM ].worldPosition = newElbowPosition; } + //----------------------------------------- -void Head::renderAvatar() +void Head::renderBody() { glColor3fv(skinColor); for (int b=0; bgetPos().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); } +//called on the other agents - assigns it to my views of the others + //--------------------------------------------------- -void Head::parseData(void *data, int size) { +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); } diff --git a/interface/src/Head.h b/interface/src/Head.h index b5ae162c80..3e2f2fcc83 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -74,30 +74,26 @@ enum AvatarJoints enum AvatarBones { AVATAR_BONE_NULL = -1, - AVATAR_BONE_PELVIS_SPINE, // connects pelvis joint with torso joint (cannot be rotated) + 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 (cannot be rotated) + 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 (cannot be rotated) + 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 (cannot be rotated) + 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 (cannot be rotated) + 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 (cannot be rotated) + 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 @@ -108,20 +104,26 @@ enum AvatarBones struct AvatarBone { AvatarBones parent; - Vector3D position; - Vector3D defaultPosePosition; - Vector3D velocity; + glm::dvec3 worldPosition; + glm::dvec3 defaultPosePosition; + glm::dvec3 velocity; double yaw; double pitch; double roll; - Orientation orientation; + Orientation worldOrientation; double length; }; struct Avatar { - Vector3D position; - Vector3D velocity; + 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 ]; }; @@ -154,15 +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 renderAvatar(); + 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); @@ -227,7 +233,7 @@ class Head : public AgentData { glm::vec3 velocity; glm::vec3 thrust; - Vector3D handOffset; + glm::dvec3 handOffset; int driveKeys[MAX_DRIVE_KEYS]; @@ -238,8 +244,8 @@ class Head : public AgentData { Avatar avatar; void initializeAvatar(); - void simulateAvatar( float deltaTime ); void updateAvatarSkeleton(); + void calculateBoneLengths(); void readSensors(); float renderYaw, renderPitch; // Pitch from view frustum when this is own head. diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 0c1fb05ebf..03ad9e7ed2 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -566,15 +566,32 @@ void display(void) glMateriali(GL_FRONT, GL_SHININESS, 96); //------------------------------------------------------------------------------------- - // set the caemra to third-person view + // set the camera to third-person view //------------------------------------------------------------------------------------- - myCamera.setTargetPosition ( (glm::dvec3)myHead.getPos() ); - myCamera.setYaw ( 0.0 ); - myCamera.setPitch ( 0.0 ); - myCamera.setRoll ( 0.0 ); - myCamera.setUp ( 0.15 ); - myCamera.setDistance ( 0.08 ); - myCamera.update(); + 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 @@ -582,7 +599,13 @@ void display(void) 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 @@ -601,7 +624,7 @@ void display(void) // if (!display_head) cloud.render(); // Draw voxels -//voxels.render(); + voxels.render(); // Draw field vectors if (display_field) field.render(); @@ -624,11 +647,12 @@ void display(void) if (!display_head && stats_on) render_world_box(); + //--------------------------------- + // Render my own head + //--------------------------------- myHead.render( true, 1 ); - //myHead.renderAvatar(); /* - // Render my own head glPushMatrix(); glLoadIdentity(); glTranslatef(0.f, 0.f, -7.f); @@ -967,7 +991,7 @@ void idle(void) if ( mouse_pressed == 1 ) { double xOffset = ( mouse_x - mouse_start_x ) / (double)WIDTH; - double yOffset = ( mouse_y - mouse_start_y ) / (double)WIDTH; + double yOffset = ( mouse_y - mouse_start_y ) / (double)HEIGHT; double leftRight = xOffset; double downUp = yOffset; @@ -1001,6 +1025,8 @@ void idle(void) } } + + void reshape(int width, int height) { WIDTH = width; @@ -1018,6 +1044,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 ) From e6a4647852c0ac2ce012dfa2350e915342653f3a Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Mon, 8 Apr 2013 18:56:31 -0700 Subject: [PATCH 06/33] added a fix for other av rotation --- interface/src/Head.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index efd07bf8d6..2b1222c09d 100755 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -397,6 +397,7 @@ void Head::simulate(float deltaTime) avatar.yaw += avatar.yawDelta * deltaTime; + Yaw = avatar.yaw; const float TEST_YAW_DECAY = 5.0; avatar.yawDelta *= ( 1.0 - TEST_YAW_DECAY * deltaTime ); From 06a5e4d8a95c6fd7b393dca2b9d77448feff3649 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 8 Apr 2013 19:03:49 -0700 Subject: [PATCH 07/33] Adding more packet headers --- shared/src/AgentList.cpp | 4 ++-- shared/src/PacketHeaders.h | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/shared/src/AgentList.cpp b/shared/src/AgentList.cpp index 729a88ca6d..221942e5dc 100644 --- a/shared/src/AgentList.cpp +++ b/shared/src/AgentList.cpp @@ -69,12 +69,12 @@ unsigned int AgentList::getSocketListenPort() { void AgentList::processAgentData(sockaddr *senderAddress, void *packetData, size_t dataBytes) { switch (((char *)packetData)[0]) { - case 'D': { + case PACKET_HEADER_DOMAIN: { // list of agents from domain server updateList((unsigned char *)packetData, dataBytes); break; } - case 'H': { + case PACKET_HEADER_HEAD: { // head data from another agent updateAgentWithData(senderAddress, packetData, dataBytes); break; diff --git a/shared/src/PacketHeaders.h b/shared/src/PacketHeaders.h index 7c76c5d7f9..bc13cc625b 100644 --- a/shared/src/PacketHeaders.h +++ b/shared/src/PacketHeaders.h @@ -5,6 +5,9 @@ // Created by Stephen Birarda on 4/8/13. // // +// The packet headers below refer to the first byte of a received UDP packet transmitted between +// any two Hifi components. For example, a packet whose first byte is 'P' is always a ping packet. +// #ifndef hifi_PacketHeaders_h #define hifi_PacketHeaders_h @@ -12,5 +15,6 @@ const char PACKET_HEADER_DOMAIN = 'D'; const char PACKET_HEADER_PING = 'P'; const char PACKET_HEADER_PING_REPLY = 'R'; +const char PACKET_HEADER_HEAD = 'H'; #endif From 7480283dd42b0ced3f2ddd39b09360797e9b9a1b Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 8 Apr 2013 19:54:14 -0700 Subject: [PATCH 08/33] cleanup of packet header constants --- injector/src/injector.cpp | 4 +++- interface/src/Audio.cpp | 3 ++- interface/src/VoxelSystem.cpp | 6 +++--- interface/src/main.cpp | 9 ++++++--- mixer/src/main.cpp | 3 ++- shared/src/AgentList.cpp | 4 ++-- shared/src/PacketHeaders.h | 7 +++++++ shared/src/SharedUtil.cpp | 2 +- shared/src/VoxelTree.cpp | 2 +- tools/sendvoxels.php | 8 ++++---- voxel/src/main.cpp | 13 +++++++------ 11 files changed, 38 insertions(+), 23 deletions(-) diff --git a/injector/src/injector.cpp b/injector/src/injector.cpp index 3845370178..3f6bb7f689 100644 --- a/injector/src/injector.cpp +++ b/injector/src/injector.cpp @@ -20,6 +20,8 @@ #include "UDPSocket.h" #include "UDPSocket.cpp" #include +#include + char EC2_WEST_AUDIO_SERVER[] = "54.241.92.53"; const int AUDIO_UDP_LISTEN_PORT = 55443; @@ -121,7 +123,7 @@ void stream(void) int leadingBytes = 1 + (sizeof(float) * 4); unsigned char dataPacket[BUFFER_LENGTH_BYTES + leadingBytes]; - dataPacket[0] = 'I'; + dataPacket[0] = PACKET_HEADER_INJECT_AUDIO; unsigned char *currentPacketPtr = dataPacket + 1; for (int p = 0; p < 4; p++) { diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index ce45670c45..e717d707a9 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include "Audio.h" #include "Util.h" @@ -150,7 +151,7 @@ int audioCallback (const void *inputBuffer, // + 12 for 3 floats for position + float for bearing + 1 attenuation byte unsigned char dataPacket[BUFFER_LENGTH_BYTES + leadingBytes]; - dataPacket[0] = 'I'; + dataPacket[0] = PACKET_HEADER_INJECT_AUDIO; unsigned char *currentPacketPtr = dataPacket + 1; // memcpy the three float positions diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index f3eb8ec957..ca6bbee7b0 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -113,15 +113,15 @@ void VoxelSystem::parseData(void *data, int size) { unsigned char *voxelData = (unsigned char *) data + 1; switch(command) { - case 'V': + case PACKET_HEADER_VOXEL_DATA: // ask the VoxelTree to read the bitstream into the tree tree->readBitstreamToTree(voxelData, size - 1); break; - case 'R': + case PACKET_HEADER_ERASE_VOXEL: // ask the tree to read the "remove" bitstream tree->processRemoveVoxelBitstream((unsigned char*)data,size); break; - case 'Z': + case PACKET_HEADER_Z_COMMAND: // the Z command is a special command that allows the sender to send high level semantic // requests, like erase all, or add sphere scene, different receivers may handle these diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 64d4e774c5..e7f794e0b7 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -63,6 +63,7 @@ #include "SerialInterface.h" #include #include +#include using namespace std; @@ -553,7 +554,7 @@ void simulateHead(float frametime) ::paintingVoxel.y >= 0.0 && ::paintingVoxel.y <= 1.0 && ::paintingVoxel.z >= 0.0 && ::paintingVoxel.z <= 1.0) { - if (createVoxelEditMessage('I',0,1,&::paintingVoxel,bufferOut,sizeOut)){ + if (createVoxelEditMessage(PACKET_HEADER_SET_VOXEL,0,1,&::paintingVoxel,bufferOut,sizeOut)){ agentList.broadcastToAgents((char*)bufferOut, sizeOut,AgentList::AGENTS_OF_TYPE_VOXEL); delete bufferOut; } @@ -1003,10 +1004,12 @@ void *networkReceive(void *args) packetcount++; bytescount += bytesReceived; - if (incomingPacket[0] == 't') { + if (incomingPacket[0] == PACKET_HEADER_TRANSMITTER_DATA) { // Pass everything but transmitter data to the agent list myHead.hand->processTransmitterData(incomingPacket, bytesReceived); - } else if (incomingPacket[0] == 'V' || incomingPacket[0] == 'Z') { + } else if (incomingPacket[0] == PACKET_HEADER_VOXEL_DATA || + incomingPacket[0] == PACKET_HEADER_Z_COMMAND || + incomingPacket[0] == PACKET_HEADER_ERASE_VOXEL) { voxels.parseData(incomingPacket, bytesReceived); } else { agentList.processAgentData(&senderAddress, incomingPacket, bytesReceived); diff --git a/mixer/src/main.cpp b/mixer/src/main.cpp index bb97dab353..80c2452e2f 100644 --- a/mixer/src/main.cpp +++ b/mixer/src/main.cpp @@ -20,6 +20,7 @@ #include #include #include "AudioRingBuffer.h" +#include "PacketHeaders.h" #ifdef _WIN32 #include "Syssocket.h" @@ -275,7 +276,7 @@ int main(int argc, const char * argv[]) while (true) { if(agentList.getAgentSocket().receive(agentAddress, packetData, &receivedBytes)) { - if (packetData[0] == 'I') { + if (packetData[0] == PACKET_HEADER_INJECT_AUDIO) { // Compute and report standard deviation for jitter calculation if (firstSample) { diff --git a/shared/src/AgentList.cpp b/shared/src/AgentList.cpp index 729a88ca6d..e0d4491700 100644 --- a/shared/src/AgentList.cpp +++ b/shared/src/AgentList.cpp @@ -69,12 +69,12 @@ unsigned int AgentList::getSocketListenPort() { void AgentList::processAgentData(sockaddr *senderAddress, void *packetData, size_t dataBytes) { switch (((char *)packetData)[0]) { - case 'D': { + case PACKET_HEADER_DOMAIN: { // list of agents from domain server updateList((unsigned char *)packetData, dataBytes); break; } - case 'H': { + case PACKET_HEADER_HEAD_DATA: { // head data from another agent updateAgentWithData(senderAddress, packetData, dataBytes); break; diff --git a/shared/src/PacketHeaders.h b/shared/src/PacketHeaders.h index 7c76c5d7f9..097a87604c 100644 --- a/shared/src/PacketHeaders.h +++ b/shared/src/PacketHeaders.h @@ -12,5 +12,12 @@ const char PACKET_HEADER_DOMAIN = 'D'; const char PACKET_HEADER_PING = 'P'; const char PACKET_HEADER_PING_REPLY = 'R'; +const char PACKET_HEADER_HEAD_DATA = 'H'; +const char PACKET_HEADER_Z_COMMAND = 'Z'; +const char PACKET_HEADER_INJECT_AUDIO = 'I'; +const char PACKET_HEADER_SET_VOXEL = 'S'; +const char PACKET_HEADER_ERASE_VOXEL = 'E'; +const char PACKET_HEADER_VOXEL_DATA = 'V'; +const char PACKET_HEADER_TRANSMITTER_DATA = 't'; #endif diff --git a/shared/src/SharedUtil.cpp b/shared/src/SharedUtil.cpp index be4d081c5a..60d3b1559f 100644 --- a/shared/src/SharedUtil.cpp +++ b/shared/src/SharedUtil.cpp @@ -131,7 +131,7 @@ bool cmdOptionExists(int argc, const char * argv[],const char* option) { // corresponding to the closest voxel which encloses a cube with // lower corners at x,y,z, having side of length S. // The input values x,y,z range 0.0 <= v < 1.0 -// message should be either 'I' for insert or 'R' for remove +// message should be either 'S' for SET or 'E' for ERASE // // IMPORTANT: The buffer is returned to you a buffer which you MUST delete when you are // done with it. diff --git a/shared/src/VoxelTree.cpp b/shared/src/VoxelTree.cpp index dfda1de2b5..8cefb45a11 100644 --- a/shared/src/VoxelTree.cpp +++ b/shared/src/VoxelTree.cpp @@ -309,7 +309,7 @@ unsigned char * VoxelTree::loadBitstreamBuffer(unsigned char *& bitstreamBuffer, if (strcmp((char *)stopOctalCode, (char *)currentVoxelNode->octalCode) == 0) { // this is is the root node for this packet // add the leading V - *(bitstreamBuffer++) = 'V'; + *(bitstreamBuffer++) = PACKET_HEADER_VOXEL_DATA; // add its octal code to the packet int octalCodeBytes = bytesRequiredForCodeLength(*currentVoxelNode->octalCode); diff --git a/tools/sendvoxels.php b/tools/sendvoxels.php index b71c50c8df..438c9a1b8a 100644 --- a/tools/sendvoxels.php +++ b/tools/sendvoxels.php @@ -68,15 +68,15 @@ if (empty($options['i']) && empty($options['zcommand'])) { $filename = $options['i']; $server = $options['s']; $port = empty($options['p']) ? 40106 : $options['p']; - $command = empty($options['c']) ? 'I' : $options['c']; + $command = empty($options['c']) ? 'S' : $options['c']; switch($command) { - case 'I': - case 'R': + case 'S': + case 'E': case 'Z': //$command is good break; default: - $command='I';// insert by default! + $command='S';// insert by default! } if ($options['testmode']) { diff --git a/voxel/src/main.cpp b/voxel/src/main.cpp index c3b955b22e..09834a2d3e 100644 --- a/voxel/src/main.cpp +++ b/voxel/src/main.cpp @@ -16,6 +16,7 @@ #include #include "VoxelAgentData.h" #include +#include #ifdef _WIN32 #include "Syssocket.h" @@ -293,8 +294,8 @@ int main(int argc, const char * argv[]) // loop to send to agents requesting data while (true) { if (agentList.getAgentSocket().receive(&agentPublicAddress, packetData, &receivedBytes)) { - // XXXBHG: Hacked in support for 'I' insert command - if (packetData[0] == 'I') { + // XXXBHG: Hacked in support for 'S' SET command + if (packetData[0] == PACKET_HEADER_SET_VOXEL) { unsigned short int itemNumber = (*((unsigned short int*)&packetData[1])); printf("got I - insert voxels - command from client receivedBytes=%ld itemNumber=%d\n", receivedBytes,itemNumber); @@ -335,10 +336,10 @@ int main(int argc, const char * argv[]) // after done inserting all these voxels, then reaverage colors randomTree.reaverageVoxelColors(randomTree.rootNode); } - if (packetData[0] == 'R') { + if (packetData[0] == PACKET_HEADER_ERASE_VOXEL) { // Send these bits off to the VoxelTree class to process them - printf("got Remove Voxels message, have voxel tree do the work... randomTree.processRemoveVoxelBitstream()\n"); + printf("got Erase Voxels message, have voxel tree do the work... randomTree.processRemoveVoxelBitstream()\n"); randomTree.processRemoveVoxelBitstream((unsigned char*)packetData,receivedBytes); // Now send this to the connected agents so they know to delete @@ -346,7 +347,7 @@ int main(int argc, const char * argv[]) agentList.broadcastToAgents(packetData,receivedBytes,AgentList::AGENTS_OF_TYPE_HEAD); } - if (packetData[0] == 'Z') { + if (packetData[0] == PACKET_HEADER_Z_COMMAND) { // the Z command is a special command that allows the sender to send the voxel server high level semantic // requests, like erase all, or add sphere scene @@ -373,7 +374,7 @@ int main(int argc, const char * argv[]) printf("rebroadcasting Z message to connected agents... agentList.broadcastToAgents()\n"); agentList.broadcastToAgents(packetData,receivedBytes,AgentList::AGENTS_OF_TYPE_HEAD); } - if (packetData[0] == 'H') { + if (packetData[0] == PACKET_HEADER_HEAD_DATA) { if (agentList.addOrUpdateAgent(&agentPublicAddress, &agentPublicAddress, packetData[0], From 17f4c5d18437d0af102a73c692e5b5d12f07f523 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 8 Apr 2013 19:56:42 -0700 Subject: [PATCH 09/33] cleanup of packet header constants --- interface/src/VoxelSystem.cpp | 1 + shared/src/VoxelTree.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index ca6bbee7b0..d901a08ebd 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -11,6 +11,7 @@ #include // to load voxels from file #include // to load voxels from file #include +#include #include #include "VoxelSystem.h" diff --git a/shared/src/VoxelTree.cpp b/shared/src/VoxelTree.cpp index 8cefb45a11..1a48a690c2 100644 --- a/shared/src/VoxelTree.cpp +++ b/shared/src/VoxelTree.cpp @@ -10,6 +10,7 @@ #include #include #include "SharedUtil.h" +#include "PacketHeaders.h" #include "CounterStats.h" #include "OctalCode.h" #include "VoxelTree.h" From ec9bd5efb32f13a4e5f9ae87246151b543a72aea Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 8 Apr 2013 19:59:58 -0700 Subject: [PATCH 10/33] hopefully fix build buster --- interface/src/Orientation.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Orientation.h b/interface/src/Orientation.h index 217366f8ef..30979c48ff 100755 --- a/interface/src/Orientation.h +++ b/interface/src/Orientation.h @@ -8,7 +8,7 @@ #ifndef __interface__orientation__ #define __interface__orientation__ -#include "Math.h" +#include #include "Vector3D.h" enum Axis From 6079ec2d918d46bda66b966771c1d1e740ce3a91 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 8 Apr 2013 20:02:10 -0700 Subject: [PATCH 11/33] hopefully fix build buster --- interface/src/Orientation.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Orientation.h b/interface/src/Orientation.h index 30979c48ff..f9f6744fc2 100755 --- a/interface/src/Orientation.h +++ b/interface/src/Orientation.h @@ -8,7 +8,7 @@ #ifndef __interface__orientation__ #define __interface__orientation__ -#include +#include // with this work? "Math.h" #include "Vector3D.h" enum Axis From 6eb503f6d0a7833495c3e2571656e32210a226da Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 8 Apr 2013 20:04:24 -0700 Subject: [PATCH 12/33] hopefully fix build buster --- interface/src/Vector3D.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Vector3D.cpp b/interface/src/Vector3D.cpp index 792d55c16a..0e6393ecac 100755 --- a/interface/src/Vector3D.cpp +++ b/interface/src/Vector3D.cpp @@ -6,7 +6,7 @@ //----------------------------------------------------------- #include "Vector3D.h" -#include "Math.h" +#include // "Math.h" //--------------------------------------- Vector3D::Vector3D() From b9b57b8cc0fa73d3737dd2fea63b61dbd817a9b3 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 8 Apr 2013 20:10:19 -0700 Subject: [PATCH 13/33] Packet reply changed to constant in packetHeaders.h --- shared/src/AgentList.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/shared/src/AgentList.cpp b/shared/src/AgentList.cpp index 221942e5dc..c3f4183fcd 100644 --- a/shared/src/AgentList.cpp +++ b/shared/src/AgentList.cpp @@ -82,8 +82,7 @@ void AgentList::processAgentData(sockaddr *senderAddress, void *packetData, size case PACKET_HEADER_PING: { // ping from another agent //std::cout << "Got ping from " << inet_ntoa(((sockaddr_in *)senderAddress)->sin_addr) << "\n"; - char reply[] = "R"; - agentSocket.send(senderAddress, reply, 1); + agentSocket.send(senderAddress, &PACKET_HEADER_PING_REPLY, 1); break; } case PACKET_HEADER_PING_REPLY: { From 87fd0f7a9141df044265e0add72d878447bd79db Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 8 Apr 2013 21:13:20 -0700 Subject: [PATCH 14/33] Fixed avatar lighting, head scaling, removed some extra log messages --- interface/src/Audio.cpp | 10 +++++----- interface/src/Head.cpp | 9 ++++----- interface/src/main.cpp | 4 ++-- mixer/src/main.cpp | 2 +- shared/src/AgentList.cpp | 4 ++-- shared/src/PacketHeaders.h | 8 +++++++- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index e717d707a9..d003de98cb 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -231,19 +231,19 @@ int audioCallback (const void *inputBuffer, if (ringBuffer->getEndOfLastWrite() != NULL) { if (!ringBuffer->isStarted() && ringBuffer->diffLastWriteNextOutput() < PACKET_LENGTH_SAMPLES + JITTER_BUFFER_SAMPLES) { - printf("Held back, buffer has %d of %d samples required.\n", ringBuffer->diffLastWriteNextOutput(), PACKET_LENGTH_SAMPLES + JITTER_BUFFER_SAMPLES); + //printf("Held back, buffer has %d of %d samples required.\n", ringBuffer->diffLastWriteNextOutput(), PACKET_LENGTH_SAMPLES + JITTER_BUFFER_SAMPLES); } else if (ringBuffer->diffLastWriteNextOutput() < PACKET_LENGTH_SAMPLES) { ringBuffer->setStarted(false); starve_counter++; packetsReceivedThisPlayback = 0; - printf("Starved #%d\n", starve_counter); + //printf("Starved #%d\n", starve_counter); data->wasStarved = 10; // Frames to render the indication that the system was starved. } else { if (!ringBuffer->isStarted()) { ringBuffer->setStarted(true); - printf("starting playback %3.1f msecs delayed, \n", (usecTimestampNow() - usecTimestamp(&firstPlaybackTimer))/1000.0); + printf("starting playback %3.1f msecs delayed \n", (usecTimestampNow() - usecTimestamp(&firstPlaybackTimer))/1000.0); } else { //printf("pushing buffer\n"); } @@ -396,7 +396,7 @@ void *receiveAudioViaUDP(void *args) { if (totalPacketsReceived > 3) stdev.addValue(tDiff); if (stdev.getSamples() > 500) { sharedAudioData->measuredJitter = stdev.getStDev(); - printf("Avg: %4.2f, Stdev: %4.2f\n", stdev.getAverage(), sharedAudioData->measuredJitter); + //printf("Avg: %4.2f, Stdev: %4.2f\n", stdev.getAverage(), sharedAudioData->measuredJitter); stdev.reset(); } @@ -404,7 +404,7 @@ void *receiveAudioViaUDP(void *args) { if (!ringBuffer->isStarted()) { - printf("Audio packet %d received at %6.0f\n", ++packetsReceivedThisPlayback, usecTimestampNow()/1000); + packetsReceivedThisPlayback++; } else { //printf("Audio packet received at %6.0f\n", usecTimestampNow()/1000); diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 2b1222c09d..1bad6e2021 100755 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -550,6 +550,8 @@ void Head::renderHead( int faceToFace, int isMine ) // Always render own hand, but don't render head unless showing face2face glEnable(GL_DEPTH_TEST); + glEnable(GL_RESCALE_NORMAL); + glPushMatrix(); //glScalef(scale, scale, scale); @@ -580,17 +582,14 @@ void Head::renderHead( int faceToFace, int isMine ) glRotatef(Roll, 0, 0, 1); // Overall scale of head - if (faceToFace) glScalef(1.5, 2.0, 2.0); + if (faceToFace) glScalef(2.0, 2.0, 2.0); else glScalef(0.75, 1.0, 1.0); glColor3fv(skinColor); - // Head glutSolidSphere(1, 30, 30); - - //std::cout << distanceToCamera << "\n"; - + // Ears glPushMatrix(); glTranslatef(1.0, 0, 0); diff --git a/interface/src/main.cpp b/interface/src/main.cpp index e7f794e0b7..3967e16842 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -609,7 +609,7 @@ void display(void) { myCamera.setYaw ( - myHead.getAvatarYaw() ); myCamera.setUp ( 0.4 ); - myCamera.setDistance( 0.08 ); + myCamera.setDistance( 0.08 ); myCamera.update(); } else @@ -619,7 +619,7 @@ void display(void) { myCamera.setYaw ( 180.0 - myHead.getAvatarYaw() ); myCamera.setUp ( 0.15 ); - myCamera.setDistance( 0.08 ); + myCamera.setDistance( 0.08 ); myCamera.update(); } diff --git a/mixer/src/main.cpp b/mixer/src/main.cpp index 80c2452e2f..7a8705b645 100644 --- a/mixer/src/main.cpp +++ b/mixer/src/main.cpp @@ -287,7 +287,7 @@ int main(int argc, const char * argv[]) stdev.addValue(tDiff); if (stdev.getSamples() > 500) { - printf("Avg: %4.2f, Stdev: %4.2f\n", stdev.getAverage(), stdev.getStDev()); + //printf("Avg: %4.2f, Stdev: %4.2f\n", stdev.getAverage(), stdev.getStDev()); stdev.reset(); } } diff --git a/shared/src/AgentList.cpp b/shared/src/AgentList.cpp index c3f4183fcd..1e01487348 100644 --- a/shared/src/AgentList.cpp +++ b/shared/src/AgentList.cpp @@ -74,7 +74,7 @@ void AgentList::processAgentData(sockaddr *senderAddress, void *packetData, size updateList((unsigned char *)packetData, dataBytes); break; } - case PACKET_HEADER_HEAD: { + case PACKET_HEADER_HEAD_DATA: { // head data from another agent updateAgentWithData(senderAddress, packetData, dataBytes); break; @@ -324,7 +324,7 @@ void *checkInWithDomainServer(void *args) { sockaddr_in tempAddress; memcpy(&tempAddress.sin_addr, pHostInfo->h_addr_list[0], pHostInfo->h_length); strcpy(DOMAIN_IP, inet_ntoa(tempAddress.sin_addr)); - printf("Domain server %s: %s\n", DOMAIN_HOSTNAME, DOMAIN_IP); + printf("Domain server %s: \n", DOMAIN_HOSTNAME); } else { printf("Failed lookup domainserver\n"); diff --git a/shared/src/PacketHeaders.h b/shared/src/PacketHeaders.h index bc13cc625b..280aa69d70 100644 --- a/shared/src/PacketHeaders.h +++ b/shared/src/PacketHeaders.h @@ -15,6 +15,12 @@ const char PACKET_HEADER_DOMAIN = 'D'; const char PACKET_HEADER_PING = 'P'; const char PACKET_HEADER_PING_REPLY = 'R'; -const char PACKET_HEADER_HEAD = 'H'; +const char PACKET_HEADER_HEAD_DATA = 'H'; +const char PACKET_HEADER_Z_COMMAND = 'Z'; +const char PACKET_HEADER_INJECT_AUDIO = 'I'; +const char PACKET_HEADER_SET_VOXEL = 'S'; +const char PACKET_HEADER_ERASE_VOXEL = 'E'; +const char PACKET_HEADER_VOXEL_DATA = 'V'; +const char PACKET_HEADER_TRANSMITTER_DATA = 't'; #endif From 60dc43041fe7ed33c3e0cdd36bd92c9cbcc1fa8f Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 8 Apr 2013 22:42:45 -0700 Subject: [PATCH 15/33] added rendering lines between avatar bones --- interface/src/Head.cpp | 64 +++++++++++++++++++++++++++++++++--------- interface/src/Head.h | 2 +- interface/src/main.cpp | 2 ++ 3 files changed, 53 insertions(+), 15 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 1bad6e2021..35a3c547b7 100755 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -961,13 +961,13 @@ 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; + glm::vec3 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 ); + float distance = glm::length( armVector ); //------------------------------------------------------------------------------- @@ -979,10 +979,10 @@ void Head::updateHandMovement() // 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; + glm::vec3 armNormal = armVector / distance; + armVector = armNormal * (float)avatar.maxArmLength; distance = avatar.maxArmLength; - glm::dvec3 constrainedPosition = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].worldPosition; + glm::vec3 constrainedPosition = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].worldPosition; constrainedPosition += armVector; avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition = constrainedPosition; } @@ -990,8 +990,8 @@ void Head::updateHandMovement() //----------------------------------------------------------------------------- // set elbow position //----------------------------------------------------------------------------- - glm::dvec3 newElbowPosition = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].worldPosition; - newElbowPosition += armVector * ONE_HALF; + glm::vec3 newElbowPosition = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].worldPosition; + newElbowPosition += armVector * (float)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; @@ -1005,21 +1005,57 @@ void Head::renderBody() { glColor3fv(skinColor); + // Render bones as spheres for (int b=0; b Date: Tue, 9 Apr 2013 10:37:07 -0700 Subject: [PATCH 16/33] Adding new AgentTypes.h and moving over to new constants --- domain/src/main.cpp | 6 ++++-- interface/src/main.cpp | 3 ++- mixer/src/main.cpp | 3 ++- shared/src/AgentList.cpp | 13 ++++++++----- shared/src/AgentTypes.h | 21 +++++++++++++++++++++ voxel/src/main.cpp | 3 ++- 6 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 shared/src/AgentTypes.h diff --git a/domain/src/main.cpp b/domain/src/main.cpp index 7ef0967e1b..9235091660 100644 --- a/domain/src/main.cpp +++ b/domain/src/main.cpp @@ -25,6 +25,8 @@ #include #include #include "AgentList.h" +#include "AgentTypes.h" +#include #include "SharedUtil.h" #ifdef _WIN32 @@ -46,7 +48,7 @@ const int LOGOFF_CHECK_INTERVAL = 5000; #define DEBUG_TO_SELF 0 int lastActiveCount = 0; -AgentList agentList('D', DOMAIN_LISTEN_PORT); +AgentList agentList(AGENT_TYPE_DOMAIN, DOMAIN_LISTEN_PORT); unsigned char * addAgentToBroadcastPacket(unsigned char *currentPosition, Agent *agentToAdd) { *currentPosition++ = agentToAdd->getType(); @@ -82,7 +84,7 @@ int main(int argc, const char * argv[]) char agentType; unsigned char *broadcastPacket = new unsigned char[MAX_PACKET_SIZE]; - *broadcastPacket = 'D'; + *broadcastPacket = PACKET_HEADER_DOMAIN; unsigned char *currentBufferPos; unsigned char *startPointer; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index cb3341c9d9..b8e2c190e7 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -55,6 +55,7 @@ #include "Texture.h" #include "Cloud.h" #include +#include #include "VoxelSystem.h" #include "Lattice.h" #include "Finger.h" @@ -70,7 +71,7 @@ using namespace std; int audio_on = 1; // Whether to turn on the audio support int simulate_on = 1; -AgentList agentList('I'); +AgentList agentList(AGENT_TYPE_INTERFACE); pthread_t networkReceiveThread; bool stopNetworkReceiveThread = false; diff --git a/mixer/src/main.cpp b/mixer/src/main.cpp index 7a8705b645..10040a05a9 100644 --- a/mixer/src/main.cpp +++ b/mixer/src/main.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include "AudioRingBuffer.h" @@ -60,7 +61,7 @@ const int AGENT_LOOPBACK_MODIFIER = 307; const int LOOPBACK_SANITY_CHECK = 0; -AgentList agentList('M', MIXER_LISTEN_PORT); +AgentList agentList(AGENT_TYPE_MIXER, MIXER_LISTEN_PORT); StDev stdev; void plateauAdditionOfSamples(int16_t &mixSample, int16_t sampleToAdd) { diff --git a/shared/src/AgentList.cpp b/shared/src/AgentList.cpp index 1e01487348..aa04d99c9a 100644 --- a/shared/src/AgentList.cpp +++ b/shared/src/AgentList.cpp @@ -11,6 +11,7 @@ #include #include #include "AgentList.h" +#include "AgentTypes.h" #include "PacketHeaders.h" #include "SharedUtil.h" @@ -180,13 +181,13 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, newAgent.activatePublicSocket(); } - if (newAgent.getType() == 'M' && audioMixerSocketUpdate != NULL) { + if (newAgent.getType() == AGENT_TYPE_MIXER && audioMixerSocketUpdate != NULL) { // this is an audio mixer // for now that means we need to tell the audio class // to use the local socket information the domain server gave us sockaddr_in *publicSocketIn = (sockaddr_in *)publicSocket; audioMixerSocketUpdate(publicSocketIn->sin_addr.s_addr, publicSocketIn->sin_port); - } else if (newAgent.getType() == 'V') { + } else if (newAgent.getType() == AGENT_TYPE_VOXEL) { newAgent.activatePublicSocket(); } @@ -199,7 +200,7 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, return true; } else { - if (agent->getType() == 'M' || agent->getType() == 'V') { + if (agent->getType() == AGENT_TYPE_MIXER || agent->getType() == AGENT_TYPE_VOXEL) { // until the Audio class also uses our agentList, we need to update // the lastRecvTimeUsecs for the audio mixer so it doesn't get killed and re-added continously agent->setLastRecvTimeUsecs(usecTimestampNow()); @@ -210,6 +211,7 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, } } +// XXXBHG - do we want to move these? const char* AgentList::AGENTS_OF_TYPE_HEAD = "H"; const char* AgentList::AGENTS_OF_TYPE_VOXEL_AND_INTERFACE = "VI"; const char* AgentList::AGENTS_OF_TYPE_VOXEL = "V"; @@ -229,7 +231,7 @@ void AgentList::pingAgents() { *payload = PACKET_HEADER_PING; for(std::vector::iterator agent = agents.begin(); agent != agents.end(); agent++) { - if (agent->getType() == 'I') { + if (agent->getType() == AGENT_TYPE_INTERFACE) { if (agent->getActiveSocket() != NULL) { // we know which socket is good for this agent, send there agentSocket.send(agent->getActiveSocket(), payload, 1); @@ -268,7 +270,8 @@ void *removeSilentAgents(void *args) { pthread_mutex_t * agentDeleteMutex = &agent->deleteMutex; - if ((checkTimeUSecs - agent->getLastRecvTimeUsecs()) > AGENT_SILENCE_THRESHOLD_USECS && agent->getType() != 'V' + if ((checkTimeUSecs - agent->getLastRecvTimeUsecs()) > AGENT_SILENCE_THRESHOLD_USECS + && agent->getType() != AGENT_TYPE_VOXEL && pthread_mutex_trylock(agentDeleteMutex) == 0) { std::cout << "Killing agent " << &(*agent) << "\n"; diff --git a/shared/src/AgentTypes.h b/shared/src/AgentTypes.h new file mode 100644 index 0000000000..1d91f8cb65 --- /dev/null +++ b/shared/src/AgentTypes.h @@ -0,0 +1,21 @@ +// +// AgentTypes.h +// hifi +// +// Created by Brad Hefta-Gaub on 2013/04/09 +// +// +// Single byte/character Agent Types used to identify various agents in the system. +// For example, an agent whose is 'V' is always a voxel server. +// + +#ifndef hifi_AgentTypes_h +#define hifi_AgentTypes_h + +const char AGENT_TYPE_DOMAIN = 'D'; +const char AGENT_TYPE_VOXEL = 'V'; +const char AGENT_TYPE_INTERFACE = 'I'; // could also be injector??? +const char AGENT_TYPE_HEAD = 'H'; // Is this needed??? +const char AGENT_TYPE_MIXER = 'M'; + +#endif diff --git a/voxel/src/main.cpp b/voxel/src/main.cpp index 09834a2d3e..3990a82eac 100644 --- a/voxel/src/main.cpp +++ b/voxel/src/main.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "VoxelAgentData.h" #include @@ -45,7 +46,7 @@ const int PACKETS_PER_CLIENT_PER_INTERVAL = 2; const int MAX_VOXEL_TREE_DEPTH_LEVELS = 4; -AgentList agentList('V', VOXEL_LISTEN_PORT); +AgentList agentList(AGENT_TYPE_VOXEL, VOXEL_LISTEN_PORT); VoxelTree randomTree; bool wantColorRandomizer = false; From 87c26a39fb1c4eaf1d9cf9a471d973553159ae3a Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Tue, 9 Apr 2013 12:54:59 -0700 Subject: [PATCH 17/33] adding more changes and small improvements to camera, and head... --- interface/src/Camera.cpp | 6 +++ interface/src/Head.cpp | 80 ++++++++++------------------------------ interface/src/main.cpp | 31 ++++++++++++---- 3 files changed, 50 insertions(+), 67 deletions(-) diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index e7bf3d751b..1481456361 100755 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -33,5 +33,11 @@ void Camera::update() position = glm::dvec3( targetPosition ); position += glm::dvec3( x, y, z ); + + //geterate the ortho-normals for the orientation based on the Euler angles + orientation.setToIdentity(); + orientation.yaw ( yaw ); + orientation.pitch ( pitch ); + orientation.roll ( roll ); } diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 2b1222c09d..c6df7de2e9 100755 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -190,7 +190,7 @@ void Head::reset() - +//this pertains to moving the head with the glasses //--------------------------------------------------- void Head::UpdatePos(float frametime, SerialInterface * serialInterface, int head_mirror, glm::vec3 * gravity) // Using serial data, update avatar/render position and angles @@ -285,10 +285,7 @@ void Head::simulate(float deltaTime) 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)); @@ -296,93 +293,54 @@ void Head::simulate(float deltaTime) thrust = glm::vec3(0); */ - const float THRUST_MAG = 10.0; - - /* - const float THRUST_LATERAL_MAG = 10.0; - const float THRUST_VERTICAL_MAG = 10.0; - */ - + const float THRUST_MAG = 10.0; + 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]) { - //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; - + avatar.thrust.x += avatar.orientation.getRight().getX() * THRUST_LATERAL_MAG; + avatar.thrust.y += avatar.orientation.getRight().getY() * THRUST_LATERAL_MAG; + avatar.thrust.z -= avatar.orientation.getRight().getZ() * THRUST_LATERAL_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; - + avatar.thrust.x -= avatar.orientation.getRight().getX() * THRUST_LATERAL_MAG; + avatar.thrust.y -= avatar.orientation.getRight().getY() * THRUST_LATERAL_MAG; + avatar.thrust.z += avatar.orientation.getRight().getZ() * THRUST_LATERAL_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; - + avatar.thrust.x -= avatar.orientation.getUp().getX() * THRUST_VERTICAL_MAG; + avatar.thrust.y -= avatar.orientation.getUp().getY() * THRUST_VERTICAL_MAG; + avatar.thrust.z += avatar.orientation.getUp().getZ() * THRUST_VERTICAL_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; - + avatar.thrust.x += avatar.orientation.getUp().getX() * THRUST_VERTICAL_MAG; + avatar.thrust.y += avatar.orientation.getUp().getY() * THRUST_VERTICAL_MAG; + avatar.thrust.z -= avatar.orientation.getUp().getZ() * THRUST_VERTICAL_MAG; //thrust.y += THRUST_VERTICAL_MAG; } @@ -1055,7 +1013,9 @@ void Head::parseData(void *data, int size) &Pitch, &Yaw, &Roll, &position.x, &position.y, &position.z, &loudness, &averageLoudness, - &handPos.x, &handPos.y, &handPos.z + &avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition.x, + &avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition.y, + &avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition.z ); if (glm::length(handPos) > 0.0) hand->setPos(handPos); diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 64d4e774c5..edaee1095a 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -608,7 +608,7 @@ void display(void) { myCamera.setYaw ( - myHead.getAvatarYaw() ); myCamera.setUp ( 0.4 ); - myCamera.setDistance( 0.08 ); + myCamera.setDistance( 0.5 ); myCamera.update(); } else @@ -618,7 +618,7 @@ void display(void) { myCamera.setYaw ( 180.0 - myHead.getAvatarYaw() ); myCamera.setUp ( 0.15 ); - myCamera.setDistance( 0.08 ); + myCamera.setDistance( 1.0 ); myCamera.update(); } @@ -653,14 +653,16 @@ void display(void) // if (!display_head) cloud.render(); // Draw voxels - voxels.render(); +//voxels.render(); // Draw field vectors if (display_field) field.render(); // Render heads of other agents - for(std::vector::iterator agent = agentList.getAgents().begin(); agent != agentList.getAgents().end(); agent++) { - if (agent->getLinkedData() != NULL) { + for(std::vector::iterator agent = agentList.getAgents().begin(); agent != agentList.getAgents().end(); agent++) + { + if (agent->getLinkedData() != NULL) + { Head *agentHead = (Head *)agent->getLinkedData(); glPushMatrix(); glm::vec3 pos = agentHead->getPos(); @@ -670,7 +672,7 @@ void display(void) } } - if (!display_head) balls.render(); + if ( !display_head ) balls.render(); // Render the world box if (!display_head && stats_on) render_world_box(); @@ -1046,6 +1048,21 @@ void idle(void) // Simulation simulateHead(1.f/FPS); + + + //test + /* + // simulate the other agents + for(std::vector::iterator agent = agentList.getAgents().begin(); agent != agentList.getAgents().end(); agent++) + { + if (agent->getLinkedData() != NULL) + { + Head *agentHead = (Head *)agent->getLinkedData(); + agentHead->simulate(1.f/FPS); + } + } + */ + simulateHand(1.f/FPS); if (simulate_on) { @@ -1078,7 +1095,7 @@ void reshape(int width, int height) glMatrixMode(GL_PROJECTION); //hello fov.setResolution(width, height) .setBounds(glm::vec3(-0.5f,-0.5f,-500.0f), glm::vec3(0.5f, 0.5f, 0.1f) ) - .setPerspective(0.7854f); + .setPerspective(0.7854f); glLoadMatrixf(glm::value_ptr(fov.getViewerScreenXform())); glMatrixMode(GL_MODELVIEW); From 712997451bda7398730660279dfa6ac76c5a1936 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 9 Apr 2013 13:00:20 -0700 Subject: [PATCH 18/33] Adding friendly names to AgentType display. --- shared/src/Agent.cpp | 35 +++++++++++++++++++++++++++++++++-- shared/src/Agent.h | 3 ++- shared/src/AgentTypes.h | 6 ++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/shared/src/Agent.cpp b/shared/src/Agent.cpp index 677b4884fe..e9e62f3c66 100644 --- a/shared/src/Agent.cpp +++ b/shared/src/Agent.cpp @@ -7,6 +7,7 @@ // #include "Agent.h" +#include "AgentTypes.h" #include #include "UDPSocket.h" #include "SharedUtil.h" @@ -90,10 +91,40 @@ Agent::~Agent() { delete linkedData; } -char Agent::getType() { +char Agent::getType() const { return type; } +// Names of Agent Types +const char* AGENT_TYPE_NAME_DOMAIN = "Domain"; +const char* AGENT_TYPE_NAME_VOXEL = "Voxel Server"; +const char* AGENT_TYPE_NAME_INTERFACE = "Client Interface"; +const char* AGENT_TYPE_NAME_HEAD = "Avatar Head"; // Is this needed??? +const char* AGENT_TYPE_NAME_MIXER = "Audio Mixer"; +const char* AGENT_TYPE_NAME_UNKNOWN = "Unknown"; + +const char* Agent::getTypeName() const { + const char* name = AGENT_TYPE_NAME_UNKNOWN; + switch (this->type) { + case AGENT_TYPE_DOMAIN: + name = AGENT_TYPE_NAME_DOMAIN; + break; + case AGENT_TYPE_VOXEL: + name = AGENT_TYPE_NAME_VOXEL; + break; + case AGENT_TYPE_INTERFACE: + name = AGENT_TYPE_NAME_INTERFACE; + break; + case AGENT_TYPE_HEAD: + name = AGENT_TYPE_NAME_HEAD; + break; + case AGENT_TYPE_MIXER: + name = AGENT_TYPE_NAME_MIXER; + break; + } + return name; +} + void Agent::setType(char newType) { type = newType; } @@ -174,7 +205,7 @@ std::ostream& operator<<(std::ostream& os, const Agent* agent) { sockaddr_in *agentPublicSocket = (sockaddr_in *)agent->publicSocket; sockaddr_in *agentLocalSocket = (sockaddr_in *)agent->localSocket; - os << "T: " << agent->type << " PA: " << inet_ntoa(agentPublicSocket->sin_addr) << + os << "T: " << agent->getTypeName() << " (" << agent->type << ") PA: " << inet_ntoa(agentPublicSocket->sin_addr) << ":" << ntohs(agentPublicSocket->sin_port) << " LA: " << inet_ntoa(agentLocalSocket->sin_addr) << ":" << ntohs(agentLocalSocket->sin_port); return os; diff --git a/shared/src/Agent.h b/shared/src/Agent.h index 1b86e95e9b..bc6a6eb714 100644 --- a/shared/src/Agent.h +++ b/shared/src/Agent.h @@ -40,7 +40,8 @@ public: pthread_mutex_t deleteMutex; - char getType(); + char getType() const; + const char* getTypeName() const; void setType(char newType); uint16_t getAgentId(); void setAgentId(uint16_t thisAgentId); diff --git a/shared/src/AgentTypes.h b/shared/src/AgentTypes.h index 1d91f8cb65..fdfce9af8b 100644 --- a/shared/src/AgentTypes.h +++ b/shared/src/AgentTypes.h @@ -12,6 +12,12 @@ #ifndef hifi_AgentTypes_h #define hifi_AgentTypes_h +// NOTE: If you add a new AGENT_TYPE_XXX then you also should add a new AGENT_TYPE_NAME_XXX and a new "case" to the +// switch statement in Agent.cpp specifically Agent::getTypeName(). +// If you don't then it will make things harder on your co-developers in debugging because the Agent +// class won't know the name and will report it as "Unknown". + +// Agent Type Codes const char AGENT_TYPE_DOMAIN = 'D'; const char AGENT_TYPE_VOXEL = 'V'; const char AGENT_TYPE_INTERFACE = 'I'; // could also be injector??? From f5634a66aae1c7a0fffe99184236ebb868e1c785 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 9 Apr 2013 13:27:15 -0700 Subject: [PATCH 19/33] Got rid of AGENT_TYPE_HEAD and fixed voxel server to use AGENT_TYPE_INTERFACE --- shared/src/Agent.cpp | 4 ---- shared/src/AgentList.cpp | 4 ++-- shared/src/AgentList.h | 5 ++--- shared/src/AgentTypes.h | 1 - voxel/src/main.cpp | 8 +++++--- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/shared/src/Agent.cpp b/shared/src/Agent.cpp index e9e62f3c66..0e8a98efc1 100644 --- a/shared/src/Agent.cpp +++ b/shared/src/Agent.cpp @@ -99,7 +99,6 @@ char Agent::getType() const { const char* AGENT_TYPE_NAME_DOMAIN = "Domain"; const char* AGENT_TYPE_NAME_VOXEL = "Voxel Server"; const char* AGENT_TYPE_NAME_INTERFACE = "Client Interface"; -const char* AGENT_TYPE_NAME_HEAD = "Avatar Head"; // Is this needed??? const char* AGENT_TYPE_NAME_MIXER = "Audio Mixer"; const char* AGENT_TYPE_NAME_UNKNOWN = "Unknown"; @@ -115,9 +114,6 @@ const char* Agent::getTypeName() const { case AGENT_TYPE_INTERFACE: name = AGENT_TYPE_NAME_INTERFACE; break; - case AGENT_TYPE_HEAD: - name = AGENT_TYPE_NAME_HEAD; - break; case AGENT_TYPE_MIXER: name = AGENT_TYPE_NAME_MIXER; break; diff --git a/shared/src/AgentList.cpp b/shared/src/AgentList.cpp index aa04d99c9a..1add03d6ff 100644 --- a/shared/src/AgentList.cpp +++ b/shared/src/AgentList.cpp @@ -212,9 +212,9 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, } // XXXBHG - do we want to move these? -const char* AgentList::AGENTS_OF_TYPE_HEAD = "H"; -const char* AgentList::AGENTS_OF_TYPE_VOXEL_AND_INTERFACE = "VI"; const char* AgentList::AGENTS_OF_TYPE_VOXEL = "V"; +const char* AgentList::AGENTS_OF_TYPE_INTERFACE = "I"; +const char* AgentList::AGENTS_OF_TYPE_VOXEL_AND_INTERFACE = "VI"; void AgentList::broadcastToAgents(char *broadcastData, size_t dataBytes,const char* agentTypes) { for(std::vector::iterator agent = agents.begin(); agent != agents.end(); agent++) { diff --git a/shared/src/AgentList.h b/shared/src/AgentList.h index ca6d844b48..e3de23154f 100644 --- a/shared/src/AgentList.h +++ b/shared/src/AgentList.h @@ -67,10 +67,9 @@ public: void startDomainServerCheckInThread(); void stopDomainServerCheckInThread(); - static const char* AGENTS_OF_TYPE_HEAD; - static const char* AGENTS_OF_TYPE_VOXEL_AND_INTERFACE; static const char* AGENTS_OF_TYPE_VOXEL; - + static const char* AGENTS_OF_TYPE_INTERFACE; + static const char* AGENTS_OF_TYPE_VOXEL_AND_INTERFACE; }; int unpackAgentId(unsigned char *packedData, uint16_t *agentId); diff --git a/shared/src/AgentTypes.h b/shared/src/AgentTypes.h index fdfce9af8b..43c1239912 100644 --- a/shared/src/AgentTypes.h +++ b/shared/src/AgentTypes.h @@ -21,7 +21,6 @@ const char AGENT_TYPE_DOMAIN = 'D'; const char AGENT_TYPE_VOXEL = 'V'; const char AGENT_TYPE_INTERFACE = 'I'; // could also be injector??? -const char AGENT_TYPE_HEAD = 'H'; // Is this needed??? const char AGENT_TYPE_MIXER = 'M'; #endif diff --git a/voxel/src/main.cpp b/voxel/src/main.cpp index 3990a82eac..01b63d63b6 100644 --- a/voxel/src/main.cpp +++ b/voxel/src/main.cpp @@ -345,7 +345,7 @@ int main(int argc, const char * argv[]) // Now send this to the connected agents so they know to delete printf("rebroadcasting delete voxel message to connected agents... agentList.broadcastToAgents()\n"); - agentList.broadcastToAgents(packetData,receivedBytes,AgentList::AGENTS_OF_TYPE_HEAD); + agentList.broadcastToAgents(packetData,receivedBytes,AgentList::AGENTS_OF_TYPE_INTERFACE); } if (packetData[0] == PACKET_HEADER_Z_COMMAND) { @@ -373,12 +373,14 @@ int main(int argc, const char * argv[]) // Now send this to the connected agents so they can also process these messages printf("rebroadcasting Z message to connected agents... agentList.broadcastToAgents()\n"); - agentList.broadcastToAgents(packetData,receivedBytes,AgentList::AGENTS_OF_TYPE_HEAD); + agentList.broadcastToAgents(packetData,receivedBytes,AgentList::AGENTS_OF_TYPE_INTERFACE); } + // If we got a PACKET_HEADER_HEAD_DATA, then we're talking to an AGENT_TYPE_INTERFACE, and we + // need to make sure we have it in our agentList. if (packetData[0] == PACKET_HEADER_HEAD_DATA) { if (agentList.addOrUpdateAgent(&agentPublicAddress, &agentPublicAddress, - packetData[0], + AGENT_TYPE_INTERFACE, agentList.getLastAgentId())) { agentList.increaseAgentId(); } From 42e1355f1eccaf06dd1819029a753be3731d240c Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 9 Apr 2013 14:11:55 -0700 Subject: [PATCH 20/33] add back voxels.render() call --- interface/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 2458318812..83a07bb32e 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -657,7 +657,7 @@ void display(void) // if (!display_head) cloud.render(); // Draw voxels -//voxels.render(); + voxels.render(); // Draw field vectors if (display_field) field.render(); From ff53b1573c93cb9b6047c9068604c12a4f566096 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Tue, 9 Apr 2013 14:35:29 -0700 Subject: [PATCH 21/33] fixed bug in avatar arm IK prototype --- interface/src/Head.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 84c7232fed..de2b1410a5 100755 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -927,7 +927,6 @@ void Head::updateHandMovement() //------------------------------------------------------------------------------- float distance = glm::length( armVector ); - //------------------------------------------------------------------------------- // if right hand is being dragged beyond maximum arm length... //------------------------------------------------------------------------------- @@ -952,7 +951,16 @@ void Head::updateHandMovement() newElbowPosition += armVector * (float)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; + avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].worldPosition = newElbowPosition; + + //----------------------------------------------------------------------------- + // set wrist position + //----------------------------------------------------------------------------- + glm::vec3 vv( avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition ); + vv -= avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].worldPosition; + glm::vec3 newWristPosition = avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].worldPosition; + newWristPosition += vv * 0.7f; + avatar.bone[ AVATAR_BONE_RIGHT_FOREARM ].worldPosition = newWristPosition; } From 7d42b93489b893013d92ed4bdf4f8951f5c34fb0 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Tue, 9 Apr 2013 14:45:19 -0700 Subject: [PATCH 22/33] condensed avatar bone line code --- interface/src/Head.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index de2b1410a5..309a192512 100755 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -736,7 +736,7 @@ void Head::initializeAvatar() //---------------------------------------------------------------------------- // left pelvis and leg //---------------------------------------------------------------------------- - avatar.bone[ AVATAR_BONE_LEFT_PELVIS ].parent = AVATAR_BONE_NULL; + avatar.bone[ AVATAR_BONE_LEFT_PELVIS ].parent = AVATAR_BONE_PELVIS_SPINE; 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; @@ -744,7 +744,7 @@ void Head::initializeAvatar() //---------------------------------------------------------------------------- // right pelvis and leg //---------------------------------------------------------------------------- - avatar.bone[ AVATAR_BONE_RIGHT_PELVIS ].parent = AVATAR_BONE_NULL; + avatar.bone[ AVATAR_BONE_RIGHT_PELVIS ].parent = AVATAR_BONE_PELVIS_SPINE; 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; @@ -971,7 +971,9 @@ void Head::renderBody() { glColor3fv(skinColor); + //----------------------------------------- // Render bones as spheres + //----------------------------------------- for (int b=0; b Date: Tue, 9 Apr 2013 15:05:37 -0700 Subject: [PATCH 23/33] added camera modes and also set initial avatar yaw to 90 --- interface/src/Camera.cpp | 5 +++++ interface/src/Camera.h | 14 +++++++++++++ interface/src/Head.cpp | 6 +++--- interface/src/main.cpp | 44 ++++++++++++++++++---------------------- 4 files changed, 42 insertions(+), 27 deletions(-) diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index 1481456361..4eb0101eda 100755 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -11,6 +11,8 @@ //------------------------ Camera::Camera() { + mode = CAMERA_MODE_THIRD_PERSON; + fieldOfView = 60.0; // default yaw = 0.0; pitch = 0.0; roll = 0.0; @@ -22,6 +24,7 @@ Camera::Camera() } + //------------------------ void Camera::update() { @@ -34,7 +37,9 @@ void Camera::update() position = glm::dvec3( targetPosition ); position += glm::dvec3( x, y, z ); + //------------------------------------------------------------------------ //geterate the ortho-normals for the orientation based on the Euler angles + //------------------------------------------------------------------------ orientation.setToIdentity(); orientation.yaw ( yaw ); orientation.pitch ( pitch ); diff --git a/interface/src/Camera.h b/interface/src/Camera.h index eed70c1c92..bee20829eb 100755 --- a/interface/src/Camera.h +++ b/interface/src/Camera.h @@ -12,6 +12,16 @@ #include "Orientation.h" #include +enum CameraMode +{ + CAMERA_MODE_NULL = -1, + CAMERA_MODE_FIRST_PERSON, + CAMERA_MODE_THIRD_PERSON, + CAMERA_MODE_MY_OWN_FACE, + NUM_CAMERA_MODES +}; + + class Camera { public: @@ -19,6 +29,7 @@ public: void update(); + void setMode ( CameraMode m ) { mode = m; } void setYaw ( double y ) { yaw = y; } void setPitch ( double p ) { pitch = p; } void setRoll ( double r ) { roll = r; } @@ -33,11 +44,14 @@ public: double getRoll () { return roll; } glm::dvec3 getPosition () { return position; } Orientation getOrientation () { return orientation; } + CameraMode getMode () { return mode; } private: + CameraMode mode; glm::dvec3 position; glm::dvec3 targetPosition; + double fieldOfView; double yaw; double pitch; double roll; diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 309a192512..8167e80e89 100755 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -688,9 +688,9 @@ void Head::initializeAvatar() 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.yaw = 90.0; + avatar.pitch = 0.0; + avatar.roll = 0.0; avatar.yawDelta = 0.0; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 83a07bb32e..9618f2c020 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -596,49 +596,45 @@ void display(void) glMaterialfv(GL_FRONT, GL_SPECULAR, specular_color); glMateriali(GL_FRONT, GL_SHININESS, 96); - //------------------------------------------------------------------------------------- - // set the camera to third-person view - //------------------------------------------------------------------------------------- + //-------------------------------------------------------- + // camera settings + //-------------------------------------------------------- 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 - //------------------------------------------------------------------------------------- { + //----------------------------------------------- + // set the camera to looking at my own face + //----------------------------------------------- myCamera.setYaw ( - myHead.getAvatarYaw() ); + myCamera.setPitch ( 0.0 ); + myCamera.setRoll ( 0.0 ); myCamera.setUp ( 0.4 ); - myCamera.setDistance( 0.5 ); + myCamera.setDistance( 0.5 ); myCamera.setDistance( 0.08 ); myCamera.update(); } else - //------------------------------------------------------------------------------------- - // set the camera to third-person view - //------------------------------------------------------------------------------------- { + //---------------------------------------------------- + // set the camera to third-person view behind my av + //---------------------------------------------------- myCamera.setYaw ( 180.0 - myHead.getAvatarYaw() ); - myCamera.setUp ( 0.15 ); - myCamera.setDistance( 1.0 ); - myCamera.setDistance( 0.08 ); + myCamera.setPitch ( 10.0 ); + myCamera.setRoll ( 0.0 ); + myCamera.setUp ( 0.2 ); + myCamera.setDistance( 1.6 ); + myCamera.setDistance( 0.5 ); myCamera.update(); } - //------------------------------------------------------------------------------------- - // transform to camera view - //------------------------------------------------------------------------------------- + //--------------------------------------------- + // transform view according to myCamera + //--------------------------------------------- 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 From 3dae70e665f1940a463c6f701fa62825d65f01f3 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Tue, 9 Apr 2013 15:23:59 -0700 Subject: [PATCH 24/33] removed glm::dvec3 and replaced with glm::vec3 in most of avatar code, except for velocity --- interface/src/Camera.h | 38 ++++++++--------- interface/src/Head.cpp | 97 +++++++++++++++++++++--------------------- interface/src/Head.h | 32 +++++++------- interface/src/main.cpp | 16 +++---- 4 files changed, 91 insertions(+), 92 deletions(-) diff --git a/interface/src/Camera.h b/interface/src/Camera.h index bee20829eb..02c063c42e 100755 --- a/interface/src/Camera.h +++ b/interface/src/Camera.h @@ -30,33 +30,33 @@ public: void update(); void setMode ( CameraMode m ) { mode = m; } - 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 setYaw ( float y ) { yaw = y; } + void setPitch ( float p ) { pitch = p; } + void setRoll ( float r ) { roll = r; } + void setUp ( float u ) { up = u; } + void setDistance ( float d ) { distance = d; } + void setTargetPosition ( glm::vec3 t ) { targetPosition = t; }; + void setPosition ( glm::vec3 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; } + float getYaw () { return yaw; } + float getPitch () { return pitch; } + float getRoll () { return roll; } + glm::vec3 getPosition () { return position; } Orientation getOrientation () { return orientation; } CameraMode getMode () { return mode; } private: CameraMode mode; - glm::dvec3 position; - glm::dvec3 targetPosition; - double fieldOfView; - double yaw; - double pitch; - double roll; - double up; - double distance; + glm::vec3 position; + glm::vec3 targetPosition; + float fieldOfView; + float yaw; + float pitch; + float roll; + float up; + float distance; Orientation orientation; }; diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 8167e80e89..3e7512a8b7 100755 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -239,9 +239,9 @@ void Head::UpdatePos(float frametime, SerialInterface * serialInterface, int hea //--------------------------------------------------- -void Head::setAvatarPosition( double x, double y, double z ) +void Head::setAvatarPosition( float x, float y, float z ) { - avatar.position = glm::dvec3( x, y, z ); + avatar.position = glm::vec3( x, y, z ); } @@ -297,7 +297,7 @@ void Head::simulate(float deltaTime) const float THRUST_LATERAL_MAG = 10.0; const float THRUST_VERTICAL_MAG = 10.0; - avatar.thrust = glm::dvec3( 0.0, 0.0, 0.0 ); + avatar.thrust = glm::vec3( 0.0, 0.0, 0.0 ); if (driveKeys[FWD]) { @@ -362,9 +362,9 @@ void Head::simulate(float deltaTime) //avatar.yawDelta *= 0.99; - avatar.velocity += avatar.thrust * (double)deltaTime; + avatar.velocity += glm::dvec3( avatar.thrust * deltaTime ); - position += avatar.velocity * (double)deltaTime; + position += (glm::vec3)avatar.velocity * deltaTime; //avatar.velocity *= 0.9; @@ -673,9 +673,9 @@ void Head::renderHead( int faceToFace, int isMine ) //--------------------------------------------------------- -void Head::setHandMovement( glm::dvec3 movement ) +void Head::setHandMovement( glm::vec3 movement ) { - handOffset = glm::dvec3( movement.x, -movement.y, movement.z ); + handOffset = glm::vec3( movement.x, -movement.y, movement.z ); } @@ -683,9 +683,9 @@ void Head::setHandMovement( glm::dvec3 movement ) //----------------------------------------- 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.position = glm::vec3( 0.0, 0.0, 0.0 ); + avatar.velocity = glm::vec3( 0.0, 0.0, 0.0 ); + avatar.thrust = glm::vec3( 0.0, 0.0, 0.0 ); avatar.orientation.setToIdentity(); avatar.yaw = 90.0; @@ -696,9 +696,8 @@ void Head::initializeAvatar() for (int b=0; b Date: Tue, 9 Apr 2013 17:12:43 -0700 Subject: [PATCH 25/33] Changed to render a small box of a fixed pixel width at screen center, useful for testing LOD Changes. --- interface/src/main.cpp | 17 ++++++++++++----- interface/src/starfield/Loader.h | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index cb3341c9d9..d91f644805 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -727,12 +727,19 @@ void display(void) } if (display_head_mouse && !display_head && stats_on) { - glPointSize(10.0f); - glColor4f(1.0, 1.0, 0.0, 0.8); - glEnable(GL_POINT_SMOOTH); - glBegin(GL_POINTS); - glVertex2f(head_mouse_x, head_mouse_y); + // Display small target box at center or head mouse target that can also be used to measure LOD + glColor3f(1.0, 1.0, 1.0); + glDisable(GL_LINE_SMOOTH); + const int PIXEL_BOX = 20; + glBegin(GL_LINE_STRIP); + glVertex2f(head_mouse_x - PIXEL_BOX/2, head_mouse_y - PIXEL_BOX/2); + glVertex2f(head_mouse_x + PIXEL_BOX/2, head_mouse_y - PIXEL_BOX/2); + glVertex2f(head_mouse_x + PIXEL_BOX/2, head_mouse_y + PIXEL_BOX/2); + glVertex2f(head_mouse_x - PIXEL_BOX/2, head_mouse_y + PIXEL_BOX/2); + glVertex2f(head_mouse_x - PIXEL_BOX/2, head_mouse_y - PIXEL_BOX/2); glEnd(); + + glEnable(GL_LINE_SMOOTH); } // Spot bouncing back and forth on bottom of screen if (0) diff --git a/interface/src/starfield/Loader.h b/interface/src/starfield/Loader.h index 0db0384734..83d63adc2c 100644 --- a/interface/src/starfield/Loader.h +++ b/interface/src/starfield/Loader.h @@ -50,7 +50,7 @@ namespace starfield { return false; } - fprintf(stderr, "Stars.cpp: read %d vertices, using %d\n", + fprintf(stderr, "Stars.cpp: read %d stars, rendering %d\n", _valRecordsRead, _ptrVertices->size()); return true; From 81b311f75385f0b0a597174c35ad983b9b23e0ff Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Tue, 9 Apr 2013 18:41:01 -0700 Subject: [PATCH 26/33] added a method to ask the avatar for it's head lookat vector --- interface/src/Head.cpp | 64 ++++++++++++++++++++---------------------- interface/src/Head.h | 1 + 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 3e7512a8b7..d06f35cc39 100755 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -272,7 +272,7 @@ void Head::setLeanSideways(float dist){ -// Simulate the head over time +// Simulate the avatar over time //--------------------------------------------------- void Head::simulate(float deltaTime) { @@ -293,64 +293,50 @@ void Head::simulate(float deltaTime) thrust = glm::vec3(0); */ - const float THRUST_MAG = 10.0; - const float THRUST_LATERAL_MAG = 10.0; - const float THRUST_VERTICAL_MAG = 10.0; + const float THRUST_MAG = 10.0; + const float YAW_MAG = 300.0; avatar.thrust = glm::vec3( 0.0, 0.0, 0.0 ); - + + //notice that the z values from avatar.orientation are flipped to accommodate different coordinate system if (driveKeys[FWD]) { - 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; + glm::vec3 front( avatar.orientation.getFront().getX(), avatar.orientation.getFront().getY(), -avatar.orientation.getFront().getZ() ); + avatar.thrust += front * THRUST_MAG; } if (driveKeys[BACK]) { - 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; + glm::vec3 front( avatar.orientation.getFront().getX(), avatar.orientation.getFront().getY(), -avatar.orientation.getFront().getZ() ); + avatar.thrust -= front * THRUST_MAG; } if (driveKeys[RIGHT]) { - avatar.thrust.x += avatar.orientation.getRight().getX() * THRUST_LATERAL_MAG; - avatar.thrust.y += avatar.orientation.getRight().getY() * THRUST_LATERAL_MAG; - avatar.thrust.z -= avatar.orientation.getRight().getZ() * THRUST_LATERAL_MAG; - //thrust.x += forward.z*-THRUST_LATERAL_MAG; - //thrust.z += forward.x*THRUST_LATERAL_MAG; + glm::vec3 right( avatar.orientation.getRight().getX(), avatar.orientation.getRight().getY(), -avatar.orientation.getRight().getZ() ); + avatar.thrust += right * THRUST_MAG; } if (driveKeys[LEFT]) { - avatar.thrust.x -= avatar.orientation.getRight().getX() * THRUST_LATERAL_MAG; - avatar.thrust.y -= avatar.orientation.getRight().getY() * THRUST_LATERAL_MAG; - avatar.thrust.z += avatar.orientation.getRight().getZ() * THRUST_LATERAL_MAG; - //thrust.x += forward.z*THRUST_LATERAL_MAG; - //thrust.z += forward.x*-THRUST_LATERAL_MAG; + glm::vec3 right( avatar.orientation.getRight().getX(), avatar.orientation.getRight().getY(), -avatar.orientation.getRight().getZ() ); + avatar.thrust -= right * THRUST_MAG; } if (driveKeys[UP]) { - avatar.thrust.x -= avatar.orientation.getUp().getX() * THRUST_VERTICAL_MAG; - avatar.thrust.y -= avatar.orientation.getUp().getY() * THRUST_VERTICAL_MAG; - avatar.thrust.z += avatar.orientation.getUp().getZ() * THRUST_VERTICAL_MAG; - //thrust.y += -THRUST_VERTICAL_MAG; + glm::vec3 up( avatar.orientation.getUp().getX(), avatar.orientation.getUp().getY(), -avatar.orientation.getUp().getZ() ); + avatar.thrust += up * THRUST_MAG; } if (driveKeys[DOWN]) { - avatar.thrust.x += avatar.orientation.getUp().getX() * THRUST_VERTICAL_MAG; - avatar.thrust.y += avatar.orientation.getUp().getY() * THRUST_VERTICAL_MAG; - avatar.thrust.z -= avatar.orientation.getUp().getZ() * THRUST_VERTICAL_MAG; - //thrust.y += THRUST_VERTICAL_MAG; + glm::vec3 up( avatar.orientation.getUp().getX(), avatar.orientation.getUp().getY(), -avatar.orientation.getUp().getZ() ); + avatar.thrust -= up * THRUST_MAG; } if (driveKeys[ROT_RIGHT]) { - avatar.yawDelta -= 300.0 * deltaTime; + avatar.yawDelta -= YAW_MAG * deltaTime; } if (driveKeys[ROT_LEFT]) { - avatar.yawDelta += 300.0 * deltaTime; + avatar.yawDelta += YAW_MAG * deltaTime; } avatar.yaw += avatar.yawDelta * deltaTime; @@ -910,6 +896,18 @@ float Head::getAvatarYaw() } +//------------------------------------------- +glm::vec3 Head::getAvatarHeadLookatDirection() +{ + return glm::vec3 + ( + avatar.bone[ AVATAR_BONE_HEAD ].worldOrientation.getFront().x, + avatar.bone[ AVATAR_BONE_HEAD ].worldOrientation.getFront().y, + avatar.bone[ AVATAR_BONE_HEAD ].worldOrientation.getFront().z + ); +} + + //------------------------------- void Head::updateHandMovement() diff --git a/interface/src/Head.h b/interface/src/Head.h index 964d44ece4..f8008ae857 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -158,6 +158,7 @@ class Head : public AgentData { float getLastMeasuredYaw() {return YawRate;} float getAvatarYaw(); + glm::vec3 getAvatarHeadLookatDirection(); void render(int faceToFace, int isMine); From 1b833fb4a9d2daa2e8adf80d5847913b7af8e61a Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Tue, 9 Apr 2013 21:14:24 -0700 Subject: [PATCH 27/33] added grid plane to aid in testing avatar navigation --- interface/src/Head.h | 18 ++++++------ interface/src/main.cpp | 65 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 69 insertions(+), 14 deletions(-) diff --git a/interface/src/Head.h b/interface/src/Head.h index f8008ae857..bf8318ef61 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -103,15 +103,15 @@ enum AvatarBones struct AvatarBone { - AvatarBones parent; - glm::vec3 worldPosition; - glm::vec3 defaultPosePosition; - glm::dvec3 velocity; - float yaw; - float pitch; - float roll; - Orientation worldOrientation; - float length; + AvatarBones parent; // which bone is this bone connected to? + glm::vec3 worldPosition; // the position at the "end" of the bone + glm::vec3 defaultPosePosition; // the parent relative position when the avatar is in the "T-pose" + glm::dvec3 velocity; // pertains to spring physics + float yaw; // the yaw Euler angle of the bone rotation off the parent + float pitch; // the pitch Euler angle of the bone rotation off the parent + float roll; // the roll Euler angle of the bone rotation off the parent + Orientation worldOrientation; // three orthogonal normals determined by yaw, pitch, roll + float length; // the length of the bone }; struct Avatar diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 2fed06120d..52b6df6c68 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -109,6 +109,8 @@ int starsTiles = 20; double starsLod = 1.0; #endif +bool showingVoxels = false; + glm::vec3 box(WORLD_SIZE,WORLD_SIZE,WORLD_SIZE); ParticleSystem balls(0, box, @@ -569,8 +571,42 @@ int render_test_direction = 1; +void drawGroundPlaneGrid( float size, int resolution ) +{ + + glColor3f( 0.4f, 0.5f, 0.3f ); + glLineWidth(2.0); + + float gridSize = 10.0; + int gridResolution = 10; + + for (int g=0; g Date: Wed, 10 Apr 2013 00:25:03 -0700 Subject: [PATCH 28/33] Improved comments at start of main.cpp, dropped unused octal.h,.cpp files, deleted many unused system variables and functions. --- interface/src/main.cpp | 377 +++++++++++++++------------------------- interface/src/octal.cpp | 29 ---- interface/src/octal.h | 26 --- 3 files changed, 138 insertions(+), 294 deletions(-) delete mode 100644 interface/src/octal.cpp delete mode 100644 interface/src/octal.h diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 72e7d51bf3..aaa05f47b0 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -1,16 +1,25 @@ -// // // Interface -// -// Show a field of objects rendered in 3D, with yaw and pitch of scene driven -// by accelerometer data -// serial port connected to Maple board/arduino. +// +// Allows you to connect to and see/hear the shared 3D space. +// Optionally uses serialUSB connection to get gyro data for head movement. +// Optionally gets UDP stream from transmitter to animate controller/hand. +// +// Usage: The interface client first attempts to contact a domain server to +// discover the appropriate audio, voxel, and avatar servers to contact. +// Right now, the default domain server is "highfidelity.below92.com" +// You can change the domain server to use your own by editing the +// DOMAIN_HOSTNAME or DOMAIN_IP strings in the file AgentList.cpp +// +// +// Welcome Aboard! +// // // Keyboard Commands: // // / = toggle stats display -// spacebar = reset gyros/head -// h = render Head +// spacebar = reset gyros/head position +// h = render Head facing yourself (mirror) // l = show incoming gyro levels // @@ -68,41 +77,31 @@ using namespace std; -int audio_on = 1; // Whether to turn on the audio support -int simulate_on = 1; - AgentList agentList(AGENT_TYPE_INTERFACE); pthread_t networkReceiveThread; bool stopNetworkReceiveThread = false; -// For testing, add milliseconds of delay for received UDP packets -int packetcount = 0; -int packets_per_second = 0; -int bytes_per_second = 0; -int bytescount = 0; +int packetCount = 0; +int packetsPerSecond = 0; +int bytesPerSecond = 0; +int bytesCount = 0; -// Getting a target location from other machine (or loopback) to display -int target_x, target_y; -int target_display = 0; +int headMirror = 1; // Whether to mirror own head when viewing it -int head_mirror = 1; // Whether to mirror own head when viewing it -int sendToSelf = 1; - -int WIDTH = 1200; -int HEIGHT = 800; +int WIDTH = 1200; // Window size +int HEIGHT = 800; int fullscreen = 0; -bool wantColorRandomizer = true; // for addSphere and load file +bool wantColorRandomizer = true; // for addSphere and load file 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 :) + // Starfield information char starFile[] = "https://s3-us-west-1.amazonaws.com/highfidelity/stars.txt"; FieldOfView fov; - Stars stars; #ifdef STARFIELD_KEYS int starsTiles = 20; @@ -110,15 +109,16 @@ double starsLod = 1.0; #endif glm::vec3 box(WORLD_SIZE,WORLD_SIZE,WORLD_SIZE); + ParticleSystem balls(0, box, - false, // Wrap? - 0.02f, // Noise - 0.3f, // Size scale - 0.0 // Gravity + false, // Wrap? + 0.02f, // Noise + 0.3f, // Size scale + 0.0 // Gravity ); -Cloud cloud(20000, // Particles +Cloud cloud(0, // Particles box, // Bounding Box false // Wrap ); @@ -133,12 +133,12 @@ Field field; Audio audio(&audioScope, &myHead); #endif -#define RENDER_FRAME_MSECS 8 -int steps_per_frame = 0; +#define IDLE_SIMULATE_MSECS 8 // How often should call simulate and other stuff + // in the idle loop? float yaw = 0.f; // The yaw, pitch for the avatar head float pitch = 0.f; -float start_yaw = 122; +float startYaw = 122.f; float renderPitch = 0.f; float renderYawRate = 0.f; float renderPitchRate = 0.f; @@ -146,31 +146,25 @@ float renderPitchRate = 0.f; // Where one's own agent begins in the world (needs to become a dynamic thing passed to the program) glm::vec3 start_location(6.1f, 0, 1.4f); -int stats_on = 0; // Whether to show onscreen text overlay with stats +int statsOn = 0; // Whether to show onscreen text overlay with stats bool starsOn = false; // Whether to display the stars bool paintOn = false; // Whether to paint voxels as you fly around VoxelDetail paintingVoxel; // The voxel we're painting if we're painting unsigned char dominantColor = 0; // The dominant color of the voxel we're painting bool perfStatsOn = false; // Do we want to display perfStats? -int noise_on = 0; // Whether to add random noise +int noiseOn = 0; // Whether to add random noise float noise = 1.0; // Overall magnitude scaling for random noise levels -int step_on = 0; -int display_levels = 0; -int display_head = 0; -int display_field = 0; +int displayLevels = 0; +int displayHead = 0; +int displayField = 0; -int display_head_mouse = 1; // Display sample mouse pointer controlled by head movement -int head_mouse_x, head_mouse_y; -int head_lean_x, head_lean_y; +int displayHeadMouse = 1; // Display sample mouse pointer controlled by head movement +int headMouseX, headMouseY; -int mouse_x, mouse_y; // Where is the mouse -int mouse_start_x, mouse_start_y; // Mouse location at start of last down click -int mouse_pressed = 0; // true if mouse has been pressed (clear when finished) - -int nearbyAgents = 0; // How many other people near you is the domain server reporting? - -int speed; +int mouseX, mouseY; // Where is the mouse +int mouseStartX, mouseStartY; // Mouse location at start of last down click +int mousePressed = 0; // true if mouse has been pressed (clear when finished) // // Serial USB Variables @@ -185,17 +179,14 @@ int first_measurement = 1; // Frame rate Measurement -int framecount = 0; +int frameCount = 0; float FPS = 120.f; -timeval timer_start, timer_end; -timeval last_frame; +timeval timerStart, timerEnd; +timeval lastTimeIdle; double elapsedTime; // Particles -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 @@ -218,34 +209,19 @@ float pointer_attenuation_quadratic[] = { 1.0f, 0.0f, 0.0f }; // for 2D view // Every second, check the frame rates and other stuff void Timer(int extra) { - gettimeofday(&timer_end, NULL); - FPS = (float)framecount / ((float)diffclock(&timer_start, &timer_end) / 1000.f); - packets_per_second = (float)packetcount / ((float)diffclock(&timer_start, &timer_end) / 1000.f); - bytes_per_second = (float)bytescount / ((float)diffclock(&timer_start, &timer_end) / 1000.f); - framecount = 0; - packetcount = 0; - bytescount = 0; + gettimeofday(&timerEnd, NULL); + FPS = (float)frameCount / ((float)diffclock(&timerStart, &timerEnd) / 1000.f); + packetsPerSecond = (float)packetCount / ((float)diffclock(&timerStart, &timerEnd) / 1000.f); + bytesPerSecond = (float)bytesCount / ((float)diffclock(&timerStart, &timerEnd) / 1000.f); + frameCount = 0; + packetCount = 0; + bytesCount = 0; glutTimerFunc(1000,Timer,0); - gettimeofday(&timer_start, NULL); + gettimeofday(&timerStart, NULL); // Ping the agents we can see agentList.pingAgents(); - - if (0) { - // Massive send packet speed test - timeval starttest, endtest; - gettimeofday(&starttest, NULL); - char junk[1000]; - junk[0] = 'J'; - for (int i = 0; i < 10000; i++) - { -// agentSocket.send((char *)"192.168.1.38", AGENT_UDP_PORT, junk, 1000); - } - gettimeofday(&endtest, NULL); - float sendTime = static_cast( diffclock(&starttest, &endtest) ); - printf("packet test = %4.1f\n", sendTime); - } // if we haven't detected gyros, check for them now if (!serialPort.active) { @@ -253,10 +229,7 @@ void Timer(int extra) } } - - - -void display_stats(void) +void displayStats(void) { // bitmap chars are about 10 pels high char legend[] = "/ - toggle this display, Q - exit, H - show head, M - show hand, T - test audio"; @@ -269,7 +242,7 @@ void display_stats(void) char stats[200]; sprintf(stats, "FPS = %3.0f Pkts/s = %d Bytes/s = %d Head(x,y,z)=( %f , %f , %f )", - FPS, packets_per_second, bytes_per_second, headPos.x,headPos.y,headPos.z); + FPS, packetsPerSecond, bytesPerSecond, headPos.x,headPos.y,headPos.z); drawtext(10, 49, 0.10f, 0, 1.0, 0, stats); if (serialPort.active) { sprintf(stats, "ADC samples = %d, LED = %d", @@ -327,26 +300,10 @@ void display_stats(void) } delete []perfStatLinesArray; // we're responsible for cleanup } - - /* - std::stringstream angles; - angles << "render_yaw: " << myHead.getRenderYaw() << ", Yaw: " << myHead.getYaw(); - drawtext(10,50,0.10, 0, 1.0, 0, (char *)angles.str().c_str()); - */ - - /* - char adc[200]; - sprintf(adc, "location = %3.1f,%3.1f,%3.1f, angle_to(origin) = %3.1f, head yaw = %3.1f, render_yaw = %3.1f", - -location[0], -location[1], -location[2], - angle_to(myHead.getPos()*-1.f, glm::vec3(0,0,0), myHead.getRenderYaw(), myHead.getYaw()), - myHead.getYaw(), myHead.getRenderYaw()); - drawtext(10, 50, 0.10, 0, 1.0, 0, adc); - */ } void initDisplay(void) { - // Set up blending function so that we can NOT clear the display glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -355,36 +312,27 @@ void initDisplay(void) glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); -// load_png_as_texture(texture_filename); - if (fullscreen) glutFullScreen(); } - - - void init(void) { voxels.init(); voxels.setViewerHead(&myHead); - myHead.setRenderYaw(start_yaw); + myHead.setRenderYaw(startYaw); - head_mouse_x = WIDTH/2; - head_mouse_y = HEIGHT/2; - head_lean_x = WIDTH/2; - head_lean_y = HEIGHT/2; + headMouseX = WIDTH/2; + headMouseY = HEIGHT/2; stars.readInput(starFile, 0); // Initialize Field values field = Field(); - printf( "Field Initialized.\n" ); - - if (noise_on) { + + if (noiseOn) { myHead.setNoise(noise); } myHead.setPos(start_location ); - myCamera.setPosition( start_location ); #ifdef MARKER_CAPTURE @@ -399,8 +347,8 @@ void init(void) } #endif - gettimeofday(&timer_start, NULL); - gettimeofday(&last_frame, NULL); + gettimeofday(&timerStart, NULL); + gettimeofday(&lastTimeIdle, NULL); } void terminate () { @@ -421,15 +369,13 @@ void reset_sensors() // // Reset serial I/O sensors // - myHead.setRenderYaw(start_yaw); + myHead.setRenderYaw(startYaw); yaw = renderYawRate = 0; pitch = renderPitch = renderPitchRate = 0; myHead.setPos(start_location); - head_mouse_x = WIDTH/2; - head_mouse_y = HEIGHT/2; - head_lean_x = WIDTH/2; - head_lean_y = HEIGHT/2; + headMouseX = WIDTH/2; + headMouseY = HEIGHT/2; myHead.reset(); @@ -440,12 +386,12 @@ void reset_sensors() void simulateHand(float deltaTime) { // If mouse is being dragged, send current force to the hand controller - if (mouse_pressed == 1) + if (mousePressed == 1) { // Add a velocity to the hand corresponding to the detected size of the drag vector const float MOUSE_HAND_FORCE = 1.5; - float dx = mouse_x - mouse_start_x; - float dy = mouse_y - mouse_start_y; + float dx = mouseX - mouseStartX; + float dy = mouseY - mouseStartY; glm::vec3 vel(dx*MOUSE_HAND_FORCE, -dy*MOUSE_HAND_FORCE*(WIDTH/HEIGHT), 0); myHead.hand->addVelocity(vel*deltaTime); } @@ -463,7 +409,7 @@ void simulateHead(float frametime) //float measured_lateral_accel = serialPort.getRelativeValue(ACCEL_X); //float measured_fwd_accel = serialPort.getRelativeValue(ACCEL_Z); - myHead.UpdatePos(frametime, &serialPort, head_mirror, &gravity); + myHead.UpdatePos(frametime, &serialPort, headMirror, &gravity); //------------------------------------------------------------------------------------- // set the position of the avatar @@ -476,13 +422,13 @@ void simulateHead(float frametime) if (powf(measured_yaw_rate*measured_yaw_rate + measured_pitch_rate*measured_pitch_rate, 0.5) > MIN_MOUSE_RATE) { - head_mouse_x += measured_yaw_rate*MOUSE_SENSITIVITY; - head_mouse_y += measured_pitch_rate*MOUSE_SENSITIVITY*(float)HEIGHT/(float)WIDTH; + headMouseX += measured_yaw_rate*MOUSE_SENSITIVITY; + headMouseY += measured_pitch_rate*MOUSE_SENSITIVITY*(float)HEIGHT/(float)WIDTH; } - head_mouse_x = max(head_mouse_x, 0); - head_mouse_x = min(head_mouse_x, WIDTH); - head_mouse_y = max(head_mouse_y, 0); - head_mouse_y = min(head_mouse_y, HEIGHT); + headMouseX = max(headMouseX, 0); + headMouseX = min(headMouseX, WIDTH); + headMouseY = max(headMouseY, 0); + headMouseY = min(headMouseY, HEIGHT); // Update render direction (pitch/yaw) based on measured gyro rates const int MIN_YAW_RATE = 100; @@ -563,12 +509,6 @@ void simulateHead(float frametime) } } -int render_test_spot = WIDTH/2; -int render_test_direction = 1; - - - - void display(void) { PerfStat("display"); @@ -601,7 +541,7 @@ void display(void) //-------------------------------------------------------- myCamera.setTargetPosition( myHead.getPos() ); - if ( display_head ) + if ( displayHead ) { //----------------------------------------------- // set the camera to looking at my own face @@ -650,13 +590,13 @@ void display(void) // Draw cloud of dots glDisable( GL_POINT_SPRITE_ARB ); glDisable( GL_TEXTURE_2D ); -// if (!display_head) cloud.render(); + if (!displayHead) cloud.render(); // Draw voxels voxels.render(); // Draw field vectors - if (display_field) field.render(); + if (displayField) field.render(); // Render heads of other agents for(std::vector::iterator agent = agentList.getAgents().begin(); agent != agentList.getAgents().end(); agent++) @@ -672,10 +612,10 @@ void display(void) } } - if ( !display_head ) balls.render(); + if ( !displayHead ) balls.render(); // Render the world box - if (!display_head && stats_on) render_world_box(); + if (!displayHead && statsOn) render_world_box(); //--------------------------------- @@ -687,7 +627,7 @@ void display(void) glPushMatrix(); glLoadIdentity(); glTranslatef(0.f, 0.f, -7.f); - myHead.render(display_head, 1); + myHead.render(displayHead, 1); glPopMatrix(); */ @@ -714,57 +654,31 @@ void display(void) //drawvec3(100, 100, 0.15, 0, 1.0, 0, myHead.getPos(), 0, 1, 0); glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, pointer_attenuation_quadratic ); - if (mouse_pressed == 1) - { - glPointSize( 10.0f ); - glColor3f(1,1,1); - //glEnable(GL_POINT_SMOOTH); - glBegin(GL_POINTS); - glVertex2f(target_x, target_y); - glEnd(); - char val[20]; - sprintf(val, "%d,%d", target_x, target_y); - drawtext(target_x, target_y-20, 0.08, 0, 1.0, 0, val, 0, 1, 0); - } - if (display_head_mouse && !display_head && stats_on) + if (displayHeadMouse && !displayHead && statsOn) { // Display small target box at center or head mouse target that can also be used to measure LOD glColor3f(1.0, 1.0, 1.0); glDisable(GL_LINE_SMOOTH); const int PIXEL_BOX = 20; glBegin(GL_LINE_STRIP); - glVertex2f(head_mouse_x - PIXEL_BOX/2, head_mouse_y - PIXEL_BOX/2); - glVertex2f(head_mouse_x + PIXEL_BOX/2, head_mouse_y - PIXEL_BOX/2); - glVertex2f(head_mouse_x + PIXEL_BOX/2, head_mouse_y + PIXEL_BOX/2); - glVertex2f(head_mouse_x - PIXEL_BOX/2, head_mouse_y + PIXEL_BOX/2); - glVertex2f(head_mouse_x - PIXEL_BOX/2, head_mouse_y - PIXEL_BOX/2); + glVertex2f(headMouseX - PIXEL_BOX/2, headMouseY - PIXEL_BOX/2); + glVertex2f(headMouseX + PIXEL_BOX/2, headMouseY - PIXEL_BOX/2); + glVertex2f(headMouseX + PIXEL_BOX/2, headMouseY + PIXEL_BOX/2); + glVertex2f(headMouseX - PIXEL_BOX/2, headMouseY + PIXEL_BOX/2); + glVertex2f(headMouseX - PIXEL_BOX/2, headMouseY - PIXEL_BOX/2); glEnd(); glEnable(GL_LINE_SMOOTH); } - // Spot bouncing back and forth on bottom of screen - if (0) - { - glPointSize(50.0f); - glColor4f(1.0, 1.0, 1.0, 1.0); - glEnable(GL_POINT_SMOOTH); - glBegin(GL_POINTS); - glVertex2f(render_test_spot, HEIGHT-100); - glEnd(); - render_test_spot += render_test_direction*50; - if ((render_test_spot > WIDTH-100) || (render_test_spot < 100)) render_test_direction *= -1.0; - - } - // Show detected levels from the serial I/O ADC channel sensors - if (display_levels) serialPort.renderLevels(WIDTH,HEIGHT); + if (displayLevels) serialPort.renderLevels(WIDTH,HEIGHT); // Display miscellaneous text stats onscreen - if (stats_on) { + if (statsOn) { glLineWidth(1.0f); glPointSize(1.0f); - display_stats(); + displayStats(); } // Draw number of nearby people always @@ -785,13 +699,9 @@ void display(void) glutSwapBuffers(); - framecount++; + frameCount++; } - - - - void testPointToVoxel() { float y=0; @@ -931,7 +841,7 @@ void key(unsigned char k, int x, int y) // Process keypresses if (k == 'q') ::terminate(); - if (k == '/') stats_on = !stats_on; // toggle stats + if (k == '/') statsOn = !statsOn; // toggle stats if (k == '*') ::starsOn = !::starsOn; // toggle stars if (k == '&') { ::paintOn = !::paintOn; // toggle paint @@ -942,8 +852,8 @@ void key(unsigned char k, int x, int y) if (k == '%') ::sendVoxelServerAddScene(); // sends add scene command to voxel server if (k == 'n') { - noise_on = !noise_on; // Toggle noise - if (noise_on) + noiseOn = !noiseOn; // Toggle noise + if (noiseOn) { myHead.setNoise(noise); } @@ -955,16 +865,16 @@ void key(unsigned char k, int x, int y) } if (k == 'h') { - display_head = !display_head; + displayHead = !displayHead; #ifndef _WIN32 - audio.setMixerLoopbackFlag(display_head); + audio.setMixerLoopbackFlag(displayHead); #endif } - if (k == 'm') head_mirror = !head_mirror; + if (k == 'm') headMirror = !headMirror; - if (k == 'f') display_field = !display_field; - if (k == 'l') display_levels = !display_levels; + if (k == 'f') displayField = !displayField; + if (k == 'l') displayLevels = !displayLevels; if (k == 'e') myHead.setDriveKeys(UP, 1); if (k == 'c') myHead.setDriveKeys(DOWN, 1); if (k == 'w') myHead.setDriveKeys(FWD, 1); @@ -981,18 +891,6 @@ void key(unsigned char k, int x, int y) #endif if (k == 'a') myHead.setDriveKeys(ROT_LEFT, 1); if (k == 'd') myHead.setDriveKeys(ROT_RIGHT, 1); - if (k == 'o') simulate_on = !simulate_on; - if (k == 'p') - { - // Add to field vector - float pos[] = {5,5,5}; - float add[] = {0.001, 0.001, 0.001}; - field.add(add, pos); - } - if (k == '1') - { - myHead.SetNewHeadTarget((randFloat()-0.5)*20.0, (randFloat()-0.5)*20.0); - } // press the . key to get a new random sphere of voxels added if (k == '.') addRandomSphere(wantColorRandomizer); @@ -1009,8 +907,8 @@ void *networkReceive(void *args) while (!stopNetworkReceiveThread) { if (agentList.getAgentSocket().receive(&senderAddress, incomingPacket, &bytesReceived)) { - packetcount++; - bytescount += bytesReceived; + packetCount++; + bytesCount += bytesReceived; if (incomingPacket[0] == PACKET_HEADER_TRANSMITTER_DATA) { // Pass everything but transmitter data to the agent list @@ -1034,18 +932,17 @@ void idle(void) timeval check; gettimeofday(&check, NULL); - // Check and render display frame - if (diffclock(&last_frame, &check) > RENDER_FRAME_MSECS) + // Only run simulation code if more than IDLE_SIMULATE_MSECS have passed since last time + + if (diffclock(&lastTimeIdle, &check) > IDLE_SIMULATE_MSECS) { - steps_per_frame++; - //---------------------------------------------------------------- // If mouse is being dragged, update hand movement in the avatar //---------------------------------------------------------------- - if ( mouse_pressed == 1 ) + if ( mousePressed == 1 ) { - float xOffset = ( mouse_x - mouse_start_x ) / (double)WIDTH; - float yOffset = ( mouse_y - mouse_start_y ) / (double)HEIGHT; + float xOffset = ( mouseX - mouseStartX ) / (double)WIDTH; + float yOffset = ( mouseY - mouseStartY ) / (double)HEIGHT; float leftRight = xOffset; float downUp = yOffset; @@ -1074,17 +971,15 @@ void idle(void) simulateHand(1.f/FPS); - if (simulate_on) { - field.simulate(1.f/FPS); - myHead.simulate(1.f/FPS); - balls.simulate(1.f/FPS); - cloud.simulate(1.f/FPS); - lattice.simulate(1.f/FPS); - myFinger.simulate(1.f/FPS); - } + field.simulate(1.f/FPS); + myHead.simulate(1.f/FPS); + balls.simulate(1.f/FPS); + cloud.simulate(1.f/FPS); + lattice.simulate(1.f/FPS); + myFinger.simulate(1.f/FPS); - if (!step_on) glutPostRedisplay(); - last_frame = check; + glutPostRedisplay(); + lastTimeIdle = check; } @@ -1120,38 +1015,38 @@ void mouseFunc( int button, int state, int x, int y ) { if( button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) { - mouse_x = x; - mouse_y = y; - mouse_pressed = 1; + mouseX = x; + mouseY = y; + mousePressed = 1; lattice.mouseClick((float)x/(float)WIDTH,(float)y/(float)HEIGHT); - mouse_start_x = x; - mouse_start_y = y; + mouseStartX = x; + mouseStartY = y; } if( button == GLUT_LEFT_BUTTON && state == GLUT_UP ) { - mouse_x = x; - mouse_y = y; - mouse_pressed = 0; + mouseX = x; + mouseY = y; + mousePressed = 0; } } void motionFunc( int x, int y) { - mouse_x = x; - mouse_y = y; + mouseX = x; + mouseY = y; lattice.mouseClick((float)x/(float)WIDTH,(float)y/(float)HEIGHT); } void mouseoverFunc( int x, int y) { - mouse_x = x; - mouse_y = y; - if (mouse_pressed == 0) + mouseX = x; + mouseY = y; + if (mousePressed == 0) { // lattice.mouseOver((float)x/(float)WIDTH,(float)y/(float)HEIGHT); -// myFinger.setTarget(mouse_x, mouse_y); +// myFinger.setTarget(mouseX, mouseY); } } @@ -1209,6 +1104,8 @@ int main(int argc, const char * argv[]) printf( "Created Display Window.\n" ); initDisplay(); + printf( "Initialized Display.\n" ); + glutDisplayFunc(display); glutReshapeFunc(reshape); @@ -1221,9 +1118,10 @@ int main(int argc, const char * argv[]) glutMouseFunc(mouseFunc); glutIdleFunc(idle); - printf( "Initialized Display.\n" ); init(); + printf( "Init() complete.\n" ); + // Check to see if the user passed in a command line option for randomizing colors if (cmdOptionExists(argc, argv, "--NoColorRandomizer")) { @@ -1235,16 +1133,17 @@ int main(int argc, const char * argv[]) const char* voxelsFilename = getCmdOption(argc, argv, "-i"); if (voxelsFilename) { voxels.loadVoxelsFile(voxelsFilename,wantColorRandomizer); + printf("Local Voxel File loaded.\n"); } // create thread for receipt of data via UDP pthread_create(&networkReceiveThread, NULL, networkReceive, NULL); - - printf( "Init() complete.\n" ); + printf("Network receive thread created.\n"); glutTimerFunc(1000, Timer, 0); glutMainLoop(); + printf("Normal exit.\n"); ::terminate(); return EXIT_SUCCESS; } diff --git a/interface/src/octal.cpp b/interface/src/octal.cpp deleted file mode 100644 index 4e5f1eb7c5..0000000000 --- a/interface/src/octal.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// -// octal.cpp -// interface -// -// Created by Philip on 2/4/13. -// Copyright (c) 2013 HighFidelity, Inc. All rights reserved. -// -// Various subroutines for converting between X,Y,Z coords and octree coordinates. -// - -#include "Util.h" -#include "octal.h" -#include - -const int X = 0; -const int Y = 1; -const int Z = 2; - -domainNode rootNode; - -// Given a position vector between zero and one (but less than one), and a voxel scale 1/2^scale, -// returns the smallest voxel at that scale which encloses the given point. -void getVoxel(float * pos, int scale, float * vpos) { - float vscale = powf(2, scale); - vpos[X] = floor(pos[X]*vscale)/vscale; - vpos[Y] = floor(pos[Y]*vscale)/vscale; - vpos[Z] = floor(pos[Z]*vscale)/vscale; -} - diff --git a/interface/src/octal.h b/interface/src/octal.h deleted file mode 100644 index cc38b59f7a..0000000000 --- a/interface/src/octal.h +++ /dev/null @@ -1,26 +0,0 @@ -// -// octal.h -// interface -// -// Created by Philip on 2/4/13. -// Copyright (c) 2013 HighFidelity, Inc. All rights reserved. -// - -#ifndef __interface__octal__ -#define __interface__octal__ - -#include - -struct domainNode { - domainNode * child[8]; - char * hostname; - char * nickname; - int domain_id; -}; - -domainNode* createNode(int lengthInBits, char * octalData, - char * hostname, char * nickname, int domain_id); - - - -#endif /* defined(__interface__octal__) */ From e910bece1ddee799898eb75b410234490e259b2a Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Wed, 10 Apr 2013 00:30:24 -0700 Subject: [PATCH 29/33] temp commented groundPlaneGrid till file is fixed --- interface/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index d6f98648c8..01c76e9254 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -602,7 +602,7 @@ void display(void) //--------------------------------------------- // draw a grid gound plane.... //--------------------------------------------- - drawGroundPlaneGrid( 5.0f, 9 ); + //drawGroundPlaneGrid( 5.0f, 9 ); // Draw cloud of dots From e19b53a344d85598a9c61ede67e673133f574e7f Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 10 Apr 2013 00:46:04 -0700 Subject: [PATCH 30/33] added key interface to toggle voxels --- interface/src/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 01c76e9254..387a9b7065 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -864,6 +864,7 @@ void key(unsigned char k, int x, int y) if (k == 'q') ::terminate(); if (k == '/') statsOn = !statsOn; // toggle stats if (k == '*') ::starsOn = !::starsOn; // toggle stars + if (k == 'V') ::showingVoxels = !::showingVoxels; // toggle voxels if (k == '&') { ::paintOn = !::paintOn; // toggle paint ::setupPaintingVoxel(); // also randomizes colors From 8f969f9ca9c96132c6debbed354b06b52d9b3b87 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Wed, 10 Apr 2013 01:03:35 -0700 Subject: [PATCH 31/33] adding ground plane grid (again???) --- interface/src/Head.cpp | 278 ++++++++++++++++++++++++++--------------- interface/src/Head.h | 8 +- 2 files changed, 185 insertions(+), 101 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index d06f35cc39..13f30084bc 100755 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -19,6 +19,7 @@ using namespace std; float skinColor[] = {1.0, 0.84, 0.66}; +float lightBlue[] = { 0.7, 0.8, 1.0 }; float browColor[] = {210.0/255.0, 105.0/255.0, 30.0/255.0}; float mouthColor[] = {1, 0, 0}; @@ -502,9 +503,9 @@ void Head::renderHead( int faceToFace, int isMine ) glTranslatef ( - avatar.bone[ AVATAR_BONE_HEAD ].worldPosition.x, - avatar.bone[ AVATAR_BONE_HEAD ].worldPosition.y, - avatar.bone[ AVATAR_BONE_HEAD ].worldPosition.z + 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 ); @@ -669,9 +670,9 @@ void Head::setHandMovement( glm::vec3 movement ) //----------------------------------------- void Head::initializeAvatar() { - avatar.position = glm::vec3( 0.0, 0.0, 0.0 ); - avatar.velocity = glm::vec3( 0.0, 0.0, 0.0 ); - avatar.thrust = glm::vec3( 0.0, 0.0, 0.0 ); + avatar.position = glm::vec3( 0.0, 0.0, 0.0 ); + avatar.velocity = glm::vec3( 0.0, 0.0, 0.0 ); + avatar.thrust = glm::vec3( 0.0, 0.0, 0.0 ); avatar.orientation.setToIdentity(); avatar.yaw = 90.0; @@ -682,9 +683,10 @@ void Head::initializeAvatar() for (int b=0; b avatar.maxArmLength ) { - avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].worldPosition += v * 0.2; + avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position += v * 0.2; } */ @@ -878,7 +885,7 @@ void Head::updateAvatarSkeleton() //------------------------------------------------------------------------ for (int b=0; b 0.0f ) + { + glm::vec3 springDirection = springVector / length; + + float force = ( length - avatar.bone[b].length ) * 0.01; + + avatar.bone[ b ].springyVelocity -= springDirection * force; + avatar.bone[ avatar.bone[b].parent ].springyVelocity += springDirection * force; + } + + avatar.bone[b].springyVelocity += ( avatar.bone[b].position - avatar.bone[b].springyPosition ) * 0.01f; + avatar.bone[b].springyVelocity *= 0.8; + avatar.bone[b].springyPosition += avatar.bone[b].springyVelocity; + } + } +} + + //------------------------------- float Head::getAvatarYaw() { @@ -901,9 +955,9 @@ glm::vec3 Head::getAvatarHeadLookatDirection() { return glm::vec3 ( - avatar.bone[ AVATAR_BONE_HEAD ].worldOrientation.getFront().x, - avatar.bone[ AVATAR_BONE_HEAD ].worldOrientation.getFront().y, - avatar.bone[ AVATAR_BONE_HEAD ].worldOrientation.getFront().z + avatar.bone[ AVATAR_BONE_HEAD ].orientation.getFront().x, + avatar.bone[ AVATAR_BONE_HEAD ].orientation.getFront().y, + avatar.bone[ AVATAR_BONE_HEAD ].orientation.getFront().z ); } @@ -915,9 +969,9 @@ void Head::updateHandMovement() //---------------------------------------------------------------- // adjust right hand and elbow according to hand offset //---------------------------------------------------------------- - avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition += handOffset; - glm::vec3 armVector = avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition; - armVector -= avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].worldPosition; + avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position += handOffset; + glm::vec3 armVector = avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position; + armVector -= avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; //------------------------------------------------------------------------------- // test to see if right hand is being dragged beyond maximum arm length @@ -932,32 +986,32 @@ void Head::updateHandMovement() //------------------------------------------------------------------------------- // reset right hand to be constrained to maximum arm length //------------------------------------------------------------------------------- - avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].worldPosition; + avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; glm::vec3 armNormal = armVector / distance; armVector = armNormal * (float)avatar.maxArmLength; distance = avatar.maxArmLength; - glm::vec3 constrainedPosition = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].worldPosition; + glm::vec3 constrainedPosition = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; constrainedPosition += armVector; - avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition = constrainedPosition; + avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position = constrainedPosition; } //----------------------------------------------------------------------------- // set elbow position //----------------------------------------------------------------------------- - glm::vec3 newElbowPosition = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].worldPosition; + glm::vec3 newElbowPosition = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; newElbowPosition += armVector * (float)ONE_HALF; glm::vec3 perpendicular = glm::vec3( -armVector.y, armVector.x, armVector.z ); newElbowPosition += perpendicular * (float)( ( 1.0 - ( avatar.maxArmLength / distance ) ) * ONE_HALF ); - avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].worldPosition = newElbowPosition; + avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position = newElbowPosition; //----------------------------------------------------------------------------- // set wrist position //----------------------------------------------------------------------------- - glm::vec3 vv( avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition ); - vv -= avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].worldPosition; - glm::vec3 newWristPosition = avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].worldPosition; + glm::vec3 vv( avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position ); + vv -= avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position; + glm::vec3 newWristPosition = avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position; newWristPosition += vv * 0.7f; - avatar.bone[ AVATAR_BONE_RIGHT_FOREARM ].worldPosition = newWristPosition; + avatar.bone[ AVATAR_BONE_RIGHT_FOREARM ].position = newWristPosition; } @@ -966,68 +1020,96 @@ void Head::updateHandMovement() //----------------------------------------- void Head::renderBody() { - glColor3fv(skinColor); - //----------------------------------------- - // Render bones as spheres + // Render bone positions as spheres //----------------------------------------- for (int b=0; bgetPos().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 + avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position.x, + avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position.y, + avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position.z ); // Ventrella change return strlen(data); } @@ -1058,7 +1140,7 @@ int Head::getBroadcastData(char* data) //--------------------------------------------------- void Head::parseData(void *data, int size) { - //glm::vec3 pos;//( (glm::vec3)avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition ); + //glm::vec3 pos;//( (glm::vec3)avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position ); // parse head data for this agent glm::vec3 handPos( 0,0,0 ); @@ -1069,9 +1151,9 @@ void Head::parseData(void *data, int size) &Pitch, &Yaw, &Roll, &position.x, &position.y, &position.z, &loudness, &averageLoudness, - &avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition.x, - &avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition.y, - &avatar.bone[ AVATAR_BONE_RIGHT_HAND ].worldPosition.z + &avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position.x, + &avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position.y, + &avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position.z ); if (glm::length(handPos) > 0.0) hand->setPos(handPos); diff --git a/interface/src/Head.h b/interface/src/Head.h index bf8318ef61..74c69492a9 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -104,13 +104,14 @@ enum AvatarBones struct AvatarBone { AvatarBones parent; // which bone is this bone connected to? - glm::vec3 worldPosition; // the position at the "end" of the bone + glm::vec3 position; // the position at the "end" of the bone glm::vec3 defaultPosePosition; // the parent relative position when the avatar is in the "T-pose" - glm::dvec3 velocity; // pertains to spring physics + glm::vec3 springyPosition; // used for special effects (a 'flexible' variant of position) + glm::dvec3 springyVelocity; // used for special effects ( the velocity of the springy position) float yaw; // the yaw Euler angle of the bone rotation off the parent float pitch; // the pitch Euler angle of the bone rotation off the parent float roll; // the roll Euler angle of the bone rotation off the parent - Orientation worldOrientation; // three orthogonal normals determined by yaw, pitch, roll + Orientation orientation; // three orthogonal normals determined by yaw, pitch, roll float length; // the length of the bone }; @@ -246,6 +247,7 @@ class Head : public AgentData { void initializeAvatar(); void updateAvatarSkeleton(); + void updateAvatarSprings(); void calculateBoneLengths(); void readSensors(); From fc122f23d28dbd460016eb7cc2ff748e0c65a01f Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 10 Apr 2013 01:32:01 -0700 Subject: [PATCH 32/33] added first cut at view frustum debuging code --- interface/src/main.cpp | 148 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 387a9b7065..531b0b50f8 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -511,6 +511,151 @@ void simulateHead(float frametime) } } +// These handy operators should probably go somewhere else, I'm surprised they don't +// already exist somewhere in OpenGL. Maybe someone can point me to them if they do exist! +glm::vec3 operator* (float lhs, const glm::vec3& rhs) +{ + glm::vec3 result = rhs; + result.x *= lhs; + result.y *= lhs; + result.z *= lhs; + return result; +} + +glm::vec3 operator* (const glm::vec3& lhs, float rhs) +{ + glm::vec3 result = lhs; + result.x *= rhs; + result.y *= rhs; + result.z *= rhs; + return result; +} + +// XXXBHG - this code is not yet working. This is here to help Jeffery debug getAvatarHeadLookatDirection() +// The code will draw a yellow line from the avatar's position to the origin, +// It also attempts to draw a cyan line from the avatar to 2 meters in front of the avatar in the direction +// it's looking. But that's not working right now. +void render_view_frustum() { + + //printf("frustum low.x=%f, low.y=%f, low.z=%f, high.x=%f, high.y=%f, high.z=%f\n",low.x,low.y,low.z,high.x,high.y,high.z); + + + // p – the camera position + // d – a vector with the direction of the camera's view ray. In here it is assumed that this vector has been normalized + // nearDist – the distance from the camera to the near plane + // nearHeight – the height of the near plane + // nearWidth – the width of the near plane + // farDist – the distance from the camera to the far plane + // farHeight – the height of the far plane + // farWidth – the width of the far plane + + glm::vec3 cameraPosition = ::myHead.getPos()*-1.0; // We need to flip the sign to make this work. + glm::vec3 cameraDirection = ::myHead.getAvatarHeadLookatDirection()*-1.0; // gak! Not sure if this is correct! + + // this is a temporary test, create a vertice that's 2 meters in front of avatar in direction their looking + glm::vec3 lookingAt = cameraPosition+(cameraDirection*2.0); + + // Some debug lines. + glDisable(GL_LIGHTING); + glColor4f(1.0, 1.0, 1.0, 1.0); + glLineWidth(1.0); + glBegin(GL_LINES); + + // line from avatar to the origin -- this one is working. + glColor3f(1,1,0); + glVertex3f(cameraPosition.x,cameraPosition.y,cameraPosition.z); + glVertex3f(0,0,0); + + // line from avatar to 2 meters in front of avatar -- this is NOT working + glColor3f(0,1,1); + glVertex3f(cameraPosition.x,cameraPosition.y,cameraPosition.z); + glVertex3f(lookingAt.x,lookingAt.y,lookingAt.z); + + /* + // Not yet ready for this... + glm::vec3 up = glm::vec3(0.0,1.0,0.0); + glm::vec3 right = glm::vec3(1.0,0.0,0.0); + float nearDist = 0.1; + float farDist = 500.0; + float fov = (0.7854f*2.0); // 45 deg * 2 = 90 deg + + float screenWidth = 800.0; // hack! We need to make this eventually be the correct height/width + float screenHeight = 600.0; + float ratio = screenWidth/screenHeight; + float nearHeight = 2 * tan(fov / 2) * nearDist; + float nearWidth = nearHeight * ratio; + float farHeight = 2 * tan(fov / 2) * farDist; + float farWidth = farHeight * ratio; + + glm::vec3 farCenter = cameraPosition+cameraDirection*farDist; + glm::vec3 farTopLeft = farCenter + (up*farHeight*0.5) - (right*farWidth*0.5); + glm::vec3 farTopRight = farCenter + (up*farHeight*0.5) + (right*farWidth*0.5); + glm::vec3 farBottomLeft = farCenter - (up*farHeight*0.5) - (right*farWidth*0.5); + glm::vec3 farBottomRight = farCenter - (up*farHeight*0.5) + (right*farWidth*0.5); + + glm::vec3 nearCenter = cameraPosition+cameraDirection*nearDist; + glm::vec3 nearTopLeft = nearCenter + (up*nearHeight*0.5) - (right*nearWidth*0.5); + glm::vec3 nearTopRight = nearCenter + (up*nearHeight*0.5) + (right*nearWidth*0.5); + glm::vec3 nearBottomLeft = nearCenter - (up*nearHeight*0.5) - (right*nearWidth*0.5); + glm::vec3 nearBottomRight = nearCenter - (up*nearHeight*0.5) + (right*nearWidth*0.5); + */ + + +/* + glColor3f(1,1,1); + + // near plane - bottom edge + glVertex3f(low.x,low.y,low.z); + glVertex3f(high.x,low.y,low.z); + + // near plane - top edge + glVertex3f(low.x,high.y,low.z); + glVertex3f(high.x,high.y,low.z); + + // near plane - right edge + glVertex3f(low.x,high.y,low.z); + glVertex3f(low.x,low.y,low.z); + + // near plane - left edge + glVertex3f(high.x,high.y,low.z); + glVertex3f(high.x,low.y,low.z); + + // far plane - bottom edge + glVertex3f(low.x,low.y,high.z); + glVertex3f(high.x,low.y,high.z); + + // far plane - top edge + glVertex3f(low.x,high.y,high.z); + glVertex3f(high.x,high.y,high.z); + + // far plane - right edge + glVertex3f(low.x,high.y,high.z); + glVertex3f(low.x,low.y,high.z); + + // far plane - left edge + glVertex3f(high.x,high.y,high.z); + glVertex3f(high.x,low.y,high.z); + + // right plane - bottom edge - near to distant + glVertex3f(low.x,low.y,low.z); + glVertex3f(low.x,low.y,high.z); + + // right plane - top edge - near to distant + glVertex3f(low.x,high.y,low.z); + glVertex3f(low.x,high.y,high.z); + + // left plane - bottom edge - near to distant + glVertex3f(high.x,low.y,low.z); + glVertex3f(high.x,low.y,high.z); + + // left plane - top edge - near to distant + glVertex3f(high.x,high.y,low.z); + glVertex3f(high.x,high.y,high.z); +*/ + glEnd(); +} + + void display(void) { //printf( "avatar head lookat = %f, %f, %f\n", myHead.getAvatarHeadLookatDirection().x, myHead.getAvatarHeadLookatDirection().y, myHead.getAvatarHeadLookatDirection().z ); @@ -637,6 +782,9 @@ void display(void) // Render the world box if (!displayHead && statsOn) render_world_box(); + + // brad's frustum for debugging + render_view_frustum(); //--------------------------------- From 597f35db3d7fe84fb5cfdf22f1990a84b175ebea Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 10 Apr 2013 09:39:43 -0700 Subject: [PATCH 33/33] moved vector math helpers to Utils.cpp/h --- interface/src/Util.cpp | 23 +++++++++++++++++++++++ interface/src/Util.h | 4 ++++ interface/src/main.cpp | 20 -------------------- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 03a11e3308..a670f48f9e 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -140,3 +140,26 @@ void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, gl glPopMatrix(); } + +// XXXBHG - These handy operators should probably go somewhere else, I'm surprised they don't +// already exist somewhere in OpenGL. Maybe someone can point me to them if they do exist! +glm::vec3 operator* (float lhs, const glm::vec3& rhs) +{ + glm::vec3 result = rhs; + result.x *= lhs; + result.y *= lhs; + result.z *= lhs; + return result; +} + +// XXXBHG - These handy operators should probably go somewhere else, I'm surprised they don't +// already exist somewhere in OpenGL. Maybe someone can point me to them if they do exist! +glm::vec3 operator* (const glm::vec3& lhs, float rhs) +{ + glm::vec3 result = lhs; + result.x *= rhs; + result.y *= rhs; + result.z *= rhs; + return result; +} + diff --git a/interface/src/Util.h b/interface/src/Util.h index c5a02df5aa..8efe6f549e 100644 --- a/interface/src/Util.h +++ b/interface/src/Util.h @@ -48,4 +48,8 @@ void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, gl double diffclock(timeval *clock1,timeval *clock2); +glm::vec3 operator* (float lhs, const glm::vec3& rhs); +glm::vec3 operator* (const glm::vec3& lhs, float rhs); + + #endif diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 531b0b50f8..00cd8d7bfc 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -511,26 +511,6 @@ void simulateHead(float frametime) } } -// These handy operators should probably go somewhere else, I'm surprised they don't -// already exist somewhere in OpenGL. Maybe someone can point me to them if they do exist! -glm::vec3 operator* (float lhs, const glm::vec3& rhs) -{ - glm::vec3 result = rhs; - result.x *= lhs; - result.y *= lhs; - result.z *= lhs; - return result; -} - -glm::vec3 operator* (const glm::vec3& lhs, float rhs) -{ - glm::vec3 result = lhs; - result.x *= rhs; - result.y *= rhs; - result.z *= rhs; - return result; -} - // XXXBHG - this code is not yet working. This is here to help Jeffery debug getAvatarHeadLookatDirection() // The code will draw a yellow line from the avatar's position to the origin, // It also attempts to draw a cyan line from the avatar to 2 meters in front of the avatar in the direction