Pseudo 3d Isometric view


Today i'd like to demonstrate another nifty use for pseudo 3d pixel manipulation - 3d isometric view!
We've all seen 2d games using isometric view, mostly popular in early strategy games like Age of Empires, or StarCraft. Rotating tiles 45 degrees creates the illusion of depth, which brings us closer to a 3d feeling.
However, using pixel manipulation and simple geometry we can do better and create a much richer sense of 3d.
The attached video shows a map created completely with 2d pixel manipulation, although it appears 3d. The effect is achieved by creating each image (building and tree) like a cake - layer by layer, with each layer getting a slight offset on the Y axis (known as sprite stacking). For example, the bottom layer of the tree will be drawn at its determined x and y, and the following layer will be at (x, y - 2).
Our tree is made up of 10 layers of stump, and 4 layers of green leaves. Our building uses 20 layers, some consisting of the same image, and others of different ones.
All assets are placed on screen, (drawn pixel by pixel) and rotated around the center axis of the screen. The player (line in the center) can move around, and rotate, and the world will always rotate around him.
Every time we draw to the canvas we need to remember to sort all our asset according to their y axis (which changes as the player rotates.)
Assets higher on the screen need to be drawn first as they are supposed to be further away, and then drawn over by closer assets obstructing them.
Another issue is the rotation of each asset. I didn't want to fiddle around with different textures and built in capabilities like image rotation, so i decided to go old school and rotate the image pixel by pixel. It's a rather neat technique, in which you calculate the distance of each pixel in the source image (the stump for example) from its center, and use that as a radius. You then "rotate" the image and figure out where to draw the new pixel in the output canvas using the color for the original pixel.
I should note that this approach is rather heavy on the cpu. There are ALOT of loops to create each layer, and even my Mac running c++ got tired when too many objects were rendered at once. However, there are games out there using it.

תגובות

פוסטים פופולריים מהבלוג הזה

Thoughts on HTML5, a Flash Developers hopeless rant

Veroni Noise