<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN"   "http://www.web3d.org/specifications/x3d-3.0.dtd">
<X3D profile='Immersiveversion='3.0xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation=' http://www.web3d.org/specifications/x3d-3.0.xsd '>
<head>
<meta name='titlecontent='ViewPositionOrientationPrototype.x3d'/>
<meta name='creatorcontent='Leonard Daly and Don Brutzman'/>
<meta name='translatorcontent='Don Brutzman'/>
<meta name='createdcontent='1 November 2000'/>
<meta name='modifiedcontent='13 June 2004'/>
<meta name='descriptioncontent='As user navigates, display local position and orientation in the console output window.'/>
<meta name='referencecontent=' http://www.realism.com/Web3D/Examples#WhereAmI '/>
<meta name='referencecontent=' http://www.realism.com/vrml/Example/WhereAmI/WhereAmI_Proto.wrl '/>
<meta name='identifiercontent='https://savage.nps.edu/Savage/Tools/Authoring/ViewPositionOrientationPrototype.x3d'/>
<meta name='identifiercontent=' http://www.web3d.org/x3d/content/examples/Basic/course/ViewPositionOrientationPrototype.x3d '/>
<meta name='generatorcontent='X3D-Edit 3.2, https://savage.nps.edu/X3D-Edit'/>
<meta name='licensecontent='../license.html'/>
</head>
<!--

Index for ProtoDeclare definition: ViewPositionOrientation
Index for DEF nodes: OutputPositionOrientation, WhereSensor
Index for Viewpoint image: Viewpoint_1
-->
<Scene>
<!-- Thanks to Leonard Daly daly@realism.com for the original design of this prototype. -->
<ProtoDeclare name='ViewPositionOrientation'>
<ProtoInterface>
<field name='enabledtype='SFBoolvalue='trueaccessType='inputOutput'/>
<field name='traceEnabledtype='SFBoolvalue='trueaccessType='initializeOnly'/>
<field name='set_traceEnabledtype='SFBoolaccessType='inputOnly'/>
<field name='position_changedtype='SFVec3faccessType='outputOnly'/>
<field name='orientation_changedtype='SFRotationaccessType='outputOnly'/>
<field name='outputViewpointStringtype='MFStringaccessType='outputOnly'/>
</ProtoInterface>
<ProtoBody>
<!-- it's a big old world out there! -->
<!-- WhereSensor ROUTEs:  [from position_changed to OutputPositionOrientation.set_position ] [from orientation_changed to OutputPositionOrientation.set_orientation ] -->
<ProximitySensor DEF='WhereSensorsize='1000000000 1000000000 1000000000'>
<IS>
<connect nodeField='enabledprotoField='enabled'/>
</IS>
</ProximitySensor>
<!-- OutputPositionOrientation ROUTEs:  [from WhereSensor.position_changed to set_position ] [from WhereSensor.orientation_changed to set_orientation ] -->
<Script DEF='OutputPositionOrientation'>
<field name='traceEnabledtype='SFBoolaccessType='initializeOnly'/>
<field name='set_traceEnabledtype='SFBoolaccessType='inputOnly'/>
<field name='set_positiontype='SFVec3faccessType='inputOnly'/>
<field name='set_orientationtype='SFRotationaccessType='inputOnly'/>
<field name='positiontype='SFVec3fvalue='0 0 0accessType='initializeOnly'/>
<field name='orientationtype='SFRotationvalue='0 1 0 0accessType='initializeOnly'/>
<field name='position_changedtype='SFVec3faccessType='outputOnly'/>
<field name='orientation_changedtype='SFRotationaccessType='outputOnly'/>
<field name='outputViewpointStringtype='MFStringaccessType='outputOnly'/>
<IS>
<connect nodeField='traceEnabledprotoField='traceEnabled'/>
<connect nodeField='set_traceEnabledprotoField='set_traceEnabled'/>
<connect nodeField='position_changedprotoField='position_changed'/>
<connect nodeField='orientation_changedprotoField='orientation_changed'/>
<connect nodeField='outputViewpointStringprotoField='outputViewpointString'/>
</IS>
<![CDATA[
          ecmascript:

function roundoff (value, digits) // for local use only
{
	resolution = 1;
	for (i = 1; i <= digits; i++ )
	{
		resolution *= 10;
	}
	return Math.round (value*resolution) / resolution; // round to resolution
}
function outputViewpoint ()
{
	outputViewpointString[0] =
'<Viewpoint position=\"' +
		roundoff (position.x, 1) + ' ' +
		roundoff (position.y, 1) + ' ' +
		roundoff (position.z, 1) + '\" orientation=\"' +
		roundoff (orientation.x, 3) + ' ' +
		roundoff (orientation.y, 3) + ' ' +
		roundoff (orientation.z, 3) + ' ' +
		roundoff (orientation.angle, 4) + '\"/>';
	tracePrint (outputViewpointString);
}
function set_position (value, timestamp)
{
	position = value; // save persistent value
	position_changed = position; // output event
	outputViewpoint ();
}
function set_orientation (value)
{
	orientation = value; // save persistent value
	orientation_changed = orientation; // output event
	outputViewpoint ();
}
function set_traceEnabled (value)
{
	traceEnabled = value;
	tracePrint ('traceEnabled=' + traceEnabled);
}
function forcePrint (text)
{
	Browser.print ('[ViewPositionOrientation]' + text);
}
function tracePrint (text)
{
	if (traceEnabled) Browser.print ('[ViewPositionOrientation]' + text);
}
        
]]>
</Script>
<ROUTE fromNode='WhereSensorfromField='position_changedtoNode='OutputPositionOrientationtoField='set_position'/>
<ROUTE fromNode='WhereSensorfromField='orientation_changedtoNode='OutputPositionOrientationtoField='set_orientation'/>
</ProtoBody>
</ProtoDeclare>
<!-- ==================== -->
<Viewpoint description='ViewPositionOrientationposition='0 0 14'/>
<Anchor description='ViewPositionOrientation Exampleparameter='target=_blank'
  url=' "ViewPositionOrientationExample.wrl" "ViewPositionOrientationExample.x3d" "https://savage.nps.edu/Savage/Tools/Authoring/ViewPositionOrientationExample.wrl" "https://savage.nps.edu/Savage/Tools/Authoring/ViewPositionOrientationExample.x3d" '>
<Shape>
<Text string='"ViewPositionOrientationPrototype" "is a prototype definition file" "" "Click this text to see" "ViewPositionOrientationExample"solid='true'>
<FontStyle justify='"MIDDLE" "MIDDLE"size='1.2'/>
</Text>
<Appearance>
<Material diffuseColor='0.6 0.8 0.4'/>
</Appearance>
</Shape>
</Anchor>
</Scene>
</X3D>
<!--

Index for ProtoDeclare definition: ViewPositionOrientation
Index for DEF nodes: OutputPositionOrientation, WhereSensor
Index for Viewpoint image: Viewpoint_1
-->

<!-- Tag color codes: <Node DEF='idName' attribute='value'/> <Prototype name='ProtoName'> <field name='fieldName'/> </Prototype> -->