Exemple #1
0
bool Camera::update()
{
	if (!m_bNeedsUpdate)
	{
		return true;
	}

	// update view and projection matrices
	Matrix44 tmp;
	//m_view.fromLookAtLH(m_position, m_lookAt, m_upVector);
	m_orientation.toRotationMatrix(tmp);
	tmp.m[3][0] = m_position.x;
	tmp.m[3][1] = m_position.y;
	tmp.m[3][2] = m_position.z;
	tmp.invert(m_view);

	if (m_bOrtho)
		m_proj.makeOrthoProjectionLH(m_width, m_height, m_nearClip, m_farClip);
	else
		m_proj.makePerspectiveProjectionLH(m_nearClip, m_farClip, m_fovY, m_aspect);

	// update frustum planes
	updateFrustum();

	// cache viewproj
	mul(m_viewproj, m_view, m_proj);
	m_bNeedsUpdate = false;

	return true;
}
bool
RendererServices::get_inverse_matrix (Matrix44 &result, ustring to)
{
    bool ok = get_matrix (result, to);
    if (ok)
        result.invert ();
    return ok;
}
bool
RendererServices::get_inverse_matrix (Matrix44 &result, TransformationPtr xform)
{
    bool ok = get_matrix (result, xform);
    if (ok)
        result.invert ();
    return ok;
}
bool
RendererServices::get_inverse_matrix (ShaderGlobals *sg, Matrix44 &result,
                                      TransformationPtr xform, float time)
{
    bool ok = get_matrix (sg, result, xform, time);
    if (ok)
        result.invert ();
    return ok;
}
bool
RendererServices::get_inverse_matrix (ShaderGlobals *sg, Matrix44 &result,
                                      ustring to)
{
    bool ok = get_matrix (sg, result, to);
    if (ok)
        result.invert ();
    return ok;
}
bool
SimpleRenderer::get_inverse_matrix (ShaderGlobals *sg, Matrix44 &result,
                                    ustring to, float time)
{
    if (to == u_camera || to == u_screen || to == u_NDC || to == u_raster) {
        Matrix44 M = m_world_to_camera;
        if (to == u_screen || to == u_NDC || to == u_raster) {
            float depthrange = (double)m_yon-(double)m_hither;
            if (m_projection == u_perspective) {
                float tanhalffov = tanf (0.5f * m_fov * M_PI/180.0);
                Matrix44 camera_to_screen (1/tanhalffov, 0, 0, 0,
                                           0, 1/tanhalffov, 0, 0,
                                           0, 0, m_yon/depthrange, 1,
                                           0, 0, -m_yon*m_hither/depthrange, 0);
                M = M * camera_to_screen;
            } else {
                Matrix44 camera_to_screen (1, 0, 0, 0,
                                           0, 1, 0, 0,
                                           0, 0, 1/depthrange, 0,
                                           0, 0, -m_hither/depthrange, 1);
                M = M * camera_to_screen;
            }
            if (to == u_NDC || to == u_raster) {
                float screenleft = -1.0, screenwidth = 2.0;
                float screenbottom = -1.0, screenheight = 2.0;
                Matrix44 screen_to_ndc (1/screenwidth, 0, 0, 0,
                                        0, 1/screenheight, 0, 0,
                                        0, 0, 1, 0,
                                        -screenleft/screenwidth, -screenbottom/screenheight, 0, 1);
                M = M * screen_to_ndc;
                if (to == u_raster) {
                    Matrix44 ndc_to_raster (m_xres, 0, 0, 0,
                                            0, m_yres, 0, 0,
                                            0, 0, 1, 0,
                                            0, 0, 0, 1);
                    M = M * ndc_to_raster;
                }
            }
        }
        result = M;
        return true;
    }

    TransformMap::const_iterator found = m_named_xforms.find (to);
    if (found != m_named_xforms.end()) {
        result = *(found->second);
        result.invert();
        return true;
    } else {
        return false;
    }
}
	Matrix44 SimpleSceneGraph::calculateRelativeTransform(const Matrix44& absoluteTransform) const
	{
		if (parent == nullptr)
		{
			return absoluteTransform;
		}

		/*
		 * Find the transform for this graph (Gr) relative to the absolute parent transform (Pa) that matches the
		 * absolute transform (Ga) i.e. such that: Ga = Pa * Gr or Gr = Ga * Pa-1
		 */
		Matrix44 inverseParentAbsoluteTransform = parent->getAbsoluteTransform();
		inverseParentAbsoluteTransform.invert();

		return absoluteTransform * inverseParentAbsoluteTransform;
	}
Exemple #8
0
bool
SimpleRenderer::get_inverse_matrix (Matrix44 &result, ustring to, float time)
{
    if (to == u_camera || to == u_screen || to == u_NDC || to == u_raster) {
        Matrix44 M = m_world_to_camera;
        if (to == u_screen || to == u_NDC || to == u_raster) {
            // arbitrary clip planes because renderer doesn't do any clipping
            float yon = 0.01f;
            float hither = 1e5f;
            float depthrange = yon - hither;
            float tanhalffov = tanf (m_fov * float(M_PI/360.0));
            Matrix44 camera_to_screen (1/tanhalffov, 0, 0, 0,
                                       0, 1/tanhalffov, 0, 0,
                                       0, 0, yon/depthrange, 1,
                                       0, 0, -yon*hither/depthrange, 0);
            M = M * camera_to_screen;
            if (to == u_NDC || to == u_raster) {
                Matrix44 screen_to_ndc (0.5f, 0, 0, 0,
                                        0, 0.5f, 0, 0,
                                        0, 0, 1.0f, 0,
                                        -0.5f, -0.5f, 0, 1);
                M = M * screen_to_ndc;
                if (to == u_raster) {
                    Matrix44 ndc_to_raster (m_xres, 0, 0, 0,
                                            0, m_yres, 0, 0,
                                            0, 0, 1, 0,
                                            0, 0, 0, 1);
                    M = M * ndc_to_raster;
                }
            }
        }
        result = M;
        return true;
    }

    TransformMap::const_iterator found = m_named_xforms.find (to);
    if (found == m_named_xforms.end())
        return false;
    result = found->second;
    result.invert();
    return true;
}