-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix depth sorting #9
Comments
You might want to look into the following answer by munificent on the gamedev stackexchange: http://gamedev.stackexchange.com/a/8355 |
@fplam been playing around with it, but the trick here is ordering planes. Choosing the nearest point rarely works. |
The latest patches – 0.1.2 and 0.1.3 – both contain improvements to Each Point is now assigned a depth, calculated by:
z is weighted to fix most arrangements where two planes come in contact at a right angle. You'll notice the "extrude" example on the homepage is now fixed (it used to have a bug, did you notice?) Happy to track down some more edge cases. Please report any funny rendering you come across. |
Cool. I guess there are always going to be edge cases, since filling canvas paths cannot be as accurate as pixel-by-pixel rendering with z-buffering. |
Sorry misclick, I write it again : I will PR this soon, with a drawing to explain in a simpler way |
Problem seems to be solved on my repo (even with jdan's temple from the gallery !) Examples : Edit : I just tested with chrome instead of firefox : it is much faster, but we can see a little bug with isomer3.html, I will watch that (probably another rounding problem) |
My current depth sorting implementation is incredibly naive. Essentially, when
Isomer.prototype.add
is given a shape, it first orders its faces, then draws them.Ordering the faces currently involves sorting them by the average distance of their points to the arbitrary point:
This fails for a number of reasons. Most notably, points located to the extreme left and right edges of the canvas (+x, -y) and (-x, +y) respectively, will be calculated to be further away than something close to the origin. Drawing shapes at these locations will cause their faces to be out of order.
Because of this limitation, drawing shapes with convex polygons as sides does not currently work, as you can see in the "star" example on the test page.
So, we need to implement some form of proper depth sorting. I imagine there are many neat tricks we can do with an isometric projection.
The text was updated successfully, but these errors were encountered: