| 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='title' content=' RelativeProximitySensorPrototype.x3d '/> |
| 6 | <meta name='description' content='Paired object-to-object collision detection using proximity sensor design pattern, implemented as a reusable prototype node.'/> |
| 7 | <meta name='creator' content='Don Brutzman and MV4204 class'/> |
| 8 | <meta name='created' content='3 September 2004'/> |
| 9 | <meta name='modified' content='28 November 2019'/> |
| 10 | <meta name='subject' content='Object-to-object collision detection'/> |
| 11 | <meta name='identifier' content=' https://www.web3d.org/x3d/content/examples/Savage/Tools/Animation/RelativeProximitySensorPrototype.x3d '/> |
| 12 | <meta name='generator' content='X3D-Edit 3.2, https://www.web3d.org/x3d/tools/X3D-Edit'/> |
| 13 | <meta name='license' content='../../license.html'/> |
| 14 | </head> |
| 15 | <Scene> |
| 16 | <WorldInfo title='RelativeProximitySensorPrototype.x3d'/> |
| 17 | <ProtoDeclare name='RelativeProximitySensor' appinfo='RelativeProximitySensor measures paired object-to-object collision detection'> |
| 18 | <ProtoInterface> |
| 19 |
<field name='description' type='SFString' accessType='inputOutput'
appinfo='describe the purpose of this sensor'/> |
| 20 |
<field name='locationPrimary' type='SFVec3f' value='0 0 0' accessType='initializeOnly'
appinfo='where is the primary object'/> |
| 21 |
<field name='set_locationPrimary' type='SFVec3f' accessType='inputOnly'
appinfo='update location of the primary object'/> |
| 22 |
<field name='locationSecondary' type='SFVec3f' value='0 0 0' accessType='initializeOnly'
appinfo='where is the secondary object'/> |
| 23 |
<field name='set_locationSecondary' type='SFVec3f' accessType='inputOnly'
appinfo='update location of the secondary object'/> |
| 24 |
<field name='proximityRangeThreshold' type='SFFloat' value='10' accessType='initializeOnly'
appinfo='distance for detecting object-to-object collision'/> |
| 25 |
<field name='set_proximityRangeThreshold' type='SFFloat' accessType='inputOnly'
appinfo='change threshold distance for detecting collision'/> |
| 26 |
<field name='isInRange' type='SFBool' accessType='outputOnly'
appinfo='is object-to-object distance less than proximityRangeThreshold?'/> |
| 27 |
<field name='isInRangeTime' type='SFTime' accessType='outputOnly'
appinfo='when did object-to-object range meet detection criteria?'/> |
| 28 |
<field name='enabled' type='SFBool' value='true' accessType='initializeOnly'
appinfo='whether sensor is active'/> |
| 29 | <field name='set_enabled' type='SFBool' accessType='inputOnly'/> |
| 30 | </ProtoInterface> |
| 31 | <ProtoBody> |
| 32 | <Group> |
| 33 | <Script> |
| 34 |
<field name='description' type='SFString' accessType='inputOutput'
appinfo='describe the purpose of this sensor'/> |
| 35 | <field name='locationPrimary' type='SFVec3f' accessType='initializeOnly'/> |
| 36 | <field name='set_locationPrimary' type='SFVec3f' accessType='inputOnly'/> |
| 37 | <field name='locationSecondary' type='SFVec3f' accessType='initializeOnly'/> |
| 38 | <field name='set_locationSecondary' type='SFVec3f' accessType='inputOnly'/> |
| 39 | <field name='proximityRangeThreshold' type='SFFloat' accessType='initializeOnly'/> |
| 40 | <field name='set_proximityRangeThreshold' type='SFFloat' accessType='inputOnly'/> |
| 41 | <field name='isInRange' type='SFBool' accessType='outputOnly'/> |
| 42 | <field name='isInRangeTime' type='SFTime' accessType='outputOnly'/> |
| 43 | <field name='enabled' type='SFBool' accessType='initializeOnly'/> |
| 44 | <field name='set_enabled' type='SFBool' accessType='inputOnly'/> |
| 45 | <!-- local Script variables --> |
| 46 | <field name='priorDistance' type='SFFloat' value='-1' accessType='initializeOnly'/> |
| 47 | <field name='newDistance' type='SFFloat' value='-1' accessType='initializeOnly'/> |
| 48 | <field name='traceEnabled' type='SFBool' value='true' accessType='initializeOnly'/> |
| 49 | <IS> |
| 50 | <connect nodeField='description' protoField='description'/> |
| 51 | <connect nodeField='locationPrimary' protoField='locationPrimary'/> |
| 52 | <connect nodeField='set_locationPrimary' protoField='set_locationPrimary'/> |
| 53 | <connect nodeField='locationSecondary' protoField='locationSecondary'/> |
| 54 | <connect nodeField='set_locationSecondary' protoField='set_locationSecondary'/> |
| 55 | <connect nodeField='proximityRangeThreshold' protoField='proximityRangeThreshold'/> |
| 56 | <connect nodeField='set_proximityRangeThreshold' protoField='set_proximityRangeThreshold'/> |
| 57 | <connect nodeField='isInRange' protoField='isInRange'/> |
| 58 | <connect nodeField='isInRangeTime' protoField='isInRangeTime'/> |
| 59 | <connect nodeField='enabled' protoField='enabled'/> |
| 60 | <connect nodeField='set_enabled' protoField='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 Example' parameter='"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> |
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. |
<!--
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>
-->
<!--
For additional help information about X3D scenes, please see X3D Tooltips, X3D Resources, and X3D Scene Authoring Hints.
-->