Changed render_view_frustum() to handle broken camera yaw

- I discovered that the Camera class has a Yaw that is actually
  180deg off of true yaw. So when the avatar is facing at a yaw
  of 0deg, we were setting the camera to 180. This was causing
  the direction vectors to be rotated from where we expected them
  to be, and as a result the frustum was wrong
- I did not fix the camera and the calls to glRotate() since I
 don't yet understan how these work. BUT. I did fix the frustum
 code to fix up this yaw before calculating the vectors
This commit is contained in:
ZappoMan 2013-04-18 01:16:54 -07:00
parent 309eb08490
commit 532dc285e7
2 changed files with 28 additions and 15 deletions

View file

@ -530,30 +530,39 @@ void render_view_frustum() {
glm::vec3 up;
glm::vec3 right;
float fov, nearClip, farClip;
float yaw, pitch, roll;
// Camera or Head?
if (::cameraFrustum) {
position = ::myCamera.getPosition();
direction = ::myCamera.getOrientation().getFront() * glm::vec3(1,1,-1);
up = ::myCamera.getOrientation().getUp() * glm::vec3(1,1,1);
right = ::myCamera.getOrientation().getRight() * glm::vec3(1,1,-1);
fov = ::myCamera.getFieldOfView();
nearClip = ::myCamera.getNearClip();
farClip = ::myCamera.getFarClip();
} else {
position = ::myAvatar.getHeadPosition();
direction = ::myAvatar.getHeadLookatDirection();
up = ::myAvatar.getHeadLookatDirectionUp();
right = ::myAvatar.getHeadLookatDirectionRight() * glm::vec3(-1,1,-1);
// NOTE: we use the same lens details if we draw from the head
fov = ::myCamera.getFieldOfView();
nearClip = ::myCamera.getNearClip();
farClip = ::myCamera.getFarClip();
}
// This bit of hackery is all because our Camera's report the incorrect yaw.
// For whatever reason, the camera has a yaw set to 180.0-trueYaw, so we basically
// need to get the "yaw" from the body
yaw = -(::myCamera.getOrientation().getYaw()-180);
pitch = ::myCamera.getOrientation().getPitch();
roll = ::myCamera.getOrientation().getRoll();
fov = ::myCamera.getFieldOfView();
nearClip = ::myCamera.getNearClip();
farClip = ::myCamera.getFarClip();
// We can't use the camera's Orientation because of it's broken yaw. so we make a new
// correct orientation to get our vectors
Orientation o;
o.yaw(yaw);
o.pitch(pitch);
o.roll(roll);
direction = o.getFront();
up = o.getUp();
right = o.getRight();
/*
printf("position.x=%f, position.y=%f, position.z=%f\n", position.x, position.y, position.z);
printf("yaw=%f, pitch=%f, roll=%f\n", yaw,pitch,roll);
printf("direction.x=%f, direction.y=%f, direction.z=%f\n", direction.x, direction.y, direction.z);
printf("up.x=%f, up.y=%f, up.z=%f\n", up.x, up.y, up.z);
printf("right.x=%f, right.y=%f, right.z=%f\n", right.x, right.y, right.z);
@ -561,7 +570,7 @@ void render_view_frustum() {
printf("nearClip=%f\n", nearClip);
printf("farClip=%f\n", farClip);
*/
// Set the viewFrustum up with the correct position and orientation of the camera
viewFrustum.setPosition(position);
viewFrustum.setOrientation(direction,up,right);

View file

@ -34,6 +34,10 @@ public:
void pitch ( float );
void roll ( float );
float getYaw() { return _yaw; };
float getPitch(){ return _pitch; };
float getRoll(){ return _roll; };
void set( Orientation );
void setToIdentity();