Hello everyone,
The short of it is my code sucks. It sucks in a lot of ways because it's written poorly. There is a ton of stuff everyone talks about around here that just goes way over my head. Everyone else seems to relate, but not me. Thing is this site is predominantly a programming website. I'd like to get some feedback on my crappy coding style. I'm also going to start asking a lot more stupid questions, like what the hell are you all talking about half the time? That last question doesn't need to be answered
Here is my code that I changed on my last blog
initilizingFunction.definePositionPlane = function( unitScale ){
var geometry = new THREE.Geometry();
var material = new THREE.MeshLambertMaterial( { side: THREE.DoubleSide } );
// 'qv(0,0,0)' is short form of 'new THREE.Vector3( 0,0,0 )'
geometry.vertices.push( qv( 0 , 0 , 0 ) );
/* the following function creates an 11 x 11 grid of vertices.
* the first vertices is located at the center of the grid.
* if we were to number the vertices 1 through 121 left from right, up to down
* then the first vertices defined would be at the position of the 61st spot in the grid.
* as the function cycle through 'i', two 'n' loops of 'l' length add move the location
* of the next declared vertices 'l' left/right depending and 'l' up/down depending.
* at the end of both 'n' loops l is incremented and the directions toggle.
*/
for( var i=0, j=61, k=61, l=1, q=-1, p=1, b=15; i<121; i+=0 ){
if( l < 11){
for( var n=0; n<l; n++ ){
j += q;
geometry.vertices.push( qv( ( j - 61 ) * u * b , 0 , ( k - 61 ) * u * b ) );
i++;
}
for( var n=0; n<l; n++ ){
k += p;
geometry.vertices.push( qv( ( j - 61 ) * u * b , 0 , ( k - 61 ) * u * b ) );
i++;
}
q*=-1;
p*=-1;
l++;
} else {
for( var n=0; n<10; n++ ){
j += q;
geometry.vertices.push( qv( ( j - 61 ) * u * b , 0 , ( k - 61 ) * u * b ) );
i++;
}
i = 121;
}
}
var face = new THREE.Face3( 0 , 10 , 120 );
geometry.faces.push( face );
face = new THREE.Face3( 0 , 120 , 110 );
geometry.faces.push( face );
geometry.computeFaceNormals();
var mesh = new THREE.Mesh( geometry , material );
mesh.visible = true;
return mesh;
};
What I'd like to know is how would you have written the function? What kind of comments would you have written? What 'best company practises' do you follow?