X3D Model Documentation: RelativeProximitySensorPrototype.x3d

  1  <?xml version="1.0" encoding="UTF-8"?>
  2 
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "https://www.web3d.org/specifications/x3d-3.0.dtd">
  3  <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'>
  4       <head>
  5            <meta name='titlecontent=' RelativeProximitySensorPrototype.x3d '/>
  6            <meta name='descriptioncontent='Paired object-to-object collision detection using proximity sensor design pattern, implemented as a reusable prototype node.'/>
  7            <meta name='creatorcontent='Don Brutzman and MV4204 class'/>
  8            <meta name='createdcontent='3 September 2004'/>
  9            <meta name='modifiedcontent='28 November 2019'/>
 10            <meta name='subjectcontent='Object-to-object collision detection'/>
 11            <meta name='identifiercontent=' https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/RelativeProximitySensorPrototype.x3d '/>
 12            <meta name='generatorcontent='X3D-Edit 3.2, https://www.web3d.org/x3d/tools/X3D-Edit'/>
 13            <meta name='licensecontent='../../license.html'/>
 14       </head>
<!--

<!-- to top DEF node index: Index for ProtoDeclare definition: RelativeProximitySensor
-->
 15       <Scene>
 16            <WorldInfo title='RelativeProximitySensorPrototype.x3d'/>
 17            <ProtoDeclare name='RelativeProximitySensorappinfo='RelativeProximitySensor measures paired object-to-object collision detection'>
 18                 <ProtoInterface>
 19                      <field name='descriptiontype='SFStringaccessType='inputOutput'
                     appinfo='describe the purpose of this sensor'/>
 20                      <field name='locationPrimarytype='SFVec3fvalue='0 0 0accessType='initializeOnly'
                     appinfo='where is the primary object'/>
 21                      <field name='set_locationPrimarytype='SFVec3faccessType='inputOnly'
                     appinfo='update location of the primary object'/>
 22                      <field name='locationSecondarytype='SFVec3fvalue='0 0 0accessType='initializeOnly'
                     appinfo='where is the secondary object'/>
 23                      <field name='set_locationSecondarytype='SFVec3faccessType='inputOnly'
                     appinfo='update location of the secondary object'/>
 24                      <field name='proximityRangeThresholdtype='SFFloatvalue='10accessType='initializeOnly'
                     appinfo='distance for detecting object-to-object collision'/>
 25                      <field name='set_proximityRangeThresholdtype='SFFloataccessType='inputOnly'
                     appinfo='change threshold distance for detecting collision'/>
 26                      <field name='isInRangetype='SFBoolaccessType='outputOnly'
                     appinfo='is object-to-object distance less than proximityRangeThreshold?'/>
 27                      <field name='isInRangeTimetype='SFTimeaccessType='outputOnly'
                     appinfo='when did object-to-object range meet detection criteria?'/>
 28                      <field name='enabledtype='SFBoolvalue='trueaccessType='initializeOnly'
                     appinfo='whether sensor is active'/>
 29                      <field name='set_enabledtype='SFBoolaccessType='inputOnly'/>
 30                 </ProtoInterface>
 31                 <ProtoBody>
 32                      <Group>
 33                           <Script>
 34                                <field name='descriptiontype='SFStringaccessType='inputOutput'
                               appinfo='describe the purpose of this sensor'/>
 35                                <field name='locationPrimarytype='SFVec3faccessType='initializeOnly'/>
 36                                <field name='set_locationPrimarytype='SFVec3faccessType='inputOnly'/>
 37                                <field name='locationSecondarytype='SFVec3faccessType='initializeOnly'/>
 38                                <field name='set_locationSecondarytype='SFVec3faccessType='inputOnly'/>
 39                                <field name='proximityRangeThresholdtype='SFFloataccessType='initializeOnly'/>
 40                                <field name='set_proximityRangeThresholdtype='SFFloataccessType='inputOnly'/>
 41                                <field name='isInRangetype='SFBoolaccessType='outputOnly'/>
 42                                <field name='isInRangeTimetype='SFTimeaccessType='outputOnly'/>
 43                                <field name='enabledtype='SFBoolaccessType='initializeOnly'/>
 44                                <field name='set_enabledtype='SFBoolaccessType='inputOnly'/>
 45                                <!-- local Script variables -->
 46                                <field name='priorDistancetype='SFFloatvalue='-1accessType='initializeOnly'/>
 47                                <field name='newDistancetype='SFFloatvalue='-1accessType='initializeOnly'/>
 48                                <field name='traceEnabledtype='SFBoolvalue='trueaccessType='initializeOnly'/>
 49                                <IS>
 50                                     <connect nodeField='descriptionprotoField='description'/>
 51                                     <connect nodeField='locationPrimaryprotoField='locationPrimary'/>
 52                                     <connect nodeField='set_locationPrimaryprotoField='set_locationPrimary'/>
 53                                     <connect nodeField='locationSecondaryprotoField='locationSecondary'/>
 54                                     <connect nodeField='set_locationSecondaryprotoField='set_locationSecondary'/>
 55                                     <connect nodeField='proximityRangeThresholdprotoField='proximityRangeThreshold'/>
 56                                     <connect nodeField='set_proximityRangeThresholdprotoField='set_proximityRangeThreshold'/>
 57                                     <connect nodeField='isInRangeprotoField='isInRange'/>
 58                                     <connect nodeField='isInRangeTimeprotoField='isInRangeTime'/>
 59                                     <connect nodeField='enabledprotoField='enabled'/>
 60                                     <connect nodeField='set_enabledprotoField='set_enabled'/>
 61                                </IS>
  <![CDATA[
            
ecmascript:

function initialize ()
{
	tracePrint ('initialize(), description=' + description + ', enabled=' + enabled +
		', traceEnabled=' + traceEnabled);
	if (!enabled) return;
	// sensor is enabled, so force initial proximity condition
	priorDistance = distance (locationPrimary, locationSecondary);
	if      (priorDistance > proximityRangeThreshold)
        {
		isInRange     = false;
                isInRangeTime = -1;
        }
	else	
        {
        	isInRange     = true;
                isInRangeTime = 0; // TODO change to current timestamp
	}
	tracePrint ('isInRange=' + isInRange + ', distance=' + priorDistance +
		', proximityRangeThreshold=' + proximityRangeThreshold);
}
function distance (p1, p2)
{
	return Math.sqrt (
		(p2.x - p1.x) * (p2.x - p1.x) +
		(p2.y - p1.y) * (p2.y - p1.y) +
		(p2.z - p1.z) * (p2.z - p1.z));
}
function computeProximity (value, timestamp) // triggering value is unused since it comes from different sources
{
	newDistance = distance (locationPrimary, locationSecondary);
//	tracePrint ('newDistance=' + newDistance);
	// test if proximity gained
	if      ((  newDistance <  proximityRangeThreshold) &&
	         (priorDistance >= proximityRangeThreshold))
	{
		isInRange     = true;
		isInRangeTime = timestamp;
		tracePrint ('isInRange=' + isInRange + ', newDistance=' + newDistance);
	}
	// test if proximity lost
	else if ((  newDistance >  proximityRangeThreshold) &&
	         (priorDistance <= proximityRangeThreshold))
	{
		isInRange     = false;
		isInRangeTime = timestamp;
		tracePrint ('isInRange=' + isInRange + ', newDistance=' + newDistance);
	}
	priorDistance = newDistance;
}
function set_description (newDescription)
{
    description = newDescription;
    tracePrint ('description=' + description);
}
function set_locationPrimary (value, timestamp)
{
	locationPrimary = value;
	if (enabled) computeProximity (value, timestamp);
}
function set_locationSecondary (value, timestamp)
{
	locationSecondary = value;
	if (enabled) computeProximity (value, timestamp);
}
function set_proximityRangeThreshold (value, timestamp)
{
	proximityRangeThreshold = value;
}
function set_enabled (value, timestamp)
{
	enabled = value;
	initialize (timestamp);
}
function tracePrint (outputString)
{
	if (traceEnabled) Browser.println ('[RelativeProximitySensor] ' + outputString);
}
function alwaysPrint (outputString)
{
	Browser.println ('[RelativeProximitySensor] ' + outputString);
}

          
]]>
 63                           </Script>
 64                      </Group>
 65                 </ProtoBody>
 66            </ProtoDeclare>
 67            <!-- ====================================== -->
 68            <!-- Example use -->
 69            <Anchor description='RelativeProximitySensor Exampleparameter='"target=_blank"'   url=' "RelativeProximitySensorExample.x3d" "https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/RelativeProximitySensorExample.x3d" "RelativeProximitySensorExample.wrl" "https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/RelativeProximitySensorExample.wrl" '>
 70                 <Shape>
 71                      <Text string='"RelativeProximitySensorPrototype" "defines a prototype" "" "Click text to see" "RelativeProximitySensorExample scene"'>
 72                           <FontStyle justify='"MIDDLE" "MIDDLE"size='0.7'/>
 73                      </Text>
 74                      <Appearance>
 75                           <Material diffuseColor='1 1 0.2'/>
 76                      </Appearance>
 77                 </Shape>
 78            </Anchor>
 79       </Scene>
 80  </X3D>
<!--

<!-- to top DEF node index: Index for ProtoDeclare definition: RelativeProximitySensor
-->
X3D Tooltips element index: Anchor, Appearance, connect, field, FontStyle, Group, head, IS, Material, meta, ProtoBody, ProtoDeclare, ProtoInterface, Scene, Script, Shape, Text, WorldInfo, X3D, plus documentation for accessType definitions, type definitions, XML data types, and field types

Event Graph ROUTE Table with 0 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.

line 33
Script
No direct ROUTE connection found for events to/from this node.
This Script has no direct access to other nodes. 

line 69
Anchor
description='RelativeProximitySensor Example' 
User-interaction hint for this node. 

Additional guidance on X3D animation can be found in the 10-Step Animation Design Process and Event Tracing hint sheets. Have fun with X3D! 😀

-->
<!-- Online at
https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/RelativeProximitySensorPrototypeIndex.html -->
<!-- Version control at
https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/content/examples/Savage/Tools/Animation/RelativeProximitySensorPrototype.x3d -->

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

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