博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
3D Math Primer for Game Programmers (Coordinate Systems)
阅读量:2442 次
发布时间:2019-05-10

本文共 6122 字,大约阅读时间需要 20 分钟。

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

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.

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.

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.

转载地址:http://npiqb.baihongyu.com/

你可能感兴趣的文章
计算机组成原理实验 ram_从理论上讲,您可以在64位计算机中放置的RAM最大数量是多少?
查看>>
多线程计算多分批计算_如何在Excel 2013中更改自动计算和多线程功能
查看>>
facebook浏览器插件_Facebook容器将Facebook与Firefox浏览器的其余部分隔离开
查看>>
从iphone复制视频报错_如何在iPhone上复制照片和视频
查看>>
自定义生成excel模板_如何在Excel中创建自定义模板
查看>>
此乃谎言_停止相信电视的谎言:关于“增强”图像的真实真相
查看>>
java 初学者_初学者:如何在Outlook 2013中创建,管理和共享日历
查看>>
word 禁用dtd_如何清除或禁用Microsoft Word 2016中的最近文档列表
查看>>
如何在Microsoft Word中使用Excel样式的电子表格
查看>>
chromecast 协议_如何解决常见的Google Chromecast问题
查看>>
谷歌浏览器运行缓慢_为什么新的Google地图在我的计算机上运行缓慢得难以忍受?
查看>>
mxn插头_如何设置Eufy智能插头
查看>>
如何在OS X和Android 5.0设备之间使用蓝牙文件传输
查看>>
homepod_设置HomePod时如何修复空白屏幕
查看>>
pc适配屏幕_如何拍摄PC游戏的屏幕截图
查看>>
macos 清空dns缓存_如何在macOS上重置DNS缓存
查看>>
nest keyword_如何修复烦人的Nest安全通知
查看>>
ov2640板球跟不上_如何解决板球无线上的Android MMS问题
查看>>
mac恢复iphone_什么是苹果公司的“安全区域”?它如何保护我的iPhone或Mac?
查看>>
widows apps_Apps键位于标准的面向Microsoft的键盘上的什么位置?
查看>>