Merge pull request #69 from PhilipRosedale/master

Added hand position to transmission
This commit is contained in:
Jeffrey Ventrella 2013-04-17 15:29:18 -07:00
commit 754856227d
5 changed files with 43 additions and 29 deletions

View file

@ -45,7 +45,7 @@ vector<unsigned char> iris_texture;
unsigned int iris_texture_width = 512; unsigned int iris_texture_width = 512;
unsigned int iris_texture_height = 256; unsigned int iris_texture_height = 256;
Head::Head() { Head::Head(bool isMine) {
initializeAvatar(); initializeAvatar();
_avatar.orientation.setToIdentity(); _avatar.orientation.setToIdentity();
@ -59,6 +59,7 @@ Head::Head() {
_bodyYawDelta = 0.0; _bodyYawDelta = 0.0;
_triggeringAction = false; _triggeringAction = false;
_mode = AVATAR_MODE_STANDING; _mode = AVATAR_MODE_STANDING;
_isMine = isMine;
initializeSkeleton(); initializeSkeleton();
@ -208,7 +209,7 @@ void Head::reset() {
//this pertains to moving the head with the glasses //this pertains to moving the head with the glasses
//--------------------------------------------------- //---------------------------------------------------
void Head::UpdatePos(float frametime, SerialInterface * serialInterface, int head_mirror, glm::vec3 * gravity) void Head::UpdateGyros(float frametime, SerialInterface * serialInterface, int head_mirror, glm::vec3 * gravity)
// Using serial data, update avatar/render position and angles // Using serial data, update avatar/render position and angles
{ {
const float PITCH_ACCEL_COUPLING = 0.5; const float PITCH_ACCEL_COUPLING = 0.5;
@ -465,8 +466,6 @@ void Head::simulate(float deltaTime) {
} }
} }
const float DEGREES_BETWEEN_VIEWER_EYES = 3; const float DEGREES_BETWEEN_VIEWER_EYES = 3;
const float DEGREES_TO_VIEWER_MOUTH = 7; const float DEGREES_TO_VIEWER_MOUTH = 7;
@ -531,7 +530,7 @@ void Head::simulate(float deltaTime) {
void Head::render(int faceToFace, int isMine) { void Head::render(int faceToFace) {
//--------------------------------------------------- //---------------------------------------------------
// show avatar position // show avatar position
@ -555,7 +554,7 @@ void Head::render(int faceToFace, int isMine) {
//--------------------------------------------------- //---------------------------------------------------
// render head // render head
//--------------------------------------------------- //---------------------------------------------------
renderHead( faceToFace, isMine ); renderHead(faceToFace);
//--------------------------------------------------- //---------------------------------------------------
// render other avatars (DEBUG TEST) // render other avatars (DEBUG TEST)
@ -615,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; int side = 0;
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
@ -661,6 +660,7 @@ void Head::renderHead( int faceToFace, int isMine ) {
glColor3fv(skinColor); glColor3fv(skinColor);
// Head // Head
if (!_isMine) glColor3f(0,0,1); // Temp: Other people are BLUE
glutSolidSphere(1, 30, 30); glutSolidSphere(1, 30, 30);
// Ears // Ears
@ -1017,10 +1017,6 @@ void Head::updateBodySprings( float deltaTime ) {
} }
} }
float Head::getBodyYaw() {
return _bodyYaw;
}
glm::vec3 Head::getHeadLookatDirection() { glm::vec3 Head::getHeadLookatDirection() {
return glm::vec3 return glm::vec3
( (
@ -1148,6 +1144,10 @@ void Head::updateHandMovement() {
glm::vec3 newWristPosition = _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position; glm::vec3 newWristPosition = _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position;
newWristPosition += vv * 0.7f; newWristPosition += vv * 0.7f;
_bone[ AVATAR_BONE_RIGHT_FOREARM ].position = newWristPosition; _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);
} }

View file

@ -103,13 +103,13 @@ struct Avatar
class Head : public AvatarData { class Head : public AvatarData {
public: public:
Head(); Head(bool isMine);
~Head(); ~Head();
Head(const Head &otherHead); Head(const Head &otherHead);
Head* clone() const; Head* clone() const;
void reset(); void reset();
void UpdatePos(float frametime, SerialInterface * serialInterface, int head_mirror, glm::vec3 * gravity); void UpdateGyros(float frametime, SerialInterface * serialInterface, int head_mirror, glm::vec3 * gravity);
void setNoise (float mag) { noise = mag; } void setNoise (float mag) { noise = mag; }
void setPitch(float p) {Pitch = p; } void setPitch(float p) {Pitch = p; }
void setYaw(float y) {Yaw = y; } void setYaw(float y) {Yaw = y; }
@ -130,7 +130,9 @@ class Head : public AvatarData {
float getYaw() {return Yaw;} float getYaw() {return Yaw;}
float getLastMeasuredYaw() {return YawRate;} float getLastMeasuredYaw() {return YawRate;}
float getBodyYaw(); float getBodyYaw() {return _bodyYaw;};
void addBodyYaw(float y) {_bodyYaw += y;};
glm::vec3 getHeadLookatDirection(); glm::vec3 getHeadLookatDirection();
glm::vec3 getHeadLookatDirectionUp(); glm::vec3 getHeadLookatDirectionUp();
glm::vec3 getHeadLookatDirectionRight(); glm::vec3 getHeadLookatDirectionRight();
@ -141,10 +143,10 @@ class Head : public AvatarData {
void setTriggeringAction( bool trigger ); void setTriggeringAction( bool trigger );
void render(int faceToFace, int isMine); void render(int faceToFace);
void renderBody(); void renderBody();
void renderHead( int faceToFace, int isMine ); void renderHead( int faceToFace);
//void renderOrientationDirections( glm::vec3 position, Orientation orientation, float size ); //void renderOrientationDirections( glm::vec3 position, Orientation orientation, float size );
void simulate(float); void simulate(float);
@ -176,6 +178,7 @@ class Head : public AvatarData {
float getTransmitterHz() { return transmitterHz; }; float getTransmitterHz() { return transmitterHz; };
private: private:
bool _isMine;
float noise; float noise;
float Pitch; float Pitch;
float Yaw; float Yaw;

View file

@ -102,7 +102,7 @@ Oscilloscope audioScope(256,200,true);
ViewFrustum viewFrustum; // current state of view frustum, perspective, orientation, etc. 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 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 Camera viewFrustumOffsetCamera; // The camera we use to sometimes show the view frustum from an offset mode
@ -234,11 +234,6 @@ void displayStats(void)
sprintf(stats, "FPS = %3.0f Pkts/s = %d Bytes/s = %d Head(x,y,z)= %4.2f, %4.2f, %4.2f ", sprintf(stats, "FPS = %3.0f Pkts/s = %d Bytes/s = %d Head(x,y,z)= %4.2f, %4.2f, %4.2f ",
FPS, packetsPerSecond, bytesPerSecond, avatarPos.x,avatarPos.y,avatarPos.z); FPS, packetsPerSecond, bytesPerSecond, avatarPos.x,avatarPos.y,avatarPos.z);
drawtext(10, statsVerticalOffset + 49, 0.10f, 0, 1.0, 0, stats); drawtext(10, statsVerticalOffset + 49, 0.10f, 0, 1.0, 0, stats);
if (serialPort.active) {
sprintf(stats, "ADC samples = %d, LED = %d",
serialPort.getNumSamples(), serialPort.getLED());
drawtext(300, statsVerticalOffset + 30, 0.10f, 0, 1.0, 0, stats);
}
std::stringstream voxelStats; std::stringstream voxelStats;
voxelStats << "Voxels Rendered: " << voxels.getVoxelsRendered(); voxelStats << "Voxels Rendered: " << voxels.getVoxelsRendered();
@ -389,7 +384,7 @@ void updateAvatar(float frametime)
float gyroPitchRate = serialPort.getRelativeValue(PITCH_RATE); float gyroPitchRate = serialPort.getRelativeValue(PITCH_RATE);
float gyroYawRate = serialPort.getRelativeValue(YAW_RATE); float gyroYawRate = serialPort.getRelativeValue(YAW_RATE);
myAvatar.UpdatePos(frametime, &serialPort, headMirror, &gravity); myAvatar.UpdateGyros(frametime, &serialPort, headMirror, &gravity);
// //
// Update gyro-based mouse (X,Y on screen) // Update gyro-based mouse (X,Y on screen)
@ -831,7 +826,7 @@ void display(void)
glPushMatrix(); glPushMatrix();
glm::vec3 pos = agentHead->getBodyPosition(); glm::vec3 pos = agentHead->getBodyPosition();
glTranslatef(-pos.x, -pos.y, -pos.z); glTranslatef(-pos.x, -pos.y, -pos.z);
agentHead->render(0, 0); agentHead->render(0);
glPopMatrix(); glPopMatrix();
} }
} }
@ -846,7 +841,7 @@ void display(void)
//Render my own avatar //Render my own avatar
myAvatar.render( true, 1 ); myAvatar.render(true);
} }
glPopMatrix(); glPopMatrix();
@ -1499,7 +1494,7 @@ void mouseoverFunc( int x, int y)
void attachNewHeadToAgent(Agent *newAgent) { void attachNewHeadToAgent(Agent *newAgent) {
if (newAgent->getLinkedData() == NULL) { if (newAgent->getLinkedData() == NULL) {
newAgent->setLinkedData(new Head()); newAgent->setLinkedData(new Head(false));
} }
} }

View file

@ -49,6 +49,7 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) {
// TODO: DRY this up to a shared method // TODO: DRY this up to a shared method
// that can pack any type given the number of bytes // that can pack any type given the number of bytes
// and return the number of bytes to push the pointer // and return the number of bytes to push the pointer
memcpy(destinationBuffer, &_bodyPosition, sizeof(float) * 3); memcpy(destinationBuffer, &_bodyPosition, sizeof(float) * 3);
destinationBuffer += sizeof(float) * 3; destinationBuffer += sizeof(float) * 3;
@ -56,6 +57,11 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) {
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyPitch); destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyPitch);
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyRoll); 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; return destinationBuffer - bufferStart;
} }
@ -71,6 +77,10 @@ void AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyYaw); sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyYaw);
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyPitch); sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyPitch);
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyRoll); sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyRoll);
memcpy(&_handPosition, sourceBuffer, sizeof(float) * 3);
sourceBuffer += sizeof(float) * 3;
} }
glm::vec3 AvatarData::getBodyPosition() { glm::vec3 AvatarData::getBodyPosition() {
@ -83,6 +93,10 @@ void AvatarData::setBodyPosition(glm::vec3 bodyPosition) {
_bodyPosition = bodyPosition; _bodyPosition = bodyPosition;
} }
void AvatarData::setHandPosition(glm::vec3 handPosition) {
_handPosition = handPosition;
}
float AvatarData::getBodyYaw() { float AvatarData::getBodyYaw() {
return _bodyYaw; return _bodyYaw;
} }

View file

@ -24,6 +24,7 @@ public:
glm::vec3 getBodyPosition(); glm::vec3 getBodyPosition();
void setBodyPosition(glm::vec3 bodyPosition); void setBodyPosition(glm::vec3 bodyPosition);
void setHandPosition(glm::vec3 handPosition);
int getBroadcastData(unsigned char* destinationBuffer); int getBroadcastData(unsigned char* destinationBuffer);
void parseData(unsigned char* sourceBuffer, int numBytes); void parseData(unsigned char* sourceBuffer, int numBytes);
@ -39,6 +40,7 @@ public:
protected: protected:
glm::vec3 _bodyPosition; glm::vec3 _bodyPosition;
glm::vec3 _handPosition;
float _bodyYaw; float _bodyYaw;
float _bodyPitch; float _bodyPitch;