Jump to content
  • Advertisement
Sign in to follow this  
streamer

simple line routine

This topic is 4872 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all. Can somebody help me? I need an c++ routine calculates x, y coordinates for line (from x1,y1 to x2,y2). This is simple question, but I don't have solution to this problem. I saw a 1000 examples on net, but all examples was too large and too complicated. I just need an small and fast routine. Pliz help :)

Share this post


Link to post
Share on other sites
Advertisement
Well, assuming that you have a variable, t, that tells you which point on the line, it is simple:
    x = x1 + t * ( x2 - x1 );
y = y1 + t * ( y2 - y1 );

Share this post


Link to post
Share on other sites
Yeah I tried to do it myself, but don't know how. I read a tons of artcles as I said, but everything is too complicated (or I just didn't understan it).
It is posible that's because I am programmer not matematician :).
Anyway thanks for your replays, sure I try to implement something on formulas posted above.

Share this post


Link to post
Share on other sites
The fastest algorithm to draw a line is Bresenham's
Search for Bresenham on google. It uses only integers numbers.

It is infinitly more quick that computing the slope. It is also used in 3D cards accelerators to compute fast the triangles bounds rasterized.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!