Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

clipping algorithm

Status
Not open for further replies.

qbasicking

Programmer
Aug 19, 2001
628
US
IF x1% < 0 THEN
dids% = x2% - x1%
fraction = 1 - (x2% / dids%)
dis1 = ((dis2 - dis1) / fraction) + dis1
diff% = dids% * fraction
x1% = 0
END IF

I am having some problem figuring out the distance at which a plane is clipped. This is for BSP rendering. I can figure it out using complicated trig, but it is too complicated and slow. What the code above is supposed to do is take a plane from x1% to x2% and clip it on the left edge of the screen.

I took the difference in the x values, to figure out which fraction of the plane is shown. Then use that fraction and the distances of the two edges to figure out the distance to the clip point.

Here is a graphical explaination

x1% screen edge x2%

| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |

say that x1% is -40 and x2% is 50. My algorithm takes that and knows that the whoe=le plain is 90 pixils and 4/5th of it is displayed. Then it takes the distance difference: Say x1% is 5 spaces from the player and x2% is 6. It takes one (the differnce) and dividies by 4/5 and then adds 5 (the starting value). Why is this not working, I don't want to have to resort to trig.
 
are you sure it should be 4/5, not 4/9?
Then dividing by fraction makes things bigger - may be you should multiply instead?
*saying that I still have no idea about things you are talking about ;)*
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top