class C_Color { public: float r; float g; float b; C_Color() {} C_Color(float r0,float g0,float b0) {r=r0;g=g0;b=b0;} ~C_Color() {} void set(void) {glColor3f(r, g, b);} }; class C_Vertex { public: float x; float y; float z; float t; C_Vertex() {t=1.;} C_Vertex(float x0,float y0,float z0) {x=x0;y=y0;z=z0;t=1.;} ~C_Vertex() {} void resize(); void homogenize(); }; class C_Point : public C_Vertex { public: C_Color color; C_Point(float x0,float y0,float z0,C_Color col) {x=x0;y=y0;z=z0;t=1.;color=col;} ~C_Point() {} void draw(); }; typedef C_Vertex C_Vector; class C_Line { public: C_Vertex p,q; C_Color color; C_Line() {} C_Line(C_Vertex p0,C_Vertex q0,C_Color col) {p=p0;q=q0;color=col;} C_Line(float x1,float y1,float z1,float x2,float y2,float z2,C_Color col); ~C_Line() {} void draw(); void homogenize(); }; class C_Polyline { public: C_Vertex *p; int numberPoints; C_Color color; C_Polyline() {numberPoints=0;} C_Polyline(int numberPoints0); C_Polyline(C_Vertex *p0,int numberPoints0); C_Polyline(C_Vertex *p0,int numberPoints0,C_Color color0); C_Polyline(const C_Polyline &pl); ~C_Polyline(); void setColor(C_Color color0) {color=color0;} C_Polyline operator =(const C_Polyline &pl); void draw(); void homogenize(); void resize(); }; class C_Polygon { public: C_Vertex *p; int numberPoints; C_Color color; C_Color *colorarray; C_Polygon() {numberPoints=0;colorarray=NULL;} C_Polygon(int numberPoints0,int enableColorArray); C_Polygon(C_Vertex *p0,int numberPoints0); C_Polygon(C_Vertex *p0,int numberPoints0,C_Color color0); C_Polygon(C_Vertex *p0,C_Color *colorarray0,int numberPoints0); C_Polygon(const C_Polygon &pg); ~C_Polygon(); C_Polygon operator =(const C_Polygon &pg); void setColor(C_Color color0) {color=color0;} void draw(); void fill(); void gradate(); void homogenize(); }; class C_Matrix { public: float m[4][4]; C_Matrix(); C_Matrix(const float m0[4][4]); C_Matrix(const C_Matrix &mx); ~C_Matrix() {} C_Matrix operator =(const C_Matrix &mx); void createIdentity(); void setTranslation(C_Vector v); void setTranslation(float dx,float dy,float dz); void setRotationX(float theta); void setRotationY(float theta); void setRotationZ(float theta); void setScale(float fx,float fy,float fz); void setPerspective(float zeye); }; class C_Face { //立体を構成する面 public: int numberVertices; //面を構成する頂点の数 int *VertexNumber; //面を構成する頂点の頂点番号 C_Face() {numberVertices=0;} C_Face(const C_Face &fc); ~C_Face(); void createFace(int VertexNumber0[],int numberV); C_Face operator =(const C_Face &fc); }; typedef struct { float kspe; // specular reflection coefficient float kdif; // diffuse reflection coefficient float kamb; // ambient light coefficient } opticalAttribute_t; class C_Polyhedron { //多面体 public: int numberVertices; //多面体を構成する頂点の数 C_Vertex *Vertex; //多面体を構成する頂点の座標 int numberFaces; //多面体を構成する面の数 C_Face *Face; //多面体を構成する面の定義 opticalAttribute_t attr; //光学的性質 C_Color color; //面の色,又は線の色 C_Polyhedron() {numberVertices=0;numberFaces=0;} C_Polyhedron(const C_Polyhedron &ph); ~C_Polyhedron(); void createPolyhedron(C_Vertex Vertex0[],int numberV,C_Face Face0[],int numberF,C_Color color0,opticalAttribute_t &attr0); C_Polyhedron operator =(const C_Polyhedron &ph); void homogenize(); }; class C_Smoothpolyhedron : public C_Polyhedron { //擬似多面体(曲面の多面体近似) public: C_Vector *NormalVector; //各擬似頂点位置の法線ベクトル C_Smoothpolyhedron() {numberVertices=0;numberFaces=0;} C_Smoothpolyhedron(const C_Smoothpolyhedron &ph); ~C_Smoothpolyhedron(); void createSmoothPolyhedron(C_Vertex Vertex0[],C_Vector NormalVector0[],int numberV,C_Face Face0[],int numberF,C_Color color0,opticalAttribute_t &attr0); C_Smoothpolyhedron operator =(const C_Smoothpolyhedron &ph); void resize(); }; class C_Scene { //画面への表示はここから float theta; //tilting angle about y axis float phi; //tilting angle about x axis float zeye; //perspective eye position C_Vector LightDirection; C_Vector ViewDirection; C_Matrix Tilting; C_Matrix Perspective; C_Matrix Transformation; C_Matrix TransformationN; C_Matrix Stack[32]; C_Matrix StackN[32]; int stackpointer; public: C_Scene(); C_Scene(float theta0,float phi0,float zeye0,C_Vector light); ~C_Scene() {} void initializeTMatrix(); void setTranslation(C_Vector v); void setTranslation(float dx,float dy,float dz); void setRotationX(float theta); void setRotationY(float theta); void setRotationZ(float theta); void setScale(float fx,float fy,float fz); void pushMatrix(); void popMatrix(); void drawAxes(); void drawPolyhedronWire(C_Polyhedron &ph); void drawPolyhedronSurface(C_Polyhedron &ph); void drawPolyhedronSurfaceZSort(C_Polyhedron &ph); C_Color PhongModel(C_Vector Normal,C_Color col,opticalAttribute_t &attr); void drawPolyhedronSmoothSurface(C_Smoothpolyhedron &ph); void drawPolyhedronSmoothSurfaceZSort(C_Smoothpolyhedron &ph); }; C_Matrix operator * (const C_Matrix &a, const C_Matrix &b); C_Vertex operator * (const C_Matrix &a, const C_Vertex &b); C_Line operator * (const C_Matrix &a, const C_Line &b); C_Polyline operator * (const C_Matrix &a, const C_Polyline &b); C_Polygon operator * (const C_Matrix &a, const C_Polygon &b); C_Polyhedron operator * (const C_Matrix &a, const C_Polyhedron &b); C_Color operator + (const C_Color &a, const C_Color &b); C_Color operator * (const float &a, const C_Color &b); C_Color operator * (const C_Color &a, const float &b); float operator * (const C_Vector &a, const C_Vector &b); //内積 C_Vector operator * (const float &a, const C_Vector &b); C_Vector operator * (const C_Vector &a, const float &b); C_Vector operator ^ (const C_Vector &a, const C_Vector &b); //外積 C_Vector operator + (const C_Vector &a, const C_Vector &b); //和 C_Vector operator - (const C_Vector &a, const C_Vector &b); //差 C_Vector operator - (const C_Vector &a); //単項マイナス演算子