<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "https://www.web3d.org/specifications/x3d-3.0.dtd">
<X3D profile='Immersive'  version='3.0 xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation =' https://www.web3d.org/specifications/x3d-3.0.xsd ' >
<head>
<meta name='titlecontent=' ProjectileSliderBarPrototype.x3d '/>
<meta name='descriptioncontent='A generic slider bar prototype. Colors, size of the bar and name are changable.'/>
<meta name='creatorcontent='Ozan APAYDIN'/>
<meta name='createdcontent='1 December 2001'/>
<meta name='modifiedcontent='20 October 2019'/>
<meta name='identifiercontent=' https://www.web3d.org/x3d/content/examples/Basic/StudentProjects/ProjectileSliderBarPrototype.x3d '/>
<meta name='generatorcontent='X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit'/>
<meta name='licensecontent=' ../license.html'/>
</head>
<!-- -->
<Scene>
<WorldInfo title='ProjectileSliderBarPrototype.x3d'/>
<ProtoDeclare name='ProjectileSliderBar'>
<ProtoInterface>
<field name='nametype='MFStringaccessType='initializeOnly'
 appinfo='Name of the Slider Bar. It appears on the left side of the bar.' />

<field name='lengthtype='SFFloatvalue='1accessType='initializeOnly'
 appinfo='Length of the Slider bar. According to given value bar will arrange itself.' />

<field name='widthtype='SFFloatvalue='1accessType='initializeOnly'
 appinfo='Width of the Slider bar. According to given value bar will arrange itself.' />

<field name='maxValuetype='SFFloatvalue='1accessType='initializeOnly'
 appinfo='Max. value of Slider Bar.It can be assigned a positive or a negative value.' />

<field name='minValuetype='SFFloatvalue='0accessType='initializeOnly'
 appinfo='Min. value of Slider Bar. It can be assigned a positive or a negative value.' />

<field name='barColortype='SFColorvalue='1 0 0accessType='initializeOnly'
 appinfo='Color of Slider Bar.' />

<field name='pointerColortype='SFColorvalue='1 1 0accessType='initializeOnly'
 appinfo='Pointer Color of Slider Bar.' />

<field name='nameColortype='SFColorvalue='1 0 1accessType='initializeOnly'
 appinfo='Slider Bar Name Color.' />

<field name='currentValueColortype='SFColorvalue='0.2 0.8 0.2accessType='initializeOnly'
 appinfo='Color of Current Value text.' />

<field name='currentValueInttype='SFInt32accessType='outputOnly'
 appinfo='If the precision is 0 current Value will be output in this eventOut field as Integer else in currentValueFloat eventOut field as Float.' />

<field name='currentValueFloattype='SFFloataccessType='outputOnly'
 appinfo='If the precision is NOT 0 current Value will be output in this eventOut field as Float else in currentValueInt eventOut field as Integer.' />

<field name='precisiontype='SFInt32value='2accessType='initializeOnly'
 appinfo='Count of the numbers after Decimal Point. Example : If precision is 2 1.562777 -> 1.56' />

<field name='translationtype='SFVec3faccessType='initializeOnly'
 appinfo='Translation values of Slider Bar to define its location on the screen.' />
</ProtoInterface>
<ProtoBody>
<Group DEF='HUDGroup'>
<Collision enabled='false'>
<!-- ROUTE information for HudProx node:  [from position_changed to HudTransform.set_translation ] [from orientation_changed to HudTransform.set_rotation ] [self-route from position_changed to center ] -->
<ProximitySensor DEF='HudProxsize='1000000 1000000 1000000'/>

<!-- ROUTE information for HudTransform node:  [from HudProx.position_changed to set_translation ] [from HudProx.orientation_changed to set_rotation ] -->
<Transform DEF='HudTransform'>
<Transform translation='0 0 -0.2'>
<Transform DEF='SliderTransform'>
<IS>
<connect nodeField='translationprotoField='translation'/>
</IS>
<Group DEF='SliderShape'>
<Transform DEF='barTransform'>
<Shape>
<Appearance>
<Material DEF='BarColordiffuseColor='0 0 1'>
<IS>
<connect nodeField='diffuseColorprotoField='barColor'/>
</IS>
</Material>
</Appearance>
<Box DEF='barsize='0.05 0.001 0.000001'/>
</Shape>
</Transform>
<!-- ROUTE information for pointerTransform node:  [from SVPlaneSensor.translation_changed to set_translation ] -->
<Transform DEF='pointerTransform'>
<Shape>
<Appearance>
<Material DEF='PointerColordiffuseColor='1 1 0'>
<IS>
<connect nodeField='diffuseColorprotoField='pointerColor'/>
</IS>
</Material>
</Appearance>
<Cone DEF='pointerbottomRadius='0.0025height='0.005'/>
</Shape>
<!-- ROUTE information for SVPlaneSensor node:  [from translation_changed to pointerTransform.set_translation ] [from translation_changed to CurrentValueFinder.updateCurrentValue ] -->
<PlaneSensor DEF='SVPlaneSensormaxPosition='0.025 0minPosition='-0.025 0'/>
</Transform>
<Transform DEF='sliderNameTransform'>
<Shape>
<Text DEF='SliderName'>
<IS>
<connect nodeField='stringprotoField='name'/>
</IS>
<FontStyle justify='"END"size='0.0085style='BOLD'/>
</Text>
<Appearance>
<Material DEF='sliderNameColor'>
<IS>
<connect nodeField='diffuseColorprotoField='nameColor'/>
</IS>
</Material>
</Appearance>
</Shape>
</Transform>
<Transform DEF='currentValueTransform'>
<Shape DEF='currentValue'>
<Text DEF='currentValueText'>
<FontStyle DEF='currentValueFontjustify='"BEGIN" "MIDDLE"size='0.0085style='BOLD'/>
</Text>
<Appearance>
<Material DEF='valueColor'>
<IS>
<connect nodeField='diffuseColorprotoField='currentValueColor'/>
</IS>
</Material>
</Appearance>
</Shape>
</Transform>
</Group>
</Transform>
</Transform>
</Transform>
</Collision>
</Group>
<Script DEF='ShapeOrganizerdirectOutput='true'>
<field name='Lengthtype='SFFloataccessType='initializeOnly'/>
<field name='Widthtype='SFFloataccessType='initializeOnly'/>
<field name='SliderNameTransformNodetype='SFNodeaccessType='initializeOnly'>
<Transform USE=' sliderNameTransform'/>
</field>
<field name='CurrentValueTransformNodetype='SFNodeaccessType='initializeOnly'>
<Transform USE=' currentValueTransform'/>
</field>
<field name='BarTransformNodetype='SFNodeaccessType='initializeOnly'>
<Transform USE=' barTransform'/>
</field>
<field name='PointerTransformNodetype='SFNodeaccessType='initializeOnly'>
<Transform USE=' pointerTransform'/>
</field>
<field name='CurrentValueTexttype='SFNodeaccessType='initializeOnly'>
<Text USE=' currentValueText'/>
</field>
<field name='SVPlaneSensorNodetype='SFNodeaccessType='initializeOnly'>
<PlaneSensor USE=' SVPlaneSensor'/>
</field>
<IS>
<connect nodeField='LengthprotoField='length'/>
<connect nodeField='WidthprotoField='width'/>
</IS>
<![CDATA[
          
ecmascript:
function initialize() {
      
   for(i = 0; i < 3; i++) { 
      BarTransformNode.scale[i] = 1;
      if(i == 2) {
         PointerTransformNode.scale[i] = 0.1; 
      }
      else {
         PointerTransformNode.scale[i] = 1;
      }
   } 
   setBarSize();
   setPointerSize();
   setCurrentValueTransform();
   setNameTransform();
}

function setBarSize() {
   BarTransformNode.scale[0] = Length * BarTransformNode.scale[0];
   BarTransformNode.scale[1] = Width * BarTransformNode.scale[1];
}

function setPointerSize() {
   PointerTransformNode.scale[0] = Width * PointerTransformNode.scale[0];
   PointerTransformNode.scale[1] = Width * PointerTransformNode.scale[1];
   SVPlaneSensorNode.minPosition[0] = Length * SVPlaneSensorNode.minPosition[0];
   SVPlaneSensorNode.maxPosition[0] = Length * SVPlaneSensorNode.maxPosition[0];
}

function setCurrentValueTransform() {
   CurrentValueTransformNode.translation[0] = (BarTransformNode.scale[0] * 0.05 / 2) + (BarTransformNode.scale[1] * 0.001 * 2);
}

function setNameTransform() {
   SliderNameTransformNode.translation[0] = -((BarTransformNode.scale[0] * 0.05 / 2) + (BarTransformNode.scale[1] * 0.001 * 2));
}

        
]]>
</Script>
<!-- ROUTE information for CurrentValueFinder node:  [from SVPlaneSensor.translation_changed to updateCurrentValue ] -->
<Script DEF='CurrentValueFinderdirectOutput='true'>
<field name='SVPlaneSensorNodetype='SFNodeaccessType='initializeOnly'>
<PlaneSensor USE=' SVPlaneSensor'/>
</field>
<field name='MaxValuetype='SFFloataccessType='initializeOnly'/>
<field name='MinValuetype='SFFloataccessType='initializeOnly'/>
<field name='CurrentValueTextNodetype='SFNodeaccessType='initializeOnly'>
<Text USE=' currentValueText'/>
</field>
<field name='updateCurrentValuetype='SFVec3faccessType='inputOnly'/>
<field name='CurrentValueInttype='SFInt32accessType='outputOnly'/>
<field name='CurrentValueFloattype='SFFloataccessType='outputOnly'/>
<field name='Precisiontype='SFInt32accessType='initializeOnly'/>
<IS>
<connect nodeField='MaxValueprotoField='maxValue'/>
<connect nodeField='MinValueprotoField='minValue'/>
<connect nodeField='CurrentValueIntprotoField='currentValueInt'/>
<connect nodeField='CurrentValueFloatprotoField='currentValueFloat'/>
<connect nodeField='PrecisionprotoField='precision'/>
</IS>
<![CDATA[
          
ecmascript:

var totalLength;

function initialize() {
   realValue = (MaxValue + MinValue) / 2;
   realValue = roundOff(realValue, Precision);
   CurrentValueFloat = realValue;
   CurrentValueInt = Math.round(realValue);
   totalLength = SVPlaneSensorNode.maxPosition[0] - SVPlaneSensorNode.minPosition[0];
   updateCurrentValueText(realValue.toString()); 
}

//Map pointer translation value to the real value
function updateCurrentValue(translation, timeEvent) {
   var displayString;
   var curPositionOnBar = translation[0] + totalLength / 2;
   var x = (MaxValue - MinValue) * curPositionOnBar / totalLength;
   
   var realValue = MinValue + x;

   if(Precision == 0) { //If 
      CurrentValueInt = Math.round(realValue);
      displayString = CurrentValueInt.toString();
   }
   else {
      CurrentValueFloat = roundOff(realValue, Precision);       
      displayString = CurrentValueFloat.toString();
   } 
      
   updateCurrentValueText(displayString);
}


function updateCurrentValueText(dispStr) {
   CurrentValueTextNode.string[0] = dispStr;
}

//A function to round the values regarding to given precision.
function roundOff(value, precision) {

   var result;
   var isNegative = false;
   var wholeInt = Math.round(value * Math.pow(10, precision));
 
   //Negative numbers creates exceptional condition, therefor they are converted
   //to positive values.
   if(wholeInt < 0) {
      wholeInt = -wholeInt;
      isNegative = true;
   }

   var whole = wholeInt.toString();
   
   var decPoint = whole.length - precision;
   
   //Exception when precision is bigger than the string length   
   if(decPoint < 0) {
      i = -decPoint;
      for(i; i > 0; i--) {  
         whole ='0' + whole;
      }

      //Calculate decPoint according to new string expanded with 0s      
      decPoint = whole.length - precision;
   }

   if(whole !='0') {
      //Put the decimal point on the appropriate place
      result = whole.substring(0, decPoint);
      result +='.';
      result += whole.substring(decPoint, whole.length);
   }
   else { //If the string is'0', then result is'0'
      result = whole;
   }
   
   //Negative numbers are altered.
   if(isNegative) {
      result ='-' + result;
   }
   //Convert the String value to Float.
   resultFloat = parseFloat(result); 
  
  
   return resultFloat;
  
}

        
]]>
</Script>
< ROUTE  fromNode=' HudProx' fromField='position_changed' toNode=' HudTransform' toField='set_translation'/>
< ROUTE  fromNode=' HudProx' fromField='orientation_changed' toNode=' HudTransform' toField='set_rotation'/>
< ROUTE  fromNode=' HudProx' fromField='position_changed' toNode=' HudProx' toField='center'/>
< ROUTE  fromNode=' SVPlaneSensor' fromField='translation_changed' toNode=' pointerTransform' toField='set_translation'/>
< ROUTE  fromNode=' SVPlaneSensor' fromField='translation_changed' toNode=' CurrentValueFinder' toField='updateCurrentValue'/>
</ProtoBody>
</ProtoDeclare>
<Viewpoint description='Slider barposition='0 0 5'/>
<ProtoInstance name='ProjectileSliderBar'>
<fieldValue name='namevalue='"AFAA"'/>
<fieldValue name='lengthvalue='1.5'/>
<fieldValue name='widthvalue='1'/>
<fieldValue name='maxValuevalue='10'/>
<fieldValue name='minValuevalue='-2'/>
</ProtoInstance>
</Scene>
</X3D>
<!--

to top <!-- Event Graph ROUTE Table shows event connections -->
 
<!-- Index for DEF nodes: bar, BarColor, barTransform, currentValue, CurrentValueFinder, currentValueFont, currentValueText, currentValueTransform, HUDGroup, HudProx, HudTransform, pointer, PointerColor, pointerTransform, ShapeOrganizer, SliderName, sliderNameColor, sliderNameTransform, SliderShape, SliderTransform, SVPlaneSensor, valueColor

Index for Viewpoint node: Viewpoint_1

Index for ProtoDeclare definition: ProjectileSliderBar
-->

Event Graph ROUTE Table entries with 5 ROUTE connections total, showing X3D event-model relationships for this scene.

Each row shows an event cascade that may occur during a single timestamp interval between frame renderings, as part of the X3D execution model.

      CurrentValueFinder
Script
No ROUTE connection found for output from this node.
Contains SFNode field with indirect access to another node. 


ShapeOrganizer
Script
No ROUTE connection found for output from this node.
Contains SFNode field with indirect access to another node. 


HudProx
ProximitySensor
position_changed
SFVec3f

ROUTE
event to
(1)
HudTransform
Transform
set_translation
SFVec3f
HudProx
ProximitySensor
orientation_changed
SFRotation

ROUTE
event to
(1)
HudTransform
Transform
set_rotation
SFRotation



ProtoInstance
ProjectileSliderBar
No ROUTE connection found for output from this node.
Contains SFNode/MFNode field with indirect access to other nodes. 


SVPlaneSensor
PlaneSensor
translation_changed
SFVec3f

ROUTE
event to
(1)
pointerTransform
Transform
set_translation
SFVec3f
SVPlaneSensor
PlaneSensor
translation_changed
SFVec3f

ROUTE
event to
(1)
CurrentValueFinder
Script
updateCurrentValue
SFVec3f


-->

<!-- Online at
https://www.web3d.org/x3d/content/examples/Basic/StudentProjects/ProjectileSliderBarPrototypeIndex.html -->
<!-- Version control at
https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/content/examples/Basic/StudentProjects/ProjectileSliderBarPrototype.x3d -->

<!-- Color legend: X3D terminology <X3dNode DEF='idName' field='value'/> matches XML terminology <XmlElement DEF='idName' attribute='value'/>
(Light-blue background: event-based behavior node or statement) (Grey background inside box: inserted documentation) (Magenta background: X3D Extensibility)
    <ProtoInstance name='ProtoName'> <field name='fieldName'/> </ProtoInstance> -->

to top <!-- For additional help information about X3D scenes, please see X3D Tooltips, X3D Resources, and X3D Scene Authoring Hints. -->