#include "svt.h" #include "draw.h" //Vector graphics drawing demo #define ARROWSTEPS 30 #define SWEEPSTEPS 20 int arrowStepCount; int sweepStepCount; iPoint arrow[4]; //Polygon of an arrowhead pointer float arrowAngle; //Direction to rotate arrow float sweepAngle; //Direction of radar sweep arm iPoint sweepArm; //Point at tip of radar sweep arm int arrowX, arrowY; //Centre of arrow int radarX, radarY; //Centre of radar sweep arm //Resets polygon for arrow to avoid cumulative rounding errors void ResetArrow() { //define a triangle polygon arrow[0].x=80; arrow[0].y=20; arrow[1].x=50; arrow[1].y=90; arrow[2].x=80; arrow[2].y=70; arrow[3].x=110; arrow[3].y=90; //obviously I could define it small but I //wanted to test these routines! ScalePoly(4, arrow, 80, 60, 0.3); MovePoly(4, arrow, -60, -40); } //Draws arrow at new angle void DrawArrow(float radAngle) { //Erase old copy DrawPoly(4, arrow, BLACK); //Recalculate new rotated angle ResetArrow(); RotatePoly(4, arrow, arrowX, arrowY, radAngle); //Draw new arrow DrawPoly(4, arrow, YELLOW); } //Draws radar arm at new angle void DrawRadarArm(float radAngle) { //Erase old line DrawLine(radarX, radarY, sweepArm.x, sweepArm.y, BLACK); //define 'north' tip position of sweep arm sweepArm.x=radarX; sweepArm.y=radarY-16; //Rotate point about centre RotatePoint(&sweepArm, radarX, radarY, radAngle); //Draw new arm DrawLine(radarX,radarY, sweepArm.x, sweepArm.y, GREEN); } //Backdrop headup display graphics - instrument panels & crosshairs void DrawBackdrop() { //Seems a bit brutal to have to close graphics but it's //the only way to clear the screen that'll let us draw //on it properly again - ClearScreen or ClearRectangle screw up CloseGraphics(); OpenGraphics(); //Side panel SetLineWidth(5); int i, j; for (i=0; i<8; i++) for (j=0; j<8; j++) { Plot(i*5,j*5,BLACK); Plot(120+i*5,j*5,BLACK); } SetLineWidth(1); //Some concentric circles DrawCircle(arrowX, arrowY, 19, RED); DrawCircle(radarX, radarY, 19, GREEN); //Crosshairs DrawLine(80, 40, 80, 80, WHITE); DrawLine(60, 60, 100, 60, WHITE); DrawCircle(80, 60, 10, WHITE); } //Setup void Start() { OpenGraphics(); SetLineWidth(1); //needed otherwise we draw huge thick points! arrowStepCount=0; sweepStepCount=0; arrowAngle = 2 * PI / ARROWSTEPS; sweepAngle = 2 * PI / SWEEPSTEPS; arrowX=20; arrowY=20; radarX=140; radarY=20; sweepArm.x=140; sweepArm.y=20; ResetArrow(); DrawBackdrop(); } //Main program loop - Run gets called until it returns false bool Run() { //Just wait around for the home key to be pressed if (GetRemoteKeyStatus(KEY_HOME)) return false; else { //reset angle counts if (arrowStepCount == ARROWSTEPS) arrowStepCount=0; if (sweepStepCount == SWEEPSTEPS) sweepStepCount=0; DrawArrow(arrowAngle * arrowStepCount++); DrawRadarArm(sweepAngle * sweepStepCount++); Show(); Sleep(250); return true; } } //Cleanup void End() { CloseGraphics(); }