What's new

3D vertex Clipping in homogenous coordinates?

Rice

Emulator Developer
I cannot get the clipping working right.

I need to draw a line (1 edge of a triangle) between two vertexes in X,Y,Z,RHW format, need to clip the vertexes to the near plane (z=0, w=0?)

My algorithm is:
//Assuming v1.z>0 and v2.z<0
//v will be the new vertex coordinates for v2

float r=v1.z/(v1.z-v2.z);
v.x = (v2.x-v1.x)*r+v1.x;
v.y = (v2.y-v1.y)*r+v1.y;
v.z = 0;
v.w= 1/((1/v2.rhw-1/v1.rhw)*r+1/v1.rhw);


I think my problem is about how to interpolate the new rhw coordinate.

And what if I want to clip the two vertexes against the far plane (z=1, w=?) by assuing v1.z<1 and v2.z>1?


Thanks very much.

Rice
 
Last edited:

Orkin

d1R3c764 & g1|\|64 m4|<3R
In homogenous space the near clipping plane is at -w, and the far plane is at w. So you need to clip z against [-w,w], and not [0,1]. I can't remember the exact equation to compute the interpolation factor right now, but once you find it, you can interpolate w the same as x and y.

I wrote a triangle clipper for my plug-in...I'll look it up and post it here when I get home this evening.

Orkin
 
Last edited:

Top