Author Topic: How does JPCT-AE Vertex works on Object3D.addTriangle(...)?  (Read 5039 times)

Offline Hellfire

  • byte
  • *
  • Posts: 3
    • View Profile
How does JPCT-AE Vertex works on Object3D.addTriangle(...)?
« on: November 25, 2022, 03:45:26 pm »
Hello friends. How does JPCT-AE Vertex works on Object3D.addTriangle(...)?
Code: [Select]
public static Object3D createCube(float scale) {
 Object3D o = new Object3D(12);
 float size = scale / 2;

// FRONT
 o.addTriangle(new SimpleVector(-size, size, size), new SimpleVector(-size, -size, size), new SimpleVector(size, size, size));
 o.addTriangle(new SimpleVector(size, size, size), new SimpleVector(size, -size, size), new SimpleVector(-size, -size, size));

// BACK
 o.addTriangle(new SimpleVector(-size, size, -size), new SimpleVector(-size, -size, -size), new SimpleVector(size, size, -size));
 o.addTriangle(new SimpleVector(size, size, -size), new SimpleVector(size, -size, -size), new SimpleVector(-size, -size, -size));

// LEFT
 o.addTriangle(new SimpleVector(-size, size, size), new SimpleVector(-size, -size, size), new SimpleVector(-size, size, -size));
 o.addTriangle(new SimpleVector(-size, size, -size), new SimpleVector(-size, -size, -size), new SimpleVector(-size, -size, size));
 
// RIGHT
 o.addTriangle(new SimpleVector(size, size, size), new SimpleVector(size, -size, size), new SimpleVector(size, size, -size));
 o.addTriangle(new SimpleVector(size, size, -size), new SimpleVector(size, -size, -size), new SimpleVector(size, -size, size));

// UPPER
 o.addTriangle(new SimpleVector(size, size, size), new SimpleVector(-size, size, size), new SimpleVector(size, size, -size));
 o.addTriangle(new SimpleVector(size, size, -size), new SimpleVector(-size, size, -size), new SimpleVector(-size, size, size));

// LOWER
 o.addTriangle(new SimpleVector(size, -size, size), new SimpleVector(-size, -size, size), new SimpleVector(size, -size, -size));
 o.addTriangle(new SimpleVector(size, -size, -size), new SimpleVector(-size, -size, -size), new SimpleVector(-size, -size, size));
 return o;
}
Result:
« Last Edit: November 25, 2022, 03:53:01 pm by Hellfire »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How does JPCT-AE Vertex works on Object3D.addTriangle(...)?
« Reply #1 on: November 26, 2022, 09:31:27 pm »
Order matters here. jPCT culls away back faces (unless you disable this with setCullling(), but the lighting will be wrong in this case). What is a back face and what isn't is defined by the order of the vertices in a triangle. In this case, reverse the order of the vertices for the faces that aren't visible and they should show up.