- 冰球游戏系统模块设计:
- Gui窗口模块:负责整个游戏界面的绘制,作为整个游戏软件的运行载体,目前计划采用Qt窗体程序进行游戏主窗口的创建;
- OpenGL模块:在Gui窗口中进行游戏元素的绘制;
- 物理引擎模块:负责进行物理逻辑的计算,主要是碰撞和速度;
- 定时器模块:负责控制绘制频率;
- 游戏元素
- AI逻辑的处理:
主要是怎样使机械手AI判断球的轨迹并进行拦截。
- 可能用到的第三方库:
- ODE物理引擎;
- qt图形库或imgui图形库,具体用哪个之后再详细考虑;
- tinyxml,目的是将游戏的资源配置在xml文件中读取,方便更改;
- 打算将游戏逻辑写在lua文件中,方便修改。
- 具体设计如下:
程序的基础框架将派生自此渲染框架,主要是实现render和initialize函数。
1 class GuiBase : public QWindow , protected QOpenGLFunctions 2 { 3 Q_OBJECT 4 5 public: 6 7 explicit GuiBase(QWindow *parent = 0); 8 9 ~GuiBase(); 10 11 virtual void render(QPainter *painter); 12 13 virtual void render(); 14 15 virtual void initialize(); 16 17 void setAnimating(bool animating); 18 19 private slots: 20 21 void renderLater(); 22 23 void renderNow(); 24 25 protected: 26 27 bool event(QEvent *event) Q_DECL_OVERRIDE; 28 29 void exposeEvent(QExposeEvent *event) Q_DECL_OVERRIDE; 30 31 private: 32 33 bool m_update_pending; 34 bool m_animating; 35 36 QOpenGLContext* m_context; 37 QOpenGLPaintDevice* m_device; 38 };
从官方文档里copy过来的一个三角形渲染框架:
1 class TriangleWindow : public GuiBase 2 { 3 public: 4 TriangleWindow(); 5 6 void initialize() Q_DECL_OVERRIDE; 7 void render() Q_DECL_OVERRIDE; 8 9 private: 10 GLuint m_posAttr; 11 GLuint m_colAttr; 12 GLuint m_matrixUniform; 13 14 QOpenGLShaderProgram *m_program; 15 int m_frame; 16 };
shader:
static const char *vertexShaderSource = "attribute highp vec4 posAttr; " "attribute lowp vec4 colAttr; " "varying lowp vec4 col; " "uniform highp mat4 matrix; " "void main() { " " col = colAttr; " " gl_Position = matrix * posAttr; " "} "; static const char *fragmentShaderSource = "varying lowp vec4 col; " "void main() { " " gl_FragColor = col; " "} ";
运行效果: