Archived

This topic is now archived and is closed to further replies.

Draw a line from point a to point b

This topic is 5672 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

How would I tell OpenGL to start draw at point a(x, y, z) and end the line at point b(x, y, z). So for example the line would start at (1, 0, 0) and end at (0, 2, -3) thx nuke

Share this post


Link to post
Share on other sites
yep... and you can change it's thickness by going:
glLineWidth(width); //1.0f is defalt
-PmanC
lol... i've been programming too much... i just commented instead of writing a sentence.

[edited by - PmanC on June 4, 2002 10:23:24 PM]

Share this post


Link to post
Share on other sites
and if you didnt know you can also use simple bresenham to draw lines (no 3d you requested sorry this time pal)


  

dx=x1-x0;
dy=y1-y0;

if (dx>0) { sx=1; }
else
if (dx<0) { sx=-1; dx=-dx; }
else {
sx =0;
}

if (dy>0) { sy=1; }
else
if (dy<0) { sy=-1; dy=-dy; }
else {
sy =0;
}

int ax =2*dx;
int ay =2*dy;

if (dy<=dx) {

for (int decy=ay-dx; /**/;x +=sx, decy+=ay)
{
draw pixel (x, y)

/* take bresenham step */
if (x==x1) {
break;
}
if (decy>=0) {

decy -=ax;
y +=sy;
}
}

}
else {

for (int decx=ax-dy; /**/; y+=sy, decx +=ax)
{
draw pixel (x, y)


/* take bresenham step */

if (y==y1) {
break;
}
if (decx>=0) {

decx -=ay;
x +=sx;
}
}
}



Share this post


Link to post
Share on other sites