//virtual public BoundingBox getBoundingBox() { return _boundingBox; } protected void CalculateNormals(Mesh parent) { if(GlobalVars.verbose) { System.Console.WriteLine("Calculating vertex normals for mesh " + parent.id); } //Get the list of faces attached to a given vertex for (int i = 0; i < parent.countVertices; i++) { //Sum together all the normals of the faces attached to this vertex List<int> faceList = parent.vertexFaces[i]; Normal normalSum = new Normal(0,0,0); for(int j = 0; j < faceList.Count; j++) { normalSum += parent.NormalForFace(faceList[j]); } normalSum.Normalize(); parent.normals[i] = normalSum; } }
private Normal CalculateNormal(Point3D point) { Normal result = new Normal(); float param_squared = _a * _a + _b * _b; float x = point.X; float y = point.Y; float z = point.Z; float sum_squared = x * x + y * y + z * z; result.X = 4.0f * x * (sum_squared - param_squared); result.Y = 4.0f * y * (sum_squared - param_squared + 2.0f * _a * _a); result.Z = 4.0f * z * (sum_squared - param_squared); result.Normalize(); return result; }