mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-05 00:46:47 +02:00
commit
797cec4513
3 changed files with 42 additions and 90 deletions
|
@ -952,6 +952,28 @@ glm::vec3 Head::getHeadLookatDirection()
|
|||
);
|
||||
}
|
||||
|
||||
//-------------------------------------------
|
||||
glm::vec3 Head::getHeadLookatDirectionUp()
|
||||
{
|
||||
return glm::vec3
|
||||
(
|
||||
avatar.orientation.getUp().x,
|
||||
avatar.orientation.getUp().y,
|
||||
-avatar.orientation.getUp().z
|
||||
);
|
||||
}
|
||||
|
||||
//-------------------------------------------
|
||||
glm::vec3 Head::getHeadLookatDirectionRight()
|
||||
{
|
||||
return glm::vec3
|
||||
(
|
||||
avatar.orientation.getRight().x,
|
||||
avatar.orientation.getRight().y,
|
||||
-avatar.orientation.getRight().z
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------
|
||||
glm::vec3 Head::getHeadPosition()
|
||||
|
|
|
@ -160,6 +160,8 @@ class Head : public AgentData {
|
|||
|
||||
float getBodyYaw();
|
||||
glm::vec3 getHeadLookatDirection();
|
||||
glm::vec3 getHeadLookatDirectionUp();
|
||||
glm::vec3 getHeadLookatDirectionRight();
|
||||
glm::vec3 getHeadPosition();
|
||||
glm::vec3 getBodyPosition();
|
||||
|
||||
|
|
|
@ -517,111 +517,42 @@ void render_view_frustum() {
|
|||
// farHeight – the height of the far plane
|
||||
// farWidth – the width of the far plane
|
||||
|
||||
glm::vec3 viewFrustumPosition = myAvatar.getHeadPosition();
|
||||
glm::vec3 viewFrustumDirection = myAvatar.getHeadLookatDirection();
|
||||
|
||||
//Jeffrey's variation:
|
||||
glm::vec3 avatarBodyPosition = myAvatar.getBodyPosition();
|
||||
glm::vec3 avatarHeadPosition = myAvatar.getHeadPosition();
|
||||
glm::vec3 avatarHeadDirection = myAvatar.getHeadLookatDirection();
|
||||
|
||||
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 = ::myAvatar.getPos()*-1.0; // We need to flip the sign to make this work.
|
||||
//glm::vec3 cameraDirection = ::myAvatar.getAvatarHeadLookatDirection()*-1.0; // gak! Not sure if this is correct!
|
||||
|
||||
float yaw = myAvatar.getYaw();
|
||||
float rightOfYaw = yaw-90.0;
|
||||
//float pitch = myAvatar.getPitch();
|
||||
//float roll = myAvatar.getRoll();
|
||||
|
||||
//printf("yaw=%f, right of yaw=%f, pitch=%f, roll=%f\n",yaw,rightOfYaw,pitch,roll);
|
||||
|
||||
// Currently we don't utilize pitch and yaw. Mainly because UI doesn't handle it.
|
||||
float directionX = sin(yaw*PI_OVER_180);
|
||||
float directionY = 0.0;
|
||||
float directionZ = cos(yaw*PI_OVER_180);
|
||||
|
||||
//printf("directionX=%f, directionY=%f, directionZ=%f\n",directionX,directionY,directionZ);
|
||||
|
||||
float directionRightX = sin(rightOfYaw*PI_OVER_180);
|
||||
float directionRightY = 0.0;
|
||||
float directionRightZ = cos(rightOfYaw*PI_OVER_180);
|
||||
|
||||
//printf("directionRightX=%f, directionRightY=%f, directionRightZ=%f\n",directionRightX,directionRightY,directionRightZ);
|
||||
|
||||
glm::vec3 cameraDirection = glm::vec3(directionX,directionY,directionZ);
|
||||
|
||||
// this is a temporary test, create a vertice that's 2 meters in front of avatar in direction their looking
|
||||
glm::vec3 lookingAt = cameraPosition+(cameraDirection*2.0);
|
||||
|
||||
// Some debug lines.
|
||||
glDisable(GL_LIGHTING);
|
||||
glColor4f(1.0, 1.0, 1.0, 1.0);
|
||||
glLineWidth(1.0);
|
||||
glBegin(GL_LINES);
|
||||
|
||||
// line from avatar to the origin -- this one is working.
|
||||
glColor3f(1,1,0);
|
||||
glVertex3f(cameraPosition.x,cameraPosition.y,cameraPosition.z);
|
||||
glVertex3f(0,0,0);
|
||||
|
||||
// line from avatar to 2 meters in front of avatar -- this is working??
|
||||
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);
|
||||
glm::vec3 right = glm::vec3(directionRightX,directionRightY,directionRightZ);
|
||||
glm::vec3 up = myAvatar.getHeadLookatDirectionUp();
|
||||
glm::vec3 right = myAvatar.getHeadLookatDirectionRight();
|
||||
float nearDist = 0.1;
|
||||
float farDist = 1.0;
|
||||
float fov = (0.7854f*2.0); // 45 deg * 2 = 90 deg
|
||||
float fovHalfAngle = 0.7854f; // 45 deg for half, so fov = 90 deg
|
||||
|
||||
float screenWidth = 800.0; // hack! We need to make this eventually be the correct height/width
|
||||
float screenHeight = 600.0;
|
||||
float screenWidth = ::WIDTH; // These values come from reshape()
|
||||
float screenHeight = ::HEIGHT;
|
||||
float ratio = screenWidth/screenHeight;
|
||||
float nearHeight = 2 * tan(fov / 2) * nearDist;
|
||||
|
||||
float nearHeight = 2 * tan(fovHalfAngle) * nearDist;
|
||||
float nearWidth = nearHeight * ratio;
|
||||
float farHeight = 2 * tan(fov / 2) * farDist;
|
||||
float farHeight = 2 * tan(fovHalfAngle) * farDist;
|
||||
float farWidth = farHeight * ratio;
|
||||
|
||||
glm::vec3 farCenter = cameraPosition+cameraDirection*farDist;
|
||||
glm::vec3 farCenter = viewFrustumPosition+viewFrustumDirection*farDist;
|
||||
glm::vec3 farTopLeft = farCenter + (up*farHeight*0.5) - (right*farWidth*0.5);
|
||||
glm::vec3 farTopRight = farCenter + (up*farHeight*0.5) + (right*farWidth*0.5);
|
||||
glm::vec3 farBottomLeft = farCenter - (up*farHeight*0.5) - (right*farWidth*0.5);
|
||||
glm::vec3 farBottomRight = farCenter - (up*farHeight*0.5) + (right*farWidth*0.5);
|
||||
|
||||
glm::vec3 nearCenter = cameraPosition+cameraDirection*nearDist;
|
||||
glm::vec3 nearCenter = viewFrustumPosition+viewFrustumDirection*nearDist;
|
||||
glm::vec3 nearTopLeft = nearCenter + (up*nearHeight*0.5) - (right*nearWidth*0.5);
|
||||
glm::vec3 nearTopRight = nearCenter + (up*nearHeight*0.5) + (right*nearWidth*0.5);
|
||||
glm::vec3 nearBottomLeft = nearCenter - (up*nearHeight*0.5) - (right*nearWidth*0.5);
|
||||
glm::vec3 nearBottomRight = nearCenter - (up*nearHeight*0.5) + (right*nearWidth*0.5);
|
||||
|
||||
|
||||
//glColor3f(1,1,1);
|
||||
// Get ready to draw some lines
|
||||
glDisable(GL_LIGHTING);
|
||||
glColor4f(1.0, 1.0, 1.0, 1.0);
|
||||
glLineWidth(1.0);
|
||||
glBegin(GL_LINES);
|
||||
|
||||
// near plane - bottom edge
|
||||
glColor3f(1,0,0);
|
||||
glVertex3f(nearBottomLeft.x,nearBottomLeft.y,nearBottomLeft.z);
|
||||
|
@ -656,8 +587,6 @@ glEnd();
|
|||
glVertex3f(farBottomLeft.x,farBottomLeft.y,farBottomLeft.z);
|
||||
glVertex3f(farTopLeft.x,farTopLeft.y,farTopLeft.z);
|
||||
|
||||
|
||||
|
||||
// right plane - bottom edge - near to distant
|
||||
glColor3f(0,0,1);
|
||||
glVertex3f(nearBottomRight.x,nearBottomRight.y,nearBottomRight.z);
|
||||
|
@ -675,7 +604,6 @@ glEnd();
|
|||
// left plane - top edge - near to distant
|
||||
glVertex3f(nearTopLeft.x,nearTopLeft.y,nearTopLeft.z);
|
||||
glVertex3f(farTopLeft.x,farTopLeft.y,farTopLeft.z);
|
||||
*/
|
||||
|
||||
glEnd();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue