Anonymous Anonymous - 3 months ago
169 0

No description

C++

is this correct perspective projection -_-

void OpenGL_Engine::PerspectiveProjectionSetup(GLuint program)
{
	GLfloat Right = 2.0f;
	GLfloat Left = 0.0f;
	GLfloat Top = 0.0f;
	GLfloat Bottom = 2.0f;
	GLfloat zFar = 3.0f;
	GLfloat zNear = 0.5f;

//	GLfloat fieldofviewinradians = 90.0 * 180.0 / M_PI;
		
	//GLfloat aspect = 640.0 / 480.0;

	GLfloat aspect = 640 / 480;
	GLfloat const tanHalfFovy = tan(80 / 2);

	GLfloat Perspectiveprojmatrix[] = {
		//XX XY XZ XW
		1 / (aspect * tanHalfFovy),
		0.0,
		0.0,
		0.0,

		//YX YY YZ YW
		0.0,
		1 / (tanHalfFovy),
		0.0,
		0.0,

		//ZX ZY ZZ ZW
		0.0,
		0.0,
		zFar / (zFar - zNear),
		1.0,

		//WX WY WZ WW
		0.0,
		0.0,
		-(zFar * zNear) / (zFar - zNear),
		0.0
	};


	GLint Perspectivematrixloc = glGetUniformLocation(program, "PerspectiveProjMatrix");
	glUniformMatrix4fv(Perspectivematrixloc, 1, GL_TRUE,
		&Perspectiveprojmatrix[0]);
}