"glbasicshape"は基本図形クラスを定義している。現在のところ以下のものを含んでいる。
- 直線
- 三角形
- 四角形
- 円(N角形)
基本的に各図形はGLObjectクラスを継承している。
- #ifndef __GLBASICSHAPE_HPP__
- #define __GLBASICSHAPE_HPP__
- #include "gl.hpp"
- namespace DECS{
- namespace GL{
- class GLLine : GLObject{
- private:
- GLPosition beginPoint_;
- GLPosition endPoint_;
- GLLine(){};
- public:
- GLLine(GLPosition beginPoint, GLPosition endPoint):
- GLObject(GL_LINES), beginPoint_(beginPoint), endPoint_(endPoint){};
- GLLine(GLPosition beginPoint, GLPosition endPoint, GLColor color):
- GLObject(GL_LINES, color), beginPoint_(beginPoint), endPoint_(endPoint){};
- GLLine(int mode, GLPosition beginPoint, GLPosition endPoint, GLColor color):
- GLObject(mode, color), beginPoint_(beginPoint), endPoint_(endPoint){};
- ~GLLine(){};
- void setPoint(GLPosition beginPoint, GLPosition endPosition);
- virtual void setColor(GLColor color);
- virtual void draw();
- };
- class GLTriangle :GLObject{
- private:
- GLPosition point1_;
- GLPosition point2_;
- GLPosition point3_;
- GLTriangle(){};
- public:
- GLTriangle(GLPosition point1, GLPosition point2, GLPosition point3):
- GLObject(GL_LINE_LOOP),
- point1_(point1), point2_(point2), point3_(point3){};
- GLTriangle(GLPosition point1, GLPosition point2, GLPosition point3,
- GLColor color):
- GLObject(GL_LINE_LOOP, color),
- point1_(point1), point2_(point2), point3_(point3){};
- GLTriangle(int mode,
- GLPosition point1, GLPosition point2, GLPosition point3):
- GLObject(mode),
- point1_(point1), point2_(point2), point3_(point3){};
- GLTriangle(int mode,
- GLPosition point1, GLPosition point2, GLPosition point3,
- GLColor color):
- GLObject(mode, color),
- point1_(point1), point2_(point2), point3_(point3){};
- ~GLTriangle(){};
- void setPoint(GLPosition point1, GLPosition point2, GLPosition point3);
- virtual void setColor(GLColor color);
- virtual void draw();
- };
- class GLSquare : GLObject{
- private:
- GLPosition point1_;
- GLPosition point2_;
- GLPosition point3_;
- GLPosition point4_;
- GLSquare(){};
- public:
- GLSquare(GLPosition point1, GLPosition point2,
- GLPosition point3, GLPosition point4):
- GLObject(GL_LINE_LOOP),
- point1_(point1), point2_(point2),
- point3_(point3), point4_(point4){};
- GLSquare(GLPosition point1, GLPosition point2,
- GLPosition point3, GLPosition point4,
- GLColor color):
- GLObject(GL_LINE_LOOP, color),
- point1_(point1), point2_(point2),
- point3_(point3), point4_(point4){};
- GLSquare(int mode,
- GLPosition point1, GLPosition point2,
- GLPosition point3, GLPosition point4):
- GLObject(mode),
- point1_(point1), point2_(point2),
- point3_(point3), point4_(point4){};
- GLSquare(int mode,
- GLPosition point1, GLPosition point2,
- GLPosition point3, GLPosition point4,
- GLColor color):
- GLObject(mode, color),
- point1_(point1), point2_(point2),
- point3_(point3), point4_(point4){};
- ~GLSquare(){};
- void setPoint(GLPosition point1, GLPosition point2,
- GLPosition point3, GLPosition point4);
- virtual void setColor(GLColor color);
- virtual void draw();
- };
- class GLCircle : GLObject{
- private:
- GLPosition center_;
- GLdouble radius_;
- int nPoint_;
- GLCircle(){};
- public:
- GLCircle(GLdouble radius):
- GLObject(GL_LINE_LOOP),
- center_(DGL_ORIGIN), radius_(radius), nPoint_(100){};
- GLCircle(GLPosition center, GLdouble radius):
- GLObject(GL_LINE_LOOP),
- center_(center), radius_(radius), nPoint_(100){};
- GLCircle(int mode, GLPosition center, GLdouble radius):
- GLObject(mode),
- center_(center), radius_(radius), nPoint_(100){};
- GLCircle(GLPosition center, GLdouble radius, GLColor color):
- GLObject(GL_LINE_LOOP, color),
- center_(center), radius_(radius), nPoint_(100){};
- GLCircle(int mode,
- GLPosition center, GLdouble radius, GLColor color):
- GLObject(mode, color),
- center_(center), radius_(radius), nPoint_(100){};
- GLCircle(int mode,
- GLPosition center, GLdouble radius, int nPoint,
- GLColor color):
- GLObject(mode, color),
- center_(center), radius_(radius), nPoint_(nPoint){};
- ~GLCircle(){};
- void setCenter(GLPosition center);
- void setRadius(GLdouble radius);
- void setNumberOfPoints(int nPoint);
- virtual void setColor(GLColor color);
- virtual void draw();
- };
- /* Following 3D Shape Classes are not supported yet.
- class GLCube : GLObject{ };
- class GLPyramid : GLObject{ };
- class GLCone : GLObject{ };
- */
- }
- }
- #endif // __GLBASICSHAPE_HPP__
基本的にサイズなどを指定してインスタンスを生成するか、インスタンス生成後にサイズや色を指定して、描画関数内で"draw()"メンバ関数を呼び出す作りになっている。
構成要素の詳細 :
- 自作OpenGLクラス(DGLLib)詳細 その1 gl.hpp
- 自作OpenGLクラス(DGLLib)詳細 その2 glutil.hpp, glutil.cpp
- 自作OpenGLクラス(DGLLib)詳細 その3 glbasicshape.hpp, glbasicshape.cpp
- 自作OpenGLクラス(DGLLib)詳細 その4 glwindow.hpp, glwindow.cpp
コメント