Merge pull request from Ventrella/master

renamed "Head" to "Avatar" and cleaned up some comments to comply with coding standards
This commit is contained in:
birarda 2013-04-24 17:04:16 -07:00
commit 080b8b7337
9 changed files with 96 additions and 185 deletions

View file

@ -27,7 +27,6 @@ const float MAX_ITERATIONS_BETWEEN_AUDIO_SENDS = (MAX_AUDIO_SEND_INTERVAL_SECS *
bool stopReceiveAgentDataThread; bool stopReceiveAgentDataThread;
bool injectAudioThreadRunning = false; bool injectAudioThreadRunning = false;
int handStateTimer = 0;
int TEMP_AUDIO_LISTEN_PORT = 55439; int TEMP_AUDIO_LISTEN_PORT = 55439;
// UDPSocket audioSocket(TEMP_AUDIO_LISTEN_PORT); // 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 // put her hand out so somebody can shake it
eve.setHandPosition(glm::vec3(eve.getPosition()[0] - 0.2, eve.setHandPosition(glm::vec3(eve.getPosition()[0] - 0.2,
0.25, 0.25,
eve.getPosition()[2] + 0.1)); 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;
}
// read eve's audio data // read eve's audio data
AudioInjector eveAudioInjector("eve.raw"); AudioInjector eveAudioInjector("eve.raw");
@ -152,6 +138,8 @@ int main(int argc, const char* argv[]) {
// int numIterationsLeftBeforeAudioSend = 0; // int numIterationsLeftBeforeAudioSend = 0;
// pthread_t injectAudioThread; // pthread_t injectAudioThread;
int handStateTimer = 0;
while (true) { while (true) {
// update the thisSend timeval to the current time // update the thisSend timeval to the current time
gettimeofday(&thisSend, NULL); 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 // 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) { if ((numMicrosecondsSleep = (DATA_SEND_INTERVAL_MSECS * 1000) - (usecTimestampNow() - usecTimestamp(&thisSend))) > 0) {
usleep(numMicrosecondsSleep); 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 // stop the receive agent data thread

View file

@ -157,7 +157,7 @@ int audioCallback (const void *inputBuffer,
// memcpy the three float positions // memcpy the three float positions
for (int p = 0; p < 3; p++) { 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); currentPacketPtr += sizeof(float);
} }
@ -165,7 +165,7 @@ int audioCallback (const void *inputBuffer,
*(currentPacketPtr++) = 255; *(currentPacketPtr++) = 255;
// memcpy the corrected render yaw // memcpy the corrected render yaw
float correctedYaw = fmodf(data->linkedHead->getRenderYaw(), 360); float correctedYaw = fmodf(data->linkedAvatar->getRenderYaw(), 360);
if (correctedYaw > 180) { if (correctedYaw > 180) {
correctedYaw -= 360; correctedYaw -= 360;
@ -259,7 +259,7 @@ int audioCallback (const void *inputBuffer,
// rotation of the head relative to body, this may effect flange effect! // 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) { if (!samplesLeftForFlange && lastYawMeasured > MIN_FLANGE_EFFECT_THRESHOLD) {
// we should flange for one second // 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. * @return Returns true if successful or false if an error occurred.
Use Audio::getError() to retrieve the error code. 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 // read the walking sound from the raw file and store it
// in the in memory array // in the in memory array
@ -472,7 +472,7 @@ Audio::Audio(Oscilloscope *s, Head *linkedHead)
audioData = new AudioData(); audioData = new AudioData();
audioData->linkedHead = linkedHead; audioData->linkedAvatar = linkedAvatar;
// setup a UDPSocket // setup a UDPSocket
audioData->audioSocket = new UDPSocket(AUDIO_UDP_LISTEN_PORT); audioData->audioSocket = new UDPSocket(AUDIO_UDP_LISTEN_PORT);

View file

@ -12,12 +12,12 @@
#include <portaudio.h> #include <portaudio.h>
#include "AudioData.h" #include "AudioData.h"
#include "Oscilloscope.h" #include "Oscilloscope.h"
#include "Head.h" #include "Avatar.h"
class Audio { class Audio {
public: public:
// initializes audio I/O // initializes audio I/O
Audio(Oscilloscope *s, Head *linkedHead); Audio(Oscilloscope *s, Avatar *linkedAvatar);
void render(); void render();
void render(int screenWidth, int screenHeight); void render(int screenWidth, int screenHeight);

View file

@ -13,7 +13,7 @@
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include "AudioRingBuffer.h" #include "AudioRingBuffer.h"
#include "UDPSocket.h" #include "UDPSocket.h"
#include "Head.h" #include "Avatar.h"
class AudioData { class AudioData {
public: public:
@ -23,7 +23,7 @@ class AudioData {
UDPSocket *audioSocket; UDPSocket *audioSocket;
Head *linkedHead; Avatar *linkedAvatar;
// store current mixer address and port // store current mixer address and port
in_addr_t mixerAddress; in_addr_t mixerAddress;

View file

@ -1,5 +1,5 @@
// //
// Head.cpp // Avatar.cpp
// interface // interface
// //
// Created by Philip Rosedale on 9/11/12. // Created by Philip Rosedale on 9/11/12.
@ -11,7 +11,7 @@
#include <vector> #include <vector>
#include <lodepng.h> #include <lodepng.h>
#include <SharedUtil.h> #include <SharedUtil.h>
#include "Head.h" #include "Avatar.h"
#include "Log.h" #include "Log.h"
#include <AgentList.h> #include <AgentList.h>
#include <AgentTypes.h> #include <AgentTypes.h>
@ -41,7 +41,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(bool isMine) { Avatar::Avatar(bool isMine) {
_orientation.setToIdentity(); _orientation.setToIdentity();
@ -128,7 +128,7 @@ Head::Head(bool isMine) {
Head::Head(const Head &otherAvatar) { Avatar::Avatar(const Avatar &otherAvatar) {
_velocity = otherAvatar._velocity; _velocity = otherAvatar._velocity;
_thrust = otherAvatar._thrust; _thrust = otherAvatar._thrust;
@ -207,25 +207,24 @@ Head::Head(const Head &otherAvatar) {
} }
} }
Head::~Head() { Avatar::~Avatar() {
if (_sphere != NULL) { if (_sphere != NULL) {
gluDeleteQuadric(_sphere); gluDeleteQuadric(_sphere);
} }
} }
Head* Head::clone() const { Avatar* Avatar::clone() const {
return new Head(*this); return new Avatar(*this);
} }
void Head::reset() { void Avatar::reset() {
_headPitch = _headYaw = _headRoll = 0; _headPitch = _headYaw = _headRoll = 0;
_head.leanForward = _head.leanSideways = 0; _head.leanForward = _head.leanSideways = 0;
} }
//this pertains to moving the head with the glasses //this pertains to moving the head with the glasses
//--------------------------------------------------- void Avatar::UpdateGyros(float frametime, SerialInterface * serialInterface, glm::vec3 * gravity)
void Head::UpdateGyros(float frametime, SerialInterface * serialInterface, 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;
@ -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); 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 // Add Body lean as impulse
_head.leanSideways += x; _head.leanSideways += x;
_head.leanForward += z; _head.leanForward += z;
} }
void Head::setLeanForward(float dist){ void Avatar::setLeanForward(float dist){
_head.leanForward = dist; _head.leanForward = dist;
} }
void Head::setLeanSideways(float dist){ void Avatar::setLeanSideways(float dist){
_head.leanSideways = dist; _head.leanSideways = dist;
} }
void Head::setMousePressed( bool d ) { void Avatar::setMousePressed( bool d ) {
_mousePressed = d; _mousePressed = d;
} }
void Head::simulate(float deltaTime) { void Avatar::simulate(float deltaTime) {
//------------------------
// update avatar skeleton // update avatar skeleton
//------------------------
updateSkeleton(); updateSkeleton();
//------------------------------------------------------------
// reset hand and arm positions according to hand movement // reset hand and arm positions according to hand movement
//------------------------------------------------------------
updateHandMovement( deltaTime ); updateHandMovement( deltaTime );
if ( !_interactingOtherIsNearby ) { if ( !_interactingOtherIsNearby ) {
@ -303,10 +298,8 @@ void Head::simulate(float deltaTime) {
_interactingOtherIsNearby = false; _interactingOtherIsNearby = false;
//-------------------------------------------------------------
// if the avatar being simulated is mine, then loop through // if the avatar being simulated is mine, then loop through
// all the other avatars for potential interactions... // all the other avatars for potential interactions...
//-------------------------------------------------------------
if ( _isMine ) if ( _isMine )
{ {
float closestDistance = 10000.0f; float closestDistance = 10000.0f;
@ -317,11 +310,9 @@ void Head::simulate(float deltaTime) {
agent != agentList->getAgents().end(); agent != agentList->getAgents().end();
agent++) { agent++) {
if (( agent->getLinkedData() != NULL && ( agent->getType() == AGENT_TYPE_AVATAR ) )) { 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 // check for collisions with other avatars and respond
//------------------------------------------------------
updateAvatarCollisionDetectionAndResponse updateAvatarCollisionDetectionAndResponse
( (
otherAvatar->getPosition(), otherAvatar->getPosition(),
@ -331,9 +322,7 @@ void Head::simulate(float deltaTime) {
deltaTime deltaTime
); );
//-------------------------------------------------
// test other avatar hand position for proximity // test other avatar hand position for proximity
//------------------------------------------------
glm::vec3 v( _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position ); glm::vec3 v( _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position );
v -= otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND ); v -= otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND );
@ -346,11 +335,8 @@ void Head::simulate(float deltaTime) {
_interactingOther = otherAvatar; _interactingOther = otherAvatar;
_interactingOtherIsNearby = true; _interactingOtherIsNearby = true;
//---------------------------------------------------------------------
// if I am holding hands with another avatar, a force is applied // 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 vectorToOtherHand = _interactingOther->_handPosition - _handHolding.position;
glm::vec3 vectorToMyHand = _bone[ AVATAR_BONE_RIGHT_HAND ].position - _handHolding.position; glm::vec3 vectorToMyHand = _bone[ AVATAR_BONE_RIGHT_HAND ].position - _handHolding.position;
@ -373,14 +359,13 @@ void Head::simulate(float deltaTime) {
updateArmIKAndConstraints( deltaTime ); updateArmIKAndConstraints( deltaTime );
if ( ! _interactingOtherIsNearby ) { if (!_interactingOtherIsNearby) {
_interactingOther = NULL; _interactingOther = NULL;
} }
if ( usingBigSphereCollisionTest ) { if ( usingBigSphereCollisionTest ) {
//--------------------------------------------------------------
// test for avatar collision response (using a big sphere :) // test for avatar collision response (using a big sphere :)
//--------------------------------------------------------------
updateAvatarCollisionDetectionAndResponse updateAvatarCollisionDetectionAndResponse
( (
_TEST_bigSpherePosition, _TEST_bigSpherePosition,
@ -406,11 +391,9 @@ void Head::simulate(float deltaTime) {
// update body springs // update body springs
updateBodySprings( deltaTime ); updateBodySprings( deltaTime );
// driving the avatar around should only apply if this is my avatar (as opposed to an avatar being driven remotely)
if ( _isMine ) { // driving the avatar around should only apply if this is my avatar (as opposed to an avatar being driven remotely) if ( _isMine ) {
//-------------------------------------------------
// this handles the avatar being driven around...
//-------------------------------------------------
_thrust = glm::vec3( 0.0, 0.0, 0.0 ); _thrust = glm::vec3( 0.0, 0.0, 0.0 );
if (_driveKeys[FWD]) { if (_driveKeys[FWD]) {
@ -444,9 +427,7 @@ void Head::simulate(float deltaTime) {
_bodyYawDelta += YAW_MAG * deltaTime; _bodyYawDelta += YAW_MAG * deltaTime;
} }
} }
//----------------------------------------------------------
float translationalSpeed = glm::length( _velocity ); float translationalSpeed = glm::length( _velocity );
float rotationalSpeed = fabs( _bodyYawDelta ); float rotationalSpeed = fabs( _bodyYawDelta );
if ( translationalSpeed + rotationalSpeed > 0.2 ) if ( translationalSpeed + rotationalSpeed > 0.2 )
@ -458,42 +439,27 @@ void Head::simulate(float deltaTime) {
_mode = AVATAR_MODE_INTERACTING; _mode = AVATAR_MODE_INTERACTING;
} }
//----------------------------------------------------------
// update body yaw by body yaw delta // update body yaw by body yaw delta
//----------------------------------------------------------
if (_isMine) { if (_isMine) {
_bodyYaw += _bodyYawDelta * deltaTime; _bodyYaw += _bodyYawDelta * deltaTime;
} }
//----------------------------------------------------------
// decay body yaw delta // decay body yaw delta
//----------------------------------------------------------
_bodyYawDelta *= (1.0 - TEST_YAW_DECAY * deltaTime); _bodyYawDelta *= (1.0 - TEST_YAW_DECAY * deltaTime);
//----------------------------------------------------------
// add thrust to velocity // add thrust to velocity
//----------------------------------------------------------
_velocity += glm::dvec3(_thrust * deltaTime); _velocity += glm::dvec3(_thrust * deltaTime);
//----------------------------------------------------------
// update position by velocity // update position by velocity
//----------------------------------------------------------
_position += (glm::vec3)_velocity * deltaTime; _position += (glm::vec3)_velocity * deltaTime;
//----------------------------------------------------------
// decay velocity // decay velocity
//----------------------------------------------------------
_velocity *= ( 1.0 - LIN_VEL_DECAY * deltaTime ); _velocity *= ( 1.0 - LIN_VEL_DECAY * deltaTime );
// //
// Update Head information // 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) { if (!_head.noise) {
// Decay back toward center // Decay back toward center
_headPitch *= (1.0f - DECAY * 2 * deltaTime); _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; return COLLISION_BODY_RADIUS;
} }
float Head::getHeight() { float Avatar::getHeight() {
return COLLISION_HEIGHT; return COLLISION_HEIGHT;
} }
glm::vec3 Head::getBodyUpDirection() { glm::vec3 Avatar::getBodyUpDirection() {
return _orientation.getUp(); return _orientation.getUp();
} }
//--------------------------------------------------------------------------------
// This is a workspace for testing avatar body collision detection and response // This is a workspace for testing avatar body collision detection and response
//-------------------------------------------------------------------------------- void Avatar::updateAvatarCollisionDetectionAndResponse
void Head::updateAvatarCollisionDetectionAndResponse
( glm::vec3 collisionPosition, float collisionGirth, float collisionHeight, glm::vec3 collisionUpVector, float deltaTime ) { ( glm::vec3 collisionPosition, float collisionGirth, float collisionHeight, glm::vec3 collisionUpVector, float deltaTime ) {
float myBodyApproximateBoundingRadius = 1.0f; float myBodyApproximateBoundingRadius = 1.0f;
@ -647,11 +611,9 @@ void Head::updateAvatarCollisionDetectionAndResponse
} }
void Head::render(bool lookingInMirror) { void Avatar::render(bool lookingInMirror) {
//---------------------------------------------------
// show avatar position // show avatar position
//---------------------------------------------------
glColor4f( 0.5f, 0.5f, 0.5f, 0.6 ); glColor4f( 0.5f, 0.5f, 0.5f, 0.6 );
glPushMatrix(); glPushMatrix();
glTranslatef(_position.x, _position.y, _position.z); glTranslatef(_position.x, _position.y, _position.z);
@ -660,9 +622,8 @@ void Head::render(bool lookingInMirror) {
glPopMatrix(); glPopMatrix();
if ( usingBigSphereCollisionTest ) { if ( usingBigSphereCollisionTest ) {
//---------------------------------------------------
// show TEST big sphere // show TEST big sphere
//---------------------------------------------------
glColor4f( 0.5f, 0.6f, 0.8f, 0.7 ); glColor4f( 0.5f, 0.6f, 0.8f, 0.7 );
glPushMatrix(); glPushMatrix();
glTranslatef(_TEST_bigSpherePosition.x, _TEST_bigSpherePosition.y, _TEST_bigSpherePosition.z); glTranslatef(_TEST_bigSpherePosition.x, _TEST_bigSpherePosition.y, _TEST_bigSpherePosition.z);
@ -671,19 +632,13 @@ void Head::render(bool lookingInMirror) {
glPopMatrix(); glPopMatrix();
} }
//---------------
// render body // render body
//---------------
renderBody(); renderBody();
//---------------------------------------------------
// render head // render head
//---------------------------------------------------
renderHead(lookingInMirror); renderHead(lookingInMirror);
//---------------------------------------------------------------------------
// if this is my avatar, then render my interactions with the other avatar // if this is my avatar, then render my interactions with the other avatar
//---------------------------------------------------------------------------
if ( _isMine ) if ( _isMine )
{ {
if ( _interactingOtherIsNearby ) { if ( _interactingOtherIsNearby ) {
@ -702,15 +657,13 @@ void Head::render(bool lookingInMirror) {
} }
void Head::renderHead(bool lookingInMirror) { void Avatar::renderHead(bool lookingInMirror) {
int side = 0; int side = 0;
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glEnable(GL_RESCALE_NORMAL); glEnable(GL_RESCALE_NORMAL);
//---------------------------------------------------
// show head orientation // show head orientation
//---------------------------------------------------
//renderOrientationDirections( _bone[ AVATAR_BONE_HEAD ].position, _bone[ AVATAR_BONE_HEAD ].orientation, 0.2f ); //renderOrientationDirections( _bone[ AVATAR_BONE_HEAD ].position, _bone[ AVATAR_BONE_HEAD ].orientation, 0.2f );
glPushMatrix(); glPushMatrix();
@ -866,7 +819,7 @@ void Head::renderHead(bool lookingInMirror) {
glPopMatrix(); glPopMatrix();
} }
void Head::startHandMovement() { void Avatar::startHandMovement() {
if (!_usingBodySprings) { if (!_usingBodySprings) {
initializeBodySprings(); initializeBodySprings();
@ -874,19 +827,19 @@ void Head::startHandMovement() {
} }
} }
void Head::stopHandMovement() { void Avatar::stopHandMovement() {
//_usingBodySprings = false; //_usingBodySprings = false;
} }
void Head::setHandMovementValues( glm::vec3 handOffset ) { void Avatar::setHandMovementValues( glm::vec3 handOffset ) {
_movedHandOffset = handOffset; _movedHandOffset = handOffset;
} }
AvatarMode Head::getMode() { AvatarMode Avatar::getMode() {
return _mode; return _mode;
} }
void Head::initializeSkeleton() { void Avatar::initializeSkeleton() {
for (int b=0; b<NUM_AVATAR_BONES; b++) { for (int b=0; b<NUM_AVATAR_BONES; b++) {
_bone[b].parent = AVATAR_BONE_NULL; _bone[b].parent = AVATAR_BONE_NULL;
@ -931,9 +884,7 @@ void Head::initializeSkeleton() {
_bone[ AVATAR_BONE_RIGHT_SHIN ].parent = AVATAR_BONE_RIGHT_THIGH; _bone[ AVATAR_BONE_RIGHT_SHIN ].parent = AVATAR_BONE_RIGHT_THIGH;
_bone[ AVATAR_BONE_RIGHT_FOOT ].parent = AVATAR_BONE_RIGHT_SHIN; _bone[ AVATAR_BONE_RIGHT_FOOT ].parent = AVATAR_BONE_RIGHT_SHIN;
//----------------------------------------------------------
// specify the default pose position // specify the default pose position
//----------------------------------------------------------
_bone[ AVATAR_BONE_PELVIS_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.3, 0.0 ); _bone[ AVATAR_BONE_PELVIS_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.3, 0.0 );
_bone[ AVATAR_BONE_MID_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.1, 0.0 ); _bone[ AVATAR_BONE_MID_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.1, 0.0 );
_bone[ AVATAR_BONE_CHEST_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.06, 0.0 ); _bone[ AVATAR_BONE_CHEST_SPINE ].defaultPosePosition = glm::vec3( 0.0, 0.06, 0.0 );
@ -983,18 +934,14 @@ void Head::initializeSkeleton() {
_bone[ AVATAR_BONE_RIGHT_SHIN ].radius = 0.015; _bone[ AVATAR_BONE_RIGHT_SHIN ].radius = 0.015;
_bone[ AVATAR_BONE_RIGHT_FOOT ].radius = 0.02; _bone[ AVATAR_BONE_RIGHT_FOOT ].radius = 0.02;
//----------------------------------------------------------------------------
// calculate bone length // calculate bone length
//----------------------------------------------------------------------------
calculateBoneLengths(); calculateBoneLengths();
//---------------------------
// generate world positions // generate world positions
//---------------------------
updateSkeleton(); updateSkeleton();
} }
void Head::calculateBoneLengths() { void Avatar::calculateBoneLengths() {
for (int b=0; b<NUM_AVATAR_BONES; b++) { for (int b=0; b<NUM_AVATAR_BONES; b++) {
_bone[b].length = glm::length( _bone[b].defaultPosePosition ); _bone[b].length = glm::length( _bone[b].defaultPosePosition );
} }
@ -1005,16 +952,12 @@ void Head::calculateBoneLengths() {
+ _bone[ AVATAR_BONE_RIGHT_HAND ].length; + _bone[ AVATAR_BONE_RIGHT_HAND ].length;
} }
void Head::updateSkeleton() { void Avatar::updateSkeleton() {
//----------------------------------
// rotate body... // rotate body...
//----------------------------------
_orientation.setToIdentity(); _orientation.setToIdentity();
_orientation.yaw( _bodyYaw ); _orientation.yaw( _bodyYaw );
//------------------------------------------------------------------------
// calculate positions of all bones by traversing the skeleton tree: // calculate positions of all bones by traversing the skeleton tree:
//------------------------------------------------------------------------
for (int b=0; b<NUM_AVATAR_BONES; b++) { for (int b=0; b<NUM_AVATAR_BONES; b++) {
if ( _bone[b].parent == AVATAR_BONE_NULL ) { if ( _bone[b].parent == AVATAR_BONE_NULL ) {
_bone[b].orientation.set( _orientation ); _bone[b].orientation.set( _orientation );
@ -1025,9 +968,7 @@ void Head::updateSkeleton() {
_bone[b].position = _bone[ _bone[b].parent ].position; _bone[b].position = _bone[ _bone[b].parent ].position;
} }
//-------------------------------------------------------------------------------------
// if this is not my avatar, then hand position comes from transmitted data // if this is not my avatar, then hand position comes from transmitted data
//-------------------------------------------------------------------------------------
if ( ! _isMine ) { if ( ! _isMine ) {
_bone[ AVATAR_BONE_RIGHT_HAND ].position = _handPosition; _bone[ AVATAR_BONE_RIGHT_HAND ].position = _handPosition;
} }
@ -1046,7 +987,7 @@ void Head::updateSkeleton() {
} }
} }
void Head::initializeBodySprings() { void Avatar::initializeBodySprings() {
for (int b=0; b<NUM_AVATAR_BONES; b++) { for (int b=0; b<NUM_AVATAR_BONES; b++) {
_bone[b].springyPosition = _bone[b].position; _bone[b].springyPosition = _bone[b].position;
_bone[b].springyVelocity = glm::vec3( 0.0f, 0.0f, 0.0f ); _bone[b].springyVelocity = glm::vec3( 0.0f, 0.0f, 0.0f );
@ -1054,7 +995,7 @@ void Head::initializeBodySprings() {
} }
void Head::updateBodySprings( float deltaTime ) { void Avatar::updateBodySprings( float deltaTime ) {
for (int b=0; b<NUM_AVATAR_BONES; b++) { for (int b=0; b<NUM_AVATAR_BONES; b++) {
glm::vec3 springVector( _bone[b].springyPosition ); glm::vec3 springVector( _bone[b].springyPosition );
@ -1094,7 +1035,7 @@ void Head::updateBodySprings( float deltaTime ) {
} }
} }
glm::vec3 Head::getHeadLookatDirection() { glm::vec3 Avatar::getHeadLookatDirection() {
return glm::vec3 return glm::vec3
( (
_orientation.getFront().x, _orientation.getFront().x,
@ -1103,7 +1044,7 @@ glm::vec3 Head::getHeadLookatDirection() {
); );
} }
glm::vec3 Head::getHeadLookatDirectionUp() { glm::vec3 Avatar::getHeadLookatDirectionUp() {
return glm::vec3 return glm::vec3
( (
_orientation.getUp().x, _orientation.getUp().x,
@ -1112,7 +1053,7 @@ glm::vec3 Head::getHeadLookatDirectionUp() {
); );
} }
glm::vec3 Head::getHeadLookatDirectionRight() { glm::vec3 Avatar::getHeadLookatDirectionRight() {
return glm::vec3 return glm::vec3
( (
_orientation.getRight().x, _orientation.getRight().x,
@ -1121,7 +1062,7 @@ glm::vec3 Head::getHeadLookatDirectionRight() {
); );
} }
glm::vec3 Head::getHeadPosition() { glm::vec3 Avatar::getHeadPosition() {
if ( _usingBodySprings ) { if ( _usingBodySprings ) {
return _bone[ AVATAR_BONE_HEAD ].springyPosition; return _bone[ AVATAR_BONE_HEAD ].springyPosition;
@ -1131,13 +1072,13 @@ glm::vec3 Head::getHeadPosition() {
} }
glm::vec3 Head::getBonePosition( AvatarBoneID b ) { glm::vec3 Avatar::getBonePosition( AvatarBoneID b ) {
return _bone[b].position; return _bone[b].position;
} }
void Head::updateHandMovement( float deltaTime ) { void Avatar::updateHandMovement( float deltaTime ) {
glm::vec3 transformedHandMovement; glm::vec3 transformedHandMovement;
transformedHandMovement transformedHandMovement
@ -1153,26 +1094,18 @@ void Head::updateHandMovement( float deltaTime ) {
} }
void Head::updateArmIKAndConstraints( float deltaTime ) { void Avatar::updateArmIKAndConstraints( float deltaTime ) {
//-------------------------------------------------------------------------------
// determine the arm vector // determine the arm vector
//-------------------------------------------------------------------------------
glm::vec3 armVector = _bone[ AVATAR_BONE_RIGHT_HAND ].position; glm::vec3 armVector = _bone[ AVATAR_BONE_RIGHT_HAND ].position;
armVector -= _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; armVector -= _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position;
//-------------------------------------------------------------------------------
// test to see if right hand is being dragged beyond maximum arm length // test to see if right hand is being dragged beyond maximum arm length
//-------------------------------------------------------------------------------
float distance = glm::length( armVector ); float distance = glm::length( armVector );
//-------------------------------------------------------------------------------
// if right hand is being dragged beyond maximum arm length... // if right hand is being dragged beyond maximum arm length...
//-------------------------------------------------------------------------------
if ( distance > _maxArmLength ) { if ( distance > _maxArmLength ) {
//-------------------------------------------------------------------------------
// reset right hand to be constrained to maximum arm length // reset right hand to be constrained to maximum arm length
//-------------------------------------------------------------------------------
_bone[ AVATAR_BONE_RIGHT_HAND ].position = _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; _bone[ AVATAR_BONE_RIGHT_HAND ].position = _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position;
glm::vec3 armNormal = armVector / distance; glm::vec3 armNormal = armVector / distance;
armVector = armNormal * _maxArmLength; armVector = armNormal * _maxArmLength;
@ -1182,18 +1115,14 @@ void Head::updateArmIKAndConstraints( float deltaTime ) {
_bone[ AVATAR_BONE_RIGHT_HAND ].position = constrainedPosition; _bone[ AVATAR_BONE_RIGHT_HAND ].position = constrainedPosition;
} }
//-----------------------------------------------------------------------------
// set elbow position // set elbow position
//-----------------------------------------------------------------------------
glm::vec3 newElbowPosition = _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; glm::vec3 newElbowPosition = _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position;
newElbowPosition += armVector * ONE_HALF; newElbowPosition += armVector * ONE_HALF;
glm::vec3 perpendicular = glm::cross( _orientation.getFront(), armVector ); glm::vec3 perpendicular = glm::cross( _orientation.getFront(), armVector );
newElbowPosition += perpendicular * ( 1.0f - ( _maxArmLength / distance ) ) * ONE_HALF; newElbowPosition += perpendicular * ( 1.0f - ( _maxArmLength / distance ) ) * ONE_HALF;
_bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position = newElbowPosition; _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position = newElbowPosition;
//-----------------------------------------------------------------------------
// set wrist position // set wrist position
//-----------------------------------------------------------------------------
glm::vec3 vv( _bone[ AVATAR_BONE_RIGHT_HAND ].position ); glm::vec3 vv( _bone[ AVATAR_BONE_RIGHT_HAND ].position );
vv -= _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position; vv -= _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position;
glm::vec3 newWristPosition = _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 // Render bone positions as spheres
//-----------------------------------------
for (int b=0; b<NUM_AVATAR_BONES; b++) { for (int b=0; b<NUM_AVATAR_BONES; b++) {
//renderBoneAsBlock( (AvatarBoneID)b); //renderBoneAsBlock( (AvatarBoneID)b);
@ -1230,9 +1158,7 @@ void Head::renderBody() {
} }
} }
//-----------------------------------------------------
// Render lines connecting the bone positions // Render lines connecting the bone positions
//-----------------------------------------------------
if ( _usingBodySprings ) { if ( _usingBodySprings ) {
glColor3f( 0.4f, 0.5f, 0.6f ); glColor3f( 0.4f, 0.5f, 0.6f );
glLineWidth(3.0); glLineWidth(3.0);
@ -1260,9 +1186,7 @@ void Head::renderBody() {
} }
} }
//---------------------------------------------------------
// if the hand is grasping, show it... // if the hand is grasping, show it...
//---------------------------------------------------------
if (( _usingBodySprings ) && ( _handState == 1 )) { if (( _usingBodySprings ) && ( _handState == 1 )) {
glPushMatrix(); glPushMatrix();
glTranslatef glTranslatef
@ -1279,9 +1203,7 @@ void Head::renderBody() {
} }
} }
void Avatar::renderBoneAsBlock( AvatarBoneID b ) {
void Head::renderBoneAsBlock( AvatarBoneID b ) {
glColor3fv( skinColor ); glColor3fv( skinColor );
glPushMatrix(); glPushMatrix();
glTranslatef( _bone[b].springyPosition.x, _bone[b].springyPosition.y, _bone[b].springyPosition.z ); glTranslatef( _bone[b].springyPosition.x, _bone[b].springyPosition.y, _bone[b].springyPosition.z );
@ -1293,13 +1215,13 @@ void Head::renderBoneAsBlock( AvatarBoneID b ) {
glPopMatrix(); glPopMatrix();
} }
void Head::SetNewHeadTarget(float pitch, float yaw) { void Avatar::SetNewHeadTarget(float pitch, float yaw) {
_head.pitchTarget = pitch; _head.pitchTarget = pitch;
_head.yawTarget = yaw; _head.yawTarget = yaw;
} }
// getting data from Android transmitte app // getting data from Android transmitte app
void Head::processTransmitterData(unsigned char* packetData, int numBytes) { void Avatar::processTransmitterData(unsigned char* packetData, int numBytes) {
// Read a packet from a transmitter app, process the data // Read a packet from a transmitter app, process the data
float accX, accY, accZ, float accX, accY, accZ,
graX, graY, graZ, graX, graY, graZ,

View file

@ -1,13 +1,13 @@
// //
// Head.h // Avatar.h
// interface // interface
// //
// Created by Philip Rosedale on 9/11/12. // Created by Philip Rosedale on 9/11/12.
// Copyright (c) 2012 High Fidelity, Inc. All rights reserved. // Copyright (c) 2012 High Fidelity, Inc. All rights reserved.
// //
#ifndef __interface__head__ #ifndef __interface__avatar__
#define __interface__head__ #define __interface__avatar__
#include <AvatarData.h> #include <AvatarData.h>
#include <Orientation.h> #include <Orientation.h>
@ -100,15 +100,6 @@ struct AvatarHandHolding
float force; float force;
}; };
/*
struct OtherAvatar
{
bool nearby;
//glm::vec3 handPosition;
//int handState;
};
*/
struct AvatarBone struct AvatarBone
{ {
AvatarBoneID parent; // which bone is this bone connected to? AvatarBoneID parent; // which bone is this bone connected to?
@ -165,12 +156,12 @@ struct AvatarHead
}; };
class Head : public AvatarData { class Avatar : public AvatarData {
public: public:
Head(bool isMine); Avatar(bool isMine);
~Head(); ~Avatar();
Head(const Head &otherHead); Avatar(const Avatar &otherAvatar);
Head* clone() const; Avatar* clone() const;
void reset(); void reset();
void UpdateGyros(float frametime, SerialInterface * serialInterface, glm::vec3 * gravity); void UpdateGyros(float frametime, SerialInterface * serialInterface, glm::vec3 * gravity);
@ -253,12 +244,10 @@ class Head : public AvatarData {
timeval _transmitterTimer; timeval _transmitterTimer;
float _transmitterHz; float _transmitterHz;
int _transmitterPackets; int _transmitterPackets;
Head* _interactingOther; Avatar* _interactingOther;
bool _interactingOtherIsNearby; bool _interactingOtherIsNearby;
//-----------------------------
// private methods... // private methods...
//-----------------------------
void initializeSkeleton(); void initializeSkeleton();
void updateSkeleton(); void updateSkeleton();
void initializeBodySprings(); void initializeBodySprings();

View file

@ -60,8 +60,8 @@ VoxelSystem::~VoxelSystem() {
pthread_mutex_destroy(&bufferWriteLock); pthread_mutex_destroy(&bufferWriteLock);
} }
void VoxelSystem::setViewerHead(Head *newViewerHead) { void VoxelSystem::setViewerAvatar(Avatar *newViewerAvatar) {
viewerHead = newViewerHead; viewerAvatar = newViewerAvatar;
} }
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
@ -187,7 +187,7 @@ int VoxelSystem::treeToArrays(VoxelNode *currentNode, const glm::vec3& nodePosi
int voxelsAdded = 0; int voxelsAdded = 0;
float halfUnitForVoxel = powf(0.5, *currentNode->octalCode) * (0.5 * TREE_SCALE); float halfUnitForVoxel = powf(0.5, *currentNode->octalCode) * (0.5 * TREE_SCALE);
glm::vec3 viewerPosition = viewerHead->getPosition(); glm::vec3 viewerPosition = viewerAvatar->getPosition();
// debug LOD code // debug LOD code
glm::vec3 debugNodePosition; glm::vec3 debugNodePosition;

View file

@ -15,7 +15,7 @@
#include <AgentData.h> #include <AgentData.h>
#include <VoxelTree.h> #include <VoxelTree.h>
#include <ViewFrustum.h> #include <ViewFrustum.h>
#include "Head.h" #include "Avatar.h"
#include "Util.h" #include "Util.h"
#include "world.h" #include "world.h"
@ -34,7 +34,7 @@ public:
void render(); void render();
void setVoxelsRendered(int v) {voxelsRendered = v;}; void setVoxelsRendered(int v) {voxelsRendered = v;};
int getVoxelsRendered() {return voxelsRendered;}; int getVoxelsRendered() {return voxelsRendered;};
void setViewerHead(Head *newViewerHead); void setViewerAvatar(Avatar *newViewerAvatar);
void loadVoxelsFile(const char* fileName,bool wantColorRandomizer); void loadVoxelsFile(const char* fileName,bool wantColorRandomizer);
void createSphere(float r,float xc, float yc, float zc, float s, bool solid, 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; static float _minDistance;
int voxelsRendered; int voxelsRendered;
Head *viewerHead; Avatar *viewerAvatar;
VoxelTree *tree; VoxelTree *tree;
GLfloat *readVerticesArray; GLfloat *readVerticesArray;
GLubyte *readColorsArray; GLubyte *readColorsArray;

View file

@ -64,7 +64,7 @@
#include "MenuColumn.h" #include "MenuColumn.h"
#include "Menu.h" #include "Menu.h"
#include "Camera.h" #include "Camera.h"
#include "Head.h" #include "Avatar.h"
#include "Particle.h" #include "Particle.h"
#include "Texture.h" #include "Texture.h"
#include "Cloud.h" #include "Cloud.h"
@ -107,7 +107,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(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 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
@ -382,7 +382,7 @@ void initDisplay(void)
void init(void) void init(void)
{ {
voxels.init(); voxels.init();
voxels.setViewerHead(&myAvatar); voxels.setViewerAvatar(&myAvatar);
myAvatar.setRenderYaw(startYaw); myAvatar.setRenderYaw(startYaw);
initializeHandController(); initializeHandController();
@ -912,7 +912,7 @@ void display(void)
agent != agentList->getAgents().end(); agent != agentList->getAgents().end();
agent++) { agent++) {
if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) {
Head *avatar = (Head *)agent->getLinkedData(); Avatar *avatar = (Avatar *)agent->getLinkedData();
avatar->render(0); avatar->render(0);
} }
} }
@ -1494,7 +1494,7 @@ void idle(void) {
{ {
if (agent->getLinkedData() != NULL) if (agent->getLinkedData() != NULL)
{ {
Head *avatar = (Head *)agent->getLinkedData(); Avatar *avatar = (Avatar *)agent->getLinkedData();
avatar->simulate(deltaTime); avatar->simulate(deltaTime);
} }
} }
@ -1605,7 +1605,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(false)); newAgent->setLinkedData(new Avatar(false));
} }
} }