slightly improved sphere generation
All checks were successful
Gitea Actions Demo / Scan the project (push) Successful in 24s
All checks were successful
Gitea Actions Demo / Scan the project (push) Successful in 24s
This commit is contained in:
@ -24,24 +24,26 @@ namespace Nebulix.Rendering
|
||||
|
||||
public void CalculateNormals()
|
||||
{
|
||||
// normals = new Vector3D<float>[vertices.Length];
|
||||
// for (int j = 0; j < vertices.Length; j++)
|
||||
// {
|
||||
// normals[j] = Vector3D<float>.Zero;
|
||||
// }
|
||||
|
||||
// return;
|
||||
for (int i = 0; i < indices.Length; i += 3)
|
||||
{
|
||||
Vector3D<float> a = vertices[indices[i]];
|
||||
Vector3D<float> b = vertices[indices[i + 1]];
|
||||
Vector3D<float> c = vertices[indices[i + 2]];
|
||||
uint i0 = indices[i];
|
||||
uint i1 = indices[i+1];
|
||||
uint i2 = indices[i+2];
|
||||
Vector3D<float> v0 = vertices[i0];
|
||||
Vector3D<float> v1 = vertices[i1];
|
||||
Vector3D<float> v2 = vertices[i2];
|
||||
|
||||
Vector3D<float> normal = Vector3D.Cross(b-a, c-a);
|
||||
Vector3D<float> normal = Vector3D.Cross(v1-v0, v2-v0);
|
||||
// Commenting this out, will result in the normals being weighted based on the triangle area
|
||||
normal = Vector3D.Normalize(normal);
|
||||
normals[indices[i]] = normal;
|
||||
normals[indices[i + 1]] = normal;
|
||||
normals[indices[i + 2]] = normal;
|
||||
normals[i0] += normal;
|
||||
normals[i1] += normal;
|
||||
normals[i2] += normal;
|
||||
}
|
||||
|
||||
for (int i = 0; i < normals.Length; i++)
|
||||
{
|
||||
normals[i] = Vector3D.Normalize(normals[i]); // smoothing for shared vertices
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,8 +86,7 @@ namespace Nebulix.Rendering
|
||||
meshData[insert + 5] = normals[i].Z;
|
||||
insert += 6;
|
||||
}
|
||||
// extractedVertices.CopyTo(meshData, 0);
|
||||
// extractedNormals.CopyTo(meshData, extractedVertices.Length);
|
||||
|
||||
gl.BindBuffer(BufferTargetARB.ArrayBuffer, vbo);
|
||||
fixed(void* data = &meshData[0])
|
||||
{
|
||||
|
Reference in New Issue
Block a user