zoukankan      html  css  js  c++  java
  • 实时控制软件第四周作业

    • 冰球游戏系统模块设计:
    1. Gui窗口模块:负责整个游戏界面的绘制,作为整个游戏软件的运行载体,目前计划采用Qt窗体程序进行游戏主窗口的创建;
    2. OpenGL模块:在Gui窗口中进行游戏元素的绘制;
    3. 物理引擎模块:负责进行物理逻辑的计算,主要是碰撞和速度;
    4. 定时器模块:负责控制绘制频率;
    5. 游戏元素
    • AI逻辑的处理:

       主要是怎样使机械手AI判断球的轨迹并进行拦截。

    • 可能用到的第三方库:
    1. ODE物理引擎;
    2. qt图形库或imgui图形库,具体用哪个之后再详细考虑;
    3. tinyxml,目的是将游戏的资源配置在xml文件中读取,方便更改;
    4. 打算将游戏逻辑写在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;
    "
        "}
    ";

      运行效果:

  • 相关阅读:
    MarkDown语法总结
    HashMap
    [LeetCode] 102. Binary Tree Level Order Traversal(二叉树的中序遍历)
    [LeetCode] 287. Find the Duplicate Number(寻找重复数字)
    [LeetCode] 215. Kth Largest Element in an Array(数组里的第 k 大元素)
    [LeetCode] 39. Combination Sum(组合的和)
    [LeetCode] 49. Group Anagrams(分组相同字母异序词)
    [LeetCode] 48. Rotate Image(旋转图片)
    [LeetCode] 647. Palindromic Substrings(回文子串)
    [LeetCode] 238. Product of Array Except Self(数组除自身元素外的乘积)
  • 原文地址:https://www.cnblogs.com/leafwaltz/p/6204730.html
Copyright © 2011-2022 走看看