Basic Herding/Flocking/Schooling

#VRML V2.0 utf8

NavigationInfo { type "EXAMINE" }
Viewpoint { position 0 10 10  orientation 1 0 0 -.8 }

EXTERNPROTO AvoidConeChaser [
	      field SFVec3f position
	      field SFVec3f goal
	      field SFFloat speed
	      field MFVec3f obstacles
	      field SFInt32 index
	      field SFFloat turnLimit
	      field SFVec3f scale
	      eventIn SFVec3f set_goal
	      eventIn MFVec3f obstacles_changed
	      eventOut MFFloat report_position
	     ] "avoidConeChaser.wrl"

EXTERNPROTO TouchFloor [ field SFVec3f scale 
			 field SFColor color
			 eventOut SFVec3f hitPoint_changed ] "touchFloor.wrl"


DEF TOUCH TouchFloor { scale 20 1 20  color .2 .2 .2 }

DEF CHASER0 AvoidConeChaser { index 0 position 5 0 -3 speed 1 turnLimit 1 scale .5 .5 .5 }
DEF CHASER1 AvoidConeChaser { index 1 position -5 0 -5 speed 1 turnLimit 1 scale .5 .5 .5 }
DEF CHASER2 AvoidConeChaser { index 2 position -5 0 4 speed 1 turnLimit 1 scale .5 .5 .5 }
DEF CHASER3 AvoidConeChaser { index 3 position -3 0 4 speed 1 turnLimit 1 scale .5 .5 .5 }
DEF CHASER4 AvoidConeChaser { index 4 position -1 0 1 speed 1 turnLimit 1 scale .5 .5 .5 }

DEF SCRIPT Script {
   eventIn SFTime beat
   eventIn MFFloat update_position
   eventOut MFVec3f chasers_moved
   field MFVec3f chaserPositions [ ]
   field SFInt32 numChasers 5
   url "vrmlscript:

function initialize() {
   chaserPositions = new MFVec3f();
}

function update_position(val) {
   i = val[0];
   x = val[1];  y = val[2];  z = val[3];
   chaserPositions[i] = new SFVec3f(x, y, z);
}

function beat(val) {
   chasers_moved = chaserPositions;
}

"
}

DEF SIMCLOCK TimeSensor { loop TRUE }

ROUTE CHASER0.report_position TO SCRIPT.update_position
ROUTE CHASER1.report_position TO SCRIPT.update_position
ROUTE CHASER2.report_position TO SCRIPT.update_position
ROUTE CHASER3.report_position TO SCRIPT.update_position
ROUTE CHASER4.report_position TO SCRIPT.update_position

ROUTE SIMCLOCK.time TO SCRIPT.beat

ROUTE SCRIPT.chasers_moved TO CHASER0.obstacles_changed
ROUTE SCRIPT.chasers_moved TO CHASER1.obstacles_changed
ROUTE SCRIPT.chasers_moved TO CHASER2.obstacles_changed
ROUTE SCRIPT.chasers_moved TO CHASER3.obstacles_changed
ROUTE SCRIPT.chasers_moved TO CHASER4.obstacles_changed

ROUTE TOUCH.hitPoint_changed TO CHASER0.set_goal
ROUTE TOUCH.hitPoint_changed TO CHASER1.set_goal
ROUTE TOUCH.hitPoint_changed TO CHASER2.set_goal
ROUTE TOUCH.hitPoint_changed TO CHASER3.set_goal
ROUTE TOUCH.hitPoint_changed TO CHASER4.set_goal


mrl