How to draw 3D surfaces and hide invisible lines?

Does anyone know how to draw 3D surfaces and hide invisible lines?

I remember reading some code from an Apple II book, and it was only about 25 lines in BASIC, and it could display some 3D surfaces, such as a mountain or a shape that looks like ripples of water. At first, invisible lines were shown, but after adding a few lines of code, invisible lines also disappeared.

Does anyone know how to do this or know the resources on the Internet for this?

+3
source share
3 answers

It depends a little on how you draw the polygons. I would recommend reading a little about OpenGL or DirectX, as they are designed to solve many of these problems for you. If you do not want to use them directly, there are already many great engines built on top of these APIs.

Assuming you draw filled polygons (textured, solid, etc.), here are a few general algorithms you could use:

  • Sort the polygons away from the camera and first draw them, otherwise known as the Artists Algorithm . This method was used by many old 3D games, such as the classic Doom, which also used the BSP Tree for efficient sorting.

  • , Z-Buffering. 3D- OpenGL DirectX.

  • , , , .

+5

. , , , min max y x. , Bresenham, , , , max , min.

, . . , x y .

. , .

+4

If you build a triangular grid, then you need to make a selection for each triangle and not draw the edges of the triangles with the reverse. You calculate the normal value as the transverse product of two consecutive edges in a triangle.

If you want to build only a contour, you will draw only the edges that go between the triangle with the front surface and the triangle with the reverse.

Or you use OpenGL, turn on the depth buffer and forget about all the basic maths :-)

+2
source

Source: https://habr.com/ru/post/1709354/


All Articles