{"id":341,"date":"2021-06-30T14:25:31","date_gmt":"2021-06-30T06:25:31","guid":{"rendered":"http:\/\/liyanliang.net\/?p=341"},"modified":"2021-06-30T14:39:59","modified_gmt":"2021-06-30T06:39:59","slug":"opengldarwcivilmodel","status":"publish","type":"post","link":"http:\/\/liyanliang.net\/index.php\/2021\/06\/30\/opengldarwcivilmodel\/","title":{"rendered":"OpenGL\u7ed8\u5236\u6865\u6881\u6a21\u578b"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/OpenGLCivilModel.gif\" alt=\"\"\/><\/figure><\/div>\n\n\n\n<p>\u672c\u6587\u4e3b\u8981\u8bb2\u8ff0\u5982\u4f55\u4f7f\u7528\u73b0\u4ee3OpenGL\u7ed8\u5236\u4e00\u4e2a\u5b8c\u6574\u7684\u6865\u6881\u6a21\u578b\uff0c\u5305\u62ec\u7bb1\u6881\u3001\u76d6\u6881\u548c\u6865\u58a9\uff0c\u5173\u4e8eOpenGL\u65b9\u9762\uff0c\u4e3b\u8981\u6dfb\u52a0\u7684shader\uff0c\u4f7f\u7528phong\u5149\u7167\u6a21\u578b\u5b9e\u73b0\u3002<\/p>\n\n\n\n<p class=\"has-cyan-bluish-gray-background-color has-background\"><strong>\u4e00\u3001\u7ed8\u5236\u7bb1\u6881<\/strong><\/p>\n\n\n\n<p><strong>1.1 \u7bb1\u6881\u7684\u7684\u622a\u9762\u548c\u5750\u6807\u7cfb<\/strong><\/p>\n\n\n\n<p>\u622a\u9762\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/20210630115220.png\" alt=\"\"\/><\/figure><\/div>\n\n\n\n<p>\u5750\u6807\u7cfb\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/20210630143610.png\" alt=\"\"\/><\/figure><\/div>\n\n\n\n<p><strong>1.2 \u7bb1\u6881\u7684\u9876\u70b9\u53ca\u5176\u6cd5\u5411\u91cf<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    float vertices[] = {\n        \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n        \/\/\u524d\u89c6\u56fe\n        \/\/ \u5de6\u7ffc\u7f18\n        \/\/ positions          \/\/ normals \n        -1.0f, 0.3f, 30.1f,    0.0f, 0.0f, 1.0f,\n        -1.0f, 0.2f, 30.1f,    0.0f, 0.0f, 1.0f,\n        -0.5f, 0.3f, 30.1f,    0.0f, 0.0f, 1.0f,\n    \n        -1.0f, 0.2f, 30.1f,    0.0f, 0.0f, 1.0f,\n        -0.5f, 0.1f, 30.1f,   0.0f, 0.0f, 1.0f,\n        -0.5f, 0.3f, 30.1f,   0.0f, 0.0f, 1.0f,\n    \n        \/\/ \u5de6\u77e9\u5f62\n        -0.5f, 0.3f,   30.1f,  0.0f, 0.0f, 1.0f,\n        -0.5f, -0.3f,  30.1f,  0.0f, 0.0f, 1.0f,\n        -0.35f, -0.3f, 30.1f,  0.0f, 0.0f, 1.0f,\n    \n        -0.5f, 0.3f,   30.1f,  0.0f, 0.0f, 1.0f,\n        -0.35f, -0.3f, 30.1f,  0.0f, 0.0f, 1.0f,\n        -0.35f, 0.3f,  30.1f,  0.0f, 0.0f, 1.0f,\n    \n        \/\/ \u4e0a\u77e9\u5f62\n        -0.35f, 0.3f, 30.1f,   0.0f, 0.0f, 1.0f,\n        -0.35f, 0.2f, 30.1f,   0.0f, 0.0f, 1.0f,\n        -0.0f, 0.3f,  30.1f,   0.0f, 0.0f, 1.0f,\n    \n        -0.35f, 0.2f, 30.1f,   0.0f, 0.0f, 1.0f,\n        -0.0f, 0.3f,  30.1f,   0.0f, 0.0f, 1.0f,\n        -0.0f, 0.2f,  30.1f,      0.0f, 0.0f, 1.0f,\n    \n        \/\/ \u4e0b\u77e9\u5f62\n        -0.35f, -0.3f, 30.1f,  0.0f, 0.0f, 1.0f,\n        -0.35f, -0.2f, 30.1f,  0.0f, 0.0f, 1.0f,\n        -0.0f, -0.3f,  30.1f,  0.0f, 0.0f, 1.0f,\n    \n        -0.35f, -0.2f, 30.1f,  0.0f, 0.0f, 1.0f,\n        -0.0f, -0.3f,  30.1f,  0.0f, 0.0f, 1.0f,\n        -0.0f, -0.2f,  30.1f,  0.0f, 0.0f, 1.0f,\n    \n        \/\/ \u5de6\u4e0a\u5012\u89d2\n        -0.35f, 0.2f,  30.1f,  0.0f, 0.0f, 1.0f,\n        -0.35f, 0.15f, 30.1f,  0.0f, 0.0f, 1.0f,\n        -0.25f, 0.2f,  30.1f,  0.0f, 0.0f, 1.0f,\n    \n        \/\/ \u5de6\u4e0b\u5012\u89d2\n        -0.35f, -0.2f,  30.1f, 0.0f, 0.0f, 1.0f,\n        -0.35f, -0.15f, 30.1f, 0.0f, 0.0f, 1.0f,\n        -0.25f, -0.2f,  30.1f, 0.0f, 0.0f, 1.0f,\n    \n            \/\/\u5bf9\u79f0 \u53f3\u8fb9\n            \/\/\u53f3\u7ffc\u7f18\n        1.0f, 0.3f, 30.1f,   0.0f, 0.0f, 1.0f,\n        1.0f, 0.2f, 30.1f,  0.0f, 0.0f, 1.0f,\n        0.5f, 0.3f, 30.1f,  0.0f, 0.0f, 1.0f,\n    \n        1.0f, 0.2f, 30.1f,   0.0f, 0.0f, 1.0f,\n        0.5f, 0.1f, 30.1f,  0.0f, 0.0f, 1.0f,\n        0.5f, 0.3f, 30.1f,  0.0f, 0.0f, 1.0f,\n    \n        \/\/ \u53f3\u77e9\u5f62\n        0.5f, 0.3f,   30.1f, 0.0f, 0.0f, 1.0f,\n        0.5f, -0.3f,  30.1f, 0.0f, 0.0f, 1.0f,\n        0.35f, -0.3f, 30.1f, 0.0f, 0.0f, 1.0f,\n    \n        0.5f, 0.3f,   30.1f, 0.0f, 0.0f, 1.0f,\n        0.35f, -0.3f, 30.1f,    0.0f, 0.0f, 1.0f,\n        0.35f, 0.3f,  30.1f,    0.0f, 0.0f, 1.0f,\n    \n        \/\/ \u4e0a\u77e9\u5f62\n        0.35f, 0.3f, 30.1f, 0.0f, 0.0f, 1.0f,\n        0.35f, 0.2f, 30.1f, 0.0f, 0.0f, 1.0f,\n        0.0f, 0.3f,  30.1f, 0.0f, 0.0f, 1.0f,\n    \n        0.35f, 0.2f, 30.1f, 0.0f, 0.0f, 1.0f,\n        0.0f, 0.3f,  30.1f, 0.0f, 0.0f, 1.0f,\n        0.0f, 0.2f,  30.1f, 0.0f, 0.0f, 1.0f,\n    \n        \/\/ \u4e0b\u77e9\u5f62\n        0.35f, -0.3f, 30.1f, 0.0f, 0.0f, 1.0f,\n        0.35f, -0.2f, 30.1f, 0.0f, 0.0f, 1.0f,\n        0.0f, -0.3f,  30.1f, 0.0f, 0.0f, 1.0f,\n    \n        0.35f, -0.2f, 30.1f, 0.0f, 0.0f, 1.0f,\n        0.0f, -0.3f,  30.1f, 0.0f, 0.0f, 1.0f,\n        0.0f, -0.2f,  30.1f,    0.0f, 0.0f, 1.0f,\n    \n        \/\/ \u53f3\u4e0a\u5012\u89d2\n        0.35f, 0.2f,  30.1f, 0.0f, 0.0f, 1.0f,\n        0.35f, 0.15f, 30.1f, 0.0f, 0.0f, 1.0f,\n        0.25f, 0.2f,  30.1f, 0.0f, 0.0f, 1.0f,\n    \n        \/\/ \u53f3\u4e0b\u5012\u89d2\n        0.35f, -0.2f,  30.1f, 0.0f, 0.0f, 1.0f,\n        0.35f, -0.15f, 30.1f, 0.0f, 0.0f, 1.0f,\n        0.25f, -0.2f,  30.1f, 0.0f, 0.0f, 1.0f,\n    \n        \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n        \/\/\u540e\u89c6\u56fe\n        \/\/ \u5de6\u7ffc\u7f18\n        -1.0f, 0.3f, -30.1f, 0.0f, 0.0f, -1.0f,\n        -1.0f, 0.2f, -30.1f, 0.0f, 0.0f, -1.0f,\n        -0.5f, 0.3f, -30.1f, 0.0f, 0.0f, -1.0f,\n    \n        -1.0f, 0.2f, -30.1f, 0.0f, 0.0f, -1.0f,\n        -0.5f, 0.1f, -30.1f,    0.0f, 0.0f, -1.0f,\n        -0.5f, 0.3f, -30.1f,    0.0f, 0.0f, -1.0f,\n    \n        \/\/ \u5de6\u77e9\u5f62\n        -0.5f, 0.3f,   -30.1f, 0.0f, 0.0f, -1.0f,\n        -0.5f, -0.3f,  -30.1f, 0.0f, 0.0f, -1.0f,\n        -0.35f, -0.3f, -30.1f, 0.0f, 0.0f, -1.0f,\n    \n        -0.5f, 0.3f,   -30.1f,  0.0f, 0.0f, -1.0f,\n        -0.35f, -0.3f, -30.1f,  0.0f, 0.0f, -1.0f,\n        -0.35f, 0.3f,  -30.1f,  0.0f, 0.0f, -1.0f,\n    \n        \/\/ \u4e0a\u77e9\u5f62\n        -0.35f, 0.3f, -30.1f,   0.0f, 0.0f, -1.0f,\n        -0.35f, 0.2f, -30.1f,   0.0f, 0.0f, -1.0f,\n        -0.0f, 0.3f,  -30.1f,   0.0f, 0.0f, -1.0f,\n    \n        -0.35f, 0.2f, -30.1f,   0.0f, 0.0f, -1.0f,\n        -0.0f, 0.3f,  -30.1f,   0.0f, 0.0f, -1.0f,\n        -0.0f, 0.2f,  -30.1f,   0.0f, 0.0f, -1.0f,\n    \n        \/\/ \u4e0b\u77e9\u5f62\n        -0.35f, -0.3f, -30.1f,  0.0f, 0.0f, -1.0f,\n        -0.35f, -0.2f, -30.1f,  0.0f, 0.0f, -1.0f,\n        -0.0f, -0.3f,  -30.1f,  0.0f, 0.0f, -1.0f,\n    \n        -0.35f, -0.2f, -30.1f,  0.0f, 0.0f, -1.0f,\n        -0.0f, -0.3f,  -30.1f,  0.0f, 0.0f, -1.0f,\n        -0.0f, -0.2f,  -30.1f,  0.0f, 0.0f, -1.0f,\n    \n        \/\/ \u5de6\u4e0a\u5012\u89d2\n        -0.35f, 0.2f,  -30.1f,  0.0f, 0.0f, -1.0f,\n        -0.35f, 0.15f, -30.1f,  0.0f, 0.0f, -1.0f,\n        -0.25f, 0.2f,  -30.1f,  0.0f, 0.0f, -1.0f,\n    \n        \/\/ \u5de6\u4e0b\u5012\u89d2\n        -0.35f, -0.2f,  -30.1f, 0.0f, 0.0f, -1.0f,\n        -0.35f, -0.15f, -30.1f, 0.0f, 0.0f, -1.0f,\n        -0.25f, -0.2f,  -30.1f, 0.0f, 0.0f, -1.0f,\n    \n        \/\/\u5bf9\u79f0 \u53f3\u8fb9\n        \/\/\u53f3\u7ffc\u7f18\n        1.0f, 0.3f, -30.1f,    0.0f, 0.0f, -1.0f,\n        1.0f, 0.2f, -30.1f,       0.0f, 0.0f, -1.0f,\n        0.5f, 0.3f, -30.1f,       0.0f, 0.0f, -1.0f,\n    \n        1.0f, 0.2f, -30.1f,    0.0f, 0.0f, -1.0f,\n        0.5f, 0.1f, -30.1f,   0.0f, 0.0f, -1.0f,\n        0.5f, 0.3f, -30.1f,   0.0f, 0.0f, -1.0f,\n    \n        \/\/ \u53f3\u77e9\u5f62\n        0.5f, 0.3f,   -30.1f,  0.0f, 0.0f, -1.0f,\n        0.5f, -0.3f,  -30.1f,  0.0f, 0.0f, -1.0f,\n        0.35f, -0.3f, -30.1f,  0.0f, 0.0f, -1.0f,\n    \n        0.5f, 0.3f,   -30.1f,  0.0f, 0.0f, -1.0f,\n        0.35f, -0.3f, -30.1f,  0.0f, 0.0f, -1.0f,\n        0.35f, 0.3f,  -30.1f,  0.0f, 0.0f, -1.0f,\n    \n        \/\/ \u4e0a\u77e9\u5f62\n        0.35f, 0.3f, -30.1f,   0.0f, 0.0f, -1.0f,\n        0.35f, 0.2f, -30.1f,   0.0f, 0.0f, -1.0f,\n        0.0f, 0.3f,  -30.1f,   0.0f, 0.0f, -1.0f,\n    \n        0.35f, 0.2f, -30.1f,   0.0f, 0.0f, -1.0f,\n        0.0f, 0.3f,  -30.1f,   0.0f, 0.0f, -1.0f,\n        0.0f, 0.2f,  -30.1f,      0.0f, 0.0f, -1.0f,\n    \n        \/\/ \u4e0b\u77e9\u5f62\n        0.35f, -0.3f, -30.1f,  0.0f, 0.0f, -1.0f,\n        0.35f, -0.2f, -30.1f,  0.0f, 0.0f, -1.0f,\n        0.0f, -0.3f,  -30.1f,  0.0f, 0.0f, -1.0f,\n    \n        0.35f, -0.2f, -30.1f,  0.0f, 0.0f, -1.0f,\n        0.0f, -0.3f,  -30.1f,  0.0f, 0.0f, -1.0f,\n        0.0f, -0.2f,  -30.1f,  0.0f, 0.0f, -1.0f,\n    \n        \/\/ \u53f3\u4e0a\u5012\u89d2\n        0.35f, 0.2f,  -30.1f, 0.0f, 0.0f, -1.0f,\n        0.35f, 0.15f, -30.1f, 0.0f, 0.0f, -1.0f,\n        0.25f, 0.2f,  -30.1f, 0.0f, 0.0f, -1.0f,\n    \n        \/\/ \u53f3\u4e0b\u5012\u89d2\n        0.35f, -0.2f,  -30.1f,  0.0f, 0.0f, -1.0f,\n        0.35f, -0.15f, -30.1f,  0.0f, 0.0f, -1.0f,\n        0.25f, -0.2f,  -30.1f,  0.0f, 0.0f, -1.0f,\n\u200b\n        \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n        \/\/\u5de6\u89c6\u56fe\n        \/\/ \u4e0a\u77e9\u5f62\n        -1.0f, 0.3f, -30.1f,  -1.0f, 0.0f, 0.0f,\n        -1.0f, 0.2f, -30.1f,  -1.0f, 0.0f, 0.0f,\n        -1.0f, 0.3f,  30.1f,  -1.0f, 0.0f, 0.0f,\n\u200b\n        -1.0f, 0.2f, -30.1f,  -1.0f, 0.0f, 0.0f,\n        -1.0f, 0.3f,  30.1f,  -1.0f, 0.0f, 0.0f,\n        -1.0f, 0.2f,  30.1f,     -1.0f, 0.0f, 0.0f,\n\u200b\n        \/\/ \u5de6\u7ffc\u7f18\u659c\u9762 \n        -1.0f, 0.2f, -30.1f,  -0.196116135f, -0.980580688f, -0.0f,\n        -0.5f, 0.1f, -30.1f,  -0.196116135f, -0.980580688f, -0.0f,\n        -1.0f, 0.2f,  30.1f,  -0.196116135f, -0.980580688f, -0.0f,\n        \n        -0.5f, 0.1f, -30.1f,  -0.196116135f, -0.980580688f, -0.0f,\n        -1.0f, 0.2f,  30.1f,  -0.196116135f, -0.980580688f, -0.0f,\n        -0.5f, 0.1f,  30.1f,  -0.196116135f, -0.980580688f, -0.0f,\n\u200b\n        \/\/ \u4e0b\u77e9\u5f62\n        -0.5f, 0.1f, -30.1f,  -1.0f, 0.0f, 0.0f,\n        -0.5f, -0.3f, -30.1f, -1.0f, 0.0f, 0.0f,\n        -0.5f, 0.1f,  30.1f,  -1.0f, 0.0f, 0.0f,\n        \n        -0.5f, -0.3f, -30.1f, -1.0f, 0.0f, 0.0f,\n        -0.5f, 0.1f,  30.1f,  -1.0f, 0.0f, 0.0f,\n        -0.5f, -0.3f, 30.1f,  -1.0f, 0.0f, 0.0f,\n\u200b\n        \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n        \/\/\u53f3\u89c6\u56fe\n        \/\/ \u4e0a\u77e9\u5f62\n        1.0f, 0.3f, -30.1f,  1.0f, 0.0f, 0.0f,\n        1.0f, 0.2f, -30.1f,     1.0f, 0.0f, 0.0f,\n        1.0f, 0.3f,  30.1f,     1.0f, 0.0f, 0.0f,\n\u200b\n        1.0f, 0.2f, -30.1f,  1.0f, 0.0f, 0.0f,\n        1.0f, 0.3f,  30.1f,  1.0f, 0.0f, 0.0f,\n        1.0f, 0.2f,  30.1f,  1.0f, 0.0f, 0.0f,\n\u200b\n        \/\/ \u53f3\u7ffc\u7f18\u659c\u9762\n        1.0f, 0.2f, -30.1f, 0.196116135f, -0.980580688f, 0.0f,\n        0.5f, 0.1f, -30.1f, 0.196116135f, -0.980580688f, 0.0f,\n        1.0f, 0.2f,  30.1f, 0.196116135f, -0.980580688f, 0.0f,\n\u200b\n        0.5f, 0.1f, -30.1f, 0.196116135f, -0.980580688f, 0.0f,\n        1.0f, 0.2f,  30.1f, 0.196116135f, -0.980580688f, 0.0f,\n        0.5f, 0.1f,  30.1f, 0.196116135f, -0.980580688f, 0.0f,\n\u200b\n        \/\/ \u4e0b\u77e9\u5f62\n        0.5f, 0.1f, -30.1f,  1.0f, 0.0f, 0.0f,\n        0.5f, -0.3f, -30.1f, 1.0f, 0.0f, 0.0f,\n        0.5f, 0.1f,  30.1f,     1.0f, 0.0f, 0.0f,\n\u200b\n        0.5f, -0.3f, -30.1f, 1.0f, 0.0f, 0.0f,\n        0.5f, 0.1f,  30.1f,     1.0f, 0.0f, 0.0f,\n        0.5f, -0.3f, 30.1f,     1.0f, 0.0f, 0.0f,\n\u200b\n        \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n        \/\/\u9644\u89c6\u56fe\n        -1.0f, 0.3f, -30.1f, 0.0f, 1.0f, 0.0f,\n        -1.0f, 0.3f,  30.1f,    0.0f, 1.0f, 0.0f,\n        1.0f, 0.3f, -30.1f,     0.0f, 1.0f, 0.0f,\n\u200b\n        -1.0f, 0.3f,  30.1f, 0.0f, 1.0f, 0.0f,\n        1.0f, 0.3f, -30.1f,     0.0f, 1.0f, 0.0f,\n        1.0f, 0.3f, 30.1f,  0.0f, 1.0f, 0.0f,\n\u200b\n        \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n        \/\/\u5e95\u89c6\u56fe\n        -0.5f, -0.3f, -30.1f, 0.0f, -1.0f, 0.0f,\n        -0.5f, -0.3f,  30.1f, 0.0f, -1.0f, 0.0f,\n        0.5f, -0.3f, -30.1f,  0.0f, -1.0f, 0.0f,\n\u200b\n        -0.5f, -0.3f,  30.1f, 0.0f, -1.0f, 0.0f,\n        0.5f, -0.3f, -30.1f,  0.0f, -1.0f, 0.0f,\n        0.5f, -0.3f, 30.1f,      0.0f, -1.0f, 0.0f,\n\u200b\n        \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n        \/\/ \u5185\u4fa7\u5e73\u9762\n\u200b\n        \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n        \/\/ \u5185-\u5de6\u534a\u90e8\u5206\n\u200b\n        \/\/ \u5de6\u77e9\u5f62\n        -0.35f, 0.15f, 30.1f,    1.0f, 0.0f, 0.0f,\n        -0.35f, -0.15f, 30.1f,   1.0f, 0.0f, 0.0f,\n        -0.35f, -0.15f, -30.1f,  1.0f, 0.0f, 0.0f,\n\u200b\n        -0.35f, 0.15f, 30.1f,    1.0f, 0.0f, 0.0f,\n        -0.35f, -0.15f, -30.1f,  1.0f, 0.0f, 0.0f,\n        -0.35f, 0.15f, -30.1f,   1.0f, 0.0f, 0.0f,\n\u200b\n        \/\/ \u4e0a\u77e9\u5f62\n        -0.25f, 0.2f, 30.1f,    0.0f, -1.0f, 0.0f,\n         0.0f, 0.2f,  30.1f,    0.0f, -1.0f, 0.0f,\n         0.0f, 0.2f, -30.1f,    0.0f, -1.0f, 0.0f,\n\u200b\n         -0.25f, 0.2f, 30.1f,    0.0f, -1.0f, 0.0f,\n          0.0f, 0.2f, -30.1f,    0.0f, -1.0f, 0.0f,\n         -0.25f, 0.2f, -30.1f,   0.0f, -1.0f, 0.0f,\n\u200b\n         \/\/ \u4e0b\u77e9\u5f62\n         -0.25f, -0.2f, 30.1f,    0.0f, 1.0f, 0.0f,\n         0.0f,  -0.2f,  30.1f,    0.0f, 1.0f, 0.0f,\n         0.0f,  -0.2f, -30.1f,    0.0f, 1.0f, 0.0f,\n\u200b\n         -0.25f, -0.2f, 30.1f,    0.0f, 1.0f, 0.0f,\n          0.0f,  -0.2f, -30.1f,   0.0f, 1.0f, 0.0f,\n         -0.25f, -0.2f, -30.1f,   0.0f, 1.0f, 0.0f,\n\u200b\n         \/\/ \u5de6\u4e0a\u659c\u9762 \n         -0.35f, 0.15f, 30.1f,    0.447213620f, -0.894427240f, 0.0f,\n         -0.25f, 0.2f,  30.1f,    0.447213620f, -0.894427240f, 0.0f,\n         -0.25f, 0.2f, -30.1f,    0.447213620f, -0.894427240f, 0.0f,\n\u200b\n         -0.35f, 0.15f, 30.1f,    0.447213620f, -0.894427240f, 0.0f,\n         -0.25f, 0.2f, -30.1f,    0.447213620f, -0.894427240f, 0.0f,\n         -0.35f, 0.15f, -30.1f,   0.447213620f, -0.894427240f, 0.0f,\n\u200b\n         \/\/ \u5de6\u4e0b\u659c\u9762  \n         -0.35f, -0.15f, 30.1f,     0.447213620f, 0.894427240f, 0.0f,\n         -0.25f, -0.2f,  30.1f,     0.447213620f, 0.894427240f, 0.0f,\n         -0.25f, -0.2f, -30.1f,     0.447213620f, 0.894427240f, 0.0f,\n\u200b\n         -0.35f, -0.15f, 30.1f,    0.447213620f, 0.894427240f, 0.0f,\n         -0.25f, -0.2f, -30.1f,    0.447213620f, 0.894427240f, 0.0f,\n         -0.35f, -0.15f, -30.1f,   0.447213620f, 0.894427240f, 0.0f,\n\u200b\n         \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n         \/\/ \u5185-\u53f3\u534a\u90e8\u5206\n\u200b\n         \/\/ \u53f3\u77e9\u5f62\n         0.35f, 0.15f, 30.1f,    -1.0f, 0.0f, 0.0f,\n         0.35f, -0.15f, 30.1f,   -1.0f, 0.0f, 0.0f,\n         0.35f, -0.15f, -30.1f,  -1.0f, 0.0f, 0.0f,\n\u200b\n         0.35f, 0.15f, 30.1f,    -1.0f, 0.0f, 0.0f,\n         0.35f, -0.15f, -30.1f,  -1.0f, 0.0f, 0.0f,\n         0.35f, 0.15f, -30.1f,   -1.0f, 0.0f, 0.0f,\n\u200b\n         \/\/ \u4e0a\u77e9\u5f62\n         0.25f, 0.2f, 30.1f,    0.0f, -1.0f, 0.0f,\n         0.0f, 0.2f,  30.1f,    0.0f, -1.0f, 0.0f,\n         0.0f, 0.2f, -30.1f,    0.0f, -1.0f, 0.0f,\n\u200b\n         0.25f, 0.2f, 30.1f,    0.0f, -1.0f, 0.0f,\n         0.0f, 0.2f, -30.1f,    0.0f, -1.0f, 0.0f,\n         0.25f, 0.2f, -30.1f,   0.0f, -1.0f, 0.0f,\n\u200b\n         \/\/ \u4e0b\u77e9\u5f62\n         0.25f, -0.2f, 30.1f,    0.0f, 1.0f, 0.0f,\n         0.0f,  -0.2f,  30.1f,    0.0f, 1.0f, 0.0f,\n         0.0f,  -0.2f, -30.1f,    0.0f, 1.0f, 0.0f,\n\u200b\n         0.25f, -0.2f, 30.1f,    0.0f, 1.0f, 0.0f,\n         0.0f,  -0.2f, -30.1f,   0.0f, 1.0f, 0.0f,\n         0.25f, -0.2f, -30.1f,   0.0f, 1.0f, 0.0f,\n\u200b\n         \/\/ \u53f3\u4e0a\u659c\u9762 \n         0.35f, 0.15f, 30.1f,    -0.447213620f, -0.894427240f, 0.0f,\n         0.25f, 0.2f,  30.1f,    -0.447213620f, -0.894427240f, 0.0f,\n         0.25f, 0.2f, -30.1f,    -0.447213620f, -0.894427240f, 0.0f,\n\u200b\n         0.35f, 0.15f, 30.1f,    -0.447213620f, -0.894427240f, 0.0f,\n         0.25f, 0.2f, -30.1f,    -0.447213620f, -0.894427240f, 0.0f,\n         0.35f, 0.15f, -30.1f,   -0.447213620f, -0.894427240f, 0.0f,\n\u200b\n         \/\/ \u53f3\u4e0b\u659c\u9762  \n         0.35f, -0.15f, 30.1f,    -0.447213620f, 0.894427240f, 0.0f,\n         0.25f, -0.2f,  30.1f,    -0.447213620f, 0.894427240f, 0.0f,\n         0.25f, -0.2f, -30.1f,    -0.447213620f, 0.894427240f, 0.0f,\n\u200b\n         0.35f, -0.15f, 30.1f,   -0.447213620f, 0.894427240f, 0.0f,\n         0.25f, -0.2f, -30.1f,   -0.447213620f, 0.894427240f, 0.0f,\n         0.35f, -0.15f, -30.1f,  -0.447213620f, 0.894427240f, 0.0f,\n        \n\u200b\n    }; <\/pre>\n\n\n\n<p><strong>1.3\u7bb1\u6881\u7684VAO\u3001VBO<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    unsigned int VBO, VAO;\n    glGenVertexArrays(1, &amp;VAO);\n    glGenBuffers(1, &amp;VBO);\n\u200b\n    glBindBuffer(GL_ARRAY_BUFFER, VBO);\n    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);\n\u200b\n    glBindVertexArray(VAO);\n\u200b\n    \/\/ position attribute\n    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0);\n    glEnableVertexAttribArray(0);\n    \/\/ normal attribute\n    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)(3 * sizeof(float)));\n    glEnableVertexAttribArray(1);\n\u200b\n\u200b\n    \/\/ \u5355\u7247\u7bb1\u6881\u7684\u4f4d\u7f6e\n    glm::vec3 beamPosition[] = {\n        glm::vec3( 0.0f,  0.0f,  0.0f),\n        glm::vec3( 2.0f,  0.0f,  0.0f),\n        glm::vec3( 4.0f,  0.0f,  0.0f),\n        glm::vec3( 6.0f,  0.0f,  0.0f),\n    };\n\u200b\n    \/\/ \u5355\u7247\u7bb1\u6881\u7684\u989c\u8272\n    glm::vec3 modelColor[] = {\n        glm::vec3( 1.0f,  0.75f, 0.51f),\n        glm::vec3( 1.0f,  0.75f, 0.51f),\n        glm::vec3( 1.0f,  0.75f, 0.51f),\n        glm::vec3( 1.0f,  0.75f, 0.51f),\n    };<\/pre>\n\n\n\n<p><strong>1.4\u7ed8\u5236\u7bb1\u6881<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">        glm::mat4 viewOrigin = camera.GetViewMatrix();\n        lightingShader.setMat4(\"view\", viewOrigin);\n\u200b\n        \/\/ \u7ed8\u5236\u7bb1\u6881\n        int nPntCount = sizeof(vertices)\/sizeof(float) \/ 2 \/ 3;\n        int nBeamCount = sizeof(beamPosition) \/ sizeof(glm::vec3);\n        \/\/ \u590d\u5236\u7bb1\u6881\n        for (int i = 0; i &lt; nBeamCount; ++i)\n        {\n            glm::mat4 model = glm::mat4(1.0);\n\u200b\n            \/\/\u79fb\u52a8\n            model = glm::translate(model, beamPosition[i]);\n            lightingShader.setMat4(\"model\", model);\n\u200b\n            \/\/\u989c\u8272\n            lightingShader.setVec3(\"objectColor\", modelColor[i]);\n            glBindVertexArray(VAO);\n            glDrawArrays(GL_TRIANGLES, 0, nPntCount);\n        }   <\/pre>\n\n\n\n<p class=\"has-cyan-bluish-gray-background-color has-background\"><strong>\u4e8c\u3001\u7ed8\u5236\u76d6\u6881<\/strong><\/p>\n\n\n\n<p><strong>2.1\u76d6\u6881\u7684\u9876\u70b9\u53ca\u5176\u6cd5\u5411\u91cf<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    float capBeamVertices[] = {\n        \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n        \/\/ \u524d\u89c6\u56fe\n        \/\/ \u5de6\u68af\u5f62\n        \/\/ positions          \/\/ normals \n        -0.5f, -0.3f, 0.31f,  0.0f, 0.0f, 1.0f,\n        -0.5f, -0.5f, 0.31f,  0.0f, 0.0f, 1.0f,\n        -0.2f, -0.3f, 0.31f,  0.0f, 0.0f, 1.0f,\n\u200b\n        -0.5f, -0.5f, 0.31f,  0.0f, 0.0f, 1.0f,\n        -0.2f, -0.7f, 0.31f,  0.0f, 0.0f, 1.0f,\n        -0.2f, -0.3f, 0.31f,  0.0f, 0.0f, 1.0f,\n\u200b\n        \/\/ \u77e9\u5f62\n        -0.2f, -0.3f, 0.31f,  0.0f, 0.0f, 1.0f,\n        -0.2f, -0.7f, 0.31f,  0.0f, 0.0f, 1.0f,\n         6.2f, -0.3f, 0.31f,  0.0f, 0.0f, 1.0f,\n\u200b\n        -0.2f, -0.7f, 0.31f,  0.0f, 0.0f, 1.0f,\n         6.2f, -0.3f, 0.31f,  0.0f, 0.0f, 1.0f,\n         6.2f, -0.7f, 0.31f,  0.0f, 0.0f, 1.0f,\n\u200b\n        \/\/\u53f3\u534a\u90e8\u5206\n        \/\/ \u53f3\u68af\u5f62\n        \/\/ positions          \/\/ normals \n        6.5f, -0.3f, 0.31f,  0.0f, 0.0f, 1.0f,\n        6.5f, -0.5f, 0.31f,  0.0f, 0.0f, 1.0f,\n        6.2f, -0.3f, 0.31f,  0.0f, 0.0f, 1.0f,\n\u200b\n        6.5f, -0.5f, 0.31f,  0.0f, 0.0f, 1.0f,\n        6.2f, -0.3f, 0.31f,  0.0f, 0.0f, 1.0f,\n        6.2f, -0.7f, 0.31f,  0.0f, 0.0f, 1.0f,\n\u200b\n        \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n        \/\/ \u540e\u89c6\u56fe\n        \/\/ \u5de6\u68af\u5f62\n        \/\/ positions          \/\/ normals \n        -0.5f, -0.3f, -0.31f,  0.0f, 0.0f, 1.0f,\n        -0.5f, -0.5f, -0.31f,  0.0f, 0.0f, 1.0f,\n        -0.2f, -0.3f, -0.31f,  0.0f, 0.0f, 1.0f,\n\u200b\n        -0.5f, -0.5f, -0.31f,  0.0f, 0.0f, 1.0f,\n        -0.2f, -0.7f, -0.31f,  0.0f, 0.0f, 1.0f,\n        -0.2f, -0.3f, -0.31f,  0.0f, 0.0f, 1.0f,\n\u200b\n        \/\/ \u77e9\u5f62\n        -0.2f, -0.3f, -0.31f,  0.0f, 0.0f, 1.0f,\n        -0.2f, -0.7f, -0.31f,  0.0f, 0.0f, 1.0f,\n         6.2f, -0.3f, -0.31f,  0.0f, 0.0f, 1.0f,\n\u200b\n        -0.2f, -0.7f, -0.31f,  0.0f, 0.0f, 1.0f,\n         6.2f, -0.3f, -0.31f,  0.0f, 0.0f, 1.0f,\n         6.2f, -0.7f, -0.31f,  0.0f, 0.0f, 1.0f,\n\u200b\n        \/\/\u53f3\u534a\u90e8\u5206\n        \/\/ \u53f3\u68af\u5f62\n        \/\/ positions          \/\/ normals \n        6.5f, -0.3f, -0.31f,  0.0f, 0.0f, 1.0f,\n        6.5f, -0.5f, -0.31f,  0.0f, 0.0f, 1.0f,\n        6.2f, -0.3f, -0.31f,  0.0f, 0.0f, 1.0f,\n\u200b\n        6.5f, -0.5f, -0.31f,  0.0f, 0.0f, 1.0f,\n        6.2f, -0.3f, -0.31f,  0.0f, 0.0f, 1.0f,\n        6.2f, -0.7f, -0.31f,  0.0f, 0.0f, 1.0f,\n\u200b\n        \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n        \/\/\u9876\u89c6\u56fe\n        \/\/ positions          \/\/ normals \n        -0.5f, -0.3f, -0.31f,  0.0f, 1.0f, 0.0f,\n        -0.5f, -0.3f,  0.31f,  0.0f, 1.0f, 0.0f,\n         6.5f, -0.3f, -0.31f,  0.0f, 1.0f, 0.0f,\n\u200b\n        -0.5f, -0.3f,  0.31f,  0.0f, 1.0f, 0.0f,\n         6.5f, -0.3f, -0.31f,  0.0f, 1.0f, 0.0f,\n         6.5f, -0.3f,  0.31f,  0.0f, 1.0f, 0.0f,\n\u200b\n        \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n        \/\/ \u5e95\u89c6\u56fe\n        \/\/ \u77e9\u5f62\n        -0.2f, -0.7f,  -0.31f,  0.0f, -1.0f, 0.0f,\n        -0.2f, -0.7f,   0.31f,  0.0f, -1.0f, 0.0f,\n         6.2f, -0.7f,  -0.31f,  0.0f, -1.0f, 0.0f,\n\u200b\n        -0.2f, -0.7f,   0.31f,  0.0f, -1.0f, 0.0f,\n         6.2f, -0.7f,  -0.31f,  0.0f, -1.0f, 0.0f,\n         6.2f, -0.7f,   0.31f,  0.0f, -1.0f, 0.0f,\n\u200b\n        \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n        \/\/ \u5de6\u89c6\u56fe\n        \/\/ \u4e0a\u77e9\u5f62\n        -0.5f,  -0.3f,  -0.31f,  -1.0f, 0.0f, 0.0f,\n        -0.5f,  -0.5f,  -0.31f,  -1.0f, 0.0f, 0.0f,\n        -0.5f,  -0.3f,   0.31f,  -1.0f, 0.0f, 0.0f,\n\u200b\n        -0.5f,  -0.5f,  -0.31f,  -1.0f, 0.0f, 0.0f,\n        -0.5f,  -0.3f,   0.31f,  -1.0f, 0.0f, 0.0f,\n        -0.5f,  -0.5f,   0.31f,  -1.0f, 0.0f, 0.0f,\n\u200b\n        \/\/ \u4e0b\u659c\u9762 \n        -0.5f,  -0.5f,  -0.31f,  -1.0f, 0.0f, 0.0f,\n        -0.2f,  -0.7f,  -0.31f,  -1.0f, 0.0f, 0.0f,\n        -0.5f,  -0.5f,   0.31f,  -1.0f, 0.0f, 0.0f,\n\u200b\n        -0.2f,  -0.7f,  -0.31f,  -1.0f, 0.0f, 0.0f,\n        -0.5f,  -0.5f,   0.31f,  -1.0f, 0.0f, 0.0f,\n        -0.2f,  -0.7f,   0.31f,  -1.0f, 0.0f, 0.0f,\n\u200b\n        \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n        \/\/ \u53f3\u89c6\u56fe\n        \/\/ \u4e0a\u77e9\u5f62\n        6.5f,  -0.3f,  -0.31f,  1.0f, 0.0f, 0.0f,\n        6.5f,  -0.5f,  -0.31f,  1.0f, 0.0f, 0.0f,\n        6.5f,  -0.5f,   0.31f,  1.0f, 0.0f, 0.0f,\n\u200b\n        6.5f,  -0.3f,  -0.31f,  1.0f, 0.0f, 0.0f,\n        6.5f,  -0.5f,   0.31f,  1.0f, 0.0f, 0.0f,\n        6.5f,  -0.3f,   0.31f,  1.0f, 0.0f, 0.0f,\n\u200b\n        \/\/ \u4e0b\u659c\u9762\n        6.5f,  -0.5f,  -0.31f,  1.0f, 0.0f, 0.0f,\n        6.2f,  -0.7f,  -0.31f,  1.0f, 0.0f, 0.0f,\n        6.5f,  -0.5f,   0.31f,  1.0f, 0.0f, 0.0f,\n\u200b\n        6.2f,  -0.7f,  -0.31f,  1.0f, 0.0f, 0.0f,\n        6.5f,  -0.5f,   0.31f,  1.0f, 0.0f, 0.0f,\n        6.2f,  -0.7f,   0.31f,  1.0f, 0.0f, 0.0f,\n\u200b\n    };<\/pre>\n\n\n\n<p><strong>2.2\u76d6\u6881\u7684VAO\u3001VBO<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    unsigned int capVBO, capVAO;\n    glGenVertexArrays(1, &amp;capVAO);\n    glGenBuffers(1, &amp;capVBO);\n\u200b\n    glBindBuffer(GL_ARRAY_BUFFER, capVBO);\n    glBufferData(GL_ARRAY_BUFFER, sizeof(capBeamVertices), capBeamVertices, GL_STATIC_DRAW);\n\u200b\n    glBindVertexArray(capVAO);\n\u200b\n    \/\/ position attribute\n    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0);\n    glEnableVertexAttribArray(0);\n    \/\/ normal attribute\n    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)(3 * sizeof(float)));\n    glEnableVertexAttribArray(1);\n\u200b\n\u200b\n    \/\/ \u5355\u7247\u7bb1\u6881\u7684\u4f4d\u7f6e\n    glm::vec3 capPosition[] = {\n        glm::vec3( 0.0f,  0.0f,   capSpace\/2.0f),  \/\/ \u524d\u4e00\n        glm::vec3( 0.0f,  0.0f,  -capSpace\/2.0f),  \/\/ \u540e\u4e00\n\u200b\n        glm::vec3( 0.0f,  0.0f,   capSpace\/2.0f + capSpace),   \/\/ \u524d\u4e8c\n        glm::vec3( 0.0f,  0.0f,  -(capSpace\/2.0f + capSpace)), \/\/ \u540e\u4e8c\n    };\n\u200b\n    \/\/ \u5355\u7247\u7bb1\u6881\u7684\u989c\u8272\n    glm::vec3 capColor[] = {\n        glm::vec3(  1.0f, 0.5f, 0.31f),\n        glm::vec3(  1.0f, 0.5f, 0.31f),\n        glm::vec3(  1.0f, 0.5f, 0.31f),\n        glm::vec3(  1.0f, 0.5f, 0.31f),\n    };<\/pre>\n\n\n\n<p><strong>2.3\u7ed8\u5236\u76d6\u6881<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">        int capCount = sizeof(capPosition) \/ sizeof(glm::vec3);\n        int nCapPtCount = sizeof(capBeamVertices)\/sizeof(float) \/ 2 \/ 3;\n        for (int iCap = 0; iCap &lt; capCount; ++iCap)\n        {\n            glm::mat4 modelCap = glm::mat4(1.0);\n            modelCap = glm::translate(modelCap, capPosition[iCap]);\n            lightingShader.setMat4(\"model\", modelCap);\n\u200b\n            lightingShader.setVec3(\"objectColor\", capColor[iCap]);\n            glBindVertexArray(capVAO);\n            glDrawArrays(GL_TRIANGLES, 0, nCapPtCount);\n        }   <\/pre>\n\n\n\n<p class=\"has-cyan-bluish-gray-background-color has-background\"><strong>\u4e09\u3001\u7ed8\u5236\u6865\u58a9<\/strong><\/p>\n\n\n\n<p><strong>3.1\u8ba1\u7b97\u5706\u5468\u4e0a\u7684\u70b9\u548c\u6cd5\u5411\u91cf<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">struct TVertex {\n    \/\/ position\n    glm::vec3 Position;\n    \/\/ normal\n    glm::vec3 Normal;\n};\n\u200b\nstd::vector&lt;TVertex> getUnitCircleVertices()\n{\n    const float PI = 3.1415926f;\n    float sectorStep = 2 * PI \/ sectorCount;\n    float sectorAngle = 0.0f;\n\u200b\n    glm::vec3 position;\n    glm::vec3 normal;\n    TVertex tVertex;\n\u200b\n    std::vector&lt;TVertex> unitCircleVertices;\n    for (int i = 0; i &lt;= sectorCount; ++i)\n    {\n        sectorAngle = i * sectorStep;\n        position.x = pierRadius * cos(sectorAngle);\n        position.y = 0.0f;\n        position.z = pierRadius * sin(sectorAngle);\n\u200b\n        normal.x = cos(sectorAngle);\n        normal.y = 0.0f;\n        normal.z = sin(sectorAngle);\n\u200b\n        tVertex.Position = position;\n        tVertex.Normal = normal;\n\u200b\n        unitCircleVertices.push_back(tVertex);\n    }\n\u200b\n    return unitCircleVertices;\n}<\/pre>\n\n\n\n<p><strong>3.2\u8ba1\u7b97\u5706\u67f1side\u548c\u4e0a\u5706\u5f62\u548c\u4e0b\u5706\u5f62<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ generate vertices for a cylinder\nvoid buildCylinderVertices(std::vector&lt;TVertex>&amp; vertices)\n{\n    std::vector&lt;TVertex> unitVertices = getUnitCircleVertices();\n\u200b\n    \/\/ \u83b7\u53d6\u4e0a\u3001\u4e0b\u5706\u5468\u70b9\u6570\u7ec4\n    std::vector&lt;TVertex> vctTop;\n    std::vector&lt;TVertex> vctBot;\n\u200b\n    TVertex tVertex;\n    for(int i = 0; i &lt; unitVertices.size(); ++i)\n    {\n        tVertex.Position = unitVertices[i].Position;\n        tVertex.Position.y = pierHeight;\n        tVertex.Normal = unitVertices[i].Normal;\n        vctTop.push_back(tVertex);  \n\u200b\n        tVertex.Position.y = 0.0f;\n        vctBot.push_back(tVertex);     \n    }\n\u200b\n    assert(vctTop.size() >= 2);\n    assert(vctBot.size() >= 2);\n\u200b\n    \/\/ put side vertices to arrays\n    for(int i = 0; i &lt; vctTop.size() - 1; ++i)\n    {\n        \/\/ \u5de6\u4e09\u89d2\u5f62\n        vertices.push_back(vctTop[i]);\n        vertices.push_back(vctBot[i]);\n        vertices.push_back(vctBot[i+1]);\n        \n        \/\/ \u53f3\u4e09\u89d2\u5f62\n        vertices.push_back(vctTop[i]);\n        vertices.push_back(vctTop[i+1]);\n        vertices.push_back(vctBot[i+1]);\n    }\n    \n    \/\/ \u9876\u90e8\u5706\u5f62\n    glm::vec3 position;\n    for (int i = 0; i &lt; vctTop.size() - 1; ++i)\n    {\n        glm::vec3 position(0.0f, pierHeight, 0.0f);\n        glm::vec3 normal(0.0f, 1.0f, 0.0f);\n        tVertex.Position = position;\n        tVertex.Normal = normal;\n        vertices.push_back(tVertex);\n\u200b\n        tVertex.Position = vctTop[i].Position;\n        vertices.push_back(tVertex);\n\u200b\n        tVertex.Position = vctTop[i+1].Position;\n        vertices.push_back(tVertex);\n    }\n\u200b\n    \/\/ \u5e95\u90e8\u5706\u5f62\n    for (int i = 0; i &lt; vctBot.size() - 1; ++i)\n    {\n        glm::vec3 position(0.0f, 0.0f, 0.0f);\n        glm::vec3 normal(0.0f, -1.0f, 0.0f);\n        tVertex.Position = position;\n        tVertex.Normal = normal;\n        vertices.push_back(tVertex);\n\u200b\n        tVertex.Position = vctBot[i].Position;\n        vertices.push_back(tVertex);\n\u200b\n        tVertex.Position = vctBot[i+1].Position;\n        vertices.push_back(tVertex);\n    }\n}<\/pre>\n\n\n\n<p><strong>3.3\u6865\u58a9\u7684VAO\u3001VBO<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"> \u00a0\/\/ generate vertices for a cylinder\nvoid buildCylinderVertices(std::vector&lt;TVertex>&amp; vertices)\n{\n    std::vector&lt;TVertex> unitVertices = getUnitCircleVertices();\n\u200b\n    \/\/ \u83b7\u53d6\u4e0a\u3001\u4e0b\u5706\u5468\u70b9\u6570\u7ec4\n    std::vector&lt;TVertex> vctTop;\n    std::vector&lt;TVertex> vctBot;\n\u200b\n    TVertex tVertex;\n    for(int i = 0; i &lt; unitVertices.size(); ++i)\n    {\n        tVertex.Position = unitVertices[i].Position;\n        tVertex.Position.y = pierHeight;\n        tVertex.Normal = unitVertices[i].Normal;\n        vctTop.push_back(tVertex);  \n\u200b\n        tVertex.Position.y = 0.0f;\n        vctBot.push_back(tVertex);     \n    }\n\u200b\n    assert(vctTop.size() >= 2);\n    assert(vctBot.size() >= 2);\n\u200b\n    \/\/ put side vertices to arrays\n    for(int i = 0; i &lt; vctTop.size() - 1; ++i)\n    {\n        \/\/ \u5de6\u4e09\u89d2\u5f62\n        vertices.push_back(vctTop[i]);\n        vertices.push_back(vctBot[i]);\n        vertices.push_back(vctBot[i+1]);\n        \n        \/\/ \u53f3\u4e09\u89d2\u5f62\n        vertices.push_back(vctTop[i]);\n        vertices.push_back(vctTop[i+1]);\n        vertices.push_back(vctBot[i+1]);\n    }\n    \n    \/\/ \u9876\u90e8\u5706\u5f62\n    glm::vec3 position;\n    for (int i = 0; i &lt; vctTop.size() - 1; ++i)\n    {\n        glm::vec3 position(0.0f, pierHeight, 0.0f);\n        glm::vec3 normal(0.0f, 1.0f, 0.0f);\n        tVertex.Position = position;\n        tVertex.Normal = normal;\n        vertices.push_back(tVertex);\n\u200b\n        tVertex.Position = vctTop[i].Position;\n        vertices.push_back(tVertex);\n\u200b\n        tVertex.Position = vctTop[i+1].Position;\n        vertices.push_back(tVertex);\n    }\n\u200b\n    \/\/ \u5e95\u90e8\u5706\u5f62\n    for (int i = 0; i &lt; vctBot.size() - 1; ++i)\n    {\n        glm::vec3 position(0.0f, 0.0f, 0.0f);\n        glm::vec3 normal(0.0f, -1.0f, 0.0f);\n        tVertex.Position = position;\n        tVertex.Normal = normal;\n        vertices.push_back(tVertex);\n\u200b\n        tVertex.Position = vctBot[i].Position;\n        vertices.push_back(tVertex);\n\u200b\n        tVertex.Position = vctBot[i+1].Position;\n        vertices.push_back(tVertex);\n    }\n}<\/pre>\n\n\n\n<p><strong>3.4\u7ed8\u5236\u6865\u58a9<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">        int pierCount = sizeof(pierPosition) \/ sizeof(glm::vec3);\n        for (int iPier = 0; iPier &lt; pierCount; ++iPier)\n        {\n            lightingShader.setMat4(\"view\", viewOrigin);\n            glm::mat4 modelPier = glm::mat4(1.0f);\n            modelPier = glm::translate(modelPier, pierPosition[iPier]);\n            lightingShader.setMat4(\"model\", modelPier);\n            lightingShader.setVec3(\"objectColor\", pierColor[iPier]);\n\u200b\n            glBindVertexArray(pierVAO);\n            glDrawArrays(GL_TRIANGLES, 0, pierVertices.size());\n        }<\/pre>\n\n\n\n<p class=\"has-cyan-bluish-gray-background-color has-background\"><strong>\u56db\u3001\u7740\u8272\u5668<\/strong><\/p>\n\n\n\n<p> <strong>4.1\u9876\u70b9\u7740\u8272\u5668<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#version 330 core\nlayout (location = 0) in vec3 aPos;\nlayout (location = 1) in vec3 aNormal;\n\u200b\nout vec3 FragPos;\nout vec3 Normal;\n\u200b\nuniform mat4 model;\nuniform mat4 view;\nuniform mat4 projection;\n\u200b\nvoid main()\n{\n    FragPos = vec3(model * vec4(aPos, 1.0));\n    Normal = mat3(transpose(inverse(model))) * aNormal;  \n    \n    gl_Position = projection * view * vec4(FragPos, 1.0);\n}<\/pre>\n\n\n\n<p><strong>4.2\u7247\u6bb5\u7740\u8272\u5668<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#version 330 core\nout vec4 FragColor;\n\u200b\nin vec3 Normal;  \nin vec3 FragPos;  \n  \nuniform vec3 lightPos; \nuniform vec3 lightDirection; \nuniform vec3 viewPos; \nuniform vec3 lightColor;\nuniform vec3 objectColor;\n\u200b\nvoid main()\n{\n    \/\/ ambient\n    float ambientStrength = 0.1;\n    vec3 ambient = ambientStrength * lightColor;\n    \n    \/\/ diffuse \n    vec3 norm = normalize(Normal);\n    \/\/vec3 lightDir = normalize(lightPos - FragPos);\n    vec3 lightDir = normalize(-lightDirection);\n    float diff = max(dot(norm, lightDir), 0.0);\n    vec3 diffuse = diff * lightColor;\n    \n    \/\/ specular\n    float specularStrength = 0.5;\n    vec3 viewDir = normalize(viewPos - FragPos);\n    vec3 reflectDir = reflect(-lightDir, norm);  \n    float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);\n    vec3 specular = specularStrength * spec * lightColor;  \n        \n    vec3 result = (ambient + diffuse + specular) * objectColor;\n    FragColor = vec4(result, 1.0);\n} <\/pre>\n\n\n\n<p class=\"has-cyan-bluish-gray-background-color has-background\"><strong>\u4e94\u3001\u9879\u76ee\u6e90\u4ee3\u7801<\/strong><\/p>\n\n\n\n<p>\u94fe\u63a5\uff1a<a href=\"https:\/\/pan.baidu.com\/s\/1EA2wd_Rooj-748uKAUugAw\">https:\/\/pan.baidu.com\/s\/1EA2wd_Rooj-748uKAUugAw<\/a> \u63d0\u53d6\u7801\uff1a3d51<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u4e3b\u8981\u8bb2\u8ff0\u5982\u4f55\u4f7f\u7528\u73b0\u4ee3OpenGL\u7ed8\u5236\u4e00\u4e2a\u5b8c\u6574\u7684\u6865\u6881\u6a21\u578b\uff0c\u5305\u62ec\u7bb1\u6881\u3001\u76d6\u6881\u548c\u6865\u58a9\uff0c\u5173\u4e8eOpenGL\u65b9\u9762\uff0c\u4e3b\u8981\u6dfb\u52a0\u7684shader\uff0c\u4f7f\u7528phong\u5149\u7167\u6a21\u578b\u5b9e\u73b0\u3002 \u4e00\u3001\u7ed8\u5236\u7bb1\u6881 1.1 \u7bb1\u6881\u7684\u7684\u622a\u9762\u548c\u5750\u6807\u7cfb \u622a\u9762\uff1a \u5750\u6807\u7cfb\uff1a 1.2 \u7bb1\u6881\u7684\u9876\u70b9\u53ca\u5176\u6cd5\u5411\u91cf 1.3\u7bb1\u6881\u7684VAO\u3001VBO 1.4\u7ed8\u5236\u7bb1\u6881 \u4e8c\u3001\u7ed8\u5236\u76d6\u6881 2.1\u76d6\u6881\u7684\u9876\u70b9\u53ca\u5176\u6cd5\u5411\u91cf 2.2\u76d6\u6881\u7684VAO\u3001VBO 2.3\u7ed8\u5236\u76d6\u6881 \u4e09\u3001\u7ed8\u5236\u6865\u58a9 3.1\u8ba1\u7b97\u5706\u5468\u4e0a\u7684\u70b9\u548c\u6cd5\u5411\u91cf 3.2\u8ba1\u7b97\u5706\u67f1side\u548c\u4e0a\u5706\u5f62\u548c\u4e0b\u5706\u5f62 3.3\u6865\u58a9\u7684VAO\u3001VBO 3.4\u7ed8\u5236\u6865\u58a9 \u56db\u3001\u7740\u8272\u5668 4.1\u9876\u70b9\u7740\u8272\u5668 4.2\u7247\u6bb5\u7740\u8272\u5668 \u4e94\u3001\u9879\u76ee\u6e90\u4ee3\u7801 \u94fe\u63a5\uff1ahttps:\/\/pan.baidu.com\/s\/1EA2wd_Rooj-748uKAUugAw \u63d0\u53d6\u7801\uff1a3d51<\/p>\n","protected":false},"author":1,"featured_media":346,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[15],"class_list":["post-341","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-opengl","tag-opengl"],"_links":{"self":[{"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/posts\/341","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/comments?post=341"}],"version-history":[{"count":7,"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/posts\/341\/revisions"}],"predecessor-version":[{"id":352,"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/posts\/341\/revisions\/352"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/media\/346"}],"wp:attachment":[{"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/media?parent=341"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/categories?post=341"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/tags?post=341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}