#include "metawndow.h" /*---------------------------------------------------------------------\ ASPECT.C Shows what to do when you are using a monitor that doesn't have square pixels and you need points at a certain angle. \---------------------------------------------------------------------*/ /*---------------------------------------------------------------------\ MapAspectPt takes oval, the angle, and gives you a matching newPoint. Note that I cheat and assume that you're in virtual coordinates. If you aren't, take SetLocal() and SetVirtual () out. \---------------------------------------------------------------------*/ void MapAspectPt (rect *oval, int angle, point *newPoint) { rect Square = { -2048, -2048, 2048, 2048 }; /* I use 2048 because the CPU can divide by 2048 by simply shifting down the bits 11 times. */ point temp; point Center; int radiusX; int radiusY; radiusX = (oval->Xmax - oval->Xmin) / 2 ; radiusY = (oval->Ymax - oval->Ymin) / 2 ; Center.X = oval->Xmin + radiusX; Center.Y = oval->Ymin + radiusY; SetLocal(); /* OvalPt give us X and Y values which we use to determine the ratio of X to Y, which is constant for any triangle of the same angle. */ OvalPt (&Square, angle, &temp); /* Several things happen here. The multiplication and division (right shift) give us the Delta X and Y. By adding them to the center X and Y we get the actual location. */ newPoint->X = Center.X + (int) (((long)radiusX * (long)temp.X) >> 11); newPoint->Y = Center.Y + (int) (((long)radiusY * (long)temp.Y) >> 11); SetVirtual (); } extern unsigned _stklen = 14336U; void main () { rect vRect; rect oval; int x; point thePoint; InitGraphics(CGA640x200); SetDisplay (GrafPg0); ScreenRect (&vRect); EraseRect (&vRect); SetRect (&vRect, 0, 0, 640, 480); /* 640 x 480 gives you square pixels given the aspect ratio of the computer monitor. This way you can draw an oval with X = Y and you'll get something that more or less looks like a circle. */ VirtualRect (&vRect); SetRect (&oval, 0, 0, 400, 400); FrameOval (&oval); for (x= 0; x < 3600; x += 300) { MoveTo (200, 200); MapAspectPt (&oval, x, &thePoint); LineTo (thePoint.X, thePoint.Y); }; getch(); SetDisplay(TextPg0); StopGraphics(); }