After a few months of theory, Yunfeng decided to write a third person called an image engine that came into the fixed perspective. On the one side, I wrote the knowledge and experience I learned in practice to a friend who had the same goal; I hope that our game industry can keep up with the world as soon as possible.
I will design something called "Third Person" (hereinafter referred to as "Lace"), I want everyone to imagine what will be like. In "Genesis", "Xianjian Qi Chuan" is used in this The perspective and successful. The graphics engine they use is called Isometric Tile Engine in English. Tile translation is a brick, means that the scenes and characters in the game are described in one piece of bricks. Many of the RPGs, SLG games are like this. In terms of intuitive visual effects, two types, according to the general players, 90 degree perspective and oblique 45 degrees. Isometric form is usually mentioned 45 Viewing angle, ISOMETRIC, there is an isometric (crystal), alternative, etc., if you have played "Time and Space Legend", or "X-COM I / II" war game, see In the game, I will feel how accurately ISOMETRIC this word ;-) Because this word emphasizes the equal axis, ISOMETRIC does not have an explanation of 45 degrees (the choice of perspective, below There will be a detailed discussion); another 90 degree form, foreign name is Rectangular Tile Engine, Rectangular Tile English, Rectangular is the meaning of the right angle. This right-angle brick has a lot of benefits to the implementation of the procedure, the biggest is to block Calculated, the computer CPU / graphics speed is still very slow, even the only manifestation means of RPG. For the current game, I feel that it is not understandable. Is it a matter of programmers? No matter how powerful The performance and real feeling of 90 degrees of plane world is far from satisfying the current players.
Here, there is no use of ISOMETRIC or TILE, because the expression of the performance I have different is different, except for the same side of the ISOMETRIC, in the internal data structure, and implementation methods, sequential sequence, occlusion calculation, etc. They will be exceeded. It will be used in size limits, angular limits, objects and unregistered scenes, and the direction of the character movement is also arbitrary, these seem to be more close to 3D, but my purpose is to avoid and polygons , Map, etc., There is an ideal efficiency on the computer in the medium-grade computer, and make more CPU time to complete a more complex time-consuming AI processing, and generate image effects. BTW, I think this design Can be called "Leaning View", do you have a professional translation?
Yunfeng's work has just begun, writing this series of articles and engine development basic synchronization, and there is no practical experience, so the error is inevitable, the article may also repeatedly revise even the previous things all. All of them. All of them. Viewpoint, algorithm belongs to Yunfeng personal opinion, welcome to criticize and correct, you can't move, say that I am misunderstanding ;-)
OK. Tone less, let us start moving the first step.
Perspective selection and coordinate transformation
Treatment of a slant angle image, a big difficulty in programming is that the coordinates in its world are reflected in the 2D screen. The x-axis in the ISOMETRIC TILE game is generally from the upper right, along the 35 degree angle. The direction of the left and right (if it is a 45-degree perspective), each Tile looks like a diamond on the screen, the entire Tile is a six-way body (see the right picture). The x-axis and Y axes are 90 degrees. This is a good Angle, but when designing Isometric Tile, a better angle is 26 degrees (Arc Tan 0.5), the corresponding perspective is 30 degrees. It looks more flat, 32:15 Tile Design is visible everywhere (such as left), Because 32 pairs of computer processing can be a very convenient value. (Between view, here, the angle between the line and the horizontal plane, especially, all the views of the game are top view, if you need to take the coordinate axis horizontally The angle conversion is a perspective, and it can take TG, then arc sin, in the design of ISOMETRIC TILE Engine, is not important, the program code is basically the same, only for the art. But after these days Reflections, I found that if the angle (non-Tile "engine design can use a relatively suitable angle, the speed of the engine will increase, this most suitable angle is 37 degrees (Arc Tan 0.75) perspective approximately 48 degrees At this point, the X, Y axis, and the X, Y-axis of the game in the game are just the relationship between the three-strand five stringed five, which provides acceleration operations in the work we need. Possible ;-) A unit in the X-axis in the game, equivalent to 0.8 units of the screen X, the change of the 0.6 units of Y. A unit in the Y-axis in the game, equivalent to the screen X - 0.8 units, Y The 0.6 unit changes. That is to say that our sprite moves AX by in the game, moving 0.8 (ab) x 0.6 (A B) on the screen, let us take a look at the screen, if we choose 640x480 Resolution. AHA, 640: 480 = 4: 3 There is such a good thing;) So a horizontal line in the game coordinate system is just the diagonal of the screen, which makes it to determine whether a coordinate point in the game world is The screen area is very simple ;-) Please see the left, the outer rhombus frame is a rectangular portion in the game world, the middle rectangle is indicated by the screen area. Our screen coordinates from the upper left corner (0, 0) to the right The lower corner (639, 479) is aware of the problem, The coordinate origin of the game world is also set on the top left corner of the screen, OK, now to count the coordinates of the game world in the game of the four corners of the screen. Due to the screen diagonal length 800, the coordinates in the upper right corner are (400, -400). ); The lower left corner is (400, 400); the lower right corner is (800, 0). Determine if a point is based on 0.900 ≤ x y ≤ 800, it is as simple as it is.
Finally talk about the optimization of the engine design, we use the most operations in the coordinate transformation, in addition to 5. The division command is the slowest, is there a way to optimize? The value of our role is not a big situation. The fastest speed can be replaced. That is, with * 205/1024 instead of / 5 and 205 = (1 5 * 8) * 5, 386 CPU calculations * 5 * 8, etc., you can use the Lea directive, very fast. Right You can replace / 1024, this doesn't have to say more ;-) Of course, the current C language compiler will automatically open to the maximum, you will automatically make you optimize, don't write embedded compilation. If I really want to write yourself, probably so many lines:
Mov EDX, EAX is divided by
Lea Eax, [EDX 4 * EDX]; EAX = 5 * a
Lea Eax, [EDX 8 * EAX]; EAX = A 8 * EAX = 41 * a
Lea Eax, [EAX 4 * EAX]; EAX = 5 * EAX = 205 * a
SAR EAX, 10; EAX = 205 * a / 1024
Note: If you write with a C language, it is best to write / 1024 directly into >> 10, although / 1024 will be optimized to be right-shifted, but the division is rounded, so the compiler is optimized, will take more things. And there are several instructions.
Is concerned about the accuracy of calculation? It doesn't matter, 205/1024 = 0.200195, a point has a 0.000195 error, so even if it accumulates to 800 points (the diagonal of the screen is the longest line) is also 0.17 Point error, and the coordinates on the screen are integers, so there is no impact. You can easily verify, even if you use 1280x1024, there is no problem.