mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 18:44:00 +02:00
fixed avatar hand position by making avatars simulate all the time,and also fixing logic of _isMine
This commit is contained in:
parent
7b60ddf057
commit
b7d6ce9747
3 changed files with 87 additions and 77 deletions
|
@ -57,13 +57,14 @@ Head::Head(bool isMine) {
|
|||
_bodyPitch = 0.0;
|
||||
_bodyRoll = 0.0;
|
||||
_bodyYawDelta = 0.0;
|
||||
_triggeringAction = false;
|
||||
_mousePressed = false;
|
||||
_mode = AVATAR_MODE_STANDING;
|
||||
_isMine = isMine;
|
||||
_maxArmLength = 0.0;
|
||||
//_transmitterTimer = 0;
|
||||
_transmitterHz = 0.0;
|
||||
_transmitterPackets = 0;
|
||||
_numOtherAvatarsInView = 0;
|
||||
|
||||
initializeSkeleton();
|
||||
|
||||
|
@ -114,7 +115,8 @@ Head::Head(bool isMine) {
|
|||
_head.noise = 0;
|
||||
|
||||
_movedHandOffset = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
_usingBodySprings = false;
|
||||
_usingBodySprings = true;
|
||||
//_usingBodySprings = false;
|
||||
_springForce = 6.0f;
|
||||
_springVelocityDecay = 16.0f;
|
||||
_renderYaw = 0.0;
|
||||
|
@ -133,11 +135,11 @@ Head::Head(bool isMine) {
|
|||
//--------------------------------------------------
|
||||
// test... just slam them into random positions...
|
||||
//--------------------------------------------------
|
||||
_DEBUG_otherAvatarListPosition[ 0 ] = glm::vec3( 0.0f, 0.3f, 2.0f );
|
||||
_DEBUG_otherAvatarListPosition[ 1 ] = glm::vec3( 4.0f, 0.3f, 2.0f );
|
||||
_DEBUG_otherAvatarListPosition[ 2 ] = glm::vec3( 2.0f, 0.3f, 2.0f );
|
||||
_DEBUG_otherAvatarListPosition[ 3 ] = glm::vec3( 1.0f, 0.3f, -4.0f );
|
||||
_DEBUG_otherAvatarListPosition[ 4 ] = glm::vec3( -2.0f, 0.3f, -2.0f );
|
||||
_otherAvatarHandPosition[ 0 ] = glm::vec3( 0.0f, 0.3f, 2.0f );
|
||||
_otherAvatarHandPosition[ 1 ] = glm::vec3( 4.0f, 0.3f, 2.0f );
|
||||
_otherAvatarHandPosition[ 2 ] = glm::vec3( 2.0f, 0.3f, 2.0f );
|
||||
_otherAvatarHandPosition[ 3 ] = glm::vec3( 1.0f, 0.3f, -4.0f );
|
||||
_otherAvatarHandPosition[ 4 ] = glm::vec3( -2.0f, 0.3f, -2.0f );
|
||||
}
|
||||
|
||||
Head::Head(const Head &otherAvatar) {
|
||||
|
@ -150,7 +152,7 @@ Head::Head(const Head &otherAvatar) {
|
|||
_bodyPitch = otherAvatar._bodyPitch;
|
||||
_bodyRoll = otherAvatar._bodyRoll;
|
||||
_bodyYawDelta = otherAvatar._bodyYawDelta;
|
||||
_triggeringAction = otherAvatar._triggeringAction;
|
||||
_mousePressed = otherAvatar._mousePressed;
|
||||
_mode = otherAvatar._mode;
|
||||
_isMine = otherAvatar._isMine;
|
||||
_renderYaw = otherAvatar._renderYaw;
|
||||
|
@ -305,8 +307,8 @@ void Head::setLeanSideways(float dist){
|
|||
_head.leanSideways = dist;
|
||||
}
|
||||
|
||||
void Head::setTriggeringAction( bool d ) {
|
||||
_triggeringAction = d;
|
||||
void Head::setMousePressed( bool d ) {
|
||||
_mousePressed = d;
|
||||
}
|
||||
|
||||
|
||||
|
@ -325,21 +327,38 @@ void Head::simulate(float deltaTime) {
|
|||
_closestOtherAvatar = -1;
|
||||
float closestDistance = 10000.0f;
|
||||
|
||||
/*
|
||||
AgentList * agentList = AgentList::getInstance();
|
||||
|
||||
_numOtherAvatarsInView =0;
|
||||
|
||||
for(std::vector<Agent>::iterator agent = agentList->getAgents().begin();
|
||||
agent != agentList->getAgents().end();
|
||||
agent++) {
|
||||
if (( agent->getLinkedData() != NULL && ( agent->getType() == AGENT_TYPE_INTERFACE ) )) {
|
||||
Head *otherAvatar = (Head *)agent->getLinkedData();
|
||||
|
||||
// when this is working, I will grab the position here...
|
||||
//glm::vec3 otherAvatarPosition = otherAvatar->getBodyPosition();
|
||||
|
||||
if ( _numOtherAvatarsInView < MAX_OTHER_AVATARS ) {
|
||||
|
||||
//-----------------------------------------------------------
|
||||
// test other avatar hand position for proximity...
|
||||
//-----------------------------------------------------------
|
||||
_otherAvatarHandPosition[ _numOtherAvatarsInView ] = otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND );
|
||||
glm::vec3 v( _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position );
|
||||
v -= _otherAvatarHandPosition[ _numOtherAvatarsInView ];
|
||||
|
||||
float distance = glm::length( v );
|
||||
if ( distance < _maxArmLength ) {
|
||||
if ( distance < closestDistance ) {
|
||||
closestDistance = distance;
|
||||
_closestOtherAvatar = _numOtherAvatarsInView;
|
||||
_numOtherAvatarsInView++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
///for testing only (prior to having real avs working)
|
||||
for (int o=0; o<NUM_OTHER_AVATARS; o++) {
|
||||
//-------------------------------------
|
||||
|
@ -357,16 +376,17 @@ void Head::simulate(float deltaTime) {
|
|||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if ( usingBigSphereCollisionTest ) {
|
||||
//--------------------------------------------------------------
|
||||
// test for avatar collision response (using a big sphere :)
|
||||
//--------------------------------------------------------------
|
||||
updateBigSphereCollisionTest(deltaTime);
|
||||
}
|
||||
|
||||
}//if ( _isMine )
|
||||
|
||||
|
||||
if ( usingBigSphereCollisionTest ) {
|
||||
//--------------------------------------------------------------
|
||||
// test for avatar collision response (using a big sphere :)
|
||||
//--------------------------------------------------------------
|
||||
updateBigSphereCollisionTest(deltaTime);
|
||||
}
|
||||
|
||||
//------------------------
|
||||
// update avatar skeleton
|
||||
//------------------------
|
||||
|
@ -592,13 +612,6 @@ void Head::updateBigSphereCollisionTest( float deltaTime ) {
|
|||
_usingBodySprings = true;
|
||||
initializeBodySprings();
|
||||
}
|
||||
/*
|
||||
else {
|
||||
if (_usingSprings) {
|
||||
_usingSprings = false;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//----------------------------------------------------------
|
||||
// add gravity to velocity
|
||||
|
@ -669,9 +682,9 @@ void Head::render(int faceToFace) {
|
|||
//---------------------------------------------------
|
||||
// render other avatars (DEBUG TEST)
|
||||
//---------------------------------------------------
|
||||
for (int o=0; o<NUM_OTHER_AVATARS; o++) {
|
||||
for (int o=0; o<_numOtherAvatarsInView; o++) {
|
||||
glPushMatrix();
|
||||
glTranslatef( _DEBUG_otherAvatarListPosition[o].x, _DEBUG_otherAvatarListPosition[o].y, _DEBUG_otherAvatarListPosition[o].z );
|
||||
glTranslatef( _otherAvatarHandPosition[o].x, _otherAvatarHandPosition[o].y, _otherAvatarHandPosition[o].z );
|
||||
glScalef( 0.03, 0.03, 0.03 );
|
||||
glutSolidSphere( 1, 10, 10 );
|
||||
glPopMatrix();
|
||||
|
@ -681,10 +694,10 @@ void Head::render(int faceToFace) {
|
|||
if ( _closestOtherAvatar != -1 ) {
|
||||
|
||||
glm::vec3 v1( _bone[ AVATAR_BONE_RIGHT_HAND ].position );
|
||||
glm::vec3 v2( _DEBUG_otherAvatarListPosition[ _closestOtherAvatar ] );
|
||||
glm::vec3 v2( _otherAvatarHandPosition[ _closestOtherAvatar ] );
|
||||
|
||||
glLineWidth( 5.0 );
|
||||
glColor4f( 0.9f, 0.5f, 0.2f, 0.6 );
|
||||
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 );
|
||||
|
@ -871,7 +884,7 @@ void Head::startHandMovement() {
|
|||
}
|
||||
|
||||
void Head::stopHandMovement() {
|
||||
_usingBodySprings = false;
|
||||
//_usingBodySprings = false;
|
||||
}
|
||||
|
||||
void Head::setHandMovementValues( glm::vec3 handOffset ) {
|
||||
|
@ -1006,28 +1019,6 @@ void Head::updateSkeleton() {
|
|||
_orientation.setToIdentity();
|
||||
_orientation.yaw( _bodyYaw );
|
||||
|
||||
/*
|
||||
glm::quat quaternion
|
||||
(
|
||||
glm::vec3
|
||||
(
|
||||
_bodyPitch * PI_OVER_180,
|
||||
_bodyYaw * PI_OVER_180,
|
||||
_bodyRoll * PI_OVER_180
|
||||
)
|
||||
);
|
||||
|
||||
glm::mat4 rotationMatrix = glm::mat4_cast( quaternion );
|
||||
|
||||
glm::vec4 right( 1.0, 0.0, 0.0, 0.0 );
|
||||
glm::vec4 up ( 0.0, 1.0, 0.0, 0.0 );
|
||||
glm::vec4 front( 0.0, 0.0, 1.0, 0.0 );
|
||||
|
||||
rightDirection = glm::vec3( right * rotationMatrix );
|
||||
upDirection = glm::vec3( up * rotationMatrix );
|
||||
frontDirection = glm::vec3( front * rotationMatrix );
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// calculate positions of all bones by traversing the skeleton tree:
|
||||
//------------------------------------------------------------------------
|
||||
|
@ -1086,7 +1077,7 @@ void Head::updateBodySprings( float deltaTime ) {
|
|||
|
||||
float force = ( length - _bone[b].length ) * _springForce * deltaTime;
|
||||
|
||||
_bone[ b ].springyVelocity -= springDirection * force;
|
||||
_bone[b].springyVelocity -= springDirection * force;
|
||||
|
||||
if ( _bone[b].parent != AVATAR_BONE_NULL ) {
|
||||
_bone[ _bone[b].parent ].springyVelocity += springDirection * force;
|
||||
|
@ -1145,6 +1136,11 @@ glm::vec3 Head::getHeadPosition() {
|
|||
}
|
||||
|
||||
|
||||
glm::vec3 Head::getBonePosition( AvatarBones b ) {
|
||||
return _bone[b].position;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Head::updateHandMovement() {
|
||||
glm::vec3 transformedHandMovement;
|
||||
|
@ -1154,13 +1150,12 @@ void Head::updateHandMovement() {
|
|||
+ _orientation.getUp() * -_movedHandOffset.y * 0.5f
|
||||
+ _orientation.getFront() * -_movedHandOffset.y;
|
||||
|
||||
|
||||
_bone[ AVATAR_BONE_RIGHT_HAND ].position += transformedHandMovement;
|
||||
|
||||
//if holding hands, add a pull to the hand...
|
||||
if ( _usingBodySprings ) {
|
||||
if ( _closestOtherAvatar != -1 ) {
|
||||
if ( _triggeringAction ) {
|
||||
if ( _mousePressed ) {
|
||||
|
||||
/*
|
||||
glm::vec3 handShakePull( DEBUG_otherAvatarListPosition[ closestOtherAvatar ]);
|
||||
|
@ -1171,7 +1166,7 @@ void Head::updateHandMovement() {
|
|||
transformedHandMovement += handShakePull;
|
||||
*/
|
||||
|
||||
_bone[ AVATAR_BONE_RIGHT_HAND ].position = _DEBUG_otherAvatarListPosition[ _closestOtherAvatar ];
|
||||
_bone[ AVATAR_BONE_RIGHT_HAND ].position = _otherAvatarHandPosition[ _closestOtherAvatar ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1251,6 +1246,18 @@ void Head::renderBody() {
|
|||
// Render bone positions as spheres
|
||||
//-----------------------------------------
|
||||
for (int b=0; b<NUM_AVATAR_BONES; b++) {
|
||||
|
||||
/*
|
||||
if ( _isMine )
|
||||
{
|
||||
printf( "my avatar: %d\n", _usingBodySprings );
|
||||
}
|
||||
else
|
||||
{
|
||||
printf( "other avatar: %d\n", _usingBodySprings );
|
||||
}
|
||||
*/
|
||||
|
||||
if ( _usingBodySprings ) {
|
||||
glColor3fv( lightBlue );
|
||||
glPushMatrix();
|
||||
|
@ -1298,7 +1305,7 @@ void Head::renderBody() {
|
|||
}
|
||||
|
||||
|
||||
if (( _usingBodySprings ) && ( _triggeringAction )) {
|
||||
if (( _usingBodySprings ) && ( _mousePressed )) {
|
||||
glColor4f( 1.0, 1.0, 0.5, 0.5 );
|
||||
glPushMatrix();
|
||||
glTranslatef
|
||||
|
|
|
@ -34,7 +34,7 @@ enum eyeContactTargets {LEFT_EYE, RIGHT_EYE, MOUTH};
|
|||
#define ROT_RIGHT 7
|
||||
#define MAX_DRIVE_KEYS 8
|
||||
|
||||
#define NUM_OTHER_AVATARS 5 // temporary - for testing purposes!
|
||||
#define MAX_OTHER_AVATARS 50 // temporary - for testing purposes!
|
||||
|
||||
enum AvatarMode
|
||||
{
|
||||
|
@ -172,7 +172,7 @@ class Head : public AvatarData {
|
|||
|
||||
AvatarMode getMode();
|
||||
|
||||
void setTriggeringAction( bool trigger );
|
||||
void setMousePressed( bool pressed );
|
||||
|
||||
void render(int faceToFace);
|
||||
|
||||
|
@ -214,10 +214,10 @@ class Head : public AvatarData {
|
|||
bool _isMine;
|
||||
glm::vec3 _TEST_bigSpherePosition;
|
||||
float _TEST_bigSphereRadius;
|
||||
glm::vec3 _DEBUG_otherAvatarListPosition[ NUM_OTHER_AVATARS ];
|
||||
bool _triggeringAction;
|
||||
glm::vec3 _otherAvatarHandPosition[ MAX_OTHER_AVATARS ];
|
||||
bool _mousePressed;
|
||||
float _bodyYawDelta;
|
||||
float _closeEnoughToInteract;
|
||||
//float _closeEnoughToInteract;
|
||||
int _closestOtherAvatar;
|
||||
bool _usingBodySprings;
|
||||
glm::vec3 _movedHandOffset;
|
||||
|
@ -230,6 +230,7 @@ class Head : public AvatarData {
|
|||
glm::vec3 _thrust;
|
||||
float _maxArmLength;
|
||||
Orientation _orientation;
|
||||
int _numOtherAvatarsInView;
|
||||
|
||||
int _driveKeys[MAX_DRIVE_KEYS];
|
||||
GLUquadric* _sphere;
|
||||
|
|
|
@ -208,7 +208,6 @@ void initializeHandController() {
|
|||
handController.rampUpRate = 0.05;
|
||||
handController.rampDownRate = 0.02;
|
||||
handController.envelope = 0.0f;
|
||||
|
||||
}
|
||||
|
||||
void updateHandController( int x, int y ) {
|
||||
|
@ -238,7 +237,8 @@ void updateHandController( int x, int y ) {
|
|||
handController.startX = WIDTH / 2;
|
||||
handController.startY = HEIGHT / 2;
|
||||
handController.envelope = 0.0;
|
||||
myAvatar.stopHandMovement();
|
||||
//prototype
|
||||
//myAvatar.stopHandMovement();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -918,6 +918,9 @@ void display(void)
|
|||
if (agent->getLinkedData() != NULL) {
|
||||
Head *avatar = (Head *)agent->getLinkedData();
|
||||
//glPushMatrix();
|
||||
|
||||
//printf( "rendering remote avatar\n" );
|
||||
|
||||
avatar->render(0);
|
||||
//glPopMatrix();
|
||||
}
|
||||
|
@ -1390,7 +1393,6 @@ void key(unsigned char k, int x, int y)
|
|||
{
|
||||
myAvatar.setNoise(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (k == 'h') {
|
||||
|
@ -1467,13 +1469,12 @@ void idle(void) {
|
|||
// update behaviors for avatar hand movement
|
||||
updateHandController( mouseX, mouseY );
|
||||
|
||||
// when the mouse is being pressed, an 'action' is being
|
||||
// triggered in the avatar. The action is context-based.
|
||||
// tell my avatar if the mouse is being pressed...
|
||||
if ( mousePressed == 1 ) {
|
||||
myAvatar.setTriggeringAction( true );
|
||||
myAvatar.setMousePressed( true );
|
||||
}
|
||||
else {
|
||||
myAvatar.setTriggeringAction( false );
|
||||
myAvatar.setMousePressed( false );
|
||||
}
|
||||
|
||||
// walking triggers the handController to stop
|
||||
|
@ -1486,7 +1487,6 @@ void idle(void) {
|
|||
//
|
||||
updateAvatar( 1.f/FPS );
|
||||
|
||||
|
||||
//loop through all the other avatars and simulate them.
|
||||
AgentList * agentList = AgentList::getInstance();
|
||||
for(std::vector<Agent>::iterator agent = agentList->getAgents().begin(); agent != agentList->getAgents().end(); agent++)
|
||||
|
@ -1494,11 +1494,13 @@ void idle(void) {
|
|||
if (agent->getLinkedData() != NULL)
|
||||
{
|
||||
Head *avatar = (Head *)agent->getLinkedData();
|
||||
|
||||
//printf( "simulating remote avatar\n" );
|
||||
|
||||
avatar->simulate(deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//updateAvatarHand(1.f/FPS);
|
||||
|
||||
field.simulate (deltaTime);
|
||||
|
|
Loading…
Reference in a new issue