#### 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

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: