diff --git a/eve/src/main.cpp b/eve/src/main.cpp index 903a2e6c96..2da001b368 100644 --- a/eve/src/main.cpp +++ b/eve/src/main.cpp @@ -27,7 +27,6 @@ const float MAX_ITERATIONS_BETWEEN_AUDIO_SENDS = (MAX_AUDIO_SEND_INTERVAL_SECS * bool stopReceiveAgentDataThread; bool injectAudioThreadRunning = false; -int handStateTimer = 0; int TEMP_AUDIO_LISTEN_PORT = 55439; // UDPSocket audioSocket(TEMP_AUDIO_LISTEN_PORT); @@ -124,20 +123,7 @@ int main(int argc, const char* argv[]) { // put her hand out so somebody can shake it eve.setHandPosition(glm::vec3(eve.getPosition()[0] - 0.2, 0.25, - eve.getPosition()[2] + 0.1)); - - // simulate the effect of pressing and un-pressing the mouse button/pad - handStateTimer ++; - if ( handStateTimer == 100 ) { - eve.setHandState(1); - } - if ( handStateTimer == 150 ) { - eve.setHandState(0); - } - if ( handStateTimer >= 200 ) { - handStateTimer = 0; - } - + eve.getPosition()[2] + 0.1)); // read eve's audio data AudioInjector eveAudioInjector("eve.raw"); @@ -152,6 +138,8 @@ int main(int argc, const char* argv[]) { // int numIterationsLeftBeforeAudioSend = 0; // pthread_t injectAudioThread; + int handStateTimer = 0; + while (true) { // update the thisSend timeval to the current time gettimeofday(&thisSend, NULL); @@ -183,7 +171,19 @@ int main(int argc, const char* argv[]) { // sleep for the correct amount of time to have data send be consistently timed if ((numMicrosecondsSleep = (DATA_SEND_INTERVAL_MSECS * 1000) - (usecTimestampNow() - usecTimestamp(&thisSend))) > 0) { usleep(numMicrosecondsSleep); - } + } + + // simulate the effect of pressing and un-pressing the mouse button/pad + handStateTimer++; + if ( handStateTimer == 100 ) { + eve.setHandState(1); + } + if ( handStateTimer == 150 ) { + eve.setHandState(0); + } + if ( handStateTimer >= 200 ) { + handStateTimer = 0; + } } // stop the receive agent data thread diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 287325c090..4b522d5823 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -157,7 +157,7 @@ int audioCallback (const void *inputBuffer, // memcpy the three float positions for (int p = 0; p < 3; p++) { - memcpy(currentPacketPtr, &data->linkedHead->getPosition()[p], sizeof(float)); + memcpy(currentPacketPtr, &data->linkedAvatar->getPosition()[p], sizeof(float)); currentPacketPtr += sizeof(float); } @@ -165,7 +165,7 @@ int audioCallback (const void *inputBuffer, *(currentPacketPtr++) = 255; // memcpy the corrected render yaw - float correctedYaw = fmodf(data->linkedHead->getRenderYaw(), 360); + float correctedYaw = fmodf(data->linkedAvatar->getRenderYaw(), 360); if (correctedYaw > 180) { correctedYaw -= 360; @@ -259,7 +259,7 @@ int audioCallback (const void *inputBuffer, // rotation of the head relative to body, this may effect flange effect! // // - int lastYawMeasured = fabsf(data->linkedHead->getLastMeasuredHeadYaw()); + int lastYawMeasured = fabsf(data->linkedAvatar->getLastMeasuredHeadYaw()); if (!samplesLeftForFlange && lastYawMeasured > MIN_FLANGE_EFFECT_THRESHOLD) { // we should flange for one second @@ -448,7 +448,7 @@ void Audio::setWalkingState(bool newWalkState) { * @return Returns true if successful or false if an error occurred. Use Audio::getError() to retrieve the error code. */ -Audio::Audio(Oscilloscope *s, Head *linkedHead) +Audio::Audio(Oscilloscope *s, Avatar *linkedAvatar) { // read the walking sound from the raw file and store it // in the in memory array @@ -472,7 +472,7 @@ Audio::Audio(Oscilloscope *s, Head *linkedHead) audioData = new AudioData(); - audioData->linkedHead = linkedHead; + audioData->linkedAvatar = linkedAvatar; // setup a UDPSocket audioData->audioSocket = new UDPSocket(AUDIO_UDP_LISTEN_PORT); diff --git a/interface/src/Audio.h b/interface/src/Audio.h index f4bf594b0c..73ff7f32d1 100644 --- a/interface/src/Audio.h +++ b/interface/src/Audio.h @@ -12,12 +12,12 @@ #include #include "AudioData.h" #include "Oscilloscope.h" -#include "Head.h" +#include "Avatar.h" class Audio { public: // initializes audio I/O - Audio(Oscilloscope *s, Head *linkedHead); + Audio(Oscilloscope *s, Avatar *linkedAvatar); void render(); void render(int screenWidth, int screenHeight); diff --git a/interface/src/AudioData.h b/interface/src/AudioData.h index fdc15998f0..520291e3e6 100644 --- a/interface/src/AudioData.h +++ b/interface/src/AudioData.h @@ -13,7 +13,7 @@ #include #include "AudioRingBuffer.h" #include "UDPSocket.h" -#include "Head.h" +#include "Avatar.h" class AudioData { public: @@ -23,7 +23,7 @@ class AudioData { UDPSocket *audioSocket; - Head *linkedHead; + Avatar *linkedAvatar; // store current mixer address and port in_addr_t mixerAddress; diff --git a/interface/src/Head.cpp b/interface/src/Avatar.cpp similarity index 86% rename from interface/src/Head.cpp rename to interface/src/Avatar.cpp index 1e6e78fef2..ae082fd71c 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Avatar.cpp @@ -1,5 +1,5 @@ // -// Head.cpp +// Avatar.cpp // interface // // Created by Philip Rosedale on 9/11/12. @@ -11,7 +11,7 @@ #include #include #include -#include "Head.h" +#include "Avatar.h" #include "Log.h" #include #include @@ -41,7 +41,7 @@ vector iris_texture; unsigned int iris_texture_width = 512; unsigned int iris_texture_height = 256; -Head::Head(bool isMine) { +Avatar::Avatar(bool isMine) { _orientation.setToIdentity(); @@ -128,7 +128,7 @@ Head::Head(bool isMine) { -Head::Head(const Head &otherAvatar) { +Avatar::Avatar(const Avatar &otherAvatar) { _velocity = otherAvatar._velocity; _thrust = otherAvatar._thrust; @@ -207,25 +207,24 @@ Head::Head(const Head &otherAvatar) { } } -Head::~Head() { +Avatar::~Avatar() { if (_sphere != NULL) { gluDeleteQuadric(_sphere); } } -Head* Head::clone() const { - return new Head(*this); +Avatar* Avatar::clone() const { + return new Avatar(*this); } -void Head::reset() { +void Avatar::reset() { _headPitch = _headYaw = _headRoll = 0; _head.leanForward = _head.leanSideways = 0; } //this pertains to moving the head with the glasses -//--------------------------------------------------- -void Head::UpdateGyros(float frametime, SerialInterface * serialInterface, glm::vec3 * gravity) +void Avatar::UpdateGyros(float frametime, SerialInterface * serialInterface, glm::vec3 * gravity) // Using serial data, update avatar/render position and angles { const float PITCH_ACCEL_COUPLING = 0.5; @@ -264,35 +263,31 @@ void Head::UpdateGyros(float frametime, SerialInterface * serialInterface, glm:: addLean(-measured_lateral_accel * frametime * HEAD_LEAN_SCALE, -measured_fwd_accel*frametime * HEAD_LEAN_SCALE); } -void Head::addLean(float x, float z) { +void Avatar::addLean(float x, float z) { // Add Body lean as impulse _head.leanSideways += x; _head.leanForward += z; } -void Head::setLeanForward(float dist){ +void Avatar::setLeanForward(float dist){ _head.leanForward = dist; } -void Head::setLeanSideways(float dist){ +void Avatar::setLeanSideways(float dist){ _head.leanSideways = dist; } -void Head::setMousePressed( bool d ) { +void Avatar::setMousePressed( bool d ) { _mousePressed = d; } -void Head::simulate(float deltaTime) { +void Avatar::simulate(float deltaTime) { - //------------------------ // update avatar skeleton - //------------------------ updateSkeleton(); - //------------------------------------------------------------ // reset hand and arm positions according to hand movement - //------------------------------------------------------------ updateHandMovement( deltaTime ); if ( !_interactingOtherIsNearby ) { @@ -303,10 +298,8 @@ void Head::simulate(float deltaTime) { _interactingOtherIsNearby = false; - //------------------------------------------------------------- // if the avatar being simulated is mine, then loop through // all the other avatars for potential interactions... - //------------------------------------------------------------- if ( _isMine ) { float closestDistance = 10000.0f; @@ -317,11 +310,9 @@ void Head::simulate(float deltaTime) { agent != agentList->getAgents().end(); agent++) { if (( agent->getLinkedData() != NULL && ( agent->getType() == AGENT_TYPE_AVATAR ) )) { - Head *otherAvatar = (Head *)agent->getLinkedData(); + Avatar *otherAvatar = (Avatar *)agent->getLinkedData(); - //------------------------------------------------------ // check for collisions with other avatars and respond - //------------------------------------------------------ updateAvatarCollisionDetectionAndResponse ( otherAvatar->getPosition(), @@ -331,9 +322,7 @@ void Head::simulate(float deltaTime) { deltaTime ); - //------------------------------------------------- // test other avatar hand position for proximity - //------------------------------------------------ glm::vec3 v( _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position ); v -= otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND ); @@ -346,11 +335,8 @@ void Head::simulate(float deltaTime) { _interactingOther = otherAvatar; _interactingOtherIsNearby = true; - //--------------------------------------------------------------------- // if I am holding hands with another avatar, a force is applied - //--------------------------------------------------------------------- - if (( _handState == 1 ) - || ( _interactingOther->_handState == 1 )) { + if (( _handState == 1 ) || ( _interactingOther->_handState == 1 )) { glm::vec3 vectorToOtherHand = _interactingOther->_handPosition - _handHolding.position; glm::vec3 vectorToMyHand = _bone[ AVATAR_BONE_RIGHT_HAND ].position - _handHolding.position; @@ -373,14 +359,13 @@ void Head::simulate(float deltaTime) { updateArmIKAndConstraints( deltaTime ); - if ( ! _interactingOtherIsNearby ) { + if (!_interactingOtherIsNearby) { _interactingOther = NULL; } if ( usingBigSphereCollisionTest ) { - //-------------------------------------------------------------- + // test for avatar collision response (using a big sphere :) - //-------------------------------------------------------------- updateAvatarCollisionDetectionAndResponse ( _TEST_bigSpherePosition, @@ -406,11 +391,9 @@ void Head::simulate(float deltaTime) { // update body springs updateBodySprings( deltaTime ); - - if ( _isMine ) { // driving the avatar around should only apply if this is my avatar (as opposed to an avatar being driven remotely) - //------------------------------------------------- - // this handles the avatar being driven around... - //------------------------------------------------- + // driving the avatar around should only apply if this is my avatar (as opposed to an avatar being driven remotely) + if ( _isMine ) { + _thrust = glm::vec3( 0.0, 0.0, 0.0 ); if (_driveKeys[FWD]) { @@ -444,9 +427,7 @@ void Head::simulate(float deltaTime) { _bodyYawDelta += YAW_MAG * deltaTime; } } - - - //---------------------------------------------------------- + float translationalSpeed = glm::length( _velocity ); float rotationalSpeed = fabs( _bodyYawDelta ); if ( translationalSpeed + rotationalSpeed > 0.2 ) @@ -458,42 +439,27 @@ void Head::simulate(float deltaTime) { _mode = AVATAR_MODE_INTERACTING; } - //---------------------------------------------------------- // update body yaw by body yaw delta - //---------------------------------------------------------- if (_isMine) { _bodyYaw += _bodyYawDelta * deltaTime; } - //---------------------------------------------------------- // decay body yaw delta - //---------------------------------------------------------- _bodyYawDelta *= (1.0 - TEST_YAW_DECAY * deltaTime); - //---------------------------------------------------------- // add thrust to velocity - //---------------------------------------------------------- _velocity += glm::dvec3(_thrust * deltaTime); - //---------------------------------------------------------- // update position by velocity - //---------------------------------------------------------- _position += (glm::vec3)_velocity * deltaTime; - //---------------------------------------------------------- // decay velocity - //---------------------------------------------------------- _velocity *= ( 1.0 - LIN_VEL_DECAY * deltaTime ); // // Update Head information // - // we will be eventually getting head rotation from elsewhere. For now, just setting it to body rotation - //_head.yaw = _bodyYaw; - //_head.pitch = _bodyPitch; - //_head.roll = _bodyRoll; - if (!_head.noise) { // Decay back toward center _headPitch *= (1.0f - DECAY * 2 * deltaTime); @@ -589,23 +555,21 @@ void Head::simulate(float deltaTime) { } -float Head::getGirth() { +float Avatar::getGirth() { return COLLISION_BODY_RADIUS; } -float Head::getHeight() { +float Avatar::getHeight() { return COLLISION_HEIGHT; } -glm::vec3 Head::getBodyUpDirection() { +glm::vec3 Avatar::getBodyUpDirection() { return _orientation.getUp(); } -//-------------------------------------------------------------------------------- // This is a workspace for testing avatar body collision detection and response -//-------------------------------------------------------------------------------- -void Head::updateAvatarCollisionDetectionAndResponse +void Avatar::updateAvatarCollisionDetectionAndResponse ( glm::vec3 collisionPosition, float collisionGirth, float collisionHeight, glm::vec3 collisionUpVector, float deltaTime ) { float myBodyApproximateBoundingRadius = 1.0f; @@ -647,11 +611,9 @@ void Head::updateAvatarCollisionDetectionAndResponse } -void Head::render(bool lookingInMirror) { +void Avatar::render(bool lookingInMirror) { - //--------------------------------------------------- // show avatar position - //--------------------------------------------------- glColor4f( 0.5f, 0.5f, 0.5f, 0.6 ); glPushMatrix(); glTranslatef(_position.x, _position.y, _position.z); @@ -660,9 +622,8 @@ void Head::render(bool lookingInMirror) { glPopMatrix(); if ( usingBigSphereCollisionTest ) { - //--------------------------------------------------- + // show TEST big sphere - //--------------------------------------------------- glColor4f( 0.5f, 0.6f, 0.8f, 0.7 ); glPushMatrix(); glTranslatef(_TEST_bigSpherePosition.x, _TEST_bigSpherePosition.y, _TEST_bigSpherePosition.z); @@ -671,19 +632,13 @@ void Head::render(bool lookingInMirror) { glPopMatrix(); } - //--------------- // render body - //--------------- renderBody(); - //--------------------------------------------------- // render head - //--------------------------------------------------- renderHead(lookingInMirror); - //--------------------------------------------------------------------------- // if this is my avatar, then render my interactions with the other avatar - //--------------------------------------------------------------------------- if ( _isMine ) { if ( _interactingOtherIsNearby ) { @@ -702,15 +657,13 @@ void Head::render(bool lookingInMirror) { } -void Head::renderHead(bool lookingInMirror) { +void Avatar::renderHead(bool lookingInMirror) { int side = 0; glEnable(GL_DEPTH_TEST); glEnable(GL_RESCALE_NORMAL); - //--------------------------------------------------- // show head orientation - //--------------------------------------------------- //renderOrientationDirections( _bone[ AVATAR_BONE_HEAD ].position, _bone[ AVATAR_BONE_HEAD ].orientation, 0.2f ); glPushMatrix(); @@ -866,7 +819,7 @@ void Head::renderHead(bool lookingInMirror) { glPopMatrix(); } -void Head::startHandMovement() { +void Avatar::startHandMovement() { if (!_usingBodySprings) { initializeBodySprings(); @@ -874,19 +827,19 @@ void Head::startHandMovement() { } } -void Head::stopHandMovement() { +void Avatar::stopHandMovement() { //_usingBodySprings = false; } -void Head::setHandMovementValues( glm::vec3 handOffset ) { +void Avatar::setHandMovementValues( glm::vec3 handOffset ) { _movedHandOffset = handOffset; } -AvatarMode Head::getMode() { +AvatarMode Avatar::getMode() { return _mode; } -void Head::initializeSkeleton() { +void Avatar::initializeSkeleton() { for (int b=0; b _maxArmLength ) { - //------------------------------------------------------------------------------- // reset right hand to be constrained to maximum arm length - //------------------------------------------------------------------------------- _bone[ AVATAR_BONE_RIGHT_HAND ].position = _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; glm::vec3 armNormal = armVector / distance; armVector = armNormal * _maxArmLength; @@ -1182,18 +1115,14 @@ void Head::updateArmIKAndConstraints( float deltaTime ) { _bone[ AVATAR_BONE_RIGHT_HAND ].position = constrainedPosition; } - //----------------------------------------------------------------------------- // set elbow position - //----------------------------------------------------------------------------- glm::vec3 newElbowPosition = _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; newElbowPosition += armVector * ONE_HALF; glm::vec3 perpendicular = glm::cross( _orientation.getFront(), armVector ); newElbowPosition += perpendicular * ( 1.0f - ( _maxArmLength / distance ) ) * ONE_HALF; _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position = newElbowPosition; - //----------------------------------------------------------------------------- // set wrist position - //----------------------------------------------------------------------------- glm::vec3 vv( _bone[ AVATAR_BONE_RIGHT_HAND ].position ); vv -= _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position; glm::vec3 newWristPosition = _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position; @@ -1204,10 +1133,9 @@ void Head::updateArmIKAndConstraints( float deltaTime ) { -void Head::renderBody() { - //----------------------------------------- +void Avatar::renderBody() { + // Render bone positions as spheres - //----------------------------------------- for (int b=0; b #include @@ -100,15 +100,6 @@ struct AvatarHandHolding float force; }; -/* -struct OtherAvatar -{ - bool nearby; - //glm::vec3 handPosition; - //int handState; -}; -*/ - struct AvatarBone { AvatarBoneID parent; // which bone is this bone connected to? @@ -165,12 +156,12 @@ struct AvatarHead }; -class Head : public AvatarData { +class Avatar : public AvatarData { public: - Head(bool isMine); - ~Head(); - Head(const Head &otherHead); - Head* clone() const; + Avatar(bool isMine); + ~Avatar(); + Avatar(const Avatar &otherAvatar); + Avatar* clone() const; void reset(); void UpdateGyros(float frametime, SerialInterface * serialInterface, glm::vec3 * gravity); @@ -253,12 +244,10 @@ class Head : public AvatarData { timeval _transmitterTimer; float _transmitterHz; int _transmitterPackets; - Head* _interactingOther; + Avatar* _interactingOther; bool _interactingOtherIsNearby; - //----------------------------- // private methods... - //----------------------------- void initializeSkeleton(); void updateSkeleton(); void initializeBodySprings(); diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index 8bf6222aec..e96dc5ef8b 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -60,8 +60,8 @@ VoxelSystem::~VoxelSystem() { pthread_mutex_destroy(&bufferWriteLock); } -void VoxelSystem::setViewerHead(Head *newViewerHead) { - viewerHead = newViewerHead; +void VoxelSystem::setViewerAvatar(Avatar *newViewerAvatar) { + viewerAvatar = newViewerAvatar; } ////////////////////////////////////////////////////////////////////////////////////////// @@ -187,7 +187,7 @@ int VoxelSystem::treeToArrays(VoxelNode *currentNode, const glm::vec3& nodePosi int voxelsAdded = 0; float halfUnitForVoxel = powf(0.5, *currentNode->octalCode) * (0.5 * TREE_SCALE); - glm::vec3 viewerPosition = viewerHead->getPosition(); + glm::vec3 viewerPosition = viewerAvatar->getPosition(); // debug LOD code glm::vec3 debugNodePosition; diff --git a/interface/src/VoxelSystem.h b/interface/src/VoxelSystem.h index 9d831ee5f2..ca4825121b 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -15,7 +15,7 @@ #include #include #include -#include "Head.h" +#include "Avatar.h" #include "Util.h" #include "world.h" @@ -34,7 +34,7 @@ public: void render(); void setVoxelsRendered(int v) {voxelsRendered = v;}; int getVoxelsRendered() {return voxelsRendered;}; - void setViewerHead(Head *newViewerHead); + void setViewerAvatar(Avatar *newViewerAvatar); void loadVoxelsFile(const char* fileName,bool wantColorRandomizer); void createSphere(float r,float xc, float yc, float zc, float s, bool solid, bool wantColorRandomizer); @@ -67,7 +67,7 @@ private: static float _minDistance; int voxelsRendered; - Head *viewerHead; + Avatar *viewerAvatar; VoxelTree *tree; GLfloat *readVerticesArray; GLubyte *readColorsArray; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 57c0b18d6d..8114795159 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -64,7 +64,7 @@ #include "MenuColumn.h" #include "Menu.h" #include "Camera.h" -#include "Head.h" +#include "Avatar.h" #include "Particle.h" #include "Texture.h" #include "Cloud.h" @@ -107,7 +107,7 @@ Oscilloscope audioScope(256,200,true); ViewFrustum viewFrustum; // current state of view frustum, perspective, orientation, etc. -Head myAvatar(true); // The rendered avatar of oneself +Avatar myAvatar(true); // The rendered avatar of oneself Camera myCamera; // My view onto the world (sometimes on myself :) Camera viewFrustumOffsetCamera; // The camera we use to sometimes show the view frustum from an offset mode @@ -382,7 +382,7 @@ void initDisplay(void) void init(void) { voxels.init(); - voxels.setViewerHead(&myAvatar); + voxels.setViewerAvatar(&myAvatar); myAvatar.setRenderYaw(startYaw); initializeHandController(); @@ -912,7 +912,7 @@ void display(void) agent != agentList->getAgents().end(); agent++) { if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { - Head *avatar = (Head *)agent->getLinkedData(); + Avatar *avatar = (Avatar *)agent->getLinkedData(); avatar->render(0); } } @@ -1494,7 +1494,7 @@ void idle(void) { { if (agent->getLinkedData() != NULL) { - Head *avatar = (Head *)agent->getLinkedData(); + Avatar *avatar = (Avatar *)agent->getLinkedData(); avatar->simulate(deltaTime); } } @@ -1605,7 +1605,7 @@ void mouseoverFunc( int x, int y) void attachNewHeadToAgent(Agent *newAgent) { if (newAgent->getLinkedData() == NULL) { - newAgent->setLinkedData(new Head(false)); + newAgent->setLinkedData(new Avatar(false)); } }