fixed a bug in avatar head lookat direction

This commit is contained in:
Jeffrey Ventrella 2013-04-10 12:12:57 -07:00
parent 861108b12b
commit ab8140e0ef
5 changed files with 103 additions and 12 deletions

View file

@ -955,9 +955,34 @@ glm::vec3 Head::getAvatarHeadLookatDirection()
{
return glm::vec3
(
avatar.bone[ AVATAR_BONE_HEAD ].orientation.getFront().x,
avatar.bone[ AVATAR_BONE_HEAD ].orientation.getFront().y,
avatar.bone[ AVATAR_BONE_HEAD ].orientation.getFront().z
avatar.orientation.getFront().x,
avatar.orientation.getFront().y,
-avatar.orientation.getFront().z
);
}
//-------------------------------------------
glm::vec3 Head::getAvatarHeadPosition()
{
return glm::vec3
(
avatar.bone[ AVATAR_BONE_HEAD ].position.x,
avatar.bone[ AVATAR_BONE_HEAD ].position.y,
avatar.bone[ AVATAR_BONE_HEAD ].position.z
);
}
//-------------------------------------------
glm::vec3 Head::getAvatarPosition()
{
return glm::vec3
(
avatar.bone[ AVATAR_BONE_PELVIS_SPINE ].position.x,
avatar.bone[ AVATAR_BONE_PELVIS_SPINE ].position.y,
avatar.bone[ AVATAR_BONE_PELVIS_SPINE ].position.z
);
}

View file

@ -160,6 +160,8 @@ class Head : public AgentData {
float getAvatarYaw();
glm::vec3 getAvatarHeadLookatDirection();
glm::vec3 getAvatarHeadPosition();
glm::vec3 getAvatarPosition();
void render(int faceToFace, int isMine);

View file

@ -163,3 +163,36 @@ glm::vec3 operator* (const glm::vec3& lhs, float rhs)
return result;
}
void drawGroundPlaneGrid( float size, int resolution )
{
glColor3f( 0.4f, 0.5f, 0.3f );
glLineWidth(2.0);
float gridSize = 10.0;
int gridResolution = 10;
for (int g=0; g<gridResolution; g++)
{
float fraction = (float)g / (float)( gridResolution - 1 );
float inc = -gridSize * ONE_HALF + fraction * gridSize;
glBegin( GL_LINE_STRIP );
glVertex3f( inc, 0.0f, -gridSize * ONE_HALF );
glVertex3f( inc, 0.0f, gridSize * ONE_HALF );
glEnd();
}
for (int g=0; g<gridResolution; g++)
{
float fraction = (float)g / (float)( gridResolution - 1 );
float inc = -gridSize * ONE_HALF + fraction * gridSize;
glBegin( GL_LINE_STRIP );
glVertex3f( -gridSize * ONE_HALF, 0.0f, inc );
glVertex3f( gridSize * ONE_HALF, 0.0f, inc );
glEnd();
}
}

View file

@ -17,8 +17,6 @@
#include <glm/glm.hpp>
// added by Ventrella for utility purposes
static const double ZERO = 0.0;
static const double ONE = 1.0;
static const double ONE_HALF = 0.5;
@ -29,11 +27,10 @@ static const double PI_OVER_180 = 3.14159265359 / 180.0;
static const double EPSILON = 0.00001; //smallish number - used as margin of error for some values
static const double SQUARE_ROOT_OF_2 = sqrt(2);
static const double SQUARE_ROOT_OF_3 = sqrt(3);
static const double METER = 1.0;
static const double DECIMETER = 0.1;
static const double CENTIMETER = 0.01;
static const double MILLIIMETER = 0.001;
static const double METER = 1.0;
static const double DECIMETER = 0.1;
static const double CENTIMETER = 0.01;
static const double MILLIIMETER = 0.001;
float azimuth_to(glm::vec3 head_pos, glm::vec3 source_pos);
float angle_to(glm::vec3 head_pos, glm::vec3 source_pos, float render_yaw, float head_yaw);
@ -51,5 +48,6 @@ double diffclock(timeval *clock1,timeval *clock2);
glm::vec3 operator* (float lhs, const glm::vec3& rhs);
glm::vec3 operator* (const glm::vec3& lhs, float rhs);
void drawGroundPlaneGrid( float size, int resolution );
#endif

View file

@ -511,6 +511,9 @@ void simulateHead(float frametime)
}
}
// XXXBHG - this code is not yet working. This is here to help Jeffery debug getAvatarHeadLookatDirection()
// The code will draw a yellow line from the avatar's position to the origin,
// It also attempts to draw a cyan line from the avatar to 2 meters in front of the avatar in the direction
@ -528,7 +531,35 @@ void render_view_frustum() {
// farDist the distance from the camera to the far plane
// farHeight the height of the far plane
// farWidth the width of the far plane
//Jeffrey's variation:
glm::vec3 avatarBodyPosition = myHead.getAvatarPosition();
glm::vec3 avatarHeadPosition = myHead.getAvatarHeadPosition();
glm::vec3 avatarHeadDirection = myHead.getAvatarHeadLookatDirection();
glm::vec3 avatarHeadDirectionEndPoint( avatarHeadPosition );
avatarHeadDirectionEndPoint += avatarHeadDirection;
glDisable(GL_LIGHTING);
glLineWidth( 3.0 );
// line from avatar head to origin
glBegin( GL_LINE_STRIP );
glColor4f( 1.0, 0.0, 0.0, 1.0 );
glVertex3f( avatarBodyPosition.x, avatarBodyPosition.y, avatarBodyPosition.z );
glVertex3f( 0.0f, 0.0f, 0.0f );
glEnd();
//line from avatar head to 1 meter in front of avatar head
glBegin( GL_LINE_STRIP );
glColor3f( 0.0f, 1.0f, 1.0f );
glVertex3f( avatarHeadPosition.x, avatarHeadPosition.y, avatarHeadPosition.z );
glVertex3f( avatarHeadDirectionEndPoint.x, avatarHeadDirectionEndPoint.y, avatarHeadDirectionEndPoint.z );
glEnd();
/*
glm::vec3 cameraPosition = ::myHead.getPos()*-1.0; // We need to flip the sign to make this work.
glm::vec3 cameraDirection = ::myHead.getAvatarHeadLookatDirection()*-1.0; // gak! Not sure if this is correct!
@ -550,7 +581,9 @@ void render_view_frustum() {
glColor3f(0,1,1);
glVertex3f(cameraPosition.x,cameraPosition.y,cameraPosition.z);
glVertex3f(lookingAt.x,lookingAt.y,lookingAt.z);
*/
/*
// Not yet ready for this...
glm::vec3 up = glm::vec3(0.0,1.0,0.0);
@ -727,7 +760,7 @@ void display(void)
//---------------------------------------------
// draw a grid gound plane....
//---------------------------------------------
//drawGroundPlaneGrid( 5.0f, 9 );
drawGroundPlaneGrid( 5.0f, 9 );
// Draw cloud of dots