示例#1
0
Matrix Camera::GetFilmToWorldMatrix() {
    GetProjectionMatrix();
    //scaling.print();
    GetModelViewMatrix();
    //modelView.print();
    Matrix m = invert(scaling * modelView);
    //m.print();
    return m;
}
示例#2
0
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();
        }
    }
}
示例#3
0
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;
}
示例#4
0
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;
}
示例#5
0
void OpenGlRenderState::Unfollow()
{
    const OpenGlMatrix T_vw = GetModelViewMatrix() * T_cw;
    SetModelViewMatrix(T_vw);
    this->follow = false;
}
示例#6
0
OpenGlMatrix OpenGlRenderState::GetProjectionModelViewMatrix() const
{
    return GetProjectionMatrix() * GetModelViewMatrix();
}