Axiom.Graphics.EdgeData.UpdateFaceNormals C# (CSharp) Method

UpdateFaceNormals() public method

Updates the face normals for this edge list based on (changed) position information, useful for animated objects.
public UpdateFaceNormals ( int vertexSet, HardwareVertexBuffer positionBuffer ) : void
vertexSet int The vertex set we are updating.
positionBuffer HardwareVertexBuffer The updated position buffer, must contain ONLY xyz.
return void
		public void UpdateFaceNormals( int vertexSet, HardwareVertexBuffer positionBuffer )
		{
			unsafe
			{
				Debug.Assert( positionBuffer.VertexSize == sizeof( float ) * 3, "Position buffer should contain only positions!" );

				// Lock buffer for reading
				IntPtr posPtr = positionBuffer.Lock( BufferLocking.ReadOnly );
				float* pVert = (float*)posPtr.ToPointer();

				// Iterate over the triangles
				for ( int i = 0; i < triangles.Count; i++ )
				{
					Triangle t = (Triangle)triangles[ i ];

					// Only update tris which are using this vertex set
					if ( t.vertexSet == vertexSet )
					{
						int offset = t.vertIndex[ 0 ] * 3;
						Vector3 v1 = new Vector3( pVert[ offset ], pVert[ offset + 1 ], pVert[ offset + 2 ] );

						offset = t.vertIndex[ 1 ] * 3;
						Vector3 v2 = new Vector3( pVert[ offset ], pVert[ offset + 1 ], pVert[ offset + 2 ] );

						offset = t.vertIndex[ 2 ] * 3;
						Vector3 v3 = new Vector3( pVert[ offset ], pVert[ offset + 1 ], pVert[ offset + 2 ] );

						t.normal = Utility.CalculateFaceNormal( v1, v2, v3 );
					}
				}
			}

			// unlock the buffer
			positionBuffer.Unlock();
		}