Can anyone explain step-by-step how the as3isolib depth-sorts isometric objects?
- by Rob Evans
The library manages to depth-sort correctly, even when using items of non-1x1 sizes. I took a look through the code but it's a big project to go through line by line!
There are some questions about the process such as:
How are the x, y, z values of each object defined? Are they the center points of the objects or something else?
I noticed that the IBounds defines the bounds of the object. If you were to visualise a cuboid of 40, 40, 90 in size, where would each of the IBounds metrics be?
I would like to know how as3isolib achieves this although I would also be happy with a generalised pseudo-code version.
At present I have a system that works 90% of the time but in cases of objects that are along the same horizontal line, the depth is calculated as the same value.
The depth calculation currently works like this:
x = object horizontal center point
y = object vertical center point
originX and Y = the origin point relative to the object so if you want the origin to be the center, the value would be originX = 0.5, originY = 0.5. If you wanted the origin to be vertical center, horizontal far right of the object it would be originX = 1.0, originY = 0.5. The origin adjusts the position that the object is transformed from.
AABB_width = The bounding box width.
AABB_height = The bounding box height.
depth = x + (AABB_width * originX) + y + (AABB_height * originY) - z;
This generates the same depth for all objects along the same horizontal x.