Code viewer for World: Sheepdog3(Submission) (clo...

//---- global constants: -------------------------------------------------------


const gridsize = 20;					// number of squares along side of world
const squaresize = 100;					// size of square in pixels
const MAXPOS = gridsize * squaresize;		// length of one side in pixels


const SKYCOLOR 	= 0xffffcc;				// a number, not a string
const BLANKCOLOR 	= SKYCOLOR ;			// make objects this color until texture arrives (from asynchronous file read)

const  LIGHTCOLOR 	= 0xffffff ;



const startRadiusConst	 	= MAXPOS * 0.8 ;		// distance from centre to start the camera at
const skyboxConst			= MAXPOS * 3 ;		// where to put skybox
const maxRadiusConst 			= MAXPOS * 5 ;		// maximum distance from camera we will render things


//---- start of World class -------------------------------------------------------

function World() {

var theagent;

function loadTextures()
{
	var manager = new THREE.LoadingManager();
	var loader = new THREE.OBJLoader( manager );

// load simple OBJ
	 loader.load( "/uploads/aaroncrawford/fishing-boat.obj", buildagent );

}


function buildagent ( object )
{
    object.scale.multiplyScalar ( 100 ); // make 3d object n times bigger
	object.traverse( paintAgent );
	theagent = object;
	threeworld.scene.add( theagent );
}

function paintAgent ( child )
{
	if ( child instanceof THREE.Mesh )
	{
       	child.material.map = THREE.ImageUtils.loadTexture( "/uploads/geoghen4/dogfurr.jpg" );
	}
}

// --- agent functions -----------------------------------


function drawAgent()	// given ai, aj, draw it
{
if ( theagent )
{
  var x = translate ( ai * squaresize );
  var z = translate ( aj * squaresize );
  var y =   ( -1 * squaresize );

 theagent.position.x = x;
 theagent.position.y = y;
 theagent.position.z = z;

}
}



this.newRun = function()
{

  if ( true  )
  {
	  threeworld.init3d ( startRadiusConst, maxRadiusConst, SKYCOLOR  );

    		var ambient = new THREE.AmbientLight();
    		threeworld.scene.add( ambient );

	   	 var thelight = new THREE.DirectionalLight ( LIGHTCOLOR, 3 );
	  	 thelight.position.set ( startRadiusConst, startRadiusConst, startRadiusConst );
	   	 threeworld.scene.add(thelight);

	  loadTextures();			// will return sometime later, but can go ahead and render now
  }
};

}

//---- end of World class -------------------------------------------------------