OpenGL ProjectionMatrix

This topic is 2559 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi guys, i'm trying to figure out the math behind finding a view matrix and a projection matrix.

Okay here are my constant
int windowWidth = 640, windowHeight = 480;

VECTOR3D cameraPosition(50.0f,-10.0f,50.0f);
VECTOR3D cameraTarget(50.0f,-10.0f, 0.0f);

so simply a camera that look right to the ground (sort of top-down view)

i determine is viewMatrix with

gluLookAt(cameraPosition.x, cameraPosition.y, cameraPosition.z, cameraTarget.x, cameraTarget.y, cameraTarget.z,0.0f, 1.0f, 0.0f);

how am i suppose to determine the camera projection matrix?
i use
gluPerspective(45.0f, (float)windowWidth/windowHeight, 1.0f, 100.0f);

Is it the right way to do it? Thank you

Share on other sites
Yes, that seems ok. The projection matrix is independent of the camera position/direction.
No problem using glu functions for now, but you might consider using your own matrix code once you get more experience with openGL (it will help later when you start using shaders)

Share on other sites
If it's not dependant on position and direction what is it dependant on?Okay but what if i change my value for
gluPerspective([color="#ff0000"]90.0f, (float)windowWidth/windowHeight, 1.0f, 100.0f);
because in my opinion it should be 90 for the half angle because i want to display a 180degree view right?

and say that i do the same for a light. It's the lookAt that doesn't seem right to me:

VECTOR3D lightPosition(50.0f,-10.0f,15.0f);

gluPerspective(90.0f, (float)windowWidth/windowHeight, 1.0f, 100.0f);
glGetFloatv(GL_MODELVIEW_MATRIX, lightProjectionMatrix);

gluLookAt( lightPosition.x, lightPosition.y, lightPosition.z,lightPosition.x, lightPosition.y, 0, 0.0f, 1.0f, 0.0f);
glGetFloatv(GL_MODELVIEW_MATRIX, lightViewMatrix);

i want it to be the same, a light that point toward the ground to light up a room.

Share on other sites
The field of view parameter is the full angle, not the half angle. Besides, 180 degree field of view doesn't make any sense either in a linear projection. The projection plane becomes infinitely large, and a finitely sized shape projected onto an infinitely large plane becomes a zero-sized object.

Your question about the light doesn't make much sense either. I don't really understand what you're asking, and as Relfos said, the projection matrix has nothing to do with the viewpoint transformation or the light.

Share on other sites
Oh okay sorry. What i really want to know is: what is needed to calculate a projection matrix and how do you calculate it. I just give my light and camera in example because i though the projection matrix was dependant on the viewMatrix. I'm asking because i'm trying to implement shadow mapping in my engine, and i really see a difference when i play with the projection matrix of the light point of view but i don't quite understand what i actually do.

Share on other sites
In that case the field of view should be the field of view of the shadow map. If you have a spot light with 45 degree field of view and the shadow map covers the same 45 degrees, then you need to render the shadow map with a 45 degree field of view. Keep in mind that if you have a wide angled light source, you may have to split the map into several pieces since you cannot have a field of view with a too wide angle.

Share on other sites
In your opinion, is it whats happening here? (in the screenshot i have join) Am i using a too wide angle light source and that's why shadow near the light look nice but as soon as i get too far, it's acting weird? I'm sorry that this post really start to look like http://www.gamedev.net/topic/616709-opengl-lighting/, but at the beginning it was suppose to be a totally different question.

1. 1
2. 2
3. 3
4. 4
Rutin
15
5. 5

• 13
• 26
• 10
• 11
• 9
• Forum Statistics

• Total Topics
633724
• Total Posts
3013556
×