'Diamond Java3D never outputs what's intended
I'm trying to do a Diamond Using Java3D, but no matter what I do, the result is never what is intended to be.
public class Tetrahedron extends IndexedTriangleArray {
public Tetrahedron() {
super(13, TriangleArray.COORDINATES | TriangleArray.NORMALS, 18);
//Base
setCoordinate(0, new Point3f(0, -1f, 0));
//Cantos
setCoordinate(1, new Point3f(1f, 0.5f, 1));
setCoordinate(2, new Point3f(1f, 0.5f, -1));
setCoordinate(3, new Point3f(-1f, 0.5f, -1));
setCoordinate(4, new Point3f(-1, 0.5f, 1));
//Feito
setCoordinate(5, new Point3f(-0.5f, 1f, 0.5f));
setCoordinate(6, new Point3f(0, 0.5f, 1f));
setCoordinate(7, new Point3f(0.5f, 1f, 0.5f));
//
setCoordinate(8, new Point3f(1f, 0.5f, 0f));
setCoordinate(9, new Point3f(0.5f, 1f, -0.5f));
//
setCoordinate(10, new Point3f(0f, 0.5f, -1f));
setCoordinate(11, new Point3f(-0.5f, 1f, -0.5f));
//
setCoordinate(12, new Point3f(-1f, 0.5f, 0f));
int[] coords = {0,1,2, 0,2,3, 0,3,4 0,4,5 ,0, 3,2,1 ,3,1,2};
float n = (float)(1.0/Math.sqrt(3));
setNormal(0, new Vector3f(n,n,-n));
setNormal(1, new Vector3f(n,-n,n));
setNormal(2, new Vector3f(-n,-n,-n));
setNormal(3, new Vector3f(-n,n,n));
setNormal(2, new Vector3f(n,n,-n));
setNormal(3, new Vector3f(n,-n,n));
int[] norms = {0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5};
setCoordinateIndices(0, coords);
setNormalIndices(0, norms);
}
}
I tried a bunch of code, some with almost the output that I wanted, but never the basic Diamond shape, the coordinates I believe are the way that a diamond shape works, soo probably the problem is on the normals. I know this must be a simple problem to resolve, but I'm new to Java3D and this problem is preventing me to continue my project.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
