Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Philip Rosedale 2013-04-23 21:00:53 -07:00
commit a440570cb4
7 changed files with 164 additions and 139 deletions

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->getBodyPosition()[p], sizeof(float)); memcpy(currentPacketPtr, &data->linkedHead->getPosition()[p], sizeof(float));
currentPacketPtr += sizeof(float); currentPacketPtr += sizeof(float);
} }

View file

@ -48,7 +48,7 @@ Head::Head(bool isMine) {
_velocity = glm::vec3( 0.0, 0.0, 0.0 ); _velocity = glm::vec3( 0.0, 0.0, 0.0 );
_thrust = glm::vec3( 0.0, 0.0, 0.0 ); _thrust = glm::vec3( 0.0, 0.0, 0.0 );
_rotation = glm::quat( 0.0f, 0.0f, 0.0f, 0.0f ); _rotation = glm::quat( 0.0f, 0.0f, 0.0f, 0.0f );
_closestOtherAvatar = 0; _nearOtherAvatar = false;
_bodyYaw = -90.0; _bodyYaw = -90.0;
_bodyPitch = 0.0; _bodyPitch = 0.0;
_bodyRoll = 0.0; _bodyRoll = 0.0;
@ -60,7 +60,7 @@ Head::Head(bool isMine) {
//_transmitterTimer = 0; //_transmitterTimer = 0;
_transmitterHz = 0.0; _transmitterHz = 0.0;
_transmitterPackets = 0; _transmitterPackets = 0;
_numOtherAvatarsInView = 0; //_numOtherAvatars = 0;
initializeSkeleton(); initializeSkeleton();
@ -117,13 +117,11 @@ Head::Head(bool isMine) {
_renderPitch = 0.0; _renderPitch = 0.0;
_sphere = NULL; _sphere = NULL;
_collisionElipsoid.colliding = false; _handHolding.position = glm::vec3( 0.0, 0.0, 0.0 );
_collisionElipsoid.position = glm::vec3( 0.0, 0.0, 0.0 ); _handHolding.velocity = glm::vec3( 0.0, 0.0, 0.0 );
_collisionElipsoid.upVector = glm::vec3( 0.0, 0.0, 0.0 ); _handHolding.force = 10.0f;
_collisionElipsoid.girth = 0.0;
_collisionElipsoid.height = 0.0;
if (iris_texture.size() == 0) { if (iris_texture.size() == 0) {
switchToResourcesParentIfRequired(); switchToResourcesParentIfRequired();
unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file); unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file);
@ -131,19 +129,19 @@ Head::Head(bool isMine) {
printLog("error %u: %s\n", error, lodepng_error_text(error)); printLog("error %u: %s\n", error, lodepng_error_text(error));
} }
} }
for (int o=0; o<MAX_OTHER_AVATARS; o++) { _otherAvatar.handPosition = glm::vec3( 0.0f, 0.0f, 0.0f );
_otherAvatarHandPosition[o] = glm::vec3( 0.0f, 0.0f, 0.0f ); _otherAvatar.handState = 0;
}
} }
Head::Head(const Head &otherAvatar) { Head::Head(const Head &otherAvatar) {
_velocity = otherAvatar._velocity; _velocity = otherAvatar._velocity;
_thrust = otherAvatar._thrust; _thrust = otherAvatar._thrust;
_rotation = otherAvatar._rotation; _rotation = otherAvatar._rotation;
_closestOtherAvatar = otherAvatar._closestOtherAvatar; _nearOtherAvatar = otherAvatar._nearOtherAvatar;
_bodyYaw = otherAvatar._bodyYaw; _bodyYaw = otherAvatar._bodyYaw;
_bodyPitch = otherAvatar._bodyPitch; _bodyPitch = otherAvatar._bodyPitch;
_bodyRoll = otherAvatar._bodyRoll; _bodyRoll = otherAvatar._bodyRoll;
@ -305,12 +303,12 @@ void Head::simulate(float deltaTime) {
//------------------------------------------------------------- //-------------------------------------------------------------
if ( _isMine ) if ( _isMine )
{ {
_closestOtherAvatar = -1; _nearOtherAvatar = false;
float closestDistance = 10000.0f; float closestDistance = 10000.0f;
AgentList * agentList = AgentList::getInstance(); AgentList * agentList = AgentList::getInstance();
_numOtherAvatarsInView =0; //_numOtherAvatars = 0;
for(std::vector<Agent>::iterator agent = agentList->getAgents().begin(); for(std::vector<Agent>::iterator agent = agentList->getAgents().begin();
agent != agentList->getAgents().end(); agent != agentList->getAgents().end();
@ -318,21 +316,34 @@ void Head::simulate(float deltaTime) {
if (( agent->getLinkedData() != NULL && ( agent->getType() == AGENT_TYPE_AVATAR ) )) { if (( agent->getLinkedData() != NULL && ( agent->getType() == AGENT_TYPE_AVATAR ) )) {
Head *otherAvatar = (Head *)agent->getLinkedData(); Head *otherAvatar = (Head *)agent->getLinkedData();
if ( _numOtherAvatarsInView < MAX_OTHER_AVATARS ) { // if ( _numOtherAvatars < MAX_OTHER_AVATARS )
{
//----------------------------------------------------------- //------------------------------------------------------
// test other avatar hand position for proximity... // check for collisions with other avatars and respond
//----------------------------------------------------------- //------------------------------------------------------
_otherAvatarHandPosition[ _numOtherAvatarsInView ] = otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND ); updateAvatarCollisionDetectionAndResponse
(
otherAvatar->getPosition(),
otherAvatar->getGirth(),
otherAvatar->getHeight(),
otherAvatar->getBodyUpDirection(),
deltaTime
);
//-------------------------------------------------
// 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 -= _otherAvatarHandPosition[ _numOtherAvatarsInView ]; v -= otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND );
float distance = glm::length( v ); float distance = glm::length( v );
if ( distance < _maxArmLength ) { if ( distance < _maxArmLength ) {
if ( distance < closestDistance ) { if ( distance < closestDistance ) {
closestDistance = distance; closestDistance = distance;
_closestOtherAvatar = _numOtherAvatarsInView; _nearOtherAvatar = true;
_numOtherAvatarsInView++; _otherAvatar.handPosition = otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND );
_otherAvatar.handState = (int)otherAvatar->getHandState();
} }
} }
} }
@ -345,16 +356,23 @@ void Head::simulate(float deltaTime) {
//-------------------------------------------------------------- //--------------------------------------------------------------
// test for avatar collision response (using a big sphere :) // test for avatar collision response (using a big sphere :)
//-------------------------------------------------------------- //--------------------------------------------------------------
updateAvatarCollisionDetectionAndResponse(_TEST_bigSpherePosition, _TEST_bigSphereRadius, deltaTime); updateAvatarCollisionDetectionAndResponse
(
_TEST_bigSpherePosition,
_TEST_bigSphereRadius,
_TEST_bigSphereRadius,
glm::vec3( 0.0, 1.0, 0.0 ),
deltaTime
);
} }
if ( AVATAR_GRAVITY ) { if ( AVATAR_GRAVITY ) {
if ( _bodyPosition.y > _bone[ AVATAR_BONE_RIGHT_FOOT ].radius * 2.0 ) { if ( _position.y > _bone[ AVATAR_BONE_RIGHT_FOOT ].radius * 2.0 ) {
_velocity += glm::dvec3( 0.0, -1.0, 0.0 ) * ( 6.0 * deltaTime ); _velocity += glm::dvec3( 0.0, -1.0, 0.0 ) * ( 6.0 * deltaTime );
} }
else { else {
if ( _bodyPosition.y < _bone[ AVATAR_BONE_RIGHT_FOOT ].radius ) { if ( _position.y < _bone[ AVATAR_BONE_RIGHT_FOOT ].radius ) {
_bodyPosition.y = _bone[ AVATAR_BONE_RIGHT_FOOT ].radius; _position.y = _bone[ AVATAR_BONE_RIGHT_FOOT ].radius;
_velocity.y = 0.0; _velocity.y = 0.0;
} }
} }
@ -369,7 +387,7 @@ void Head::simulate(float deltaTime) {
// reset hand and arm positions according to hand movement // reset hand and arm positions according to hand movement
//------------------------------------------------------------ //------------------------------------------------------------
if (_usingBodySprings) { if (_usingBodySprings) {
updateHandMovement(); updateHandMovement( deltaTime );
updateBodySprings( deltaTime ); updateBodySprings( deltaTime );
} }
@ -445,7 +463,7 @@ void Head::simulate(float deltaTime) {
//---------------------------------------------------------- //----------------------------------------------------------
// update position by velocity // update position by velocity
//---------------------------------------------------------- //----------------------------------------------------------
_bodyPosition += (glm::vec3)_velocity * deltaTime; _position += (glm::vec3)_velocity * deltaTime;
//---------------------------------------------------------- //----------------------------------------------------------
// decay velocity // decay velocity
@ -563,37 +581,25 @@ float Head::getHeight() {
glm::vec3 Head::getBodyUpDirection() { glm::vec3 Head::getBodyUpDirection() {
return _orientation.getUp(); return _orientation.getUp();
} }
bool Head::testForCollision( glm::vec3 collisionPosition, float collisionGirth, float collisionHeight, glm::vec3 collisionUpVector ) {
_collisionElipsoid.colliding = false;
_collisionElipsoid.position = glm::vec3( 0.0, 0.0, 0.0 );
_collisionElipsoid.upVector = glm::vec3( 0.0, 0.0, 0.0 );
_collisionElipsoid.girth = 0.0;
_collisionElipsoid.height = 0.0;
return false;
}
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// 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 Head::updateAvatarCollisionDetectionAndResponse( glm::vec3 collisionPosition, float collisionRadius, float deltaTime ) { void Head::updateAvatarCollisionDetectionAndResponse
( glm::vec3 collisionPosition, float collisionGirth, float collisionHeight, glm::vec3 collisionUpVector, float deltaTime ) {
float myBodyApproximateBoundingRadius = 1.0f; float myBodyApproximateBoundingRadius = 1.0f;
glm::vec3 vectorFromMyBodyToBigSphere(_bodyPosition - collisionPosition); glm::vec3 vectorFromMyBodyToBigSphere(_position - collisionPosition);
bool jointCollision = false; bool jointCollision = false;
float distanceToBigSphere = glm::length(vectorFromMyBodyToBigSphere); float distanceToBigSphere = glm::length(vectorFromMyBodyToBigSphere);
if ( distanceToBigSphere < myBodyApproximateBoundingRadius + collisionRadius ) if ( distanceToBigSphere < myBodyApproximateBoundingRadius + collisionGirth )
{ {
for (int b=0; b<NUM_AVATAR_BONES; b++) for (int b=0; b<NUM_AVATAR_BONES; b++)
{ {
glm::vec3 vectorFromJointToBigSphereCenter(_bone[b].springyPosition - collisionPosition); glm::vec3 vectorFromJointToBigSphereCenter(_bone[b].springyPosition - collisionPosition);
float distanceToBigSphereCenter = glm::length(vectorFromJointToBigSphereCenter); float distanceToBigSphereCenter = glm::length(vectorFromJointToBigSphereCenter);
float combinedRadius = _bone[b].radius + collisionRadius; float combinedRadius = _bone[b].radius + collisionGirth;
if ( distanceToBigSphereCenter < combinedRadius ) if ( distanceToBigSphereCenter < combinedRadius )
{ {
jointCollision = true; jointCollision = true;
@ -630,12 +636,11 @@ void Head::render(bool lookingInMirror) {
//--------------------------------------------------- //---------------------------------------------------
glColor4f( 0.5f, 0.5f, 0.5f, 0.6 ); glColor4f( 0.5f, 0.5f, 0.5f, 0.6 );
glPushMatrix(); glPushMatrix();
glTranslatef(_bodyPosition.x, _bodyPosition.y, _bodyPosition.z); glTranslatef(_position.x, _position.y, _position.z);
glScalef( 0.03, 0.03, 0.03 ); glScalef( 0.03, 0.03, 0.03 );
glutSolidSphere( 1, 10, 10 ); glutSolidSphere( 1, 10, 10 );
glPopMatrix(); glPopMatrix();
if ( usingBigSphereCollisionTest ) { if ( usingBigSphereCollisionTest ) {
//--------------------------------------------------- //---------------------------------------------------
// show TEST big sphere // show TEST big sphere
@ -664,10 +669,10 @@ void Head::render(bool lookingInMirror) {
if ( _isMine ) if ( _isMine )
{ {
if (_usingBodySprings) { if (_usingBodySprings) {
if ( _closestOtherAvatar != -1 ) { if ( _nearOtherAvatar ) {
glm::vec3 v1( _bone[ AVATAR_BONE_RIGHT_HAND ].position ); glm::vec3 v1( _bone[ AVATAR_BONE_RIGHT_HAND ].position );
glm::vec3 v2( _otherAvatarHandPosition[ _closestOtherAvatar ] ); glm::vec3 v2( _otherAvatar.handPosition );
glLineWidth( 8.0 ); glLineWidth( 8.0 );
glColor4f( 0.7f, 0.4f, 0.1f, 0.6 ); glColor4f( 0.7f, 0.4f, 0.1f, 0.6 );
@ -970,9 +975,6 @@ void Head::initializeSkeleton() {
updateSkeleton(); updateSkeleton();
} }
void Head::calculateBoneLengths() { void Head::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 );
@ -997,7 +999,7 @@ void Head::updateSkeleton() {
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 );
_bone[b].position = _bodyPosition; _bone[b].position = _position;
} }
else { else {
_bone[b].orientation.set( _bone[ _bone[b].parent ].orientation ); _bone[b].orientation.set( _bone[ _bone[b].parent ].orientation );
@ -1036,7 +1038,7 @@ void Head::updateBodySprings( float deltaTime ) {
glm::vec3 springVector( _bone[b].springyPosition ); glm::vec3 springVector( _bone[b].springyPosition );
if ( _bone[b].parent == AVATAR_BONE_NULL ) { if ( _bone[b].parent == AVATAR_BONE_NULL ) {
springVector -= _bodyPosition; springVector -= _position;
} }
else { else {
springVector -= _bone[ _bone[b].parent ].springyPosition; springVector -= _bone[ _bone[b].parent ].springyPosition;
@ -1114,7 +1116,7 @@ glm::vec3 Head::getBonePosition( AvatarBoneID b ) {
void Head::updateHandMovement() { void Head::updateHandMovement( float deltaTime ) {
glm::vec3 transformedHandMovement; glm::vec3 transformedHandMovement;
transformedHandMovement transformedHandMovement
@ -1126,19 +1128,31 @@ void Head::updateHandMovement() {
setHandState(_mousePressed); setHandState(_mousePressed);
//if holding hands, add a pull to the hand... //---------------------------------------------------------------------
if ( _usingBodySprings ) { // if holding hands with another avatar, add a force to the hand...
if ( _closestOtherAvatar != -1 ) { //---------------------------------------------------------------------
if ( _mousePressed ) { if (( getHandState() == 1 )
|| ( _otherAvatar.handState == 1 )) {
glm::vec3 handToHandVector( _otherAvatarHandPosition[ _closestOtherAvatar ]); //if ( _usingBodySprings )
handToHandVector -= _bone[ AVATAR_BONE_RIGHT_HAND ].position; {
if ( _nearOtherAvatar ) {
glm::vec3 vectorToOtherHand = _otherAvatar.handPosition - _handHolding.position;
glm::vec3 vectorToMyHand = _bone[ AVATAR_BONE_RIGHT_HAND ].position - _handHolding.position;
_bone[ AVATAR_BONE_RIGHT_HAND ].position = _otherAvatarHandPosition[ _closestOtherAvatar ]; _handHolding.velocity *= 0.7;
_handHolding.velocity += ( vectorToOtherHand + vectorToMyHand ) * _handHolding.force * deltaTime;
_handHolding.position += _handHolding.velocity;
_bone[ AVATAR_BONE_RIGHT_HAND ].position = _handHolding.position;
} }
} }
} }
else {
_handHolding.position = _bone[ AVATAR_BONE_RIGHT_HAND ].position;
_handHolding.velocity = glm::vec3( 0.0, 0.0, 0.0 );
}
//------------------------------------------------------------------------------- //-------------------------------------------------------------------------------
// determine the arm vector // determine the arm vector
//------------------------------------------------------------------------------- //-------------------------------------------------------------------------------
@ -1247,8 +1261,10 @@ void Head::renderBody() {
} }
} }
if (( _usingBodySprings ) && ( getHandState() )) { //---------------------------------------------------------
glColor4f( 1.0, 1.0, 0.5, 0.5 ); // if the hand is grasping, show it...
//---------------------------------------------------------
if (( _usingBodySprings ) && ( getHandState() == 1 )) {
glPushMatrix(); glPushMatrix();
glTranslatef glTranslatef
( (
@ -1256,7 +1272,10 @@ void Head::renderBody() {
_bone[ AVATAR_BONE_RIGHT_HAND ].springyPosition.y, _bone[ AVATAR_BONE_RIGHT_HAND ].springyPosition.y,
_bone[ AVATAR_BONE_RIGHT_HAND ].springyPosition.z _bone[ AVATAR_BONE_RIGHT_HAND ].springyPosition.z
); );
glutSolidSphere( 0.03f, 10.0f, 5.0f ); glColor4f( 1.0, 1.0, 0.8, 0.3 ); glutSolidSphere( 0.020f, 10.0f, 10.0f );
glColor4f( 1.0, 1.0, 0.4, 0.2 ); glutSolidSphere( 0.025f, 10.0f, 10.0f );
glColor4f( 1.0, 1.0, 0.2, 0.1 ); glutSolidSphere( 0.030f, 10.0f, 10.0f );
glPopMatrix(); glPopMatrix();
} }
} }

View file

@ -29,7 +29,7 @@ const float YAW_MAG = 300.0;
const float TEST_YAW_DECAY = 5.0; const float TEST_YAW_DECAY = 5.0;
const float LIN_VEL_DECAY = 5.0; const float LIN_VEL_DECAY = 5.0;
const float COLLISION_BODY_RADIUS = 0.3; const float COLLISION_BODY_RADIUS = 0.1;
const float COLLISION_HEIGHT = 1.5; const float COLLISION_HEIGHT = 1.5;
enum eyeContactTargets {LEFT_EYE, RIGHT_EYE, MOUTH}; enum eyeContactTargets {LEFT_EYE, RIGHT_EYE, MOUTH};
@ -93,6 +93,20 @@ struct AvatarCollisionElipsoid
glm::vec3 upVector; glm::vec3 upVector;
}; };
struct AvatarHandHolding
{
glm::vec3 position;
glm::vec3 velocity;
float force;
};
struct OtherAvatar
{
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?
@ -177,6 +191,7 @@ class Head : public AvatarData {
glm::vec3 getHeadPosition(); glm::vec3 getHeadPosition();
glm::vec3 getBonePosition( AvatarBoneID b ); glm::vec3 getBonePosition( AvatarBoneID b );
glm::vec3 getBodyUpDirection(); glm::vec3 getBodyUpDirection();
//int getHandState();
float getGirth(); float getGirth();
float getHeight(); float getHeight();
@ -190,13 +205,11 @@ class Head : public AvatarData {
void startHandMovement(); void startHandMovement();
void stopHandMovement(); void stopHandMovement();
void setHandMovementValues( glm::vec3 movement ); void setHandMovementValues( glm::vec3 movement );
void updateHandMovement(); void updateHandMovement( float deltaTime );
float getAverageLoudness() {return _head.averageLoudness;}; float getAverageLoudness() {return _head.averageLoudness;};
void setAverageLoudness(float al) {_head.averageLoudness = al;}; void setAverageLoudness(float al) {_head.averageLoudness = al;};
bool testForCollision( glm::vec3 collisionPosition, float collisionGirth, float collisionHeight, glm::vec3 collisionUpVector );
void SetNewHeadTarget(float, float); void SetNewHeadTarget(float, float);
// Set what driving keys are being pressed to control thrust levels // Set what driving keys are being pressed to control thrust levels
@ -208,47 +221,38 @@ class Head : public AvatarData {
void addThrust(glm::vec3 newThrust) { _thrust += newThrust; }; void addThrust(glm::vec3 newThrust) { _thrust += newThrust; };
glm::vec3 getThrust() { return _thrust; }; glm::vec3 getThrust() { return _thrust; };
//
// Related to getting transmitter UDP data used to animate the avatar hand // Related to getting transmitter UDP data used to animate the avatar hand
//
void processTransmitterData(unsigned char * packetData, int numBytes); void processTransmitterData(unsigned char * packetData, int numBytes);
float getTransmitterHz() { return _transmitterHz; }; float getTransmitterHz() { return _transmitterHz; };
private: private:
AvatarHead _head; AvatarHead _head;
bool _isMine; bool _isMine;
glm::vec3 _TEST_bigSpherePosition; glm::vec3 _TEST_bigSpherePosition;
float _TEST_bigSphereRadius; float _TEST_bigSphereRadius;
glm::vec3 _otherAvatarHandPosition[ MAX_OTHER_AVATARS ]; OtherAvatar _otherAvatar;
bool _mousePressed; bool _mousePressed;
float _bodyYawDelta; float _bodyYawDelta;
int _closestOtherAvatar; bool _nearOtherAvatar;
bool _usingBodySprings; bool _usingBodySprings;
glm::vec3 _movedHandOffset; glm::vec3 _movedHandOffset;
float _springVelocityDecay; float _springVelocityDecay;
float _springForce; float _springForce;
glm::quat _rotation; // the rotation of the avatar body as a whole expressed as a quaternion glm::quat _rotation; // the rotation of the avatar body as a whole expressed as a quaternion
AvatarBone _bone[ NUM_AVATAR_BONES ]; AvatarBone _bone[ NUM_AVATAR_BONES ];
AvatarMode _mode; AvatarMode _mode;
glm::dvec3 _velocity; AvatarHandHolding _handHolding;
glm::vec3 _thrust; glm::dvec3 _velocity;
float _maxArmLength; glm::vec3 _thrust;
Orientation _orientation; float _maxArmLength;
int _numOtherAvatarsInView; Orientation _orientation;
int _driveKeys[MAX_DRIVE_KEYS]; int _driveKeys[MAX_DRIVE_KEYS];
GLUquadric* _sphere; GLUquadric* _sphere;
float _renderYaw; float _renderYaw;
float _renderPitch; // Pitch from view frustum when this is own head float _renderPitch; // Pitch from view frustum when this is own head
timeval _transmitterTimer;
AvatarCollisionElipsoid _collisionElipsoid; float _transmitterHz;
int _transmitterPackets;
//
// Related to getting transmitter UDP data used to animate the avatar hand
//
timeval _transmitterTimer;
float _transmitterHz;
int _transmitterPackets;
//----------------------------- //-----------------------------
// private methods... // private methods...
@ -258,10 +262,16 @@ class Head : public AvatarData {
void initializeBodySprings(); void initializeBodySprings();
void updateBodySprings( float deltaTime ); void updateBodySprings( float deltaTime );
void calculateBoneLengths(); void calculateBoneLengths();
void updateAvatarCollisionDetectionAndResponse( glm::vec3, float radius, float deltaTime );
void readSensors(); void readSensors();
void renderBoneAsBlock( AvatarBoneID b ); void renderBoneAsBlock( AvatarBoneID b );
void updateAvatarCollisionDetectionAndResponse
(
glm::vec3 collisionPosition,
float collisionGirth,
float collisionHeight,
glm::vec3 collisionUpVector,
float deltaTime
);
}; };
#endif #endif

View file

@ -185,7 +185,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->getBodyPosition(); glm::vec3 viewerPosition = viewerHead->getPosition();
// debug LOD code // debug LOD code
glm::vec3 debugNodePosition; glm::vec3 debugNodePosition;

View file

@ -306,7 +306,7 @@ void displayStats(void)
char legend2[] = "* - toggle stars, & - toggle paint mode, '-' - send erase all, '%' - send add scene"; char legend2[] = "* - toggle stars, & - toggle paint mode, '-' - send erase all, '%' - send add scene";
drawtext(10, statsVerticalOffset + 32, 0.10f, 0, 1.0, 0, legend2); drawtext(10, statsVerticalOffset + 32, 0.10f, 0, 1.0, 0, legend2);
glm::vec3 avatarPos = myAvatar.getBodyPosition(); glm::vec3 avatarPos = myAvatar.getPosition();
char stats[200]; char stats[200];
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 ",
@ -398,8 +398,8 @@ void init(void)
if (noiseOn) { if (noiseOn) {
myAvatar.setNoise(noise); myAvatar.setNoise(noise);
} }
myAvatar.setBodyPosition(start_location); myAvatar.setPosition(start_location);
myCamera.setPosition( start_location ); myCamera.setPosition(start_location);
#ifdef MARKER_CAPTURE #ifdef MARKER_CAPTURE
@ -440,7 +440,7 @@ void reset_sensors()
renderYawRate = 0; renderYawRate = 0;
renderPitchRate = 0; renderPitchRate = 0;
myAvatar.setBodyPosition(start_location); myAvatar.setPosition(start_location);
headMouseX = WIDTH/2; headMouseX = WIDTH/2;
headMouseY = HEIGHT/2; headMouseY = HEIGHT/2;
@ -540,7 +540,7 @@ void updateAvatar(float frametime)
// If I'm in paint mode, send a voxel out to VOXEL server agents. // If I'm in paint mode, send a voxel out to VOXEL server agents.
if (::paintOn) { if (::paintOn) {
glm::vec3 avatarPos = myAvatar.getBodyPosition(); glm::vec3 avatarPos = myAvatar.getPosition();
// For some reason, we don't want to flip X and Z here. // For some reason, we don't want to flip X and Z here.
::paintingVoxel.x = avatarPos.x/10.0; ::paintingVoxel.x = avatarPos.x/10.0;
@ -822,7 +822,7 @@ void display(void)
//---------------------------------------------------- //----------------------------------------------------
// set the camera to third-person view behind my av // set the camera to third-person view behind my av
//---------------------------------------------------- //----------------------------------------------------
myCamera.setTargetPosition ( myAvatar.getBodyPosition() ); myCamera.setTargetPosition ( myAvatar.getPosition() );
myCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() ); myCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() );
myCamera.setPitch ( 0.0 ); // temporarily, this must be 0.0 or else bad juju myCamera.setPitch ( 0.0 ); // temporarily, this must be 0.0 or else bad juju
myCamera.setRoll ( 0.0 ); myCamera.setRoll ( 0.0 );
@ -1264,7 +1264,7 @@ void shiftPaintingColor()
} }
void setupPaintingVoxel() { void setupPaintingVoxel() {
glm::vec3 avatarPos = myAvatar.getBodyPosition(); glm::vec3 avatarPos = myAvatar.getPosition();
::paintingVoxel.x = avatarPos.z/-10.0; // voxel space x is negative z head space ::paintingVoxel.x = avatarPos.z/-10.0; // voxel space x is negative z head space
::paintingVoxel.y = avatarPos.y/-10.0; // voxel space y is negative y head space ::paintingVoxel.y = avatarPos.y/-10.0; // voxel space y is negative y head space
@ -1493,7 +1493,7 @@ void idle(void) {
// //
updateAvatar(deltaTime); updateAvatar(deltaTime);
//loop through all the other avatars and simulate them. //loop through all the other avatars and simulate them...
AgentList * agentList = AgentList::getInstance(); AgentList * agentList = AgentList::getInstance();
for(std::vector<Agent>::iterator agent = agentList->getAgents().begin(); agent != agentList->getAgents().end(); agent++) for(std::vector<Agent>::iterator agent = agentList->getAgents().begin(); agent != agentList->getAgents().end(); agent++)
{ {
@ -1501,9 +1501,6 @@ void idle(void) {
{ {
Head *avatar = (Head *)agent->getLinkedData(); Head *avatar = (Head *)agent->getLinkedData();
avatar->simulate(deltaTime); avatar->simulate(deltaTime);
//not ready yet...
//myAvatar.testForCollision( avatar->getBodyPosition(), avatar->getGirth(), avatar->getHeight(), avatar->getBodyUpDirection() );
} }
} }
@ -1514,7 +1511,6 @@ void idle(void) {
glutPostRedisplay(); glutPostRedisplay();
lastTimeIdle = check; lastTimeIdle = check;
} }
// Read serial data // Read serial data

View file

@ -69,7 +69,7 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) {
// and return the number of bytes to push the pointer // and return the number of bytes to push the pointer
// Body world position // Body world position
memcpy(destinationBuffer, &_bodyPosition, sizeof(float) * 3); memcpy(destinationBuffer, &_position, sizeof(float) * 3);
destinationBuffer += sizeof(float) * 3; destinationBuffer += sizeof(float) * 3;
// Body rotation (NOTE: This needs to become a quaternion to save two bytes) // Body rotation (NOTE: This needs to become a quaternion to save two bytes)
@ -125,7 +125,7 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
unsigned char* startPosition = sourceBuffer; unsigned char* startPosition = sourceBuffer;
// Body world position // Body world position
memcpy(&_bodyPosition, sourceBuffer, sizeof(float) * 3); memcpy(&_position, sourceBuffer, sizeof(float) * 3);
sourceBuffer += sizeof(float) * 3; sourceBuffer += sizeof(float) * 3;
// Body rotation (NOTE: This needs to become a quaternion to save two bytes) // Body rotation (NOTE: This needs to become a quaternion to save two bytes)
@ -171,14 +171,14 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
return sourceBuffer - startPosition; return sourceBuffer - startPosition;
} }
glm::vec3 AvatarData::getBodyPosition() { glm::vec3 AvatarData::getPosition() {
return glm::vec3(_bodyPosition.x, return glm::vec3(_position.x,
_bodyPosition.y, _position.y,
_bodyPosition.z); _position.z);
} }
void AvatarData::setBodyPosition(glm::vec3 bodyPosition) { void AvatarData::setPosition(glm::vec3 position) {
_bodyPosition = bodyPosition; _position = position;
} }
void AvatarData::setHandPosition(glm::vec3 handPosition) { void AvatarData::setHandPosition(glm::vec3 handPosition) {

View file

@ -20,8 +20,8 @@ public:
AvatarData* clone() const; AvatarData* clone() const;
glm::vec3 getBodyPosition(); glm::vec3 getPosition();
void setBodyPosition(glm::vec3 bodyPosition); void setPosition(glm::vec3 position);
void setHandPosition(glm::vec3 handPosition); void setHandPosition(glm::vec3 handPosition);
int getBroadcastData(unsigned char* destinationBuffer); int getBroadcastData(unsigned char* destinationBuffer);
@ -48,7 +48,7 @@ public:
// Hand State // Hand State
void setHandState(char s) { _handState = s; }; void setHandState(char s) { _handState = s; };
const float getHandState() const {return _handState; }; const float getHandState() const {return _handState; }; //@Philip - shouldn't this be an int or a char?
// Instantaneous audio loudness to drive mouth/facial animation // Instantaneous audio loudness to drive mouth/facial animation
void setLoudness(float l) { _audioLoudness = l; }; void setLoudness(float l) { _audioLoudness = l; };
@ -75,7 +75,7 @@ public:
void setCameraFarClip(float farClip) { _cameraFarClip = farClip; } void setCameraFarClip(float farClip) { _cameraFarClip = farClip; }
protected: protected:
glm::vec3 _bodyPosition; glm::vec3 _position;
glm::vec3 _handPosition; glm::vec3 _handPosition;
// Body rotation // Body rotation