Drawing a 2D line
Hi, I have a little problem with drawing 2D lines:
I know how to do it with bresenham, but the problem is if one or two of the endpoints of the line are outside the screen, what''s the best way to find the points where the line enters the screen, IF it enters it?
Thanks.
When I search for that all I find are assignements for students, which obviously don''t contain the answer
I found something!
Thanks a lot, and I learned about the existance of new algorithms now too
I used one with "cohen sutherland" which appearantly isn't the fastest one, but I changed all the floats to ints and it still works perfectly and fast enough for me.
[edited by - Boops on September 3, 2003 11:35:49 AM]
Thanks a lot, and I learned about the existance of new algorithms now too
I used one with "cohen sutherland" which appearantly isn't the fastest one, but I changed all the floats to ints and it still works perfectly and fast enough for me.
[edited by - Boops on September 3, 2003 11:35:49 AM]
Hey, sorry for yet another post in here....
But I needed this 2D line drawing to draw 3D lines (software), and it works nicely except for one thing:
What do I have to do if one endpoint of the line is in front of the camera, while the other endpoint is behind the camera? Things seem to screw up :s
But I needed this 2D line drawing to draw 3D lines (software), and it works nicely except for one thing:
What do I have to do if one endpoint of the line is in front of the camera, while the other endpoint is behind the camera? Things seem to screw up :s
You must clip the line to the near plane so that it both begins and ends in front of the camera. The 1/z you probably do to convert from 3d to screen coordinates is only valid when z>0 (and will crash if z==0).
For example, let''s assume point A is behind the camera (Az<0) and B is in front. Camera''s z coordinate is defined as zero, and near plane distance (Nz) is a positive non-zero. You need to create a new point A'' so that A''z == neardist.
A''x = Ax + (Bx-Ax) * (Nz-Az) / (Bz-Az)
A''y = Ay + (By-Ay) * (Nz-Az) / (Bz-Az)
A''z = Nz
For example, let''s assume point A is behind the camera (Az<0) and B is in front. Camera''s z coordinate is defined as zero, and near plane distance (Nz) is a positive non-zero. You need to create a new point A'' so that A''z == neardist.
A''x = Ax + (Bx-Ax) * (Nz-Az) / (Bz-Az)
A''y = Ay + (By-Ay) * (Nz-Az) / (Bz-Az)
A''z = Nz
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement