mat4 Camera::getViewMatrixInverse() const { updateVM(); mat4 inv; if (viewMatrix_.invert(inv)) return inv; else return mat4::identity; }
// This is called to set up the Camera-View void Camera::look(float windowRatio) { MatStack.matrixMode(MatrixStack::PROJECTION); MatStack.loadIdentity(); updateFrustum(); MatStack.loadMatrix(getFrustumMatrix(windowRatio)); MatStack.matrixMode(MatrixStack::MODELVIEW); MatStack.loadIdentity(); updateVM(); MatStack.loadMatrix(viewMatrix_); }
// This is called to set up the Camera-View void Camera::look() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); updateFrustum(); loadMatrix(getFrustumMatrix()); //getProjectionMatrix(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); updateVM(); loadMatrix(viewMatrix_); }
void Camera::setViewMatrix(const mat4& mvMat) { mat4 inv = glm::inverse(mvMat); // preserve the focallength float focallength = glm::length(focus_ - position_); // calculate world-coordinates vec4 pos = (inv * vec4(0.f, 0.f, 0.f, 1.f)); vec4 look = (inv * vec4(0.f, 0.f, -1.f, 0.f)); vec4 focus = pos + focallength * look; vec4 up = (inv * vec4(0.f, 1.f, 0.f, 0.f)); positionCamera(pos.xyz(), focus.xyz(), up.xyz()); updateVM(); }
mat4 Camera::getViewMatrix() const { updateVM(); return viewMatrix_; }
mat4 Camera::getRotateMatrix() const { updateVM(); return viewMatrix_.getRotationalPart(); }
mat4 Camera::getViewMatrixInverse() const { updateVM(); return glm::inverse(viewMatrix_); }