Example #1
0
/**
 * @brief
 */
void R_MatricesChanged_default(void) {

	r_default_program_t *p = &r_default_program;

	if (r_state.active_program->matrix_dirty[R_MATRIX_MODELVIEW]) {
		// recalculate normal matrix if the modelview has changed.
		static matrix4x4_t normalMatrix;

		R_GetMatrix(R_MATRIX_MODELVIEW, &normalMatrix);
		Matrix4x4_Invert_Full(&normalMatrix, &normalMatrix);
		Matrix4x4_Transpose(&normalMatrix, &normalMatrix);
		R_ProgramParameterMatrix4fv(&p->normal_mat, (const GLfloat *) normalMatrix.m);
	}
}
Example #2
0
/*
===============
R_ScreenToWorld

Convert a given point from screen into world space
===============
*/
void GAME_EXPORT R_ScreenToWorld( const vec3_t screen, vec3_t point )
{
	matrix4x4	screenToWorld;
	float	w;

	if( !point || !screen )
		return;

	Matrix4x4_Invert_Full( screenToWorld, RI.worldviewProjectionMatrix );

	point[0] = screen[0] * screenToWorld[0][0] + screen[1] * screenToWorld[0][1] + screen[2] * screenToWorld[0][2] + screenToWorld[0][3];
	point[1] = screen[0] * screenToWorld[1][0] + screen[1] * screenToWorld[1][1] + screen[2] * screenToWorld[1][2] + screenToWorld[1][3];
	point[2] = screen[0] * screenToWorld[2][0] + screen[1] * screenToWorld[2][1] + screen[2] * screenToWorld[2][2] + screenToWorld[2][3];
	w = screen[0] * screenToWorld[3][0] + screen[1] * screenToWorld[3][1] + screen[2] * screenToWorld[3][2] + screenToWorld[3][3];
	if( w != 0.0f ) VectorScale( point, ( 1.0f / w ), point );
}