From ab8140e0efeb3b4e8ccfcb1513b03fff48ed4eeb Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Wed, 10 Apr 2013 12:12:57 -0700 Subject: [PATCH] fixed a bug in avatar head lookat direction --- interface/src/Head.cpp | 31 ++++++++++++++++++++++++++++--- interface/src/Head.h | 2 ++ interface/src/Util.cpp | 33 +++++++++++++++++++++++++++++++++ interface/src/Util.h | 12 +++++------- interface/src/main.cpp | 37 +++++++++++++++++++++++++++++++++++-- 5 files changed, 103 insertions(+), 12 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 13f30084bc..1f2e7d92fc 100755 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -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 ); } diff --git a/interface/src/Head.h b/interface/src/Head.h index 74c69492a9..68e0a15d95 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -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); diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index a670f48f9e..627af610fe 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -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 - -// 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 diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 00cd8d7bfc..9086385b96 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -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