Agent

by k6e2n0t12

HTML

<!-- <div id="container" style="position: absolute; left:0px; top:0px"></div>
 -->
<div id="info">
    webgl tutorial 26 <br/>
	Agent<br/>
	Seek, Collision, Arrival<br/>
</div>
 <div id="container"></div>

<script src="https://jyunming-chen.github.io/tutsplus/js/r69/three.js"></script>
<script src="https://jyunming-chen.github.io/tutsplus/js/OrbitControls.js"></script>
<script src="https://jyunming-chen.github.io/tutsplus/js/KeyboardState.js"></script>
<script src="https://k6e2n0t12.github.io/school-project/agent.js"></script>
<!-- ------------------------------------------------------------ -->

CSS

body {
		background-color: #fff;
		color: #111;
		margin: 0px;
		overflow: hidden;
		font-family: Monospace;
		font-size: 20px;
		position: absolute;
	}
	#info {
		position: absolute;
		top: 0px; width: 100%;
		
		padding: 5px;
		text-align: center;
		color: #ffff00
	}
	strong {color:red}

JavaScript

var container, scene, camera, renderer, controls,decoy,dis=0.5;
var clock = new THREE.Clock();

var mouse = new THREE.Vector2(), plane;
var tracer = new THREE.Vector3();
var decoyPos = new THREE.Vector3(20,0,20);

init();
animate();

// agent stuff
var ob, agent;

// picking

// FUNCTIONS 		
function init() 
{
	// SCENE
	scene = new THREE.Scene();

	// CAMERA
	var SCREEN_WIDTH = window.innerWidth, SCREEN_HEIGHT = window.innerHeight;
	var VIEW_ANGLE = 45, ASPECT = SCREEN_WIDTH / SCREEN_HEIGHT, NEAR = 0.1, FAR = 20000;
	camera = new THREE.PerspectiveCamera( VIEW_ANGLE, ASPECT, NEAR, FAR);
	scene.add(camera);
	camera.position.set(0,150,400);
	camera.lookAt(scene.position);	

	//ob = new Obstacle (new THREE.Vector3 (20,0,30),20);
	//scene.add (ob.mesh);
	agent = new Agent (new THREE.Vector3 (0,0,0), 
			new THREE.Vector3(10,0,-5));
	scene.add (agent.mesh);
	
	renderer = new THREE.WebGLRenderer( {antialias:true} );
	renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
	renderer.setClearColor (0x888888);
	
	container = document.getElementById( 'container' );
	container.appendChild( renderer.domElement );

	// CONTROLS
	controls = new THREE.OrbitControls( camera, renderer.domElement );

	var gridXZ = new THREE.GridHelper(100, 10);
	gridXZ.setColors( new THREE.Color(0xff0000), new THREE.Color(0xffffff) );
	scene.add(gridXZ);

	// for picking
	plane = new THREE.Mesh(
		new THREE.PlaneBufferGeometry( 200, 200, 8, 8 ),
		new THREE.MeshBasicMaterial( { color: 0xff0000, opacity: 0.25, transparent: true } )
	);
	plane.rotation.x = -Math.PI/2;
	plane.visible = false;   // invisible, for picking only
	scene.add( plane );

	// LIGHT
	var light = new THREE.PointLight(0xffffff);
	light.position.set(0,250,0);
	scene.add(light);
	
	decoy = new THREE.Mesh (new THREE.CylinderGeometry(3,3,1,20),
			new THREE.MeshBasicMaterial({color:0xffff00}));
	
	scene.add(decoy);
	

	window.addEventListener ('resize', onWindowResize, false);	
	//window.addEventListener( 'mousemove', onDocumentMouseMove,...