Home Game Development opengl – What ought to the Z coordinate be after reworked by the projection matrix?

opengl – What ought to the Z coordinate be after reworked by the projection matrix?

0
opengl – What ought to the Z coordinate be after reworked by the projection matrix?

[ad_1]

I’m engaged on an OpenGL 1.x implementation for the Sega Dreamcast. Because the Dreamcast did not have any {hardware} T&L all the vertex transformation pipeline must be carried out in software program.

What additionally must be carried out in software program is clipping to the near-Z airplane as failure to clip leads to the polygon being dropped fully from rendering by the {hardware}.

I’m having some hassle getting the remodel -> clip -> perspective divide course of working accurately and mainly I can sum up the issue as follows:

  • I remodel polygon vertices by the modelview and projection matrices
  • I clip every polygon in opposition to the W = 0.000001 airplane
  • This leads to new vertices on the close to airplane with a W of 0.000001, however a Z which is twice the close to airplane distance
  • At perspective divide vertex.z /= vertex.w leads to an excessive worth as a result of we’re dividing a Z worth (e.g. 0.2) by 0.000001

Something appears very unsuitable right here. The projection matrix is being generated in the identical method as described within the glFrustum docs.

So my query is, if I’ve a coordinate on the close to airplane, ought to its Z worth be zero after remodel by the projection matrix or ought to it’s the near-z distance, or one thing else?

After clipping polygons to the W = 0.000001 airplane, ought to the generated Z coordinates be -0.000001?

Update:

Here is the projection matrix as calculated by: gluPerspective(45.0f, 640.0f / 480.0f, 0.44f, 100.0f);

1.810660 0.000000 0.000000 0.000000
0.000000 2.414213 0.000000 0.000000
0.000000 0.000000 -1.008839 -0.883889
0.000000 0.000000 -1.000000 0.000000

Does this look right? It’s the worth within the right-hand column I’m unsure about…

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here