Externprotos

#VRML V2.0 utf8

Background { skyColor 1 1 1 }
NavigationInfo { type "NONE" }

Viewpoint { 
   position 0 1 1.2
   orientation 1 0 0 -.79
}

EXTERNPROTO Piece [ 
		   field SFVec3f t 
		   field SFRotation r
		  ] "piece.wrl"

# board
Group {
   children [
      DEF SPINNER CylinderSensor { offset -3 }
      DEF GAME Transform {
	 rotation 0 1 0 -3
	 children [
	    Piece { t -.35 .11 -.45 } Piece { t -.35 .11 -.45 } 
	    Piece { t -.25 .11 -.45 } Piece { t -.25 .11 -.45 } 
	    Piece { t -.15 .11 -.45 } Piece { t -.15 .11 -.45 } 
	    Piece { t -.05 .11 -.45 } Piece { t -.05 .11 -.45 } 
	    Piece { t .05 .11 -.45 } Piece { t .05 .11 -.45 } 
	    Piece { t .15 .11 -.45 } Piece { t .15 .11 -.45 } 
	    Piece { t .25 .11 -.45 } Piece { t .25 .11 -.45 } 
	    Piece { t .35 .11 -.45 } Piece { t .35 .11 -.45 } 
	    Piece { t -.35 .11 -.45 } Piece { t -.35 .11 -.45 } 
	    Piece { t -.25 .11 -.45 } Piece { t -.25 .11 -.45 } 
	    Piece { t -.15 .11 -.45 } Piece { t -.15 .11 -.45 } 
	    Piece { t -.05 .11 -.45 } Piece { t -.05 .11 -.45 } 
	    Piece { t .05 .11 -.45 } Piece { t .05 .11 -.45 } 
	    Piece { t .15 .11 -.45 } Piece { t .15 .11 -.45 } 
	    Piece { t .25 .11 -.45 } Piece { t .25 .11 -.45 } 
	    Piece { t .05 .11 -.05 } Piece { t -.05 .11 .05 } 

	    Piece { t -.35 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t -.25 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t -.15 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t -.05 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t .05 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t .15 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t .25 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t .35 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t -.35 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t -.25 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t -.15 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t -.05 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t .05 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t .15 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t .25 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t .35 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t -.35 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t -.25 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t -.15 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t -.05 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t .05 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t .15 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t .25 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t .35 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t -.35 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t -.25 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t -.15 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t -.05 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t .05 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t .15 .11 .45  r 1 0 0 -1.57 } 
	    Piece { t .05 .11 .05  r 1 0 0 -1.57 } 
	    Piece { t -.05 .11 -.05  r 1 0 0 -1.57 } 

	    Shape {
	       appearance Appearance { 
		  material Material {
		     shininess 0
		     emissiveColor .2 .8 .3
		     diffuseColor .2 .8 .3
		  }
	       }
	       geometry Box { size 1 .2 1 }
	    }
	    Shape {  
	       appearance Appearance {  
		  material Material { diffuseColor 0 0 0 }  
	       }  
	       geometry IndexedLineSet {  
		  coord Coordinate {  
		     point [ .5 .1 .5, .5 .1 -.5, 
			     -.5 .1 -.5, -.5 .1 .5 
			     .5 -.1 .5, .5 -.1 -.5, 
			     -.5 -.1 -.5, -.5 -.1 .5 ]
		  }  
		  coordIndex [ 0 1 2 3 0 -1 4 5 6 7 4 -1 
			       0 4 -1 1 5 -1 2 6 -1 3 7 -1 ]  
	       }  
	    }
	   ]
      }
     ]
}

ROUTE SPINNER.rotation_changed TO GAME.rotation

DEF LOADED ProximitySensor { size 1000 1000 1000 }

DEF SCRIPT Script {
   eventIn SFBool go
   eventOut MFNode newNodes
   url "vrmlscript:

function makeGridString()
{
   points = ' ';
   indices = ' ';
   for(i=0; i<9; i++) {
      x = (i-4)/10.0;
      points += x + ' .101 -.4 ';
      points += x + ' .101 .4 ';
      indices += (i*2) + ' ';
      indices += (i*2+1) + ' -1 ';
   }
   for(i=0; i<9; i++) {
      z = (i-4)/10.0;
      points += '-.4 .101 ' + z + ' ';
      points += '.4 .101 ' + z + ' ';
      indices += (18+i*2) + ' ';
      indices += (18+i*2+1) + ' -1 ';
   }

   str = 
   'Shape { ' +
   '  appearance Appearance { ' +
   '    material Material { diffuseColor 0 0 0 shininess .1 } ' +
   '  } ' +
   '  geometry IndexedLineSet { ' +
   '    coord Coordinate { ' +
   '      point [ ' + points + ' ] ' +
   '    } ' +
   '    coordIndex [ ' + indices + ' ] ' +
   '  } ' +
   '} ';   

   return str;
}

function go() {
   gridString = makeGridString();
   newNodes = Browser.createVrmlFromString(gridString);
}


"
}

ROUTE LOADED.isActive TO SCRIPT.go
ROUTE SCRIPT.newNodes TO GAME.addChildren

##################################################
#VRML V2.0 utf8

PROTO Piece [
	     field SFVec3f t 0 0 0
	     field SFRotation r 1 0 0 1.57
	    ]
{
   Transform {
      translation IS t
      rotation IS r
      scale .8 .8 .8
      children [
	 Group {
	    children [
	       DEF SLIDER PlaneSensor {
		  minPosition -2 -2
		  maxPosition 2 2
	       }
	       DEF SLIDETRANS Transform {
		  children Transform {
		     rotation 1 0 0 -1.57
		     children [
			Shape {  
			   appearance Appearance {  
			#      material Material {}  
			   }  
			   geometry IndexedFaceSet {  
			      coord Coordinate {  
				 point [ .05 -.01 .05, .05 -.01 -.05, 
					 -.05 -.01 -.05, -.05 -.01 .05 
					 .05 0 .05, .05 0 -.05, 
					 -.05 0 -.05, -.05 0 .05 
					 .05 .01 .05, .05 .01 -.05, 
					 -.05 .01 -.05, -.05 .01 .05 
					]
			      }  
			      coordIndex [ 3 2 1 0 -1 8 9 10 11 -1 
					   0 4 7 3 -1 1 5 4 0 -1
					   2 6 5 1 -1 3 7 6 2 -1
					   4 8 11 7 -1 5 9 8 4 -1
					   6 10 9 5 -1 7 11 10 6 -1 ]
			      color Color { color [ .1 .1 .1, 1 1 1 ] }
			      colorIndex [ 0 1 0 0 0 0 1 1 1 1 ]
			      colorPerVertex FALSE
			   }  
			}
		       ]
		  }
	       }
	    ]
	 }
	 Group {
	    children [
	       DEF TIMER TimeSensor { cycleInterval .75 }
	       DEF FLIPPER Script {
		  eventIn SFFloat set_fraction
                  eventIn SFBool isFlipping
		  eventOut SFRotation rotation_changed
		  field SFBool flipped FALSE
		  field SFBool flipping FALSE
		  url "vrmlscript:
                    function set_fraction(val) {
                      if(flipped) {
                        rotation_changed = new SFRotation(0, 1, 0, val*Math.PI);
                      }
                      else {
                        rotation_changed = new SFRotation(0, 1, 0, (1-val)*Math.PI);
                      }
                    }
                    function isFlipping(val) {
                      if(val && flipped) {
                        flipping = TRUE;
                        flipped = FALSE;
                      }
                      else if(val) {
                        flipping = TRUE;
                        flipped = TRUE;
                      }
                      else {
                        flipping = FALSE;
                      }
                    }"
	       }
	       DEF FLIPTRANS Transform {
		  children Transform {
		     rotation 1 0 0 -1.57
		     children [
			DEF TOUCH TouchSensor {}
			Shape {  
			   appearance Appearance {  
			      # material Material {}  
			   }  
			   geometry IndexedFaceSet {  
			      coord Coordinate {  
				 point [ .025 -.011 .025, .025 -.011 -.025, 
					 -.025 -.011 -.025, -.025 -.011 .025,
					 .025 .011 .025, .025 .011 -.025, 
					 -.025 .011 -.025, -.025 .011 .025 
					]
			      }  
			      coordIndex [ 3 2 1 0 -1 4 5 6 7 -1 ]
			      color Color { color [ 0 0 0, 1 1 1 ] }
			      colorIndex [ 1 0 ]
			      colorPerVertex FALSE
			   }  
			}
		       ]
		  }
	       }
	      ]
	 }
	]
   }
   ROUTE TOUCH.touchTime TO TIMER.startTime
   ROUTE TIMER.isActive TO FLIPPER.isFlipping
   ROUTE TIMER.fraction_changed TO FLIPPER.set_fraction
   ROUTE FLIPPER.rotation_changed TO FLIPTRANS.rotation
   ROUTE FLIPPER.rotation_changed TO SLIDETRANS.rotation
   ROUTE SLIDER.translation_changed TO SLIDETRANS.translation
   ROUTE SLIDER.translation_changed TO FLIPTRANS.translation
}

		  
	    



mrl