qbasicking
Programmer
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.
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.