官术网_书友最值得收藏!

Co-ordinate systems

We're using Direct3D to display our 2D world, which means we need to consider the differences between how we work with 3D and what we need for 2D, and adapt to make everything fit together. For our purposes DirectXTK will take care of most of this; however it's useful to know what's going on, and understand the concepts involved so that you can delve into advanced concepts in future to create some amazing visuals.

In 2D the world is represented as a Cartesian plane, with the X-axis representing the horizontal axis, and the Y-axis representing the vertical. Many 2D systems, including Direct3D and DirectXTK, position the co-ordinate (0, 0), also known as the origin, at the top-left corner of the screen.

2D and 3D

3D adds a third dimension, Z, to the mix, which represents the axis perpendicular to both X and Y, heading "away" from the viewer if you view the X/Y plane head on. When referring to the camera, this represents the depth of the image, and can be translated to the 2D world to add layering and depth between the flat images.

This brings us to another topic—cameras. A camera is a virtual representation of real life cameras; they handle defining what is actually rendered on screen, and where, allowing for us to easily move the view around without messing with the entire game world.

You may be used to cameras in 3D games that have perspective (objects get smaller, the further away they are). A projection is the transformation from a 3D world to a flat 2D world, which is often called screen space. A perspective projection allows us to turn the lines and shapes of the world into a flat image that conveys depth by angling lines towards the horizon to introduce perspective.

A cube in perspective (left) and orthographic (right) projections

The problem with using the perspective projection for 2D is that we may want our sprites to look 3D, but they contain no depth information. When rendered with sprites sitting behind them, they will look mismatched and wrong. This is where the Orthographic projection comes into play. An orthographic projection prevents perspective from entering the image and allows us to control the illusion of the depth in a way that fits with the 2D sprites we are using.

主站蜘蛛池模板: 台江县| 佛坪县| 巴塘县| 呈贡县| 高州市| 偃师市| 庆阳市| 壤塘县| 绍兴市| 定西市| 泉州市| 凤山县| 巴楚县| 缙云县| 菏泽市| 玛沁县| 府谷县| 建始县| 澜沧| 贵溪市| 当雄县| 搜索| 武陟县| 清新县| 南川市| 三原县| 扶风县| 都江堰市| 资源县| 通城县| 凤城市| 航空| 浦东新区| 汪清县| 手游| 舟曲县| 仙桃市| 宁河县| 香格里拉县| 巴东县| 乌拉特后旗|