////////////// OpenGL drawtools for 2D Functions ver 1 ///////////////// #include #include #include "drawtools2D.h" matrix2D_t createIdentity(void) { matrix2D_t u; int i,j; for (i=0;i<3;i++) { for(j=0;j<3;j++) u.m[i][j]=0.; u.m[i][i]=1.; } return u; } matrix2D_t multiply(matrix2D_t a,matrix2D_t b) { matrix2D_t c;//c=a*b int i,j,k; for (i=0;i<3;i++) for (j=0;j<3;j++) { c.m[i][j]=0; for (k=0;k<3;k++) c.m[i][j]+=a.m[i][k]*b.m[k][j]; } return c; } vector2D_t multiply(matrix2D_t a, vector2D_t b) { vector2D_t c;//c=a*b int i,j; for (i=0;i<3;i++) { c.v[i]=0; for (j=0;j<3;j++) c.v[i]+=a.m[i][j]*b.v[j]; } return c; } matrix2D_t operator * (matrix2D_t a, matrix2D_t b) { matrix2D_t c;//c=a*b int i,j,k; for (i=0;i<3;i++) for (j=0;j<3;j++) { c.m[i][j]=0; for (k=0;k<3;k++) c.m[i][j]+=a.m[i][k]*b.m[k][j]; } return c; } vector2D_t operator * (matrix2D_t a, vector2D_t b) { vector2D_t c;//c=a*b int i,j; for (i=0;i<3;i++) { c.v[i]=0; for (j=0;j<3;j++) c.v[i]+=a.m[i][j]*b.v[j]; } return c; } matrix2D_t translationMTX(float dx,float dy) { matrix2D_t trans=createIdentity(); trans.m[0][2]=dx; trans.m[1][2]=dy; return trans; } matrix2D_t rotationMTX(float theta) { matrix2D_t rotate=createIdentity(); float cs=cos(theta); float sn=sin(theta); rotate.m[0][0]=cs; rotate.m[0][1]=-sn; rotate.m[1][0]=sn; rotate.m[1][1]=cs; return rotate; } matrix2D_t scalingMTX(float factorx,float factory) { matrix2D_t scale=createIdentity(); scale.m[0][0]=factorx; scale.m[1][1]=factory; return scale; } vector2D_t Point2Vector(point2D_t pnt) { vector2D_t vec; vec.v[0]=pnt.x; vec.v[1]=pnt.y; vec.v[2]=1.; return vec; } void setColor(color_t col) { glColor3f(col.r, col.g, col.b); } void drawDot(point2D_t pt) { glBegin(GL_POINTS); glVertex2f(pt.x, pt.y); glEnd(); } void drawDot(vector2D_t vc) { glBegin(GL_POINTS); glVertex2f(vc.v[0], vc.v[1]); glEnd(); } void drawLine(point2D_t p1,point2D_t p2) { glBegin(GL_LINES); glVertex2f(p1.x, p1.y); glVertex2f(p2.x, p2.y); glEnd(); } void drawLine(vector2D_t v1,vector2D_t v2) { glBegin(GL_LINES); glVertex2f(v1.v[0], v1.v[1]); glVertex2f(v2.v[0], v2.v[1]); glEnd(); } void drawLine(float x1,float y1,float x2,float y2) { glBegin(GL_LINES); glVertex2f(x1, y1); glVertex2f(x2, y2); glEnd(); } //n: number of points void drawPolyline(point2D_t pnt[],int n) { int i; glBegin(GL_LINE_STRIP); for (i=0;i