#VRML V2.0 utf8
# scrcam.wrl - browser camera extensions
Transform { 
	children 
	[
		Transform { 
			translation 0 -2 0
			children 
			[
				Shape {
					appearance	Appearance {
					    material Material {
						    diffuseColor	1 1 0
						}
					}
					geometry DEF EGRID1 ElevationGrid {
                        height [ 0 0 0 0 0 0 0 0 0 0 0 0    0 0 0 0 0 0 0 0 0 0 0 0
								 0 0 0 0 0 0 0 0 0 0 0 0    0 0 0 0 0 0 0 0 0 0 0 0
								 0 0 0 0 0 0 0 0 0 0 0 0    0 0 0 0 0 0 0 0 0 0 0 0
								 0 0 0 0 0 0 0 0 0 0 0 0    0 0 0 0 0 0 0 0 0 0 0 0
								 0 0 0 0 0 0 0 0 0 0 0 0    0 0 0 0 0 0 0 0 0 0 0 0
								 0 0 0 0 0 0 0 0 0 0 0 0    0 0 0 0 0 0 0 0 0 0 0 0
							   ]
                        xDimension 12
                        zDimension 12
                        xSpacing 1
                        zSpacing 1
                        solid FALSE
                    }
				}
				DEF TOUCHEG TouchSensor {}	
				DEF TIMER1 TimeSensor {
					cycleInterval 4
					loop TRUE
				}	
			]
        }

		DEF SCR-EG1 Script {
			eventIn SFFloat fraction
            eventOut MFFloat heights
            field MFFloat dist[]
			url "JavaScript: 
				function initialize() {
					var i, j;

					xCenter = (12 * 1)/2; // xDimension * xSize
					zCenter = (12 * 1)/2; // xDimension * xSize

					for (i = 0; i < 12; i++)
					{
						for (j = 0; j < 12; j++)
						{
							 dist[i*12+j] = Math.sqrt((5.5 - i)*(5.5 - i) + (5.5 - j)*(5.5 - j));
						}
					}
				}

				function fraction (value) {
					var i, j, d, x;

					for (i = 0; i < 12; i++)
					{
						for (j = 0; j < 12; j++)
						{	 // 5.5 * 1.414 / 2 = half max height = 3.535
							 heights[i*12+j] = Math.sin((6.28*value)-dist[i*12+j]);
						}
					}
				}"
		}

	]
}


ROUTE TOUCHEG.touchTime TO TIMER1.startTime
ROUTE TIMER1.fraction TO SCR-EG1.fraction
ROUTE SCR-EG1.heights TO EGRID1.set_height