#VRML V2.0 utf8
 
# arquivo: app_fioMedio1.wrl

DEF vista1 Viewpoint {
  description "Vista-1"
  position  .0 .0 .3
}

Group {
  children [
    Transform {
      children [
		# Botao gerador de leituras
        DEF butao Transform { 
	       translation .12 .09 0.01
	       children [
	         Shape {
               appearance Appearance {
                 material Material { diffuseColor 0.4 0.4 0.4 }
               }
               geometry Box { size 0.02 0.02 0.001 }
             }

             Transform {
	           rotation 1 0 0 1.57 
	           children Shape {
                 appearance Appearance {
                   material Material { diffuseColor 1 0 0 }
                 }
                 geometry Cylinder { 
		            radius 0.005
		            height 0.005
		            top TRUE 
		         }
               }
             }	            
           ]
        }# /Botao gerador de leituras

		DEF sensorButao TouchSensor {}

		# Texto "Clique" do botao gerador de leituras
        Transform {
	       translation .12 .11 0.01
	       children Shape {
             appearance Appearance {
               material Material { diffuseColor 0 0 0 }
             }
             geometry Text { 
               string "Clique"
               fontStyle FontStyle { size .02 }
	         }
           }
        }# /Texto "Clique" do botao gerador de leituras 

		# Leitura gerada para FioMedio
		Transform {
	       translation .14 0.09 0.01
	       children Shape {
             appearance Appearance {
               material Material { diffuseColor 0 0 0 }
             }
             geometry DEF texto1 Text { 
               string ""
               fontStyle FontStyle { size .02 }
	         }
           }
        } 
		# /Leitura gerada para FioMedio
				
		DEF lente Transform {
	       children Inline { url "lente.wrl" }
        }
	  ]
    }
    DEF regua Transform {
      children Inline { url "regua.wrl" }
    }
  ]#/children
}#Group


DEF setar Script {
  eventIn  SFBool b	
   
  eventOut MFString valorFioMedio
 	  
  eventOut SFVec3f posRegua

  eventOut SFVec3f escLente

  url "javascript:
    function b(value) {

      var mm =Math.floor(Math.random()*10);
      var cm =Math.floor(Math.random()*10);
      var dm =Math.floor(Math.random()*10);
      var m =Math.floor(Math.random()*10/3);
     
      var leitura = m +'.' +dm +'' +cm +'' +mm;
	  var fioMed =+leitura;
     
      valorFioMedio =new MFString(fioMed);
				
      posRegua =new SFVec3f(3);
      posRegua[0] =0.;
      posRegua[1] =-fioMed;
      posRegua[2] =0.;
	  
	  var na =Math.floor(Math.random()*10);
      // Mapeando valores 'na' [0-9] em distancias [1. - 65.] metros
      
	  dist = na *(65. -1.)/9 +1.;
	  dist =Math.floor(dist*1000)/1000;

	  var metadeAlfa =Math.atan(1/200.);
      var fioSup =dist *Math.tan(metadeAlfa) +fioMed;

	  fioSup =Math.floor(fioSup*1000)/1000;
     
	  // forcando operacao com inteiros 		
      var fioInf =2*Math.floor(fioMed*1000) -Math.floor(fioSup*1000); 
      fioInf =Math.floor(fioInf)/1000;

	  escLente =new SFVec3f(3);
      escLente[0] =dist;
      escLente[1] =dist;
      escLente[2] =1;
 	         
     }
  "
}
ROUTE sensorButao.isActive TO setar.b

ROUTE setar.valorFioMedio TO texto1.string
 
ROUTE setar.escLente TO lente.scale 

ROUTE setar.posRegua TO regua.translation

Background {skyColor 0.999 0.999 0 }
