diff options
Diffstat (limited to 'indra/newview/llviewercamera.cpp')
-rw-r--r-- | indra/newview/llviewercamera.cpp | 78 |
1 files changed, 31 insertions, 47 deletions
diff --git a/indra/newview/llviewercamera.cpp b/indra/newview/llviewercamera.cpp index d915f11e74..9949bae8ac 100644 --- a/indra/newview/llviewercamera.cpp +++ b/indra/newview/llviewercamera.cpp @@ -83,16 +83,18 @@ LLViewerCamera::LLViewerCamera() : LLCamera() } } -bool LLViewerCamera::updateCameraLocation(const LLVector3 ¢er, const LLVector3 &up_direction, const LLVector3 &point_of_interest) +void LLViewerCamera::updateCameraLocation(const LLVector3 ¢er, const LLVector3 &up_direction, const LLVector3 &point_of_interest) { // do not update if avatar didn't move if (!LLViewerJoystick::getInstance()->getCameraNeedsUpdate()) { - return true; + return; } - LLVector3 last_position = getOrigin(); - LLVector3 last_axis = getAtAxis(); + LLVector3 last_position; + LLVector3 last_axis; + last_position = getOrigin(); + last_axis = getAtAxis(); mLastPointOfInterest = point_of_interest; @@ -102,49 +104,30 @@ bool LLViewerCamera::updateCameraLocation(const LLVector3 ¢er, const LLVecto regp = gAgent.getRegion(); } - F32 water_height = regp ? regp->getWaterHeight() : 0.f; + F32 water_height = (NULL != regp) ? regp->getWaterHeight() : 0.f; LLVector3 origin = center; - // Move origin[VZ] far enough (up or down) from the water surface - static const F32 MIN_DIST_TO_WATER = 0.2f; - F32& zpos = origin.mV[VZ]; - if (zpos < water_height + MIN_DIST_TO_WATER) { - if (zpos >= water_height) + if (origin.mV[2] > water_height) { - zpos = water_height + MIN_DIST_TO_WATER; + origin.mV[2] = llmax(origin.mV[2], water_height + 0.20f); } - else if (zpos > water_height - MIN_DIST_TO_WATER) + else { - zpos = water_height - MIN_DIST_TO_WATER; + origin.mV[2] = llmin(origin.mV[2], water_height - 0.20f); } } - LLVector3 at(point_of_interest - origin); - at.normalize(); - if (at.isNull() || !at.isFinite()) - return false; - - LLVector3 left(up_direction % at); - left.normalize(); - if (left.isNull() || !left.isFinite()) - return false; - - LLVector3 up = at % left; - up.normalize(); - if (up.isNull() || !up.isFinite()) - return false; - - setOrigin(origin); - setAxes(at, left, up); + setOriginAndLookAt(origin, up_direction, point_of_interest); mVelocityDir = origin - last_position ; F32 dpos = mVelocityDir.normVec() ; LLQuaternion rotation; rotation.shortestArc(last_axis, getAtAxis()); - F32 drot, x, y, z; + F32 x, y, z; + F32 drot; rotation.getAngleAxis(&drot, &x, &y, &z); add(sVelocityStat, dpos); @@ -157,8 +140,6 @@ bool LLViewerCamera::updateCameraLocation(const LLVector3 ¢er, const LLVecto // update pixel meter ratio using default fov, not modified one mPixelMeterRatio = (F32)(getViewHeightInPixels()/ (2.f*tanf(mCameraFOVDefault*0.5f))); // update screen pixel area - - return true; mScreenPixelArea =(S32)((F32)getViewHeightInPixels() * ((F32)getViewHeightInPixels() * getAspect())); } @@ -166,6 +147,7 @@ const LLMatrix4 &LLViewerCamera::getProjection() const { calcProjection(getFar()); return mProjectionMatrix; + } const LLMatrix4 &LLViewerCamera::getModelview() const @@ -178,12 +160,13 @@ const LLMatrix4 &LLViewerCamera::getModelview() const void LLViewerCamera::calcProjection(const F32 far_distance) const { - F32 fov_y = getView(); - F32 z_far = far_distance; - F32 z_near = getNear(); - F32 aspect = getAspect(); + F32 fov_y, z_far, z_near, aspect, f; + fov_y = getView(); + z_far = far_distance; + z_near = getNear(); + aspect = getAspect(); - F32 f = 1 / tan(fov_y * 0.5f); + f = 1/tan(fov_y*0.5f); mProjectionMatrix.setZero(); mProjectionMatrix.mMatrix[0][0] = f/aspect; @@ -289,9 +272,9 @@ void LLViewerCamera::updateFrustumPlanes(LLCamera& camera, bool ortho, bool zfli } void LLViewerCamera::setPerspective(bool for_selection, - S32 x, S32 y_from_bot, S32 width, S32 height, - bool limit_select_distance, - F32 z_near, F32 z_far) + S32 x, S32 y_from_bot, S32 width, S32 height, + bool limit_select_distance, + F32 z_near, F32 z_far) { F32 fov_y, aspect; fov_y = getView(); @@ -353,7 +336,7 @@ void LLViewerCamera::setPerspective(bool for_selection, { float offset = mZoomFactor - 1.f; int pos_y = mZoomSubregion / llceil(mZoomFactor); - int pos_x = mZoomSubregion - (pos_y * llceil(mZoomFactor)); + int pos_x = mZoomSubregion - (pos_y*llceil(mZoomFactor)); glm::mat4 translate; translate = glm::translate(glm::vec3(offset - (F32)pos_x * 2.f, offset - (F32)pos_y * 2.f, 0.f)); @@ -366,7 +349,7 @@ void LLViewerCamera::setPerspective(bool for_selection, calcProjection(z_far); // Update the projection matrix cache - proj_mat *= glm::perspective(fov_y, aspect, z_near, z_far); + proj_mat *= glm::perspective(fov_y,aspect,z_near,z_far); gGL.loadMatrix(glm::value_ptr(proj_mat)); @@ -374,7 +357,7 @@ void LLViewerCamera::setPerspective(bool for_selection, gGL.matrixMode(LLRender::MM_MODELVIEW); - glm::mat4 modelview(glm::make_mat4((GLfloat*)OGL_TO_CFR_ROTATION)); + glm::mat4 modelview(glm::make_mat4((GLfloat*) OGL_TO_CFR_ROTATION)); GLfloat ogl_matrix[16]; @@ -390,9 +373,9 @@ void LLViewerCamera::setPerspective(bool for_selection, // however, it is also unused (the GL matricies are used for selection, (see LLCamera::sphereInFrustum())) and so i'm not // comfortable hacking on it. calculateFrustumPlanesFromWindow((F32)(x - width / 2) / (F32)gViewerWindow->getWindowWidthScaled() - 0.5f, - (F32)(y_from_bot - height / 2) / (F32)gViewerWindow->getWindowHeightScaled() - 0.5f, - (F32)(x + width / 2) / (F32)gViewerWindow->getWindowWidthScaled() - 0.5f, - (F32)(y_from_bot + height / 2) / (F32)gViewerWindow->getWindowHeightScaled() - 0.5f); + (F32)(y_from_bot - height / 2) / (F32)gViewerWindow->getWindowHeightScaled() - 0.5f, + (F32)(x + width / 2) / (F32)gViewerWindow->getWindowWidthScaled() - 0.5f, + (F32)(y_from_bot + height / 2) / (F32)gViewerWindow->getWindowHeightScaled() - 0.5f); } @@ -406,6 +389,7 @@ void LLViewerCamera::setPerspective(bool for_selection, updateFrustumPlanes(*this); } + // Uses the last GL matrices set in set_perspective to project a point from // screen coordinates to the agent's region. void LLViewerCamera::projectScreenToPosAgent(const S32 screen_x, const S32 screen_y, LLVector3* pos_agent) const |