c++ - Filling a cube (back-face culling algorithm)? -


i want fill cube. found back-face culling algorithm. can explain me how works? have 8 points in vector:

check here

maybe know easier algorithm or explain me should back-face culling?

(wallx[0] - point 0; wallx[1] - point 1; wallx[2] - point 2 image)

code 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 watching"<<endl; 

presumably, want render cube opaque solid.

this indeed done painting faces, in such way see faces closer viewer.

i assume that

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

you can resort 2 methods:

  • the painter's algorithm, i.e. painting faces front. can achieve sorting faces on depth coordinate of closest vertex of each face. easy little inefficient paint 6 faces when 3 enough.

  • backface culling, i.e. ignoring faces have depth component of normal vector pointing rear. little of vector calculus.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -