×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# clipping algorithm

 Forum Search FAQs Links MVPs

## clipping algorithm

(OP)
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.

### RE: clipping algorithm

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 ;)*

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

#### Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!