<?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 content='CrossHairPrototype.x3d' name='title'/>
    <meta content='Prototype for a heads-up display (HUD) crosshair showing center of screen, useful for assessing lookAt point.' name='description'/>
    <meta content='Don Brutzman' name='creator'/>
    <meta content='1 February 2003' name='created'/>
    <meta content='28 November 2019' name='modified'/>
    <meta content='crosshair display' name='subject'/>
    <meta content='https://www.web3d.org/x3d/content/examples/Savage/Tools/HeadsUpDisplays/CrossHairPrototype.x3d' name='identifier'/>
    <meta content='X3D-Edit 3.2, https://www.web3d.org/x3d/tools/X3D-Edit' name='generator'/>
    <meta content='../../license.html' name='license'/>
  </head>
  <Scene>
    <WorldInfo title='CrossHairPrototype.x3d'/>
    <ProtoDeclare appinfo='CrossHair prototype provides a heads-up display (HUD) crosshair at the view center, which is useful for assessing NavigationInfo lookAt point' name='CrossHair'>
      <ProtoInterface>
        <field accessType='initializeOnly' appinfo='whether CrossHair prototype is enabled or not' name='enabled' type='SFBool' value='true'/>
        <field accessType='inputOnly' appinfo='control whether enabled/disabled' name='set_enabled' type='SFBool'/>
        <field accessType='inputOutput' appinfo='color of CrossHair marker' name='markerColor' type='SFColor' value='0.3 0.3 0.8'/>
        <field accessType='inputOutput' appinfo='size of CrossHair in meters' name='scale' type='SFVec3f' value='1 1 1'/>
        <field accessType='inputOutput' appinfo='distance in front of HUD viewpoint' name='positionOffsetFromCamera' type='SFVec3f' value='0 0 -3'/>
      </ProtoInterface>
      <ProtoBody>
        <Switch DEF='ShowSwitch' whichChoice='-1'>
          <Group>
            <ProximitySensor DEF='WhereSensor' size='1000000000 1000000000 1000000000'>
              <IS>
                <connect nodeField='enabled' protoField='enabled'/>
              </IS>
            </ProximitySensor>
            <Transform DEF='CameraLocation'>
              <Transform DEF='CameraOffset'>
                <IS>
                  <connect nodeField='translation' protoField='positionOffsetFromCamera'/>
                  <connect nodeField='scale' protoField='scale'/>
                </IS>
                <Shape>
                  <IndexedLineSet coordIndex='0 1 -1 2 3 -1'>
                    <Coordinate point='0 1 0 0 -1 0 1 0 0 -1 0 0'/>
                  </IndexedLineSet>
                  <Appearance>
                    <Material DEF='CircleMaterial' diffuseColor='0 0 0'>
                      <IS>
                        <connect nodeField='emissiveColor' protoField='markerColor'/>
                      </IS>
                    </Material>
                  </Appearance>
                </Shape>
              </Transform>
              <Group>
                <Script DEF='EnabledScript'>
                  <field accessType='initializeOnly' name='enabled' type='SFBool'/>
                  <field accessType='inputOnly' name='set_enabled' type='SFBool'/>
                  <field accessType='outputOnly' name='whichChoice' type='SFInt32'/>
                  <IS>
                    <connect nodeField='enabled' protoField='enabled'/>
                    <connect nodeField='set_enabled' protoField='set_enabled'/>
                  </IS>
                  <![CDATA[
ecmascript:

function initialize ()
{
	if (enabled) whichChoice =  0;
	else                        whichChoice = -1;
//	Browser.println ('enabled=' + enabled + ', whichChoice=' + whichChoice);
}

function set_enabled (value, timestamp)
{
	if (value) whichChoice =  0;
	else       whichChoice = -1;
//	Browser.println ('set_enabled=' + value + ', whichChoice=' + whichChoice);
}
]]>
                </Script>
                <ROUTE fromField='isActive' fromNode='WhereSensor' toField='set_enabled' toNode='EnabledScript'/>
                <ROUTE fromField='whichChoice' fromNode='EnabledScript' toField='whichChoice' toNode='ShowSwitch'/>
              </Group>
            </Transform>
          </Group>
        </Switch>
        <ROUTE fromField='position_changed' fromNode='WhereSensor' toField='set_translation' toNode='CameraLocation'/>
        <ROUTE fromField='orientation_changed' fromNode='WhereSensor' toField='set_rotation' toNode='CameraLocation'/>
      </ProtoBody>
    </ProtoDeclare>
    <!-- ======================== -->
    <NavigationInfo speed='10' type='"FLY" "ANY"'/>
    <ProtoInstance name='CrossHair'>
      <fieldValue name='enabled' value='true'/>
      <fieldValue name='markerColor' value='1 0.5 0'/>
      <fieldValue name='scale' value='1 1 1'/>
      <fieldValue name='positionOffsetFromCamera' value='0 0 -3'/>
    </ProtoInstance>
    <Group DEF='TextMenu'>
      <Transform>
        <Anchor description='CrossHair Example' parameter='"target=_blank"' url='"CrossHairExample.x3d" "https://www.web3d.org/x3d/content/examples/Savage/Tools/HeadsUpDisplays/CrossHairExample.x3d" "CrossHairExample.wrl" "https://www.web3d.org/x3d/content/examples/Savage/Tools/HeadsUpDisplays/CrossHairExample.wrl"'>
          <Shape>
            <Text string='"CrossHairPrototype is a" "prototype definition file." "Click text to see" "CrossHairExample"'>
              <FontStyle justify='"MIDDLE" "MIDDLE"' size='0.8'/>
            </Text>
            <Appearance>
              <Material diffuseColor='0.8 0.8 0.4'/>
            </Appearance>
          </Shape>
        </Anchor>
      </Transform>
    </Group>
  </Scene>
</X3D>