What I want to do is to simulate the vertex transformation until I have normalized device coordinates.
Currently I am doing it like that:
1 load projection matrix §
2 multiply it with my modelview matrix (MV)
3 and finally specify my vertices (v).
4 perform perspective division on my vertices
That means after step 1 and 2 my current modelview matrix is M = P*MV
The vertices (v) are then transformed with this matrix: v’ = PMVv
But I don’t know how I can do the last step:
–>perspective division<–
Is there an easy way to do this?
Thanks!
[This message has been edited by A027298 (edited 10-23-2002).]
I don’t use glut functions. It was just an example.
Is there a way in Opengl to perform perspective division manually?
If I am wrong with the following please correct me:
I transform my vertices (v) to the unit cube: v’ = PMVv,
and do perspective division on v’. That means doing perspective division to transform vertices to the unit cube is necessary.
If you multiply your vertices with the matrixes yourself, you must have access to your vertex data, otherwise you can’t do the matrix math either. And there is no reason for doing the matrix math with a library that doesn’t give you the result, because then it makes no difference when you let OpenGL do it for you.
If what you want is to let OpenGL do the matrix math for you, but do the perspective division yourself, this is not possible, but I don’t see a reason why you would want to do that.
I want to do the following:
I want to map my scene to post-perspective space (the space of normalized device coordinates). That means, as a result I want to see my scene after rendering on my screen in the unit cube.
This is my idea, but which doesn’t work:
(Pc = Projection matrix of camera,
Mc = Modelview matrix of camera
Ps = Projection matrix of my scene
Ms = Modelview matrix of my scene)
At first I transform my camera with Pc*Mc to post-perspective space.
If I have this done, then I transform my scene with Ps * Ms to post-perspective space.
The final matrix is now: PcMcPsMs
to transform a vertex to post-perspective space: v’ = PcMcPsMs*v
(I note that if I want to have the standard way, that means without this post-perspective thing I get a transformed vertex like that: v’ = Pc * Modelview * v)
I don’t think this is possible with standard OpenGL, so you have to do the multiplication with the first two matrices yourself, then do perspective division and let OpenGL do the rest.
Of course you can also write a vertex program that does this calculation for you (v = Sv; v /= v.w; v = Cv ;), but then you need a card that supports it.
[This message has been edited by Overmind (edited 10-25-2002).]
I think the code way is the easiest way to show it:
glLoadIdentity();
1 gluPerspective(15.0f, 1.0, 1.0f, 150.0f);
2 gluLookAt(Xpos, Ypos, Zpos, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f);
//1 Here I set the projection matrix of the camera, which looks then (2) to the unit cube
3 glFrustum(l, r, b, t, n, f);
4 gluLookAt(Xeye, Yeye, Zeye, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f);
// 3 Here I set the ‘normal’ projection, which I also normally use and just set up the ‘normal’ camera
renderscene();
Maybe it’s not nice, but short and even better: It works.
[This message has been edited by A027298 (edited 10-27-2002).]