Question

What would be the best approach for implementing a z-order system, where something like the following becomes possible:

There are 4 rectangles: A, B, C and D.

Rectangle A overlaps Rectangle B.

Rectangle B overlaps Rectangle C.

Rectangle C overlaps Rectangle D.

Rectangle D overlaps Rectangle A.

Just like a cardboard box. I believe it's called cyclic overlapping.

I know this is a wierd question, but I was just wondering... :)

Était-ce utile?

La solution

The thing about the cardboard box example is that the pieces of cardboard are not exactly aligned towards the camera. In essence it is a (rather flat) 3D structure of slightly tilted planes that overlap eachother. As far as cardboard boxes go they're also not planar but slightly bent in order to close the box. In MS-paint pseudo perspective:

enter image description here

This is possible in 3D by tilting the planes so that they overlap. This is a case where the painters algorithm fails, and is one of the reasons where the Z buffer comes in handy to resolve which of the object actually occludes the other.

If you are working in a purely 2D world and you cannot tilt the planes to achieve the pseudo-3D effect that you're after you would need to subdivide the planes and draw the overlapping parts using a different Z level than you would use for the rest of the box - essentially doing your own clipping.

You might be able to get by by doing some sort of Z-buffer trickery to emulate the same thing as well, but essentially you should use a 3D structure for what is a 3D problem.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top