Hello.
I'm making a 3D rendering engine that doesn't use sprites, only draws on graphics.
Three points of each triangle is represented by three Vector3D objects.
To reorder drawing order of every triangle, I get the Z position of the Vector3D with the furthest Z value (biggest Z value), and the one with the closest Z value (smallest) then add them up, divide them into two (to get the average Z) then sort the array containing the triangles by the average Z values. Like:
1, 2, 3 -> 1 + 3 -> 4 -> 4 / 2 -> 2.
This way, I can start drawing from the furthest triangle and end up with the closest one. But sometimes there are bugs, where some triangles that should be behind others show up in front of them. How shall I fix this? Is there any other efficient and easy-to-understand way to reorder the drawing order?
Thanks! ![]()
North America
Europe, Middle East and Africa
Asia Pacific