nicolasbol

11-15-2009, 09:39 PM

Guys,

I've tried to Google this but I cannot figure out how it's done.

Let's take a real example and try to do everything by hand:

Here is a triangle on screen ( I know it looks like a quad but it looks like this because of the perspective and the third point is far on the side:

http://fabiensanglard.net/doomIphone/clipping.jpg

With the following matrix PVM:

Matrix pvm.

-----------------

-2.4651 0.0000 -2.6528 117.7031

0.0000 2.4142 0.0000 0.0000

-0.7399 0.0000 0.6876 -50.6078

-0.7325 0.0000 0.6807 -30.2037

-----------------

And the following triangle:

face[0] = [-130 , 50 , 200 , 1].

face[1] = [-100 , 0 , 200 , 1].

face[2] = [-100 , 0, -200 , 1].

We get the canonical Space coordinate:

canSpace[0] = [-92 , 121 , 183 , 201]

canSpace[1] = [-166 , 0 , 161 , 179]

canSpace[2] = [895 , 0 ,-114 ,-93]

After the W divide:

wdivide[0] = [-0.459 , 0.600 , 0.910 , 1.000].

wdivide[1] = [-0.928 , 0.000 , 0.898 , 1.000].

wdivide[2] = [-9.611 ,-0.000 , 1.226 ,1.000].

We move to unit cube (+1 and * 0.5 )

p1 unitCube[ 0.27 , 0.80 , 0.910133 , 1.00]

p2 unitCube[ 0.04 , 0.50 , 0.897879 , 1.00]

p3 unitCube[ -4.31 , 0.50 , 1.225966 ,1.00]

And finally the viewPort transform ( my iPhone screen is 320*480)

p1 screen[ x=86.52 , y=384.01, z=0.910133 ].

p2 screen[ x=11.48 , y=240.00, z=0.897879 ].

p3 screen[ x=-1377.83 ,y=240.00 , z=1.225966].

This triangle is partially on screen, 2 vertices are on screen with the third way off. I believe the hardware is generating two new vertices ( according to "real time rendering" book, this is done in unit cube space).

But I have no idea how it is done. Aynbody can enlight me on this one ?

I've tried to Google this but I cannot figure out how it's done.

Let's take a real example and try to do everything by hand:

Here is a triangle on screen ( I know it looks like a quad but it looks like this because of the perspective and the third point is far on the side:

http://fabiensanglard.net/doomIphone/clipping.jpg

With the following matrix PVM:

Matrix pvm.

-----------------

-2.4651 0.0000 -2.6528 117.7031

0.0000 2.4142 0.0000 0.0000

-0.7399 0.0000 0.6876 -50.6078

-0.7325 0.0000 0.6807 -30.2037

-----------------

And the following triangle:

face[0] = [-130 , 50 , 200 , 1].

face[1] = [-100 , 0 , 200 , 1].

face[2] = [-100 , 0, -200 , 1].

We get the canonical Space coordinate:

canSpace[0] = [-92 , 121 , 183 , 201]

canSpace[1] = [-166 , 0 , 161 , 179]

canSpace[2] = [895 , 0 ,-114 ,-93]

After the W divide:

wdivide[0] = [-0.459 , 0.600 , 0.910 , 1.000].

wdivide[1] = [-0.928 , 0.000 , 0.898 , 1.000].

wdivide[2] = [-9.611 ,-0.000 , 1.226 ,1.000].

We move to unit cube (+1 and * 0.5 )

p1 unitCube[ 0.27 , 0.80 , 0.910133 , 1.00]

p2 unitCube[ 0.04 , 0.50 , 0.897879 , 1.00]

p3 unitCube[ -4.31 , 0.50 , 1.225966 ,1.00]

And finally the viewPort transform ( my iPhone screen is 320*480)

p1 screen[ x=86.52 , y=384.01, z=0.910133 ].

p2 screen[ x=11.48 , y=240.00, z=0.897879 ].

p3 screen[ x=-1377.83 ,y=240.00 , z=1.225966].

This triangle is partially on screen, 2 vertices are on screen with the third way off. I believe the hardware is generating two new vertices ( according to "real time rendering" book, this is done in unit cube space).

But I have no idea how it is done. Aynbody can enlight me on this one ?