missile_0_00.x3d source
<?xml version="1.0" encoding="UTF-8"?>

<X3D>
<Scene>
<Viewpoint position='0 20 5' orientation='1 0 0 -1'/>
<NavigationInfo
type='"NONE"'
/>
<!-- UFO -->

<Transform DEF='UFO-Tf'>
<Transform scale='1 0.5 0.5'>
<Shape>
<Appearance>
<Material DEF='UFO-Mt0' diffuseColor='0.8 0.8 0.9'/>
</Appearance>
<Sphere/>
</Shape>
</Transform>
<Transform translation='1 0 0.2' scale='0.3 0.3 1'>
<Shape>
<Appearance DEF='UFO-Ap'>
<Material DEF='UFO-Mt1' diffuseColor='0.8 0.9 0.8'/>
</Appearance>
<Sphere/>
</Shape>
</Transform>
<Transform translation='-1 0 0.2' scale='0.3 0.3 1'>
<Shape>
<Appearance USE='UFO-Ap'/>
<Sphere/>
</Shape>
</Transform>
</Transform>

<!-- UFO turn TimeSensor -->
<TimeSensor DEF='UFOOI-TiS' loop='TRUE'/>

<!-- UFO turn animation -->
<OrientationInterpolator DEF='UFO-OI'
key='0 0.25 0.5 0.75 1'
keyValue='0 0 1 0
0 0 1 1.5708
0 0 1 3.1416
0 0 1 4.7124
0 0 1 6.2832
'
/>

<ROUTE fromNode='UFOOI-TiS' fromField='fraction_changed' toNode='UFO-OI' toField='set_fraction'/>
<ROUTE fromNode='UFO-OI' fromField='value_changed' toNode='UFO-Tf' toField='rotation'/>

<!-- UFO move TimeSensor -->
<TimeSensor DEF='UFOPI-TiS' loop='TRUE' cycleInterval='10'/>

<!-- UFO move animation -->
<PositionInterpolator DEF='UFO-PI'
key='0 0.5 1'
keyValue='-10 0 -20
10 0 -20
-10 0 -20
'
/>

<ROUTE fromNode='UFOPI-TiS' fromField='fraction_changed' toNode='UFO-PI' toField='set_fraction'/>
<ROUTE fromNode='UFO-PI' fromField='value_changed' toNode='UFO-Tf' toField='translation'/>

<!-- ##################################################################################### -->

<!-- Meteo 0 -->
<Transform DEF='Meteo0-Tf'>
<Shape DEF='Meteo-Sp'>
<Appearance>
<Material diffuseColor='0.8 0 0'/>
</Appearance>
<Sphere/>
</Shape>
</Transform>

<!-- Meteo 0 move TimeSensor -->
<TimeSensor DEF='Meteo0-TiS' loop='TRUE' cycleInterval='5'/>

<!-- Meteo 0 move animation -->
<PositionInterpolator DEF='Meteo0-PI'
key='0 1'
keyValue='-12 0 -17
12 0 -17
'
/>

<ROUTE fromNode='Meteo0-TiS' fromField='fraction_changed' toNode='Meteo0-PI' toField='set_fraction'/>
<ROUTE fromNode='Meteo0-PI' fromField='value_changed' toNode='Meteo0-Tf' toField='translation'/>

<!-- Meteo 1 -->
<Transform DEF='Meteo1-Tf'>
<Shape USE='Meteo-Sp'/>
</Transform>

<!-- Meteo 1 move TimeSensor -->
<TimeSensor DEF='Meteo1-TiS' loop='TRUE' cycleInterval='7'/>

<!-- Meteo 1 move animation -->
<PositionInterpolator DEF='Meteo1-PI'
key='0 1'
keyValue='12 0 -14
-12 0 -14
'
/>

<ROUTE fromNode='Meteo1-TiS' fromField='fraction_changed' toNode='Meteo1-PI' toField='set_fraction'/>
<ROUTE fromNode='Meteo1-PI' fromField='value_changed' toNode='Meteo1-Tf' toField='translation'/>

<!-- Meteo 2 -->
<Transform DEF='Meteo2-Tf'>
<Shape USE='Meteo-Sp'/>
</Transform>

<!-- Meteo 2 move TimeSensor -->
<TimeSensor DEF='Meteo2-TiS' loop='TRUE' cycleInterval='8'/>

<!-- Meteo 2 move animation -->
<PositionInterpolator DEF='Meteo2-PI'
key='0 1'
keyValue='-12 0 -11
12 0 -11
'
/>
<ROUTE fromNode='Meteo2-TiS' fromField='fraction_changed' toNode='Meteo2-PI' toField='set_fraction'/>
<ROUTE fromNode='Meteo2-PI' fromField='value_changed' toNode='Meteo2-Tf' toField='translation'/>

<!-- ##################################################################################### -->

<!-- missile and explosion -->
<Transform DEF='Missile-Tf'>
<Switch DEF='Missile-Sw' whichChoice='0'>

<!-- 0 missile -->
<Transform rotation='1 0 0 -1.5708'>
<Shape>
<Appearance>
<Material diffuseColor='1 0.9 0.5'/>
</Appearance>
<Cone bottomRadius='0.5'/>
</Shape>
</Transform>

<!-- 1 explosion -->
<Transform DEF='Expl-Tf'>
<Shape>
<Appearance>
<Material DEF='Expl-Mt' diffuseColor='1 0.5 0'/>
</Appearance>
<Sphere radius='0.7'/>
</Shape>
</Transform>
</Switch>
</Transform>

<!-- missile move TimeSensor -->
<TimeSensor DEF='Missile-TiS' cycleInterval='20'/>

<!-- missile explosion TimeSensor -->
<TimeSensor DEF='Expl-TiS' cycleInterval='0.5'/>

<!-- missile explosion expansion animation -->
<PositionInterpolator DEF='Expl-PI'
key='0 1'
keyValue='1 1 1
2 2 2
'
/>
<ROUTE fromNode='Expl-TiS' fromField='fraction_changed' toNode='Expl-PI' toField='set_fraction'/>
<ROUTE fromNode='Expl-PI' fromField='value_changed' toNode='Expl-Tf' toField='scale'/>

<!-- missile explosion color change animation -->
<ColorInterpolator DEF='Expl-CI'
key='0 0.5 1'
keyValue='1 1 0.5
0.6 0 0
0.2 0 0
'
/>
<ROUTE fromNode='Expl-TiS' fromField='fraction_changed' toNode='Expl-CI' toField='set_fraction'/>
<ROUTE fromNode='Expl-CI' fromField='value_changed' toNode='Expl-Mt' toField='diffuseColor'/>

<!-- ##################################################################################### -->

<!-- console -->
<Transform DEF='Console-Tf'>

<!-- slider -->
<Transform translation='0 -1.5 -5'>
<Transform DEF='Slider-Tf'>
<Shape>
<Appearance>
<Material diffuseColor='0 0.8 0'/>
</Appearance>
<Sphere radius='0.2'/>
</Shape>
</Transform>
<Shape>
<Appearance>
<Material diffuseColor='0.5 0 0'/>
</Appearance>
<Box size='2 0.1 0.1'/>
</Shape>
<PlaneSensor DEF='Slider-PlS' minPosition='-1 0' maxPosition='1 0'/>
</Transform>

<!-- button -->
<Transform translation='1.5 -1.5 -5' rotation='1 0 0 -1.5708'>
<Shape>
<Appearance>
<Material diffuseColor='1 0.5 0'/>
</Appearance>
<Cylinder radius='0.3' height='0.1'/>
</Shape>
<TouchSensor DEF='Button-ThS'/>
</Transform>

<!-- score -->
<Transform translation='-1.5 -1.7 -5'>
<Shape>
<Appearance>
<Material diffuseColor='1 1 0.999'/>
</Appearance>
<Text DEF='Score-Tx'
string='"0"'
>
<FontStyle size='0.5'
justify='"MIDDLE"'
/>
</Text>
</Shape>
</Transform>
</Transform>

<ROUTE fromNode='Slider-PlS' fromField='translation_changed' toNode='Slider-Tf' toField='translation'/>
<ROUTE fromNode='Button-ThS' fromField='touchTime' toNode='Missile-TiS' toField='startTime'/>

<ProximitySensor DEF='PrS' size='1000 1000 1000'/>
<ROUTE fromNode='PrS' fromField='position_changed' toNode='Console-Tf' toField='set_translation'/>
<ROUTE fromNode='PrS' fromField='orientation_changed' toNode='Console-Tf' toField='set_rotation'/>

<Script DEF='Sc'>
<field accessType='inputOnly' type='SFVec3f' name='set_translationPlS'/>
<field accessType='inputOnly' type='SFFloat' name='set_fraction'/>
<field accessType='inputOnly' type='SFBool' name='settingMissile'/>
<field accessType='outputOnly' type='SFVec3f' name='missilePos'/>
<field accessType='outputOnly' type='SFTime' name='stopTimeMissile'/>
<field accessType='outputOnly' type='SFTime' name='startTimeExpl'/>
<field accessType='outputOnly' type='SFInt32' name='whichChoice'/>
<field accessType='outputOnly' type='MFString' name='scStr'/>
<field accessType='outputOnly' type='SFColor' name='emiColorUfo'/>
<field accessType='initializeOnly' type='SFNode' name='UFO'>
<Transform USE='UFO-Tf'/>
</field>
<field accessType='initializeOnly' type='MFNode' name='Meteos'>
<Transform USE='Meteo0-Tf'/>
<Transform USE='Meteo1-Tf'/>
<Transform USE='Meteo2-Tf'/>
</field>
<field accessType='initializeOnly' type='SFInt32' name='score' value='0'/>
<field accessType='initializeOnly' type='MFColor' name='ufoColors'
value='0 0 0
1 0 0
'
/>
<![CDATA[ecmascript:

// スライダーの x 座標に従ってミサイルを横に移動させる
function set_translationPlS (val) {

missilePos.x = val.x * 5;

}

function set_fraction (f,et) {

// TimeSensor の進み具合によってミサイルを奥に進める
missilePos.z = f * -20;

// ミサイルが奥に到達したら手前に戻す
if ( f >= 1 ) missilePos.z = 0;

// ミサイルとUFOの当たり判定
if ( isHit(missilePos, UFO.translation ) ) {

// 当たっているなら、ミサイルの動きを止め爆発させる
stopTimeMissile = et;
startTimeExpl = et;
whichChoice = 1;
emiColorUfo = ufoColors[1];

// 得点を10点上げる
score += 10;
scStr[0] = score;

}

// ミサイルと隕石の当たり判定
for ( var i = 0; i < Meteos.length; i++ ) {

if ( isHit(missilePos, Meteos[i].translation ) ) {

// 当たっているなら、ミサイルの動きを止め爆発させる
stopTimeMissile = et;
startTimeExpl = et;
whichChoice = 1;

}

}

}

// 2つの位置ベクトルの距離が 1.5 以下なら true を返す
function isHit (va,vb) {

return ( va.subtract(vb).length() <= 1.5 );

}

// ミサイルの爆発アニメが終わったらミサイルを再セット
function settingMissile (val) {

if (!val) {

whichChoice = 0;
missilePos.z = 0;
emiColorUfo = ufoColors[0];

}
}
]]>
</Script>

<ROUTE fromNode='Slider-PlS' fromField='translation_changed' toNode='Sc' toField='set_translationPlS'/>
<ROUTE fromNode='Missile-TiS' fromField='fraction_changed' toNode='Sc' toField='set_fraction'/>
<ROUTE fromNode='Expl-TiS' fromField='isActive' toNode='Sc' toField='settingMissile'/>

<ROUTE fromNode='Sc' fromField='missilePos' toNode='Missile-Tf' toField='translation'/>
<ROUTE fromNode='Sc' fromField='stopTimeMissile' toNode='Missile-TiS' toField='stopTime'/>
<ROUTE fromNode='Sc' fromField='startTimeExpl' toNode='Expl-TiS' toField='startTime'/>
<ROUTE fromNode='Sc' fromField='whichChoice' toNode='Missile-Sw' toField='whichChoice'/>
<ROUTE fromNode='Sc' fromField='scStr' toNode='Score-Tx' toField='string'/>
<ROUTE fromNode='Sc' fromField='emiColorUfo' toNode='UFO-Mt0' toField='emissiveColor'/>
<ROUTE fromNode='Sc' fromField='emiColorUfo' toNode='UFO-Mt1' toField='emissiveColor'/>
</Scene>
</X3D>