From 532dc285e71152775d4db551cbbae80443c7a17f Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 18 Apr 2013 01:16:54 -0700 Subject: [PATCH] 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 --- interface/src/main.cpp | 39 ++++++++++++++++++----------- libraries/avatars/src/Orientation.h | 4 +++ 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 87ad2873d1..5bcae2cbeb 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -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); diff --git a/libraries/avatars/src/Orientation.h b/libraries/avatars/src/Orientation.h index becddbd338..06425cf5dc 100755 --- a/libraries/avatars/src/Orientation.h +++ b/libraries/avatars/src/Orientation.h @@ -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();