void LineDDA(void) { double dx=(X2-X1); double dy=(Y2-Y1); float xInc,yInc,x=X1,y=Y1; /* Find out whether to increment x or y */ int dStart = 2*dy - dx; int dE = 2*dy; int dNE = 2*(dy - dx); /* Clears buffers to preset values */ glClear(GL_COLOR_BUFFER_BIT); /* Plot the points */ glBegin(GL_POINTS); /* Plot the first point */ glVertex2d(x,y); int d; /* For every step, find an intermediate vertex */ d = dStart; while(x<X2 && y<Y2) { if(d<0){ d = d + dE; }else{ d = d + dNE; y = y + 1; } x = x + 1; printf("%0.6lf %0.6lf\n",floor(x), floor(y)); glVertex2d(round_value(x), round_value(y)); } glEnd(); glFlush(); }
Vec2<Type> &Vec2<Type>::rotate(const Vec2<Type>& hotspot, const Angle &angle) { // Move the hotspot to 0,0 Vec2<Type> r(x - hotspot.x, y - hotspot.y); float radians = angle.to_radians(); float sin_angle = sinf(radians); float cos_angle = cosf(radians); float dest_x = (float) r.x * cos_angle - (float) r.y * sin_angle; float dest_y = (float) r.x * sin_angle + (float) r.y * cos_angle; x = round_value(dest_x + hotspot.x); y = round_value(dest_y + hotspot.y); return *this; }