CSC 4356/Prog3/prog3.js
//Generate a new array of normals
Generate a new array of normals
Generate a new array of normals
function vecNormal()
{
		for (var i in bunny.positions)
		{
				normals.push([0, 0, 0]);
		}
		for (var i = 0; i < bunny.triangles.length; i++)
		{
				var triangles = bunny.triangles[i];
				var a = normalize(vecSubtraction(bunny.positions[triangles[1]], bunny.positions[triangles[0]]));
				var b = normalize(vecSubtraction(bunny.positions[triangles[2]], bunny.positions[triangles[0]]));
				n = normalize(vecCrossProduct(a, b));
				normals[triangles[0]] = vecAddition(normals[triangles[0]], n);
				normals[triangles[1]] = vecAddition(normals[triangles[1]], n);
				normals[triangles[2]] = vecAddition(normals[triangles[2]], n);
		}
		for (var i in normals)
		{
				i = normalize(i);
		}
}
function vecNormal ( ) { for ( var i in bunny . positions ) { normals . push ( [ 0 , 0 , 0 ] ) ; } for ( var i = 0 ; i < bunny . triangles . length ; i ++ ) { var triangles = bunny . triangles [ i ] ; var a = normalize ( vecSubtraction ( bunny . positions [ triangles [ 1 ] ] , bunny . positions [ triangles [ 0 ] ] ) ) ; var b = normalize ( vecSubtraction ( bunny . positions [ triangles [ 2 ] ] , bunny . positions [ triangles [ 0 ] ] ) ) ; n = normalize ( vecCrossProduct ( a , b ) ) ; normals [ triangles [ 0 ] ] = vecAddition ( normals [ triangles [ 0 ] ] , n ) ; normals [ triangles [ 1 ] ] = vecAddition ( normals [ triangles [ 1 ] ] , n ) ; normals [ triangles [ 2 ] ] = vecAddition ( normals [ triangles [ 2 ] ] , n ) ; } for ( var i in normals ) { i = normalize ( i ) ; } }
Generate a new array of normals
Generate a new array of normals