T
Thorsten Kiefer
Hi,
I wrote normal calculator for IndexTriangleFanStrip, but it calculates
partially wrong normals, can anyone help me with that ?
public static Vector3f[] computeNormals(Point3f[] coords, int[]
coordIndices, int[] stripCounts) {
Vector3f[] normals = new Vector3f[coords.length];
for (int i = 0; i < normals.length; ++i) {
normals = new Vector3f();
}
Vector3f[] coordVs = new Vector3f[coords.length];
for (int i = 0; i < coordVs.length; ++i) {
coordVs = new Vector3f(coords);
}
int stripStart = 0;
for (int i = 0; i < stripCounts.length; ++i) {
Vector3f x0 = coordVs[coordIndices[stripStart]];
for (int j = 2; j < stripCounts; ++j) {
Vector3f x1 = coordVs[coordIndices[stripStart + j]];
Vector3f x2 = coordVs[coordIndices[stripStart + j - 1]];
Vector3f d1 = new Vector3f();
Vector3f d2 = new Vector3f();
Vector3f cp = new Vector3f();
d1.sub(x1, x0);
d2.sub(x2, x0);
cp.cross(d1, d2);
normals[coordIndices[stripStart]].add(cp);
normals[coordIndices[stripStart + j]].add(cp);
normals[coordIndices[stripStart + j - 1]].add(cp);
}
stripStart += stripCounts;
}
for (int i = 0; i < normals.length; ++i) {
normals.normalize();
}
return normals;
}
Best Wishes
Thorsten
I wrote normal calculator for IndexTriangleFanStrip, but it calculates
partially wrong normals, can anyone help me with that ?
public static Vector3f[] computeNormals(Point3f[] coords, int[]
coordIndices, int[] stripCounts) {
Vector3f[] normals = new Vector3f[coords.length];
for (int i = 0; i < normals.length; ++i) {
normals = new Vector3f();
}
Vector3f[] coordVs = new Vector3f[coords.length];
for (int i = 0; i < coordVs.length; ++i) {
coordVs = new Vector3f(coords);
}
int stripStart = 0;
for (int i = 0; i < stripCounts.length; ++i) {
Vector3f x0 = coordVs[coordIndices[stripStart]];
for (int j = 2; j < stripCounts; ++j) {
Vector3f x1 = coordVs[coordIndices[stripStart + j]];
Vector3f x2 = coordVs[coordIndices[stripStart + j - 1]];
Vector3f d1 = new Vector3f();
Vector3f d2 = new Vector3f();
Vector3f cp = new Vector3f();
d1.sub(x1, x0);
d2.sub(x2, x0);
cp.cross(d1, d2);
normals[coordIndices[stripStart]].add(cp);
normals[coordIndices[stripStart + j]].add(cp);
normals[coordIndices[stripStart + j - 1]].add(cp);
}
stripStart += stripCounts;
}
for (int i = 0; i < normals.length; ++i) {
normals.normalize();
}
return normals;
}
Best Wishes
Thorsten