/* #include #include #include #include #include "mpe_graphics.h" #include "mpe.h" */ int XDIM = 800; int YDIM = 600; int ZDIM = 400; #define PI 3.1415927 // zoom ratio - right now, not tied to ZDIM, but probably should! double ZR = 0.25; double tiltR = PI/2; // tilt angle in radians // shortening ratio (scales z axis): usually should set to one: double SR = 1.0; int xshift, yshift; // these are static shift values for entire window //MPE_XGraph graph; double toDegrees (double radians) { return radians * 180/PI; } double toRadians (double degrees) { return degrees * PI/180; } // critical function to convert 3d coordinate to 2d coordinate // returns 0 on success int point(int x, int y, int z, int *x2, int *y2) { double s; s = (1-((1-ZR)*z/((double)ZDIM))); *x2 = (int) ((s*x) + (z * cos(tiltR) * SR)); *y2 = (int) ((s*y) + (z * sin(tiltR) * SR)); *y2 += (int)abs(yshift); if(xshift<0) *x2 -= (int)xshift; return 0; } void drawbox(MPE_XGraph graph, int x0, int y0, int z0, int xd, int yd, int zd, MPE_Color mc) { int a, b, u, v, x, y, p, q; point(x0,y0,z0,&a,&b); point(x0+xd,y0,z0,&x,&y); point(x0,y0+yd,z0,&u,&v); point(x0+xd,y0+yd,z0,&p,&q); // front MPE_Draw_line(graph,a,b,x,y,mc); MPE_Draw_line(graph,a,b,u,v,mc); MPE_Draw_line(graph,u,v,p,q,mc); MPE_Draw_line(graph,p,q,x,y,mc); // sides point(x0,y0,z0+zd,&x,&y); point(x0,y0+yd,z0+zd,&p,&q); MPE_Draw_line(graph,a,b,x,y,mc); MPE_Draw_line(graph,u,v,p,q,mc); MPE_Draw_line(graph,x,y,p,q,mc); point(x0+xd,y0,z0+zd,&a,&b); point(x0+xd,y0+yd,z0+zd,&u,&v); MPE_Draw_line(graph,x,y,a,b,mc); MPE_Draw_line(graph,p,q,u,v,mc); MPE_Draw_line(graph,a,b,u,v,mc); point(x0+xd,y0,z0,&x,&y); point(x0+xd,y0+yd,z0,&p,&q); MPE_Draw_line(graph,a,b,x,y,mc); MPE_Draw_line(graph,u,v,p,q,mc); } void drawline(MPE_XGraph graph, int x0, int y0, int z0, int x1, int y1, int z1, MPE_Color mc) { int a, b, x, y; point(x0,y0,z0,&a,&b); point(x1,y1,z1,&x,&y); MPE_Draw_line(graph,a,b,x,y,mc); } // fill circle with scaled radius void fillcircle(MPE_XGraph graph, int x0, int y0, int z0, double r, MPE_Color mc) { int x, y; double rs; point(x0,y0,z0,&x,&y); rs = (1-((1-ZR)*((double)z0)/ZDIM)) * r; // printf("%d, %f and %f\n",z0,rs,r); if (rs<1) rs = 1; MPE_Fill_circle(graph,x,y,(int)rs,mc); // MPE_Draw_circle(graph,x,y,(int)rs-2,MPE_BLACK); // 3d effect? } // drawcircle with scaled radius void drawcircle(MPE_XGraph graph, int x0, int y0, int z0, double r, MPE_Color mc) { int x, y; double rs; point(x0,y0,z0,&x,&y); rs = (1-((1-ZR)*((double)z0)/ZDIM)) * r; // printf("%d, %f and %f\n",z0,rs,r); if (rs<1) rs = 1; MPE_Draw_circle(graph,x,y,(int)rs,mc); } double dscale(double x, double z0) { return (1-((1-ZR)*((double)z0)/ZDIM)) * x; }