温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Chapter 4. Math for 3D Graphics(3D图形中的数学)

发布时间:2020-03-04 23:17:31 来源:网络 阅读:431 作者:萌谷王 栏目:游戏开发

周一到周五,每天一篇,北京时间早上7点准时更新~

What You’ll Learn in This Chapter(本章你将会学到啥)

What a vector is, and why you should care about them(什么是向量以及为什么你需要注意他们)
What a matrix is, and why you should care more about them(什么是矩阵以及为什么你需要更注意它们)
How we use matrices and vectors to move geometry around(我们如何使用矩阵和向量来移动几何物体)
What the OpenGL conventions and coordinate spaces are(OpenGL中的转换以及坐标空间是啥)
So far, you have learned to draw points, lines, and triangles and have written simple shaders that pass your hard-coded vertex data through unmodified(现在,你已经学过了如何绘制点、线以及三角形,并且我们写了一些简单的shader,它们不对数据进行修改,仅仅是起到了在图形管线中传递数据的作用). We haven’t really been rendering in 3D—which is odd for a book on 3D graphics!(我们还没有真正的渲染3D的东西,这对于一本3D图形的书来说不是很奇怪吗) Well, to turn a collection of shapes into a coherent scene, you must arrange them in relation to one another and to the viewer(然而,要有条理的去在3D场景中组织物体,你必须管理他们之间的相对关系以及和摄像机的关系). In this chapter, you start moving shapes and objects around in your coordinate system(在本小节,你将开始在你的坐标系统中移动物体). The ability to place and orient your objects in a scene is a crucial tool for any 3D graphics programmer(对于3D程序员来说,在场景中去放置和旋转物体的能力是非常关键的). As you will see, it is actually convenient to describe your objects’ dimensions around the origin and then transform the objects into the desired positions(你将会看到,去定义物体的维度以及控制物体的位置还是比较容易的)

Is This the Dreaded Math Chapter?(这是一个狗带的数学章节吗)

In most books on 3D graphics programming, yes, this would be the dreaded math chapter(在大多数3D图形书籍里,确实,这就是一章狗带的数学内容). However, you can relax; we take a more moderate approach to these principles than some texts(不过,你可以放轻松,我们将使用一些更舒适的手段来讲解这些原理而不是紧靠文字描述)

One of the fundamental mathematical operations that will be performed by your shaders is the coordinate transform, which boils down to multiplying matrices with vectors and with each other(最基本的数学操作中的一个就是你会在shader中用到的坐标系转换,它涉及到矩阵与矩阵以及矩阵与向量的乘法). The keys to object and coordinate transformations are two matrix conventions used by OpenGL programmers(对于OpenGL程序员来说,坐标系转换的关键在于两个矩阵). To familiarize you with these matrices, this chapter strikes a compromise between two extremes in computer graphics philosophy(为了让你熟悉 这些矩阵,本章节将采用计算机图形学中两种极端 思路的这种方案来进行讲解). On the one hand, we could warn you, “Please review a textbook on linear algebra before reading this chapter.”(一方面,我们会警告你说,请在阅读本章之前,先看一看线性代数的 书) On the other hand, we could perpetuate the deceptive reassurance that you can “learn to do 3D graphics without all those complex mathematical formulas.”(另一方面,我们也会不断的告诉你,即便没有那些复杂的数学理论,你也可以学会3D图形学) But we don’t agree with either camp(但是,我们实际上两边都不同意)

In reality, you can get along just fine without understanding the finer mathematics of 3D graphics, just as you can drive your car every day without having to know anything at all about automotive mechanics and the internal combustion engine(实际上,你可以在不必精通3D数学的情况下,很好的处理3D编程问题,就像你不必懂什么汽车生产以及发动机的原理就能开车一样). But you had better know enough about your car to realize that you need an oil change every so often, that you have to fill the tank with gas regularly, and that you must change the tires when they get bald(但是你最好是更多的了解你的车子,这样你就可以知道什么时候该加油了 ,什么时候该打气了). This knowledge makes you a responsible (and safe!) automobile owner(这些知识能让你更好的玩转你的车子). If you want to be a responsible and capable OpenGL programmer, the same standards apply(如果你希望变成一个更强的OpenGL程序员,道理是一样的). You need to understand at least the basics so you know what can be done and which tools best suit the job(你至少需要了解最基本的数学,这样你才能知道你可以做什么以及什么工具是最适合你的项目的). If you are a beginner you will find that, with some practice, matrix math and vectors will gradually make more sense, and you will develop a more intuitive (and powerful) ability to make full use of the concepts we introduce in this chapter(如果你是一个新手,你将会发现,随着不断的练习,你将会得到更多的矩阵以及向量方面的体会,并且你将能更好的去理解我们本章节提到的这些概念)

So even if you don’t already have the ability to multiply two matrices in your head, you need to know what matrices are and how they serve as the means to OpenGL’s 3D magic(所以,即便你不知道如何计算矩阵的乘法,你需要知道什么是矩阵,以及他们在OpenGL中的意义). But before you go dusting off that old linear algebra textbook (doesn’t everyone have one?)(但是在你开始再次翻开你的线性代数课本之前,不要害怕:因为我们的sb7库里面应包含了一个叫vmath的组件,它能很好的帮你解决数学计算方面的问题), have no fear: The sb7 library has a component called vmath that contains a number of useful classes and functions that can be used to represent and manipulate vectors and matrices. They can be used directly with OpenGL and are very similar in syntax and appearance to GLSL—the language you’ll be writing your shaders in(他们可以像你即将在shader中使用矩阵的方式一样使用). So, you don’t have to do all your matrix and vector manipulation yourself, but it’s still a good idea to know what they are and how to apply them(所以你并不需要自己亲手实现所有这些数学计算,但是知道怎么实现这些数学计算以及如何应用他们任然是值得你努力的方向). See—you can eat your cake and have it, too!

本日的翻译就到这里,明天见,拜拜~~

第一时间获取最新桥段,请关注东汉书院以及图形之心公众号

东汉书院,等你来玩哦

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI