Cylinder Sensor Controlled Texture Display

#VRML V2.0 utf8

PROTO PngFrame [ field MFString url ""]
{
   Transform {
      children Billboard {
	 children Shape {
	    appearance Appearance {
	       texture ImageTexture { url IS url }
	    }
	    geometry IndexedFaceSet {
	       coord Coordinate { point [ 1 1 0, -1 1 0, -1 -1 0, 1 -1 0 ] }
	       coordIndex [ 0 1 2 3 -1 ]
	       texCoord TextureCoordinate { point [ 1 1, 0 1, 0 0, 1 0 ] }
	    }
	 }
      }
   }
} 

Group {
   children [
      DEF SPINNER CylinderSensor {}
      Shape {
	 appearance Appearance { material Material { transparency 1 } }
	 geometry Cylinder { radius .75 }
      }
      DEF FRAMES Switch {
	 whichChoice 0
	 choice [
		 PngFrame { url "Textures/frame1.png" }
		 PngFrame { url "Textures/frame2.png" }
		 PngFrame { url "Textures/frame3.png" }
		 PngFrame { url "Textures/frame4.png" }
		 PngFrame { url "Textures/frame5.png" }
		 PngFrame { url "Textures/frame6.png" }
		 PngFrame { url "Textures/frame7.png" }
		 PngFrame { url "Textures/frame8.png" }
		 PngFrame { url "Textures/frame9.png" }
		 PngFrame { url "Textures/frame10.png" }
		 PngFrame { url "Textures/frame11.png" }
		 PngFrame { url "Textures/frame12.png" }
		 PngFrame { url "Textures/frame13.png" }
		 PngFrame { url "Textures/frame14.png" }
		 PngFrame { url "Textures/frame15.png" }
		 PngFrame { url "Textures/frame16.png" }
		]
      }
     ]
}

# ground for ref geometry
Transform {
   translation 0 -.9 0
   scale 4 1 4
   children Shape {
      appearance Appearance {
	 material Material { emissiveColor .2 .2 .2 }
	 texture ImageTexture { url "Textures/twist.gif" }
	 textureTransform TextureTransform { scale 15 15 }
      }
      geometry DEF IFSXZ IndexedFaceSet {
	 coord Coordinate { point [ 1 0 -1, -1 0 -1, -1 0 1, 1 0 1 ] }
	 coordIndex [ 0 1 2 3 -1 ]
	 texCoord TextureCoordinate { point [ 1 1, 0 1, 0 0, 1 0 ] }
	 solid FALSE
      }
   }
}

# shadow polygon
DEF SHAD Transform {
   translation -.25 -.85 -.1
   children Shape {
      appearance Appearance {
	 texture ImageTexture { url "Textures/shadow.png" }
      }
      geometry USE IFSXZ
   }
}

Viewpoint { position -1 0 5 }
NavigationInfo { 
   type "FLY" 
   avatarSize [ .25 .1 .75 ]
}

DEF SCRIPT Script {	
   eventIn SFRotation rotation
   eventOut SFInt32 frame
   field SFInt32 numFrames 16
   url "vrmlscript:

// since % is only returning integers in vrmlscript...
function mod(n, d) { return n - Math.floor(n/d) * d; }

function rotation(val) {
   angle = val.angle;
   twopi = 2 * Math.PI;
   if(val.y < 0) { angle = twopi - angle; }
   // angle = angle % twopi
   angle = mod(angle, twopi);
   frame = Math.round((angle / (2.0 * Math.PI)) * (numFrames-1));
}
"

}

ROUTE SPINNER.rotation_changed TO SHAD.rotation
ROUTE SPINNER.rotation_changed TO SCRIPT.rotation
ROUTE SCRIPT.frame TO FRAMES.whichChoice


mrl