3D Math Primer for Game Programmers (Coordinate Systems)

In this article, I would like to provide a brief math primer for people who would like to get involved in game programming.  This is not an exhaustive explanation of all the math theory that one will have to know in order to be a successful game programmer, but it’s the very minimum amount of information that is necessary to know before you can begin as a game programmer.

This article assumes you have a minimum understanding vectors, and matrices.  I will simply show applications of vectors and matrices and how they apply to game programming.

Coordinate Systems

Before we can talk about transformations, we must make a formal definition of what our coordinate system is.  The default coordinate system used by DirectX is a left-handed coordinate system. The default coordinate system used by OpenGL is a right-handed coordinate system.

The easiest way to remember what coordinate system you are using is to use your hands.  If you point your thumb, your index finger, and your middle finger orthogonal to each other, then each finger will point in the direction of a positive cardinal axis in your coordinate space.  Using your left hand, your thumb points to the right (the  axis), your index finger points up (the  axis), and your middle finger points away from you (the  axis).

Using your right-hand, your thumb (the  axis) and your index finger (the  axis) still point in the same direction, but the middle finger (the  axis) points in the opposite direction.  If we rotated our hand around the index finger (the  axis) in order to get your thumb to point to the right, then your middle finger (the  axis) would be pointing towards you.

Another important note to remember is the direction of rotation. If you point your thumb in the positive direction of the axis of rotation and curl your fingers around that imaginary axis, your fingers will curl in the positive direction of rotation.  If you do this on your left hand your fingers will curl in a clockwise direction when looking down at your thumb.  However if you do this on your right hand, your fingers will curl in a counter-clockwise direction when looking down at your thumb.

This can be seen in the images below:

Left-hand Rule

Left-hand Rule

Right-hand Rule

Right-hand Rule

The following table shows the direction of rotation for positive and negative rotations depending on the handedness of the coordinate system.

  Left-hand coordinate system Right-hand coordinate system
Viewed From Positive Rotation Negative Rotation Positive Rotation Negative Rotation
The negative end looking toward the positive end Counter-Clockwise Clockwise Clockwise Counter-Clockwise
The positive end looking toward the negative end Clockwise Counter-Clockwise Counter-Clockwise Clockwise

Coordinate Spaces

In a 3D game engine, we usually deal with several different coordinates spaces.  Among the most commonly used spaces are Object space, World space, Inertial space (惯性空间), and Camera space.

Object Space

In object space, also known as local space, or modeling space, an object’s vertices are expressed relative to the object that they describe.  That is, the way the artist intended for them to be displayed if you didn’t move the object from the origin.

The image below shows an example of an object in object space.  As you can see from the image, the object is placed at it’s relative origin.

Local space object

Object shown in local space.

World Space

The world coordinate space is the global coordinate space for which all other object spaces are described.  The image below shows an object described in world space.  Notice how the object’s world transformation places it away from the world-origin by some translation, and rotation.

World Space

Object shown in world space.

Inertial Space

The inertial space is the “halfway” space between object space and world space.  The origin of inertial space has the same origin as object space, and the axes of inertial space are parallel to that of the world space axes.

To transform a point from object space to inertial space requires only a rotation and to transform a point from inertial space to world space requires only a translation.

The image blow shows an example of inertial space.

Object show in inertial space.

Camera Space

Camera space is the coordinate space that is associated with the observer.  Camera space is considered to be the origin and orientation of what we are looking at.  The camera’s coordinate axis usually assume the positive  axis points right, the positive axis points up, and in a left-handed coordinate system, the positive  axis points forward, or at the scene.  In a right-handed coordinate system, the  axis is reversed, so the negative  axis points forward, or at the object in our scene.  A more common name for these camera axes are the “Right”, “Up”, and “At” axes.

The camera space transformation together with the projection transformation is useful for answering such questions as:

  1. Is an object completely in view of the camera, partially in view, or not in view at all,
  2. Is one object closer to the camera than the other,
  3. Is an object directly in front of, above, below, to the left, or to the right of the camera.

Combining Coordinate Spaces

In 3D computer graphics, coordinate spaces are described using a homogeneous coordinate system.  A homogeneous coordinate system allows us to represent all of our affine transformations (translation, rotation, scale, and perspective projection) in a similar way so they can easily be combined into a single representation.

Any number coordinate spaces can be combined using matrix multiplication which results in a single matrix that can be applied to all the vertices of an object.

Even multiple world coordinate spaces can be combined in order to derive a final coordinate space that describes the location of all of our vertices in an object.  This is useful for nested coordinate spaces where the position of an object is expressed relative to a “parent” object.  When the parent object’s world transform is changed, the transform of the child object is also changed implicitly.  Using this method, complex scenes can be constructed from several smaller scenes and placed into the larger scene to create a complete world.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 《3D数学基础:图形与游戏开发(英文版)pdf》是一本以图形和游戏开发为背景的数学教材。这本书主要介绍了在图形和游戏开发中所需的基本数学概念和技巧。 首先,这本书详细介绍了三维几何学的基本原理。它讲解了点、向量和矩阵等基本概念,以及它们在三维坐标系中的表示和操作。读者将学习如何使用三维几何学来描述和变换图形对象。 此外,该书还介绍了常见的三维变换,包括平移、旋转和缩放等。它解释了这些变换是如何通过矩阵乘法来实现的,并且给出了实际应用的示例。 另外,书中还介绍了向量和矩阵运算的常见技巧,如点积、叉积和矩阵逆运算等。这些概念在图形和游戏开发中使用频繁,对于处理光照和碰撞检测等问题非常重要。 此外,该书还涵盖了一些高级主题,如三维投影、三角函数和曲线插值等。这些主题对于实现更复杂的图形效果和动画很有帮助。 总的来说,《3D数学基础:图形与游戏开发(英文版)pdf》是一本非常实用的数学教材,适合对图形和游戏开发感兴趣的读者。通过学习这本书,读者将建立起在图形和游戏开发中所需的数学基础,并能够应用这些知识来实现各种图形效果和游戏功能。 ### 回答2: 《3D数学基础:图形和游戏开发(英文版)PDF》是一本关于计算机图形学和游戏开发中的3D数学入门手册。在此书中,作者详细介绍了各种与3D图形学相关的数学原理和技术。 该书的主要内容包括向量、矩阵、变换、投影、相机、光照、纹理、几何形状等方面的基础知识。通过学习这些数学概念,读者可以更好地理解和掌握3D图形的建模、渲染和动画等技术。 这本书突出了实践性和应用性。每个数学概念都配有详细的解释、示例和应用,读者可以通过实际的编程实践来加深对数学原理的理解。此外,该书还提供了大量的习题和练习题,读者可以通过解答这些问题来加强自己的数学能力和应用能力。 《3D数学基础:图形和游戏开发(英文版)PDF》适合初学者和有一定编程基础的读者阅读。对于计算机图形学和游戏开发的爱好者和从业者来说,掌握3D数学是非常重要的基础。 总之,这本书是一本介绍和应用3D图形学中数学原理和技术的入门手册。读者可以通过学习这本书来建立起对3D数学的基本理解,为进一步深入学习和应用图形学和游戏开发打下坚实的基础。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值