Matrix Camera::GetFilmToWorldMatrix() { GetProjectionMatrix(); //scaling.print(); GetModelViewMatrix(); //modelView.print(); Matrix m = invert(scaling * modelView); //m.print(); return m; }
void OpenGlRenderState::Follow(const OpenGlMatrix& T_wc, bool follow) { this->T_cw = T_wc.Inverse(); if(follow != this->follow) { if(follow) { const OpenGlMatrix T_vc = GetModelViewMatrix() * T_wc; SetModelViewMatrix(T_vc); this->follow = true; }else{ Unfollow(); } } }
dVector dSceneRender::ScreenToGlobal (const dVector& screen) const { dFloat width = dFloat (GetViewPortWidth()); dFloat height = dFloat (GetViewPortHeight()); dVector p0 (2.0f * screen.m_x / width - 1.0f, 2.0f * (height - screen.m_y) / height - 1.0f, 2.0f * screen.m_z - 1.0f, 1.0f); dMatrix modelview (GetModelViewMatrix()); dMatrix projection (GetProjectionMatrix()); dMatrix matrix (modelview * projection); dMatrix invMatrix (matrix.Inverse4x4()); dVector p1 (invMatrix.RotateVector4x4(p0)); p1.m_w = 1.0f / p1.m_w; p1 = p1.Scale(p1.m_w); p1.m_w = 1.0f; return p1; }
dVector dSceneRender::GlobalToScreen (const dVector& global) const { dMatrix modelview (GetModelViewMatrix()); dMatrix projection (GetProjectionMatrix()); dVector screen (projection.RotateVector4x4(modelview.TransformVector(global))); //dMatrix matrix (modelview * projection); //dMatrix invMatrix (matrix.Inverse4x4()); //dVector p2 (invMatrix.RotateVector4x4(screen)); dAssert (screen.m_w > 0.0f); screen.m_w = 1.0f / screen.m_w; screen = screen.Scale(screen.m_w); dFloat width = dFloat (GetViewPortWidth()); dFloat height = dFloat (GetViewPortHeight()); screen.m_x = 0.5f * (screen.m_x + 1.0f) * width; screen.m_y = height - 0.5f * (screen.m_y + 1.0f) * height; screen.m_z = 0.5f * (screen.m_z + 1.0f); screen.m_w = 1.0f; return screen; }
void OpenGlRenderState::Unfollow() { const OpenGlMatrix T_vw = GetModelViewMatrix() * T_cw; SetModelViewMatrix(T_vw); this->follow = false; }
OpenGlMatrix OpenGlRenderState::GetProjectionModelViewMatrix() const { return GetProjectionMatrix() * GetModelViewMatrix(); }