mirror of
https://github.com/LearnOpenGL-CN/LearnOpenGL-CN.git
synced 2025-08-23 04:35:28 +08:00
4
.github/workflows/deploy.yml
vendored
4
.github/workflows/deploy.yml
vendored
@@ -14,9 +14,7 @@ jobs:
|
|||||||
- name: install dependencies
|
- name: install dependencies
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
pip install PyYAML==5.1.2
|
pip install mkdocs==1.4.2 python-markdown-math==0.8
|
||||||
pip install mkdocs==0.16.3
|
|
||||||
python setup.py install
|
|
||||||
- name: build site
|
- name: build site
|
||||||
shell: bash
|
shell: bash
|
||||||
run: mkdocs build --clean
|
run: mkdocs build --clean
|
||||||
|
@@ -61,11 +61,10 @@ learnopengl.com系列教程的中文翻译,目前正在校对及翻译中。
|
|||||||
|
|
||||||
## 构建
|
## 构建
|
||||||
|
|
||||||
首先请安装Python,2和3都可以,之后初始化环境:
|
首先请安装Python 3.7+,之后初始化环境:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ pip install mkdocs
|
$ pip install mkdocs==1.4.2 python-markdown-math==0.8
|
||||||
$ python setup.py install
|
|
||||||
```
|
```
|
||||||
|
|
||||||
初始化以后,每次构建只需要输入以下指令即可,构建后的文件在`site`文件夹内:
|
初始化以后,每次构建只需要输入以下指令即可,构建后的文件在`site`文件夹内:
|
||||||
|
@@ -20,17 +20,17 @@
|
|||||||
class BallObject : public GameObject
|
class BallObject : public GameObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// 球的状态
|
// 球的状态
|
||||||
GLfloat Radius;
|
GLfloat Radius;
|
||||||
GLboolean Stuck;
|
GLboolean Stuck;
|
||||||
|
|
||||||
|
|
||||||
BallObject();
|
BallObject();
|
||||||
BallObject(glm::vec2 pos, GLfloat radius, glm::vec2 velocity, Texture2D sprite);
|
BallObject(glm::vec2 pos, GLfloat radius, glm::vec2 velocity, Texture2D sprite);
|
||||||
|
|
||||||
glm::vec2 Move(GLfloat dt, GLuint window_width);
|
glm::vec2 Move(GLfloat dt, GLuint window_width);
|
||||||
void Reset(glm::vec2 position, glm::vec2 velocity);
|
void Reset(glm::vec2 position, glm::vec2 velocity);
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
<fun>BallObject</fun>的构造函数不但初始化了其自身的值,而且实际上也潜在地初始化了<fun>GameObject</fun>。<fun>BallObject</fun>类拥有一个<fun>Move</fun>函数,该函数用于根据球的速度来移动球,并检查它是否碰到了场景的任何边界,如果碰到的话就会反转球的速度:
|
<fun>BallObject</fun>的构造函数不但初始化了其自身的值,而且实际上也潜在地初始化了<fun>GameObject</fun>。<fun>BallObject</fun>类拥有一个<fun>Move</fun>函数,该函数用于根据球的速度来移动球,并检查它是否碰到了场景的任何边界,如果碰到的话就会反转球的速度:
|
||||||
@@ -41,7 +41,7 @@ glm::vec2 BallObject::Move(GLfloat dt, GLuint window_width)
|
|||||||
{
|
{
|
||||||
// 如果没有被固定在挡板上
|
// 如果没有被固定在挡板上
|
||||||
if (!this->Stuck)
|
if (!this->Stuck)
|
||||||
{
|
{
|
||||||
// 移动球
|
// 移动球
|
||||||
this->Position += this->Velocity * dt;
|
this->Position += this->Velocity * dt;
|
||||||
// 检查是否在窗口边界以外,如果是的话反转速度并恢复到正确的位置
|
// 检查是否在窗口边界以外,如果是的话反转速度并恢复到正确的位置
|
||||||
@@ -60,10 +60,10 @@ glm::vec2 BallObject::Move(GLfloat dt, GLuint window_width)
|
|||||||
this->Velocity.y = -this->Velocity.y;
|
this->Velocity.y = -this->Velocity.y;
|
||||||
this->Position.y = 0.0f;
|
this->Position.y = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return this->Position;
|
return this->Position;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
除了反转球的速度之外,我们还需要把球沿着边界重新放置回来。只有在没有被固定时球才能够移动。
|
除了反转球的速度之外,我们还需要把球沿着边界重新放置回来。只有在没有被固定时球才能够移动。
|
||||||
@@ -77,16 +77,16 @@ glm::vec2 BallObject::Move(GLfloat dt, GLuint window_width)
|
|||||||
- BallObject: [header](https://learnopengl.com/code_viewer.php?code=in-practice/breakout/ball_object_collisions.h), [code](https://learnopengl.com/code_viewer.php?code=in-practice/breakout/ball_object_collisions)
|
- BallObject: [header](https://learnopengl.com/code_viewer.php?code=in-practice/breakout/ball_object_collisions.h), [code](https://learnopengl.com/code_viewer.php?code=in-practice/breakout/ball_object_collisions)
|
||||||
|
|
||||||
|
|
||||||
首先我们在游戏中添加球。与玩家挡板相似,我们创建一个球对象并且定义两个用来初始化球的常量。对于球的纹理,我们会使用在LearnOpenGL Breakout游戏中完美适用的一张图片:[球纹理](../../../../img/06/Breakout/05/01/awesomeface.png)。
|
首先我们在游戏中添加球。与玩家挡板相似,我们创建一个球对象并且定义两个用来初始化球的常量。对于球的纹理,我们会使用在LearnOpenGL Breakout游戏中完美适用的一张图片:[球纹理](../../../img/06/Breakout/05/01/awesomeface.png)。
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
// 初始化球的速度
|
// 初始化球的速度
|
||||||
const glm::vec2 INITIAL_BALL_VELOCITY(100.0f, -350.0f);
|
const glm::vec2 INITIAL_BALL_VELOCITY(100.0f, -350.0f);
|
||||||
// 球的半径
|
// 球的半径
|
||||||
const GLfloat BALL_RADIUS = 12.5f;
|
const GLfloat BALL_RADIUS = 12.5f;
|
||||||
|
|
||||||
BallObject *Ball;
|
BallObject *Ball;
|
||||||
|
|
||||||
void Game::Init()
|
void Game::Init()
|
||||||
{
|
{
|
||||||
[...]
|
[...]
|
||||||
@@ -101,7 +101,7 @@ void Game::Init()
|
|||||||
void Game::Update(GLfloat dt)
|
void Game::Update(GLfloat dt)
|
||||||
{
|
{
|
||||||
Ball->Move(dt, this->Width);
|
Ball->Move(dt, this->Width);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
除此之外,由于球初始是固定在挡板上的,我们必须让玩家能够从固定的位置重新移动它。我们选择使用空格键来从挡板释放球。这意味着我们必须稍微修改<fun>ProcessInput</fun>函数:
|
除此之外,由于球初始是固定在挡板上的,我们必须让玩家能够从固定的位置重新移动它。我们选择使用空格键来从挡板释放球。这意味着我们必须稍微修改<fun>ProcessInput</fun>函数:
|
||||||
@@ -149,7 +149,7 @@ void Game::Render()
|
|||||||
[...]
|
[...]
|
||||||
Ball->Draw(*Renderer);
|
Ball->Draw(*Renderer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
结果就是球会跟随着挡板,并且当我们按下空格键时球开始自由运动。球会在左侧、右侧和顶部边界合理地反弹,但看起来不会撞击任何的砖块,就像我们可以在下边的视频中看到的那样:
|
结果就是球会跟随着挡板,并且当我们按下空格键时球开始自由运动。球会在左侧、右侧和顶部边界合理地反弹,但看起来不会撞击任何的砖块,就像我们可以在下边的视频中看到的那样:
|
||||||
|
@@ -1,7 +0,0 @@
|
|||||||
# 雾
|
|
||||||
|
|
||||||
**未完成**
|
|
||||||
|
|
||||||
这篇教程暂时还没有完成,您可以经常来刷新看看是否有更新的进展。
|
|
||||||
|
|
||||||
<img src="../../img/development.png" class="clean">
|
|
@@ -1,7 +0,0 @@
|
|||||||
# 卡通着色
|
|
||||||
|
|
||||||
**未完成**
|
|
||||||
|
|
||||||
这篇教程暂时还没有完成,您可以经常来刷新看看是否有更新的进展。
|
|
||||||
|
|
||||||
<img src="../../img/development.png" class="clean">
|
|
64
mdx_math.py
64
mdx_math.py
@@ -1,64 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
'''
|
|
||||||
Math extension for Python-Markdown
|
|
||||||
==================================
|
|
||||||
|
|
||||||
Adds support for displaying math formulas using [MathJax](http://www.mathjax.org/).
|
|
||||||
|
|
||||||
Author: 2015, Dmitry Shachnev <mitya57@gmail.com>.
|
|
||||||
'''
|
|
||||||
|
|
||||||
import markdown
|
|
||||||
|
|
||||||
class MathExtension(markdown.extensions.Extension):
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
self.config = {
|
|
||||||
'enable_dollar_delimiter': [False, 'Enable single-dollar delimiter'],
|
|
||||||
'render_to_span': [False,
|
|
||||||
'Render to span elements rather than script for fallback'],
|
|
||||||
}
|
|
||||||
super(MathExtension, self).__init__(*args, **kwargs)
|
|
||||||
|
|
||||||
def extendMarkdown(self, md, md_globals):
|
|
||||||
def handle_match_inline(m):
|
|
||||||
if self.getConfig('render_to_span'):
|
|
||||||
node = markdown.util.etree.Element('span')
|
|
||||||
node.set('class', 'tex')
|
|
||||||
node.text = ("\\\\(" + markdown.util.AtomicString(m.group(3)) +
|
|
||||||
"\\\\)")
|
|
||||||
else:
|
|
||||||
node = markdown.util.etree.Element('script')
|
|
||||||
node.set('type', 'math/tex')
|
|
||||||
node.text = markdown.util.AtomicString(m.group(3))
|
|
||||||
return node
|
|
||||||
|
|
||||||
def handle_match(m):
|
|
||||||
node = markdown.util.etree.Element('script')
|
|
||||||
node.set('type', 'math/tex; mode=display')
|
|
||||||
if '\\begin' in m.group(2):
|
|
||||||
node.text = markdown.util.AtomicString(m.group(2) + m.group(4) + m.group(5))
|
|
||||||
else:
|
|
||||||
node.text = markdown.util.AtomicString(m.group(3))
|
|
||||||
return node
|
|
||||||
|
|
||||||
inlinemathpatterns = (
|
|
||||||
markdown.inlinepatterns.Pattern(r'(?<!\\|\$)(\$)([^\$]+)(\$)'), # $...$
|
|
||||||
markdown.inlinepatterns.Pattern(r'(?<!\\)(\\\()(.+?)(\\\))') # \(...\)
|
|
||||||
)
|
|
||||||
mathpatterns = (
|
|
||||||
markdown.inlinepatterns.Pattern(r'(?<!\\)(\$\$)([^\$]+)(\$\$)'), # $$...$$
|
|
||||||
markdown.inlinepatterns.Pattern(r'(?<!\\)(\\\[)(.+?)(\\\])'), # \[...\]
|
|
||||||
markdown.inlinepatterns.Pattern(r'(?<!\\)(\\begin{([a-z]+?\*?)})(.+?)(\\end{\3})')
|
|
||||||
)
|
|
||||||
if not self.getConfig('enable_dollar_delimiter'):
|
|
||||||
inlinemathpatterns = inlinemathpatterns[1:]
|
|
||||||
for i, pattern in enumerate(inlinemathpatterns):
|
|
||||||
pattern.handleMatch = handle_match_inline
|
|
||||||
md.inlinePatterns.add('math-inline-%d' % i, pattern, '<escape')
|
|
||||||
for i, pattern in enumerate(mathpatterns):
|
|
||||||
pattern.handleMatch = handle_match
|
|
||||||
md.inlinePatterns.add('math-%d' % i, pattern, '<escape')
|
|
||||||
|
|
||||||
def makeExtension(*args, **kwargs):
|
|
||||||
return MathExtension(*args, **kwargs)
|
|
@@ -1,4 +1,4 @@
|
|||||||
pages:
|
nav:
|
||||||
- 主页: 'index.md'
|
- 主页: 'index.md'
|
||||||
- 目录:
|
- 目录:
|
||||||
- 简介: 'intro.md'
|
- 简介: 'intro.md'
|
||||||
@@ -100,4 +100,6 @@ extra_css:
|
|||||||
|
|
||||||
docs_dir: 'docs'
|
docs_dir: 'docs'
|
||||||
|
|
||||||
theme_dir: 'yeti'
|
theme:
|
||||||
|
name: null
|
||||||
|
custom_dir: 'yeti'
|
||||||
|
26
setup.py
26
setup.py
@@ -1,26 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
from distutils.core import setup
|
|
||||||
|
|
||||||
long_description = \
|
|
||||||
"""This extension adds math formulas support to Python-Markdown_
|
|
||||||
(works with version 2.6 or newer).
|
|
||||||
|
|
||||||
.. _Python-Markdown: https://github.com/waylan/Python-Markdown
|
|
||||||
|
|
||||||
You can find the source on GitHub_.
|
|
||||||
Please refer to the `README file`_ for details on how to use it.
|
|
||||||
|
|
||||||
.. _GitHub: https://github.com/mitya57/python-markdown-math
|
|
||||||
.. _`README file`: https://github.com/mitya57/python-markdown-math/blob/master/README.md
|
|
||||||
"""
|
|
||||||
|
|
||||||
setup(name='python-markdown-math',
|
|
||||||
description='Math extension for Python-Markdown',
|
|
||||||
long_description=long_description,
|
|
||||||
author='Dmitry Shachnev',
|
|
||||||
author_email='mitya57@gmail.com',
|
|
||||||
version='0.2',
|
|
||||||
url='https://github.com/mitya57/python-markdown-math',
|
|
||||||
py_modules=['mdx_math'],
|
|
||||||
license='BSD')
|
|
@@ -1,20 +1,20 @@
|
|||||||
{% if meta.source %}
|
{% if page.meta.source %}
|
||||||
<div class="source-links">
|
<div class="source-links">
|
||||||
{% for filename in meta.source %}
|
{% for filename in page.meta.source %}
|
||||||
<span class="label label-primary">{{ filename }}</span>
|
<span class="label label-primary">{{ filename }}</span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{{ content }}
|
{{ page.content }}
|
||||||
|
|
||||||
<div id="disqus_thread"></div>
|
<div id="disqus_thread"></div>
|
||||||
<script>
|
<script>
|
||||||
(function() {
|
(function() {
|
||||||
var d = document, s = d.createElement('script');
|
var d = document, s = d.createElement('script');
|
||||||
|
|
||||||
s.src = '//learnopengl-cn.disqus.com/embed.js';
|
s.src = '//learnopengl-cn.disqus.com/embed.js';
|
||||||
|
|
||||||
s.setAttribute('data-timestamp', +new Date());
|
s.setAttribute('data-timestamp', +new Date());
|
||||||
(d.head || d.body).appendChild(s);
|
(d.head || d.body).appendChild(s);
|
||||||
})();
|
})();
|
||||||
|
@@ -4,13 +4,12 @@
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
{% if page_description %}<meta name="description" content="{{ page_description }}">{% endif %}
|
{% if config.site_description %}<meta name="description" content="{{ config.site_description }}">{% endif %}
|
||||||
{% if site_author %}<meta name="author" content="{{ site_author }}">{% endif %}
|
{% if config.site_author %}<meta name="author" content="{{ config.site_author }}">{% endif %}
|
||||||
{% if canonical_url %}<link rel="canonical" href="{{ canonical_url }}">{% endif %}
|
{% if page.canonical_url %}<link rel="canonical" href="{{ page.canonical_url }}">{% endif %}
|
||||||
{% if favicon %}<link rel="shortcut icon" href="{{ favicon }}">
|
<link rel="shortcut icon" href="{{ base_url }}/img/favicon.ico">
|
||||||
{% else %}<link rel="shortcut icon" href="{{ base_url }}/img/favicon.ico">{% endif %}
|
|
||||||
|
|
||||||
<title>{% if page_title %}{{ page_title }} - {% endif %}{{ site_name }}</title>
|
<title>{% if page.title %}{{ page.title }} - {% endif %}{{ config.site_name }}</title>
|
||||||
|
|
||||||
<link href="{{ base_url }}/css/bootstrap-custom.min.css" rel="stylesheet">
|
<link href="{{ base_url }}/css/bootstrap-custom.min.css" rel="stylesheet">
|
||||||
<link href="{{ base_url }}/css/font-awesome-4.0.3.css" rel="stylesheet">
|
<link href="{{ base_url }}/css/font-awesome-4.0.3.css" rel="stylesheet">
|
||||||
@@ -57,7 +56,6 @@
|
|||||||
<script src="{{ base_url }}/js/bootstrap-3.0.3.min.js"></script>
|
<script src="{{ base_url }}/js/bootstrap-3.0.3.min.js"></script>
|
||||||
<script src="{{ base_url }}/js/highlight.pack.js"></script>
|
<script src="{{ base_url }}/js/highlight.pack.js"></script>
|
||||||
<script>var base_url = '{{ base_url }}';</script>
|
<script>var base_url = '{{ base_url }}';</script>
|
||||||
<script data-main="{{ base_url }}/mkdocs/js/search.js" src="{{ base_url }}/mkdocs/js/require.js"></script>
|
|
||||||
<script src="{{ base_url }}/js/base.js"></script>
|
<script src="{{ base_url }}/js/base.js"></script>
|
||||||
{%- for path in extra_javascript %}
|
{%- for path in extra_javascript %}
|
||||||
<script src="{{ path }}"></script>
|
<script src="{{ path }}"></script>
|
@@ -1,6 +1,6 @@
|
|||||||
{% if not nav_item.children %}
|
{% if not nav_item.children %}
|
||||||
<li {% if nav_item.active %}class="active"{% endif %}>
|
<li {% if nav_item.active %}class="active"{% endif %}>
|
||||||
<a href="{{ nav_item.url }}">{{ nav_item.title }}</a>
|
<a href="{{ nav_item.url|url }}">{{ nav_item.title }}</a>
|
||||||
</li>
|
</li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li class="dropdown-submenu">
|
<li class="dropdown-submenu">
|
||||||
|
@@ -12,7 +12,7 @@
|
|||||||
</button>
|
</button>
|
||||||
|
|
||||||
<!-- Main title -->
|
<!-- Main title -->
|
||||||
<a class="navbar-brand" href="{{ homepage_url }}">{{ site_name }}</a>
|
<a class="navbar-brand" href="{{ nav.homepage.url|url }}">{{ config.site_name }}</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Expanded navigation -->
|
<!-- Expanded navigation -->
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
</li>
|
</li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li {% if nav_item.active %}class="active"{% endif %}>
|
<li {% if nav_item.active %}class="active"{% endif %}>
|
||||||
<a href="{{ nav_item.url }}">{{ nav_item.title }}</a>
|
<a href="{{ nav_item.url|url }}">{{ nav_item.title }}</a>
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@@ -44,25 +44,25 @@
|
|||||||
<i class="fa fa-search"></i> 搜索
|
<i class="fa fa-search"></i> 搜索
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li {% if not previous_page %}class="disabled"{% endif %}>
|
<li {% if not page.previous_page %}class="disabled"{% endif %}>
|
||||||
<a rel="next" {% if previous_page %}href="{{ previous_page.url }}"{% endif %}>
|
<a rel="next" {% if page.previous_page %}href="{{ page.previous_page.url|url }}"{% endif %}>
|
||||||
<i class="fa fa-arrow-left"></i> 上一节
|
<i class="fa fa-arrow-left"></i> 上一节
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li {% if not next_page %}class="disabled"{% endif %}>
|
<li {% if not page.next_page %}class="disabled"{% endif %}>
|
||||||
<a rel="prev" {% if next_page %}href="{{ next_page.url }}"{% endif %}>
|
<a rel="prev" {% if page.next_page %}href="{{ page.next_page.url|url }}"{% endif %}>
|
||||||
下一节 <i class="fa fa-arrow-right"></i>
|
下一节 <i class="fa fa-arrow-right"></i>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{% if repo_url %}
|
{% if config.repo_url %}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ repo_url }}">
|
<a href="{{ config.repo_url }}">
|
||||||
{% if repo_name == 'GitHub' %}
|
{% if config.repo_name == 'GitHub' %}
|
||||||
<i class="fa fa-github"></i>
|
<i class="fa fa-github"></i>
|
||||||
{% elif repo_name == 'Bitbucket' %}
|
{% elif config.repo_name == 'Bitbucket' %}
|
||||||
<i class="fa fa-bitbucket"></i>
|
<i class="fa fa-bitbucket"></i>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ repo_name }}
|
{{ config.repo_name }}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
<div class="bs-sidebar hidden-print affix well" role="complementary">
|
<div class="bs-sidebar hidden-print affix well" role="complementary">
|
||||||
<ul class="nav bs-sidenav">
|
<ul class="nav bs-sidenav">
|
||||||
{% for toc_item in toc %}
|
{% for toc_item in page.toc %}
|
||||||
<li class="main {% if toc_item.active %}active{% endif %}"><a href="{{ toc_item.url }}">{{ toc_item.title }}</a></li>
|
<li class="main {% if toc_item.active %}active{% endif %}"><a href="{{ toc_item.url|url }}">{{ toc_item.title }}</a></li>
|
||||||
{% for toc_item in toc_item.children %}
|
{% for toc_item in toc_item.children %}
|
||||||
<li><a href="{{ toc_item.url }}">{{ toc_item.title }}</a></li>
|
<li><a href="{{ toc_item.url|url }}">{{ toc_item.title }}</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
Reference in New Issue
Block a user