CMPS-3480 Computer Graphics
Lab-2
Elements of the lab:
We will do some coding together. Do your work in your Odin 3480/2 folder. $ cp /home/fac/gordon/p/3480/code/2/* . We will add the following features together... 1. connecting points with lines 2. adding more points (and lines) 3. add the Bresenham's algorithm to draw lines 4. adding anchors to see points better 5. grab a point with the mouse and move it rubber-band lines Our program will look something like thisWith rigid lines...
![]()
Copy and paste the following function into your program. void myBresenhamLine(int x0, int y0, int x1, int y1) { //Bresenham line algorithm, integers only. int steep = (abs(y1 - y0) > abs(x1 - x0)); if (steep) { SWAP(x0, y0); SWAP(x1, y1); } if (x0 > x1) { SWAP(x0, x1); SWAP(y0, y1); } int ystep = (y1 > y0) ? 1 : -1; int yDiff = abs(y1 - y0); int xDiff = x1 - x0; int err = xDiff; int x, y = y0; for (x=x0; x<=x1; x++) { if (steep) x11.drawPoint(y, x); else x11.drawPoint(x, y); err -= yDiff; if (err <= 0) { y += ystep; err += xDiff; } } } On key-press 'L', make your program switch line drawing type between Bresenham and the X11 line function. Closest point to mouse 1. Whenever the mouse is moved, look for the closest point to the mouse cursor. 2. If the distance is a short distance, draw a red box around the close point. Remember, all drawing is done from render(). Set a flag to draw the red box. g.redbox = -1 No points have a red box. g.redbox = 0 g.pt[0] needs a red box around it. g.redbox = 3 g.pt[3] needs a red box around it.