From 952cb2f2ae2bf4ba118656a3a55349874bb7b9f7 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Wed, 17 Apr 2013 15:14:30 -0700 Subject: [PATCH] Added head _isMine variable, added hand position transmission! --- interface/src/Head.cpp | 18 ++++++++++++------ interface/src/Head.h | 7 ++++--- interface/src/main.cpp | 8 ++++---- libraries/avatars/src/AvatarData.cpp | 14 ++++++++++++++ libraries/avatars/src/AvatarData.h | 2 ++ 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 2fdb6efe72..0a7390613b 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -45,7 +45,7 @@ vector iris_texture; unsigned int iris_texture_width = 512; unsigned int iris_texture_height = 256; -Head::Head() { +Head::Head(bool isMine) { initializeAvatar(); _avatar.orientation.setToIdentity(); @@ -59,6 +59,7 @@ Head::Head() { _bodyYawDelta = 0.0; _triggeringAction = false; _mode = AVATAR_MODE_STANDING; + _isMine = isMine; initializeSkeleton(); @@ -529,7 +530,7 @@ void Head::simulate(float deltaTime) { -void Head::render(int faceToFace, int isMine) { +void Head::render(int faceToFace) { //--------------------------------------------------- // show avatar position @@ -553,7 +554,7 @@ void Head::render(int faceToFace, int isMine) { //--------------------------------------------------- // render head //--------------------------------------------------- - renderHead( faceToFace, isMine ); + renderHead(faceToFace); //--------------------------------------------------- // render other avatars (DEBUG TEST) @@ -613,7 +614,7 @@ void Head::renderOrientationDirections( glm::vec3 position, Orientation orientat -void Head::renderHead( int faceToFace, int isMine ) { +void Head::renderHead( int faceToFace) { int side = 0; glEnable(GL_DEPTH_TEST); @@ -659,6 +660,7 @@ void Head::renderHead( int faceToFace, int isMine ) { glColor3fv(skinColor); // Head + if (!_isMine) glColor3f(0,0,1); // Temp: Other people are BLUE glutSolidSphere(1, 30, 30); // Ears @@ -1059,8 +1061,8 @@ void Head::updateHandMovement() { + _avatar.orientation.getUp() * -_movedHandOffset.y * 0.5f + _avatar.orientation.getFront() * -_movedHandOffset.y; - _bone[ AVATAR_BONE_RIGHT_HAND ].position += transformedHandMovement; - + _bone[ AVATAR_BONE_RIGHT_HAND ].position += transformedHandMovement; + //if holding hands, add a pull to the hand... if ( _usingSprings ) { if ( _closestOtherAvatar != -1 ) { @@ -1142,6 +1144,10 @@ void Head::updateHandMovement() { glm::vec3 newWristPosition = _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position; newWristPosition += vv * 0.7f; _bone[ AVATAR_BONE_RIGHT_FOREARM ].position = newWristPosition; + + // Set the vector we send for hand position to other people to be our right hand + setHandPosition(_bone[ AVATAR_BONE_RIGHT_HAND ].position); + } diff --git a/interface/src/Head.h b/interface/src/Head.h index 30fa9ba936..fae52332ab 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -103,7 +103,7 @@ struct Avatar class Head : public AvatarData { public: - Head(); + Head(bool isMine); ~Head(); Head(const Head &otherHead); Head* clone() const; @@ -143,10 +143,10 @@ class Head : public AvatarData { void setTriggeringAction( bool trigger ); - void render(int faceToFace, int isMine); + void render(int faceToFace); void renderBody(); - void renderHead( int faceToFace, int isMine ); + void renderHead( int faceToFace); //void renderOrientationDirections( glm::vec3 position, Orientation orientation, float size ); void simulate(float); @@ -178,6 +178,7 @@ class Head : public AvatarData { float getTransmitterHz() { return transmitterHz; }; private: + bool _isMine; float noise; float Pitch; float Yaw; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 547ac38a57..b2b7055db5 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -102,7 +102,7 @@ Oscilloscope audioScope(256,200,true); ViewFrustum viewFrustum; // current state of view frustum, perspective, orientation, etc. -Head myAvatar; // The rendered avatar of oneself +Head 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 @@ -826,7 +826,7 @@ void display(void) glPushMatrix(); glm::vec3 pos = agentHead->getBodyPosition(); glTranslatef(-pos.x, -pos.y, -pos.z); - agentHead->render(0, 0); + agentHead->render(0); glPopMatrix(); } } @@ -841,7 +841,7 @@ void display(void) //Render my own avatar - myAvatar.render( true, 1 ); + myAvatar.render(true); } glPopMatrix(); @@ -1494,7 +1494,7 @@ void mouseoverFunc( int x, int y) void attachNewHeadToAgent(Agent *newAgent) { if (newAgent->getLinkedData() == NULL) { - newAgent->setLinkedData(new Head()); + newAgent->setLinkedData(new Head(false)); } } diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 0bf9ddff74..9be48b04ac 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -51,6 +51,7 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { // TODO: DRY this up to a shared method // that can pack any type given the number of bytes // and return the number of bytes to push the pointer + memcpy(destinationBuffer, &_bodyPosition, sizeof(float) * 3); destinationBuffer += sizeof(float) * 3; @@ -58,6 +59,11 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyPitch); destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyRoll); + memcpy(destinationBuffer, &_handPosition, sizeof(float) * 3); + destinationBuffer += sizeof(float) * 3; + + //std::cout << _handPosition.x << ", " << _handPosition.y << ", " << _handPosition.z << "\n"; + return destinationBuffer - bufferStart; } @@ -73,6 +79,10 @@ void AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyYaw); sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyPitch); sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyRoll); + + memcpy(&_handPosition, sourceBuffer, sizeof(float) * 3); + sourceBuffer += sizeof(float) * 3; + } glm::vec3 AvatarData::getBodyPosition() { @@ -85,6 +95,10 @@ void AvatarData::setBodyPosition(glm::vec3 bodyPosition) { _bodyPosition = bodyPosition; } +void AvatarData::setHandPosition(glm::vec3 handPosition) { + _handPosition = handPosition; +} + float AvatarData::getBodyYaw() { return _bodyYaw; } diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 5e7f52a04d..b650a317f8 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -24,6 +24,7 @@ public: glm::vec3 getBodyPosition(); void setBodyPosition(glm::vec3 bodyPosition); + void setHandPosition(glm::vec3 handPosition); int getBroadcastData(unsigned char* destinationBuffer); void parseData(unsigned char* sourceBuffer, int numBytes); @@ -39,6 +40,7 @@ public: protected: glm::vec3 _bodyPosition; + glm::vec3 _handPosition; float _bodyYaw; float _bodyPitch;