Exemple #1
0
void MOCamera::enable(void)
{
	MRenderingContext * render = MEngine::getInstance()->getRenderingContext();
	

	// get viewport
	render->getViewport(m_currentViewport);

	// projection mode
	render->setMatrixMode(M_MATRIX_PROJECTION);
	render->loadIdentity();

	float ratio = (m_currentViewport[2] / (float)m_currentViewport[3]);

	MVector3 scale = getTransformedScale();
	MVector3 iScale(1.0f / scale.x, 1.0f / scale.y, 1.0f / scale.z);

	MMatrix4x4 iScaleMatrix;
	iScaleMatrix.setScale(iScale);

	MMatrix4x4 inverseMatrix = ((*getMatrix()) * iScaleMatrix).getInverse();

	// perspective view
	if(! isOrtho())
	{
		// normal perspective projection
		render->setPerspectiveView(m_fov, ratio, m_clippingNear, m_clippingFar);

		// model view mode
		render->setMatrixMode(M_MATRIX_MODELVIEW);
		render->loadIdentity();

		render->multMatrix(&inverseMatrix);

		// get current matrices
		render->getModelViewMatrix(&m_currentViewMatrix);
		render->getProjectionMatrix(&m_currentProjMatrix);
		return;
	}

	// ortho view
	float height = m_fov * 0.5f;
	float width = height * ratio;

	render->setOrthoView(-width, width, -height, height, m_clippingNear, m_clippingFar);

	// model view mode
	render->setMatrixMode(M_MATRIX_MODELVIEW);
	render->loadIdentity();
	
	render->multMatrix(&inverseMatrix);

	// get current matrices
	render->getModelViewMatrix(&m_currentViewMatrix);
	render->getProjectionMatrix(&m_currentProjMatrix);
}
Exemple #2
0
void MOCamera::updateProjMatrix(void)
{
	MRenderingContext * render = MEngine::getInstance()->getRenderingContext();
	render->getViewport(m_currentViewport);
	
	float ratio = (m_currentViewport[2] / (float)m_currentViewport[3]);

	// perspective view
	if(! isOrtho())
	{
		// normal perspective projection
		createPerspectiveView(&m_currentProjMatrix, m_fov, ratio, m_clippingNear, m_clippingFar);
		return;
	}

	// ortho view
	float height = m_fov * 0.5f;
	float width = height * ratio;

	createOrthoView(&m_currentProjMatrix, -width, width, -height, height, m_clippingNear, m_clippingFar);
}