TheGhastModding

Normals

Feb 6th, 2018
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.45 KB | None | 0 0
  1.     private void calculateNormals() {
  2.         normals = new Vector[countSides()];
  3.         Vector u;
  4.         Vector v;
  5.         for(int i = 0; i < normals.length; i++) {
  6.             //U = y - x
  7.             u = vertices[i + 1].substract(vertices[i]);
  8.             //V = z - x;
  9.             v = vertices[i + 2].substract(vertices[i]);
  10.             /*
  11.             Nx = Uy*Vz - Uz*Vy
  12.             Ny = Uz*Vx - Ux*Vz
  13.             Nz = Ux*Vy - Uy*Vx
  14.              */
  15.             normals[i] = new Vector(u.y * v.z - u.z * v.y, u.z * v.x - u.x * v.z, u.x * v.y - u.y * v.x);
  16.         }
  17.     }
Advertisement
Add Comment
Please, Sign In to add comment