////////////// OpenGL drawtools for 3D Functions ver 1 ///////////////// typedef struct { float x; float y; float z; } point3D_t; typedef struct { float v[4]; } vector3D_t; typedef struct { float m[4][4]; } matrix3D_t; typedef struct { float r; float g; float b; } color_t; matrix3D_t createIdentity(void); matrix3D_t multiply(matrix3D_t a,matrix3D_t b); matrix3D_t operator * (matrix3D_t a, matrix3D_t b); vector3D_t multiply(matrix3D_t a, vector3D_t b); vector3D_t operator * (matrix3D_t a, vector3D_t b); matrix3D_t translationMTX(float dx,float dy,float dz); matrix3D_t rotationXMTX(float theta); matrix3D_t rotationYMTX(float theta); matrix3D_t rotationZMTX(float theta); matrix3D_t scalingMTX(float factorx,float factory,float factorz); matrix3D_t perspectiveMTX(float eyelength); vector3D_t Point2Vector(point3D_t pnt); point3D_t Vector2Point(vector3D_t vec); vector3D_t homogenizeVector(vector3D_t vec); vector3D_t unitVector(vector3D_t vec); // inner product (dot product) of homogeneous vector float operator * (vector3D_t a, vector3D_t b); // outer product (cross product ) of homogeneous vector // i j k // a0 a1 a2 // b0 b1 b2 vector3D_t operator ^ (vector3D_t a, vector3D_t b); vector3D_t operator - (vector3D_t v1,vector3D_t v0); vector3D_t operator - (vector3D_t v); vector3D_t operator * (float r, vector3D_t b); vector3D_t operator * (vector3D_t b, float r); float funcPositive(float x); float power(float x,float y); color_t operator + (color_t c1, color_t c2); color_t operator * (float r, color_t c); color_t operator * (color_t c, float r); //PhongModel color calculation // LightVector, NormalVector, ViewVector, ColorofObject color_t PhongModel(vector3D_t Light,vector3D_t Normal,vector3D_t View,color_t col); void setColor(color_t col); void drawDot(point3D_t pt); void drawDot(vector3D_t vc); void drawLine(point3D_t p1,point3D_t p2); void drawLine(vector3D_t v1,vector3D_t v2); void drawLine(float x1,float y1,float x2,float y2); //n: number of points void drawPolyline(point3D_t pnt[],int n); void drawPolyline(vector3D_t vct[],int n); //n: number of vertices void drawPolygon(point3D_t pnt[],int n); void drawPolygon(vector3D_t vct[],int n); // The function fillPolygon can fills only convex polygons //n: number of vertices void fillPolygon(point3D_t pnt[],int n,color_t color); void fillPolygon(vector3D_t vct[],int n,color_t color); // The function gradatePolygon can fills only convex polygons // The vertices will be painted with corresponding given colors. // The points inside the polygon will be painted with the mixed color. //n: number of vertices void gradatePolygon(point3D_t pnt[],color_t col[],int num); void gradatePolygon(vector3D_t vct[],color_t col[],int num);