View Full Version : simulate vertex transformation

A027298

10-23-2002, 12:46 AM

Hi folks

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 (P)

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' = P*MV*v

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).]

Overmind

10-23-2002, 10:44 AM

Perspective division is just dividing a vectors components by its w component.

v[x] /= v[w]

v[y] /= v[w]

v[z] /= v[w]

So you get a 2D screen space coordinate + depth component out of a 4D affine coordinate.

A027298

10-23-2002, 05:25 PM

That's clear to me, but how can I do it if I have no access to my vertices, for example when I use glut functions?

Korval

10-23-2002, 06:13 PM

That's clear to me, but how can I do it if I have no access to my vertices, for example when I use glut functions?

Stop using those glut functions. Or, since the source is avaliable, copy those glut functions and return the results.

A027298

10-23-2002, 06:24 PM

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' = P*MV*v,

and do perspective division on v'. That means doing perspective division to transform vertices to the unit cube is necessary.

Overmind

10-24-2002, 11:03 AM

I think I don't understand your problem.

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.

A027298

10-24-2002, 05:56 PM

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: Pc*Mc*Ps*Ms

to transform a vertex to post-perspective space: v' = Pc*Mc*Ps*Ms*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)

Overmind

10-25-2002, 01:13 PM

Ah, I think now I understand your problem.

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 = S*v; v /= v.w; v = C*v ;), but then you need a card that supports it.

[This message has been edited by Overmind (edited 10-25-2002).]

A027298

10-26-2002, 07:20 PM

Originally posted by Overmind:

I don't think this is possible with standard OpenGL

Thanks, but I got it done. It's possible in OpenGL, but you have to take care of the camera position.

Overmind

10-27-2002, 01:31 AM

Thanks, but I got it done.

Wow. Can you describe how?

A027298

10-27-2002, 04:54 PM

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).]

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.