bool GLCamera::RotCamBase(double angle) { GLVertex3 org; GLMatrix mx = fCamBase*fCamTrans; GLVector3 fwd = mx.GetBaseVec(1); fCamBase.Rotate(org, fwd, angle); return (angle != 0); }
void GLCamera::Apply(int pickx, int picky, int pickw, int pickh) { glViewport(vpX, vpY, vpW, vpH); if(vpW == 0 || vpH == 0) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); return; } glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(fieldOfView, vpW/vpH, 1.0, 1000.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); GLMatrix mx = fCamBase*fCamTrans; GLVector3 pos = mx.GetTranslation(); GLVector3 fwd = mx.GetBaseVec(1); GLVector3 center = pos-fwd; GLVector3 up = fCamBase.GetBaseVec(3); gluLookAt(pos[0], pos[1], pos[2], center[0], center[1], center[2], up[0], up[1], up[2]); UpdateCache(); GLPlane clipPlane(EyeDirection(), EyePoint()); for (int i = 0; i < 8; i++) { double sx = (i&1) ? -1 : 1; double sy = (i&2) ? -1 : 1; double sz = (i&4) ? -1 : 1; double cdist = clipPlane.DistanceTo(GLVertex3(sceneSize*sx, sceneSize*sy, sceneSize*sz)); if (i == 0) farClip = nearClip = cdist; if (cdist < nearClip) nearClip = cdist; if (cdist > farClip) farClip = cdist; } nearClip *= 0.49; farClip *= 2.01; if (farClip < 2.0) farClip = 2.0; if (nearClip < farClip/1000.0) nearClip = farClip/1000.0; glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (pickw > 0 && pickh > 0) { int vport[4] = { vpX, vpY, vpW, vpH }; gluPickMatrix(pickx, vpH-picky, pickw, pickh, vport); gluPerspective(fieldOfView, vpW/vpH, nearClip, farClip); } else gluPerspective(fieldOfView, vpW/vpH, nearClip, farClip); glMatrixMode(GL_MODELVIEW); UpdateCache(); }