-6

I want to fill my cube. I found back-face culling algorithm. Can you explain me how it works? I have 8 points in vector:

CHECK HERE

Maybe you know another easier algorithm or explain me what I should do with back-face culling?

(wallX[0] - point 0; wallX[1] - point 1; wallX[2] - point 2 from image)

Code for fist wall:

x1[0]=wallX[1]-wallX[0];
y1[0]=wallY[1]-wallY[0];
z1[0]=wallZ[1]-wallZ[0];

x2[0]=wallX[2]-wallX[0];
y2[0]=wallY[2]-wallY[0];
z2[0]=wallZ[2]-wallZ[0];

x3[0]=0;
y3[0]=0;
z3[0]=1000;

wall1={y2[0]*z1[0]-z2[0]*y1[0], z2[0]*x1[0]-x2[0]*z1[0], x2[0]*y1[0]-y2[0]*x1[0]};
wall1*={X3, Y3, Z3};
if(wall1[2]>0) cout<<"wall is watching"<<endl;
Donald Duck
  • 8,409
  • 22
  • 75
  • 99
urusmi
  • 1
  • 1
  • Have you tried researching back-face culling yourself before posting here?? – xander Aug 15 '17 at 09:17
  • What are you using to render the cube? Usually OpenGL or DirectX have already multiple culling algorithms included, you don't have to write it yourself. – xander Aug 15 '17 at 09:27
  • I can't use OpenGL or DirectX, I must write algorithm to fill my cube. I must write it at myself. – urusmi Aug 15 '17 at 09:28
  • Possible duplicate of [Algorithm to fill triangle](https://stackoverflow.com/questions/39038505/algorithm-to-fill-triangle) – Spektre Aug 23 '17 at 11:51

1 Answers1

2

Presumably, you want to render the cube as an opaque solid.

This is indeed done by painting the faces, in such a way that you see the faces closer to the viewer.

I assume that

  • you have a polygon painting algorithm,
  • you are able to compute the color/shading to assign to every face.

You can resort to two methods:

  • the painter's algorithm, i.e. painting all faces from back to front. You can achieve this by sorting the faces on the depth coordinate of the closest vertex of each face. This is easy to do but a little inefficient as you will paint six faces when three are enough.

  • backface culling, i.e. ignoring the faces that have the depth component of their normal vector pointing to the rear. just a little of vector calculus.