From ce1ceb849fac9a73b0cbf1547f7c6c6fcef77853 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Thu, 25 Apr 2013 23:32:04 -0700 Subject: [PATCH 01/14] Added HandControl class and also Avatar Touch class --- interface/src/Avatar.cpp | 61 +++++---------- interface/src/Avatar.h | 16 +++- interface/src/AvatarTouch.cpp | 43 ++++++++++ interface/src/AvatarTouch.h | 28 +++++++ interface/src/HandControl.cpp | 93 ++++++++++++++++++++++ interface/src/HandControl.h | 42 ++++++++++ interface/src/main.cpp | 143 +++++++++------------------------- 7 files changed, 280 insertions(+), 146 deletions(-) create mode 100644 interface/src/AvatarTouch.cpp create mode 100644 interface/src/AvatarTouch.h create mode 100644 interface/src/HandControl.cpp create mode 100644 interface/src/HandControl.h diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index dc09953459..4f6502c24c 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -303,7 +303,7 @@ void Avatar::simulate(float deltaTime) { // if the avatar being simulated is mine, then loop through // all the other avatars for potential interactions... if ( _isMine ) - { + { float closestDistance = 10000.0f; AgentList * agentList = AgentList::getInstance(); @@ -330,7 +330,7 @@ void Avatar::simulate(float deltaTime) { float distance = glm::length( v ); if ( distance < _maxArmLength + _maxArmLength ) { - + //if ( distance < closestDistance ) { // perhaps I don't need this if we want to allow multi-avatar interactions { closestDistance = distance; @@ -341,14 +341,18 @@ void Avatar::simulate(float deltaTime) { if (( _handState == 1 ) || ( _interactingOther->_handState == 1 )) { glm::vec3 vectorToOtherHand = _interactingOther->_handPosition - _handHolding.position; glm::vec3 vectorToMyHand = _bone[ AVATAR_BONE_RIGHT_HAND ].position - _handHolding.position; - + _handHolding.velocity *= 0.7; _handHolding.velocity += ( vectorToOtherHand + vectorToMyHand ) * _handHolding.force * deltaTime; _handHolding.position += _handHolding.velocity; _bone[ AVATAR_BONE_RIGHT_HAND ].position = _handHolding.position; + } } + + _avatarTouch.setMyHandPosition( _bone[ AVATAR_BONE_RIGHT_HAND ].position ); + _avatarTouch.setYourPosition( otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND ) ); } } } @@ -356,9 +360,11 @@ void Avatar::simulate(float deltaTime) { // Set the vector we send for hand position to other people to be our right hand setHandPosition(_bone[ AVATAR_BONE_RIGHT_HAND ].position); + //update the effects of touching another avatar + _avatarTouch.simulate(deltaTime); + }//if ( _isMine ) - updateArmIKAndConstraints( deltaTime ); if (!_interactingOtherIsNearby) { @@ -413,30 +419,14 @@ void Avatar::simulate(float deltaTime) { _thrust = glm::vec3( 0.0, 0.0, 0.0 ); - if (_driveKeys[FWD]) { - _thrust += _orientation.getFront() * THRUST_MAG; - } - if (_driveKeys[BACK]) { - _thrust -= _orientation.getFront() * THRUST_MAG; - } - if (_driveKeys[RIGHT]) { - _thrust += _orientation.getRight() * THRUST_MAG; - } - if (_driveKeys[LEFT]) { - _thrust -= _orientation.getRight() * THRUST_MAG; - } - if (_driveKeys[UP]) { - _thrust += _orientation.getUp() * THRUST_MAG; - } - if (_driveKeys[DOWN]) { - _thrust -= _orientation.getUp() * THRUST_MAG; - } - if (_driveKeys[ROT_RIGHT]) { - _bodyYawDelta -= YAW_MAG * deltaTime; - } - if (_driveKeys[ROT_LEFT]) { - _bodyYawDelta += YAW_MAG * deltaTime; - } + if (_driveKeys[FWD ]) {_thrust += THRUST_MAG * deltaTime * _orientation.getFront();} + if (_driveKeys[BACK ]) {_thrust -= THRUST_MAG * deltaTime * _orientation.getFront();} + if (_driveKeys[RIGHT ]) {_thrust += THRUST_MAG * deltaTime * _orientation.getRight();} + if (_driveKeys[LEFT ]) {_thrust -= THRUST_MAG * deltaTime * _orientation.getRight();} + if (_driveKeys[UP ]) {_thrust += THRUST_MAG * deltaTime * _orientation.getUp();} + if (_driveKeys[DOWN ]) {_thrust -= THRUST_MAG * deltaTime * _orientation.getUp();} + if (_driveKeys[ROT_RIGHT]) {_bodyYawDelta -= YAW_MAG * deltaTime;} + if (_driveKeys[ROT_LEFT ]) {_bodyYawDelta += YAW_MAG * deltaTime;} } // update body yaw by body yaw delta @@ -658,21 +648,12 @@ void Avatar::render(bool lookingInMirror) { // if this is my avatar, then render my interactions with the other avatar if ( _isMine ) { + if ( _interactingOtherIsNearby ) { - - glm::vec3 v1( _bone[ AVATAR_BONE_RIGHT_HAND ].position ); - glm::vec3 v2( _interactingOther->_handPosition ); - - glLineWidth( 8.0 ); - glColor4f( 0.7f, 0.4f, 0.1f, 0.6 ); - glBegin( GL_LINE_STRIP ); - glVertex3f( v1.x, v1.y, v1.z ); - glVertex3f( v2.x, v2.y, v2.z ); - glEnd(); + _avatarTouch.render(); } } } - void Avatar::renderHead(bool lookingInMirror) { int side = 0; @@ -835,7 +816,7 @@ void Avatar::renderHead(bool lookingInMirror) { glPopMatrix(); } - + void Avatar::startHandMovement() { if (!_usingBodySprings) { diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index ea19565d39..ccc3f34026 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -14,6 +14,7 @@ #include "Field.h" #include "world.h" +#include "AvatarTouch.h" #include "InterfaceConfig.h" #include "SerialInterface.h" @@ -24,7 +25,7 @@ const bool AVATAR_GRAVITY = true; const float DECAY = 0.1; -const float THRUST_MAG = 10.0; +const float THRUST_MAG = 1200.0; const float YAW_MAG = 500.0; //JJV - changed from 300.0; const float TEST_YAW_DECAY = 5.0; const float LIN_VEL_DECAY = 5.0; @@ -46,6 +47,8 @@ enum eyeContactTargets {LEFT_EYE, RIGHT_EYE, MOUTH}; #define MAX_OTHER_AVATARS 10 // temporary - for testing purposes! + + enum AvatarMode { AVATAR_MODE_STANDING = 0, @@ -84,6 +87,16 @@ enum AvatarBoneID NUM_AVATAR_BONES }; + +/* +static glm::vec3 avatarDefaultPose[NUM_AVATAR_BONES] = +{ + glm::vec3( 0.0f, 0.0f, 0.0f ), + glm::vec3( 0.0f, 0.0f, 0.0f ) +}; +*/ + + struct AvatarCollisionElipsoid { bool colliding; @@ -252,6 +265,7 @@ class Avatar : public AvatarData { Avatar* _interactingOther; bool _interactingOtherIsNearby; float _pelvisStandingHeight; + AvatarTouch _avatarTouch; // private methods... void initializeSkeleton(); diff --git a/interface/src/AvatarTouch.cpp b/interface/src/AvatarTouch.cpp new file mode 100644 index 0000000000..bd99cecd2b --- /dev/null +++ b/interface/src/AvatarTouch.cpp @@ -0,0 +1,43 @@ +// +// AvatarTouch.cpp +// interface +// +// Created by Jeffrey Ventrella +// Copyright (c) 2012 High Fidelity, Inc. All rights reserved. +// + +#include +#include +#include "AvatarTouch.h" +#include "InterfaceConfig.h" + +AvatarTouch::AvatarTouch() { + + _myHandPosition = glm::vec3( 0.0f, 0.0f, 0.0f ); + _yourHandPosition = glm::vec3( 0.0f, 0.0f, 0.0f ); +} + +void AvatarTouch::setMyHandPosition( glm::vec3 position ) { + _myHandPosition = position; +} + +void AvatarTouch::setYourPosition( glm::vec3 position ) { + _yourHandPosition = position; +} + + +void AvatarTouch::render() { + + glm::vec3 v1( _myHandPosition ); + glm::vec3 v2( _yourHandPosition ); + + glLineWidth( 8.0 ); + glColor4f( 0.7f, 0.4f, 0.1f, 0.6 ); + glBegin( GL_LINE_STRIP ); + glVertex3f( v1.x, v1.y, v1.z ); + glVertex3f( v2.x, v2.y, v2.z ); + glEnd(); +} + +void AvatarTouch::simulate (float deltaTime) { + } diff --git a/interface/src/AvatarTouch.h b/interface/src/AvatarTouch.h new file mode 100644 index 0000000000..8371ea3a19 --- /dev/null +++ b/interface/src/AvatarTouch.h @@ -0,0 +1,28 @@ +// +// AvatarTouch.h +// interface +// +// Created by Jeffrey Ventrella +// Copyright (c) 2012 High Fidelity, Inc. All rights reserved. +// + +#ifndef __interface__AvatarTouch__ +#define __interface__AvatarTouch__ + +#include + +class AvatarTouch { +public: + AvatarTouch(); + + void setMyHandPosition( glm::vec3 position ); + void setYourPosition ( glm::vec3 position ); + void simulate(float deltaTime); + void render(); + +private: + glm::vec3 _myHandPosition; + glm::vec3 _yourHandPosition; +}; + +#endif diff --git a/interface/src/HandControl.cpp b/interface/src/HandControl.cpp new file mode 100644 index 0000000000..37efc755c2 --- /dev/null +++ b/interface/src/HandControl.cpp @@ -0,0 +1,93 @@ +// +// HandControl.cpp +// interface +// +// Created by Jeffrey Ventrella +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. +// + +#include "HandControl.h" + +// this class takes mouse movements normalized within the screen +// dimensions and uses those to determine avatar hand movements, as well +// as states for ramping up and ramping down the amplitude of such movements. +// +// This class might expand to accommodate 3D input devices +// + +HandControl::HandControl() { + + _enabled = false; + _width = 0; + _height = 0; + _startX = 0; + _startY = 0; + _x = 0; + _y = 0; + _lastX = 0; + _lastY = 0; + _velocityX = 0; + _velocityY = 0; + _rampUpRate = 0.05; + _rampDownRate = 0.02; + _envelope = 0.0f; +} + +void HandControl::setScreenDimensions( int width, int height ) { + _width = width; + _height = height; + _startX = _width / 2; + _startY = _height / 2; +} + +void HandControl::update( int x, int y ) { + _lastX = _x; + _lastY = _y; + _x = x; + _y = y; + _velocityX = _x - _lastX; + _velocityY = _y - _lastY; + + // if the mouse is moving, ramp up the envelope to increase amplitude of hand movement... + if (( _velocityX != 0 ) + || ( _velocityY != 0 )) { + _enabled = true; + if ( _envelope < 1.0 ) { + _envelope += _rampUpRate; + if ( _envelope >= 1.0 ) { + _envelope = 1.0; + } + } + } + + // if not enabled ramp down the envelope to decrease amplitude of hand movement... + if ( ! _enabled ) { + if ( _envelope > 0.0 ) { + _envelope -= _rampDownRate; + if ( _envelope <= 0.0 ) { + _startX = _width / 2; + _startY = _height / 2; + _envelope = 0.0; + } + } + } + + _leftRight = 0.0; + _downUp = 0.0; + _backFront = 0.0; + + // if envelope is greater than zero, apply mouse movement to values to be output + if ( _envelope > 0.0 ) { + _leftRight += ( ( _x - _startX ) / (float)_width ) * _envelope; + _downUp += ( ( _y - _startY ) / (float)_height ) * _envelope; + } +} + +glm::vec3 HandControl::getValues() { + return glm::vec3( _leftRight, _downUp, _backFront ); +} + +void HandControl::stop() { + _enabled = false; +} + diff --git a/interface/src/HandControl.h b/interface/src/HandControl.h new file mode 100644 index 0000000000..7663004fbf --- /dev/null +++ b/interface/src/HandControl.h @@ -0,0 +1,42 @@ +// +// HandControl.h +// interface +// +// Created by Jeffrey Ventrella +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. +// + +#ifndef __interface__HandControl__ +#define __interface__HandControl__ + +#include + +class HandControl { +public: + HandControl(); + void setScreenDimensions(int width, int height); + void update( int x, int y ); + glm::vec3 getValues(); + void stop(); + +private: + bool _enabled; + int _width; + int _height; + int _startX; + int _startY; + int _x; + int _y; + int _lastX; + int _lastY; + int _velocityX; + int _velocityY; + float _rampUpRate; + float _rampDownRate; + float _envelope; + float _leftRight; + float _downUp; + float _backFront; +}; + +#endif diff --git a/interface/src/main.cpp b/interface/src/main.cpp index fcaff494c1..629715fe09 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -81,6 +81,7 @@ #include #include "ViewFrustum.h" +#include "HandControl.h" using namespace std; @@ -101,6 +102,8 @@ int HEIGHT = 800; int fullscreen = 0; float aspectRatio = 1.0f; +bool USING_FIRST_PERSON_EFFECT = false; + bool wantColorRandomizer = true; // for addSphere and load file Oscilloscope audioScope(256,200,true); @@ -171,6 +174,8 @@ int displayField = 0; int displayHeadMouse = 1; // Display sample mouse pointer controlled by head movement int headMouseX, headMouseY; +HandControl handControl; + int mouseX = 0; int mouseY = 0; @@ -180,80 +185,6 @@ int mousePressed = 0; // true if mouse has been pressed (clear when finished) Menu menu; // main menu int menuOn = 1; // Whether to show onscreen menu -struct HandController -{ - bool enabled; - int startX; - int startY; - int x; - int y; - int lastX; - int lastY; - int velocityX; - int velocityY; - float rampUpRate; - float rampDownRate; - float envelope; -}; - -HandController handController; - -void initializeHandController() { - handController.enabled = false; - handController.startX = WIDTH / 2; - handController.startY = HEIGHT / 2; - handController.x = 0; - handController.y = 0; - handController.lastX = 0; - handController.lastY = 0; - handController.velocityX = 0; - handController.velocityY = 0; - handController.rampUpRate = 0.05; - handController.rampDownRate = 0.02; - handController.envelope = 0.0f; -} - -void updateHandController( int x, int y ) { - handController.lastX = handController.x; - handController.lastY = handController.y; - handController.x = x; - handController.y = y; - handController.velocityX = handController.x - handController.lastX; - handController.velocityY = handController.y - handController.lastY; - - if (( handController.velocityX != 0 ) - || ( handController.velocityY != 0 )) { - handController.enabled = true; - myAvatar.startHandMovement(); - if ( handController.envelope < 1.0 ) { - handController.envelope += handController.rampUpRate; - if ( handController.envelope >= 1.0 ) { - handController.envelope = 1.0; - } - } - } - - if ( ! handController.enabled ) { - if ( handController.envelope > 0.0 ) { - handController.envelope -= handController.rampDownRate; - if ( handController.envelope <= 0.0 ) { - handController.startX = WIDTH / 2; - handController.startY = HEIGHT / 2; - handController.envelope = 0.0; - } - } - } - - if ( handController.envelope > 0.0 ) { - float leftRight = ( ( handController.x - handController.startX ) / (float)WIDTH ) * handController.envelope; - float downUp = ( ( handController.y - handController.startY ) / (float)HEIGHT ) * handController.envelope; - float backFront = 0.0; - myAvatar.setHandMovementValues( glm::vec3( leftRight, downUp, backFront ) ); - } -} - - - // // Serial USB Variables // @@ -385,7 +316,7 @@ void init(void) voxels.setViewerAvatar(&myAvatar); myAvatar.setRenderYaw(startYaw); - initializeHandController(); + handControl.setScreenDimensions(WIDTH, HEIGHT); headMouseX = WIDTH/2; headMouseY = HEIGHT/2; @@ -820,37 +751,38 @@ void display(void) float thirdPersonDistance = 1.f; float thirdPersonTightness = 8.0f; - myCamera.setPitch (thirdPersonPitch ); - myCamera.setUpShift (thirdPersonUpShift ); - myCamera.setDistance (thirdPersonDistance ); - myCamera.setTightness(thirdPersonTightness); - - /* - if ( myAvatar.getSpeed() < 0.02 ) { - if (myCamera.getMode() != CAMERA_MODE_FIRST_PERSON ) { - myCamera.setMode(CAMERA_MODE_FIRST_PERSON); - } + if ( USING_FIRST_PERSON_EFFECT ) { + if ( myAvatar.getSpeed() < 0.02 ) { - printf( "myCamera.getModeShift() = %f\n", myCamera.getModeShift()); + if (myCamera.getMode() != CAMERA_MODE_FIRST_PERSON ) { + myCamera.setMode(CAMERA_MODE_FIRST_PERSON); + } + + printf( "myCamera.getModeShift() = %f\n", myCamera.getModeShift()); - myCamera.setPitch ( thirdPersonPitch + myCamera.getModeShift() * ( firstPersonPitch - thirdPersonPitch )); - myCamera.setUpShift ( thirdPersonUpShift + myCamera.getModeShift() * ( firstPersonUpShift - thirdPersonUpShift )); - myCamera.setDistance ( thirdPersonDistance + myCamera.getModeShift() * ( firstPersonDistance - thirdPersonDistance )); - myCamera.setTightness ( thirdPersonTightness + myCamera.getModeShift() * ( firstPersonTightness - thirdPersonTightness )); - } else { - if (myCamera.getMode() != CAMERA_MODE_THIRD_PERSON ) { - myCamera.setMode(CAMERA_MODE_THIRD_PERSON); + myCamera.setPitch ( thirdPersonPitch + myCamera.getModeShift() * ( firstPersonPitch - thirdPersonPitch )); + myCamera.setUpShift ( thirdPersonUpShift + myCamera.getModeShift() * ( firstPersonUpShift - thirdPersonUpShift )); + myCamera.setDistance ( thirdPersonDistance + myCamera.getModeShift() * ( firstPersonDistance - thirdPersonDistance )); + myCamera.setTightness ( thirdPersonTightness + myCamera.getModeShift() * ( firstPersonTightness - thirdPersonTightness )); + } else { + if (myCamera.getMode() != CAMERA_MODE_THIRD_PERSON ) { + myCamera.setMode(CAMERA_MODE_THIRD_PERSON); + } + + printf( "myCamera.getModeShift() = %f\n", myCamera.getModeShift()); + + myCamera.setPitch ( firstPersonPitch + myCamera.getModeShift() * ( thirdPersonPitch - firstPersonPitch )); + myCamera.setUpShift ( firstPersonUpShift + myCamera.getModeShift() * ( thirdPersonUpShift - firstPersonUpShift )); + myCamera.setDistance ( firstPersonDistance + myCamera.getModeShift() * ( thirdPersonDistance - firstPersonDistance )); + myCamera.setTightness ( firstPersonTightness + myCamera.getModeShift() * ( thirdPersonTightness - firstPersonTightness )); } - - printf( "myCamera.getModeShift() = %f\n", myCamera.getModeShift()); - - myCamera.setPitch ( firstPersonPitch + myCamera.getModeShift() * ( thirdPersonPitch - firstPersonPitch )); - myCamera.setUpShift ( firstPersonUpShift + myCamera.getModeShift() * ( thirdPersonUpShift - firstPersonUpShift )); - myCamera.setDistance ( firstPersonDistance + myCamera.getModeShift() * ( thirdPersonDistance - firstPersonDistance )); - myCamera.setTightness ( firstPersonTightness + myCamera.getModeShift() * ( thirdPersonTightness - firstPersonTightness )); + } else { + myCamera.setPitch (thirdPersonPitch ); + myCamera.setUpShift (thirdPersonUpShift ); + myCamera.setDistance (thirdPersonDistance ); + myCamera.setTightness(thirdPersonTightness); } - */ - + myCamera.setTargetPosition( myAvatar.getHeadPosition() ); myCamera.setTargetYaw ( 180.0 - myAvatar.getBodyYaw() ); myCamera.setRoll ( 0.0 ); @@ -1503,7 +1435,8 @@ void idle(void) { float deltaTime = 1.f/FPS; // update behaviors for avatar hand movement - updateHandController( mouseX, mouseY ); + handControl.update( mouseX, mouseY ); + myAvatar.setHandMovementValues( handControl.getValues() ); // tell my avatar if the mouse is being pressed... if ( mousePressed == 1 ) { @@ -1513,9 +1446,9 @@ void idle(void) { myAvatar.setMousePressed( false ); } - // walking triggers the handController to stop + // walking triggers the handControl to stop if ( myAvatar.getMode() == AVATAR_MODE_WALKING ) { - handController.enabled = false; + handControl.stop(); } // From 46041b2ed9658526e9eacc51eddcf8084ccc3d5b Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 26 Apr 2013 10:21:14 -0700 Subject: [PATCH 02/14] Style tweaks: preface privates with underscore, capitalize enum members. --- interface/src/Avatar.cpp | 2 +- interface/src/ChatEntry.cpp | 32 ++++++++++++++-------------- interface/src/ChatEntry.h | 7 +++--- interface/src/main.cpp | 6 +++--- libraries/avatars/src/AvatarData.cpp | 2 +- libraries/avatars/src/AvatarData.h | 11 +++++++--- 6 files changed, 32 insertions(+), 28 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 305555577b..8086a3a07a 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -654,7 +654,7 @@ void Avatar::render(bool lookingInMirror) { glTranslatef(width * 0.5, 0, 0); glDisable(GL_LIGHTING); - if (_keyState == NoKeyDown) { + if (_keyState == NO_KEY_DOWN) { drawtext(0, 0, chatMessageScale, 180, 1.0, 0, _chatMessage.c_str(), 0, 1, 0); } else { diff --git a/interface/src/ChatEntry.cpp b/interface/src/ChatEntry.cpp index b658cbaefd..aca13a79ac 100644 --- a/interface/src/ChatEntry.cpp +++ b/interface/src/ChatEntry.cpp @@ -15,8 +15,8 @@ using namespace std; const int MAX_CONTENT_LENGTH = 140; void ChatEntry::clear () { - contents.clear(); - cursorPos = 0; + _contents.clear(); + _cursorPos = 0; } bool ChatEntry::key(unsigned char k) { @@ -25,22 +25,22 @@ bool ChatEntry::key(unsigned char k) { return false; case '\b': - if (cursorPos != 0) { - contents.erase(cursorPos - 1, 1); - cursorPos--; + if (_cursorPos != 0) { + _contents.erase(_cursorPos - 1, 1); + _cursorPos--; } return true; case 127: // delete - if (cursorPos < contents.size()) { - contents.erase(cursorPos, 1); + if (_cursorPos < _contents.size()) { + _contents.erase(_cursorPos, 1); } return true; default: - if (contents.size() != MAX_CONTENT_LENGTH) { - contents.insert(cursorPos, 1, k); - cursorPos++; + if (_contents.size() != MAX_CONTENT_LENGTH) { + _contents.insert(_cursorPos, 1, k); + _cursorPos++; } return true; } @@ -49,24 +49,24 @@ bool ChatEntry::key(unsigned char k) { void ChatEntry::specialKey(unsigned char k) { switch (k) { case GLUT_KEY_LEFT: - if (cursorPos != 0) { - cursorPos--; + if (_cursorPos != 0) { + _cursorPos--; } break; case GLUT_KEY_RIGHT: - if (cursorPos != contents.size()) { - cursorPos++; + if (_cursorPos != _contents.size()) { + _cursorPos++; } break; } } void ChatEntry::render(int screenWidth, int screenHeight) { - drawtext(20, screenHeight - 150, 0.10, 0, 1.0, 0, contents.c_str(), 1, 1, 1); + drawtext(20, screenHeight - 150, 0.10, 0, 1.0, 0, _contents.c_str(), 1, 1, 1); float width = 0; - for (string::iterator it = contents.begin(), end = it + cursorPos; it != end; it++) { + for (string::iterator it = _contents.begin(), end = it + _cursorPos; it != end; it++) { width += glutStrokeWidth(GLUT_STROKE_ROMAN, *it)*0.10; } glDisable(GL_LINE_SMOOTH); diff --git a/interface/src/ChatEntry.h b/interface/src/ChatEntry.h index ea9fc8eb77..db92822158 100644 --- a/interface/src/ChatEntry.h +++ b/interface/src/ChatEntry.h @@ -14,7 +14,7 @@ class ChatEntry { public: - const std::string& getContents () const { return contents; } + const std::string& getContents () const { return _contents; } void clear (); @@ -25,9 +25,8 @@ public: private: - std::string contents; - - int cursorPos; + std::string _contents; + int _cursorPos; }; #endif /* defined(__interface__ChatEntry__) */ diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 06478f4a7e..f1abfb36aa 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -1389,7 +1389,7 @@ void specialkey(int k, int x, int y) void keyUp(unsigned char k, int x, int y) { if (::chatEntryOn) { - myAvatar.setKeyState(AvatarData::NoKeyDown); + myAvatar.setKeyState(NO_KEY_DOWN); return; } @@ -1407,7 +1407,7 @@ void key(unsigned char k, int x, int y) if (::chatEntryOn) { if (chatEntry.key(k)) { myAvatar.setKeyState(k == '\b' || k == 127 ? // backspace or delete - AvatarData::DeleteKeyDown : AvatarData::InsertKeyDown); + DELETE_KEY_DOWN : INSERT_KEY_DOWN); myAvatar.setChatMessage(string(chatEntry.getContents().size(), 'X')); } else { @@ -1486,7 +1486,7 @@ void key(unsigned char k, int x, int y) if (k == '\r') { ::chatEntryOn = true; - myAvatar.setKeyState(AvatarData::NoKeyDown); + myAvatar.setKeyState(NO_KEY_DOWN); myAvatar.setChatMessage(string()); } } diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index b80fbc445e..8881c397af 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -51,7 +51,7 @@ AvatarData::AvatarData() : _cameraAspectRatio(0.0f), _cameraNearClip(0.0f), _cameraFarClip(0.0f), - _keyState(NoKeyDown) { + _keyState(NO_KEY_DOWN) { } diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 39a53481fa..88d5c1ac1f 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -15,6 +15,13 @@ #include +enum KeyState +{ + NO_KEY_DOWN, + INSERT_KEY_DOWN, + DELETE_KEY_DOWN +}; + class AvatarData : public AgentData { public: AvatarData(); @@ -76,8 +83,6 @@ public: void setCameraNearClip(float nearClip) { _cameraNearClip = nearClip; } void setCameraFarClip(float farClip) { _cameraFarClip = farClip; } - enum KeyState { NoKeyDown, InsertKeyDown, DeleteKeyDown }; - // key state void setKeyState(KeyState s) { _keyState = s; } KeyState keyState() const { return _keyState; } @@ -118,7 +123,7 @@ protected: float _cameraNearClip; float _cameraFarClip; - // key state (nothing, down, up, backspace) + // key state KeyState _keyState; // chat message From b9fdba27113b59a97ae7b45486a991f170655575 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 26 Apr 2013 11:08:41 -0700 Subject: [PATCH 03/14] Rather than creating a thread to read datagrams, just set the socket to nonblocking mode and check it before simulating. This addresses one aspect of the lack of synchronization on AgentList, but there are other issues... --- interface/src/main.cpp | 68 ++++++++++++------------------ libraries/shared/src/UDPSocket.cpp | 14 +++++- libraries/shared/src/UDPSocket.h | 3 ++ 3 files changed, 43 insertions(+), 42 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index f1abfb36aa..582a03ed00 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -39,8 +39,6 @@ #include #endif -#include - #include #include #include @@ -88,10 +86,7 @@ using namespace std; void reshape(int width, int height); // will be defined below void loadViewFrustum(ViewFrustum& viewFrustum); // will be defined below - -pthread_t networkReceiveThread; -bool stopNetworkReceiveThread = false; - +unsigned char incomingPacket[MAX_PACKET_SIZE]; int packetCount = 0; int packetsPerSecond = 0; int bytesPerSecond = 0; @@ -429,8 +424,6 @@ void terminate () { #ifndef _WIN32 audio.terminate(); #endif - stopNetworkReceiveThread = true; - pthread_join(networkReceiveThread, NULL); exit(EXIT_SUCCESS); } @@ -1492,41 +1485,34 @@ void key(unsigned char k, int x, int y) } // Receive packets from other agents/servers and decide what to do with them! -void *networkReceive(void *args) +void networkReceive() { sockaddr senderAddress; ssize_t bytesReceived; - unsigned char *incomingPacket = new unsigned char[MAX_PACKET_SIZE]; - while (!stopNetworkReceiveThread) { - if (AgentList::getInstance()->getAgentSocket().receive(&senderAddress, incomingPacket, &bytesReceived)) { - packetCount++; - bytesCount += bytesReceived; - - switch (incomingPacket[0]) { - case PACKET_HEADER_TRANSMITTER_DATA: - myAvatar.processTransmitterData(incomingPacket, bytesReceived); - break; - case PACKET_HEADER_VOXEL_DATA: - case PACKET_HEADER_Z_COMMAND: - case PACKET_HEADER_ERASE_VOXEL: - voxels.parseData(incomingPacket, bytesReceived); - break; - case PACKET_HEADER_BULK_AVATAR_DATA: - AgentList::getInstance()->processBulkAgentData(&senderAddress, - incomingPacket, - bytesReceived); - break; - default: - AgentList::getInstance()->processAgentData(&senderAddress, incomingPacket, bytesReceived); - break; - } + while (AgentList::getInstance()->getAgentSocket().receive(&senderAddress, incomingPacket, &bytesReceived)) { + packetCount++; + bytesCount += bytesReceived; + + switch (incomingPacket[0]) { + case PACKET_HEADER_TRANSMITTER_DATA: + myAvatar.processTransmitterData(incomingPacket, bytesReceived); + break; + case PACKET_HEADER_VOXEL_DATA: + case PACKET_HEADER_Z_COMMAND: + case PACKET_HEADER_ERASE_VOXEL: + voxels.parseData(incomingPacket, bytesReceived); + break; + case PACKET_HEADER_BULK_AVATAR_DATA: + AgentList::getInstance()->processBulkAgentData(&senderAddress, + incomingPacket, + bytesReceived); + break; + default: + AgentList::getInstance()->processAgentData(&senderAddress, incomingPacket, bytesReceived); + break; } } - - delete[] incomingPacket; - pthread_exit(0); - return NULL; } void idle(void) { @@ -1560,6 +1546,9 @@ void idle(void) { // updateAvatar(deltaTime); + // read incoming packets from network + networkReceive(); + //loop through all the other avatars and simulate them... AgentList* agentList = AgentList::getInstance(); for(AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { @@ -1703,6 +1692,7 @@ int main(int argc, const char * argv[]) listenPort = atoi(portStr); } AgentList::createInstance(AGENT_TYPE_AVATAR, listenPort); + AgentList::getInstance()->getAgentSocket().setBlocking(false); gettimeofday(&applicationStartupTime, NULL); const char* domainIP = getCmdOption(argc, argv, "--domain"); @@ -1785,10 +1775,6 @@ int main(int argc, const char * argv[]) printLog("Local Voxel File loaded.\n"); } - // create thread for receipt of data via UDP - pthread_create(&networkReceiveThread, NULL, networkReceive, NULL); - printLog("Network receive thread created.\n"); - glutTimerFunc(1000, Timer, 0); glutMainLoop(); diff --git a/libraries/shared/src/UDPSocket.cpp b/libraries/shared/src/UDPSocket.cpp index 0fa5ce08a4..31040946e0 100644 --- a/libraries/shared/src/UDPSocket.cpp +++ b/libraries/shared/src/UDPSocket.cpp @@ -119,7 +119,7 @@ unsigned short loadBufferWithSocketInfo(char *addressBuffer, sockaddr *socket) { } } -UDPSocket::UDPSocket(int listeningPort) { +UDPSocket::UDPSocket(int listeningPort) : blocking(true) { init(); // create the socket handle = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); @@ -191,6 +191,18 @@ bool UDPSocket::init() { return true; } +void UDPSocket::setBlocking(bool blocking) { + this->blocking = blocking; + +#ifdef _WIN32 + u_long mode = blocking ? 0 : 1; + ioctlsocket(handle, FIONBIO, &mode); +#else + int flags = fcntl(handle, F_GETFL, 0); + fcntl(handle, F_SETFL, blocking ? (flags & ~O_NONBLOCK) : (flags | O_NONBLOCK)); +#endif +} + // Receive data on this socket with retrieving address of sender bool UDPSocket::receive(void *receivedData, ssize_t *receivedBytes) { diff --git a/libraries/shared/src/UDPSocket.h b/libraries/shared/src/UDPSocket.h index 2bc5638b5e..80c093d6f4 100644 --- a/libraries/shared/src/UDPSocket.h +++ b/libraries/shared/src/UDPSocket.h @@ -23,12 +23,15 @@ class UDPSocket { UDPSocket(int listening_port); ~UDPSocket(); bool init(); + void setBlocking(bool blocking); + bool isBlocking() { return blocking; } int send(sockaddr *destAddress, const void *data, size_t byteLength); int send(char *destAddress, int destPort, const void *data, size_t byteLength); bool receive(void *receivedData, ssize_t *receivedBytes); bool receive(sockaddr *recvAddress, void *receivedData, ssize_t *receivedBytes); private: int handle; + bool blocking; }; bool socketMatch(sockaddr *first, sockaddr *second); From 948f9607f631d27c17198de4bbbd15438ff6ce76 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 26 Apr 2013 11:49:52 -0700 Subject: [PATCH 04/14] send head position as source position to mixer --- interface/src/Audio.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index f90027d25a..df1e547d31 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -151,10 +151,8 @@ int audioCallback (const void *inputBuffer, unsigned char *currentPacketPtr = dataPacket + 1; // memcpy the three float positions - for (int p = 0; p < 3; p++) { - memcpy(currentPacketPtr, &data->linkedAvatar->getPosition()[p], sizeof(float)); - currentPacketPtr += sizeof(float); - } + memcpy(currentPacketPtr, &data->linkedAvatar->getHeadPosition(), sizeof(float) * 3); + currentPacketPtr += (sizeof(float) * 3); // tell the mixer not to add additional attenuation to our source *(currentPacketPtr++) = 255; From 57c39ceb9908e622cc574d34c1a785f9eae09c26 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 26 Apr 2013 11:53:07 -0700 Subject: [PATCH 05/14] add some debugging to audio mixer for distance attenuation --- audio-mixer/src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index 9cb977dc1c..bc9de27844 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -127,7 +127,7 @@ void *sendBuffer(void *args) for (AgentList::iterator otherAgent = agentList->begin(); otherAgent != agentList->end(); otherAgent++) { - if (otherAgent != agent || ( otherAgent == agent && agentWantsLoopback)) { + if (otherAgent != agent || (otherAgent == agent && agentWantsLoopback)) { AudioRingBuffer* otherAgentBuffer = (AudioRingBuffer*) otherAgent->getLinkedData(); float *agentPosition = agentRingBuffer->getPosition(); @@ -146,6 +146,7 @@ void *sendBuffer(void *args) float minCoefficient = std::min(1.0f, powf(0.5, (logf(DISTANCE_RATIO * distanceToAgent) / logf(3)) - 1)); + printf("The DC between agent %d and %d is %f\n", agent->getAgentId(), otherAgent->getAgentId(), minCoefficient); distanceCoeffs[lowAgentIndex][highAgentIndex] = minCoefficient; } From e2cb1866ed0073bac8ad2fc3b859da3d8d82fde2 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 26 Apr 2013 11:59:26 -0700 Subject: [PATCH 06/14] add another line of debugging for audio mixer distance coeff --- audio-mixer/src/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index bc9de27844..9dd7b29008 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -146,6 +146,7 @@ void *sendBuffer(void *args) float minCoefficient = std::min(1.0f, powf(0.5, (logf(DISTANCE_RATIO * distanceToAgent) / logf(3)) - 1)); + printf("The distance between the two agents is %d\n", distanceToAgent); printf("The DC between agent %d and %d is %f\n", agent->getAgentId(), otherAgent->getAgentId(), minCoefficient); distanceCoeffs[lowAgentIndex][highAgentIndex] = minCoefficient; } From 7744685de4117a4f477473844e34e836ce4304e5 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 26 Apr 2013 12:01:47 -0700 Subject: [PATCH 07/14] debug of distance should be float and not integer --- audio-mixer/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index 9dd7b29008..8909475ab3 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -146,7 +146,7 @@ void *sendBuffer(void *args) float minCoefficient = std::min(1.0f, powf(0.5, (logf(DISTANCE_RATIO * distanceToAgent) / logf(3)) - 1)); - printf("The distance between the two agents is %d\n", distanceToAgent); + printf("The distance between the two agents is %f\n", distanceToAgent); printf("The DC between agent %d and %d is %f\n", agent->getAgentId(), otherAgent->getAgentId(), minCoefficient); distanceCoeffs[lowAgentIndex][highAgentIndex] = minCoefficient; } From e9592f9360684a430a3f29ecfdd9b9761387b608 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 26 Apr 2013 12:55:13 -0700 Subject: [PATCH 08/14] moved handController --- interface/src/main.cpp | 77 ++---------------------------------------- 1 file changed, 2 insertions(+), 75 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 43651377cf..404f3bbfa9 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -180,80 +180,6 @@ int menuOn = 1; // Whether to show onscreen menu ChatEntry chatEntry; // chat entry field bool chatEntryOn = false; // Whether to show the chat entry -/* -struct HandController -{ - bool enabled; - int startX; - int startY; - int x; - int y; - int lastX; - int lastY; - int velocityX; - int velocityY; - float rampUpRate; - float rampDownRate; - float envelope; -}; - -HandController handController; - -void initializeHandController() { - handController.enabled = false; - handController.startX = WIDTH / 2; - handController.startY = HEIGHT / 2; - handController.x = 0; - handController.y = 0; - handController.lastX = 0; - handController.lastY = 0; - handController.velocityX = 0; - handController.velocityY = 0; - handController.rampUpRate = 0.05; - handController.rampDownRate = 0.02; - handController.envelope = 0.0f; -} - -void updateHandController( int x, int y ) { - handController.lastX = handController.x; - handController.lastY = handController.y; - handController.x = x; - handController.y = y; - handController.velocityX = handController.x - handController.lastX; - handController.velocityY = handController.y - handController.lastY; - - if (( handController.velocityX != 0 ) - || ( handController.velocityY != 0 )) { - handController.enabled = true; - myAvatar.startHandMovement(); - if ( handController.envelope < 1.0 ) { - handController.envelope += handController.rampUpRate; - if ( handController.envelope >= 1.0 ) { - handController.envelope = 1.0; - } - } - } - - if ( ! handController.enabled ) { - if ( handController.envelope > 0.0 ) { - handController.envelope -= handController.rampDownRate; - if ( handController.envelope <= 0.0 ) { - handController.startX = WIDTH / 2; - handController.startY = HEIGHT / 2; - handController.envelope = 0.0; - } - } - } - - if ( handController.envelope > 0.0 ) { - float leftRight = ( ( handController.x - handController.startX ) / (float)WIDTH ) * handController.envelope; - float downUp = ( ( handController.y - handController.startY ) / (float)HEIGHT ) * handController.envelope; - float backFront = 0.0; - myAvatar.setHandMovementValues( glm::vec3( leftRight, downUp, backFront ) ); - } -} - -*/ // @@ -1536,7 +1462,8 @@ void idle(void) { float deltaTime = 1.f/FPS; - // update behaviors for avatar hand movement + // update behaviors for avatar hand movement: handControl takes mouse values as input, + // and gives back 3D values modulated for smooth transitioning between interaction modes. handControl.update( mouseX, mouseY ); myAvatar.setHandMovementValues( handControl.getValues() ); From 21f1669388bf6b094f1a47e33dc68701ed2f5e53 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 26 Apr 2013 13:10:44 -0700 Subject: [PATCH 09/14] How'd those tabs get in there? --- interface/src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 7c9e5bdf77..7a7b4aa2ca 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -1534,9 +1534,9 @@ void idle(void) { // Sample hardware, update view frustum if needed, Lsend avatar data to mixer/agents // updateAvatar(deltaTime); - - // read incoming packets from network - networkReceive(); + + // read incoming packets from network + networkReceive(); //loop through all the other avatars and simulate them... AgentList* agentList = AgentList::getInstance(); From 59ef9e5d7ef6583bc23ca6036a2882c788a610dc Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 26 Apr 2013 13:21:49 -0700 Subject: [PATCH 10/14] removed incomplete code snippet in Avatar.h --- interface/src/Avatar.cpp | 11 ++++++----- interface/src/Avatar.h | 10 ---------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index d2e53c3fbf..3de87186f2 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -592,6 +592,7 @@ void Avatar::updateAvatarCollisionDetectionAndResponse(glm::vec3 collisionPositi } void Avatar::render(bool lookingInMirror) { + /* // show avatar position glColor4f( 0.5f, 0.5f, 0.5f, 0.6 ); @@ -958,11 +959,11 @@ void Avatar::initializeSkeleton() { calculateBoneLengths(); _pelvisStandingHeight = - _bone[ AVATAR_BONE_PELVIS_SPINE ].length + - _bone[ AVATAR_BONE_LEFT_THIGH ].length + - _bone[ AVATAR_BONE_LEFT_SHIN ].length + - _bone[ AVATAR_BONE_LEFT_FOOT ].length + - _bone[ AVATAR_BONE_RIGHT_FOOT ].radius; + _bone[ AVATAR_BONE_PELVIS_SPINE ].length + + _bone[ AVATAR_BONE_LEFT_THIGH ].length + + _bone[ AVATAR_BONE_LEFT_SHIN ].length + + _bone[ AVATAR_BONE_LEFT_FOOT ].length + + _bone[ AVATAR_BONE_RIGHT_FOOT ].radius; // generate world positions updateSkeleton(); diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 20c02eee84..6afb65c904 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -89,16 +89,6 @@ enum AvatarBoneID NUM_AVATAR_BONES }; - -/* -static glm::vec3 avatarDefaultPose[NUM_AVATAR_BONES] = -{ - glm::vec3( 0.0f, 0.0f, 0.0f ), - glm::vec3( 0.0f, 0.0f, 0.0f ) -}; -*/ - - struct AvatarCollisionElipsoid { bool colliding; From 2486b6e15c0380a54cddd887ff5441746095f19e Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 26 Apr 2013 13:33:36 -0700 Subject: [PATCH 11/14] moved inline functions from Camera.h to Camera.cpp as per Stephen's request --- interface/src/Camera.cpp | 42 +++++++++++++++++++++++++++++++--------- interface/src/Camera.h | 11 ++++++----- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index 6118a9ead5..fa7722df88 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -65,25 +65,49 @@ void Camera::updateFollowMode( float deltaTime ) { } // update _yaw (before position!) - _yaw += ( _idealYaw - _yaw ) * t; - _orientation.yaw ( _yaw ); + _yaw += (_idealYaw - _yaw) * t; + _orientation.yaw(_yaw); - float radian = ( _yaw / 180.0 ) * PIE; + float radian = (_yaw / 180.0) * PIE; // update _position //these need to be checked to make sure they correspond to the correct coordinate system. - double x = _distance * -sin( radian ); - double z = _distance * cos( radian ); + double x = _distance * -sin(radian); + double z = _distance * cos(radian); double y = _upShift; - _idealPosition = _targetPosition + glm::vec3( x, y, z ); - //_idealPosition += _orientation.getRight() * _rightShift; - //_idealPosition += _orientation.getUp () * _upShift; + _idealPosition = _targetPosition + glm::vec3(x, y, z); // pull position towards ideal position - _position += ( _idealPosition - _position ) * t; + _position += (_idealPosition - _position) * t; } +void Camera::setMode(CameraMode m) { + _mode = m; + _modeShift = 0.0f; +} + +void Camera::setFieldOfView(float f) { + _fieldOfView = f; + _frustumNeedsReshape = true; +} + +void Camera::setAspectRatio(float a) { + _aspectRatio = a; + _frustumNeedsReshape = true; +} + +void Camera::setNearClip (float n) { + _nearClip = n; + _frustumNeedsReshape = true; +} + +void Camera::setFarClip (float f) { + _farClip = f; + _frustumNeedsReshape = true; +} + + // call to find out if the view frustum needs to be reshaped bool Camera::getFrustumNeedsReshape() { diff --git a/interface/src/Camera.h b/interface/src/Camera.h index 51760867c0..8864df3745 100644 --- a/interface/src/Camera.h +++ b/interface/src/Camera.h @@ -29,7 +29,6 @@ public: void update( float deltaTime ); - void setMode ( CameraMode m ) { _mode = m; _modeShift = 0.0f; } void setYaw ( float y ) { _yaw = y; } void setPitch ( float p ) { _pitch = p; } void setRoll ( float r ) { _roll = r; } @@ -41,10 +40,12 @@ public: void setPosition ( glm::vec3 p ) { _position = p; } void setOrientation ( Orientation o ) { _orientation.set(o); } void setTightness ( float t ) { _tightness = t; } - void setFieldOfView ( float f ) { _fieldOfView = f; _frustumNeedsReshape = true; } - void setAspectRatio ( float a ) { _aspectRatio = a; _frustumNeedsReshape = true; } - void setNearClip ( float n ) { _nearClip = n; _frustumNeedsReshape = true; } - void setFarClip ( float f ) { _farClip = f; _frustumNeedsReshape = true; } + + void setMode ( CameraMode m ); + void setFieldOfView ( float f ); + void setAspectRatio ( float a ); + void setNearClip ( float n ); + void setFarClip ( float f ); float getYaw () { return _yaw; } float getPitch () { return _pitch; } From 5442362b3aa39109d8b2d3417763640a34e23a94 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 26 Apr 2013 17:01:54 -0700 Subject: [PATCH 12/14] change DISTANCE_RATIO const in audio-mixer main --- audio-mixer/src/main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index 8909475ab3..a561cbe2bd 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -52,11 +52,10 @@ const float BUFFER_SEND_INTERVAL_USECS = (BUFFER_LENGTH_SAMPLES_PER_CHANNEL / SA const long MAX_SAMPLE_VALUE = std::numeric_limits::max(); const long MIN_SAMPLE_VALUE = std::numeric_limits::min(); -const float DISTANCE_RATIO = 3.0/4.2; +const float DISTANCE_RATIO = 3.0f / 0.3f; const float PHASE_AMPLITUDE_RATIO_AT_90 = 0.5; const int PHASE_DELAY_AT_90 = 20; - const int AGENT_LOOPBACK_MODIFIER = 307; const int LOOPBACK_SANITY_CHECK = 0; From c26becf6cbb11db30d5cb7b708da01dcd8a91446 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 26 Apr 2013 17:10:52 -0700 Subject: [PATCH 13/14] Added toggle for nonblocking networking; default to threaded for now, since we're seeing lower frame rates. --- interface/src/main.cpp | 81 +++++++++++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 25 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 7a7b4aa2ca..fa135bbd74 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -39,6 +39,8 @@ #include #endif +#include + #include #include #include @@ -85,6 +87,10 @@ using namespace std; void reshape(int width, int height); // will be defined below void loadViewFrustum(ViewFrustum& viewFrustum); // will be defined below +bool enableNetworkThread = true; +pthread_t networkReceiveThread; +bool stopNetworkReceiveThread = false; + unsigned char incomingPacket[MAX_PACKET_SIZE]; int packetCount = 0; int packetsPerSecond = 0; @@ -416,6 +422,11 @@ void terminate () { audio.terminate(); #endif + if (enableNetworkThread) { + stopNetworkReceiveThread = true; + pthread_join(networkReceiveThread, NULL); + } + exit(EXIT_SUCCESS); } @@ -1474,34 +1485,43 @@ void key(unsigned char k, int x, int y) } // Receive packets from other agents/servers and decide what to do with them! -void networkReceive() +void* networkReceive(void* args) { sockaddr senderAddress; ssize_t bytesReceived; - - while (AgentList::getInstance()->getAgentSocket().receive(&senderAddress, incomingPacket, &bytesReceived)) { - packetCount++; - bytesCount += bytesReceived; - - switch (incomingPacket[0]) { - case PACKET_HEADER_TRANSMITTER_DATA: - myAvatar.processTransmitterData(incomingPacket, bytesReceived); - break; - case PACKET_HEADER_VOXEL_DATA: - case PACKET_HEADER_Z_COMMAND: - case PACKET_HEADER_ERASE_VOXEL: - voxels.parseData(incomingPacket, bytesReceived); - break; - case PACKET_HEADER_BULK_AVATAR_DATA: - AgentList::getInstance()->processBulkAgentData(&senderAddress, - incomingPacket, - bytesReceived); - break; - default: - AgentList::getInstance()->processAgentData(&senderAddress, incomingPacket, bytesReceived); - break; + + while (!stopNetworkReceiveThread) { + if (AgentList::getInstance()->getAgentSocket().receive(&senderAddress, incomingPacket, &bytesReceived)) { + packetCount++; + bytesCount += bytesReceived; + + switch (incomingPacket[0]) { + case PACKET_HEADER_TRANSMITTER_DATA: + myAvatar.processTransmitterData(incomingPacket, bytesReceived); + break; + case PACKET_HEADER_VOXEL_DATA: + case PACKET_HEADER_Z_COMMAND: + case PACKET_HEADER_ERASE_VOXEL: + voxels.parseData(incomingPacket, bytesReceived); + break; + case PACKET_HEADER_BULK_AVATAR_DATA: + AgentList::getInstance()->processBulkAgentData(&senderAddress, + incomingPacket, + bytesReceived); + break; + default: + AgentList::getInstance()->processAgentData(&senderAddress, incomingPacket, bytesReceived); + break; + } + } else if (!enableNetworkThread) { + break; } } + + if (enableNetworkThread) { + pthread_exit(0); + } + return NULL; } void idle(void) { @@ -1536,7 +1556,9 @@ void idle(void) { updateAvatar(deltaTime); // read incoming packets from network - networkReceive(); + if (!enableNetworkThread) { + networkReceive(0); + } //loop through all the other avatars and simulate them... AgentList* agentList = AgentList::getInstance(); @@ -1680,7 +1702,10 @@ int main(int argc, const char * argv[]) listenPort = atoi(portStr); } AgentList::createInstance(AGENT_TYPE_AVATAR, listenPort); - AgentList::getInstance()->getAgentSocket().setBlocking(false); + enableNetworkThread = !cmdOptionExists(argc, argv, "--nonblocking"); + if (!enableNetworkThread) { + AgentList::getInstance()->getAgentSocket().setBlocking(false); + } gettimeofday(&applicationStartupTime, NULL); const char* domainIP = getCmdOption(argc, argv, "--domain"); @@ -1763,6 +1788,12 @@ int main(int argc, const char * argv[]) printLog("Local Voxel File loaded.\n"); } + // create thread for receipt of data via UDP + if (enableNetworkThread) { + pthread_create(&networkReceiveThread, NULL, networkReceive, NULL); + printLog("Network receive thread created.\n"); + } + glutTimerFunc(1000, Timer, 0); glutMainLoop(); From 14012ee44bdf4255b6652ecf19c03d682d22035a Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 26 Apr 2013 17:11:51 -0700 Subject: [PATCH 14/14] remove the debugging to confirm that distance attenuation is working --- audio-mixer/src/main.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index a561cbe2bd..a7c34b8a36 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -145,8 +145,6 @@ void *sendBuffer(void *args) float minCoefficient = std::min(1.0f, powf(0.5, (logf(DISTANCE_RATIO * distanceToAgent) / logf(3)) - 1)); - printf("The distance between the two agents is %f\n", distanceToAgent); - printf("The DC between agent %d and %d is %f\n", agent->getAgentId(), otherAgent->getAgentId(), minCoefficient); distanceCoeffs[lowAgentIndex][highAgentIndex] = minCoefficient; }