- 最后登录
- 2013-6-5
- 注册时间
- 2011-12-5
- 阅读权限
- 90
- 积分
- 17782
- 纳金币
- 17782
- 精华
- 0
|
主要内容:交互
LOD细节级别
LOD此节点会根据视点到物体的距离做出不同的事件,例如根据不同的距离显示不同的图形。
range 层次范围
<LOD range="15">
<Shape>
<Box/>
</Shape>
<Shape>
<Text string="hello"/>
</Shape>
</LOD>
<LOD range="15 30">
<Shape>
<Box/>
</Shape>
<Shape>
<Text string="hello"/>
</Shape>
<Shape>
<Cone />
</Shape>
</LOD>
Collision碰撞
Collision当视点与物体发生碰撞时发生事件
collideTime 发生碰撞的时间事件
<Collision DEF='C' enabled='true'>
<Transform DEF='Mover' translation='0 1 0'>
<Shape>
<Appearance>
<ImageTexture url="2.jpg" />
</Appearance>
<Sphere radius='0.2'/>
</Shape>
</Transform>
</Collision>
<TimeSensor DEF='Clock' cycleInterval='8' />
使起初不会转?
记得以前的TimeSensor?
<TimeSensor DEF='Clock' cycleInterval='8' loop='true' />
通过set_startTime启动TimeSensor
<OrientationInterpolator DEF='Or' key='0, 0.5, 1' keyValue='0 1 0 0.0, 0 1 0 3.14, 0 1 0 6.28'/>
<ROUTE fromNode='C' fromField='collideTime' toNode='Clock' toField='set_startTime'/>
<ROUTE fromNode='Clock' fromField='fraction_changed' toNode='Or' toField='set_fraction'/>
<ROUTE fromNode='Or' fromField='value_changed' toNode='Mover' toField='set_rotation'/>
Anchor超链接
des cription 描述
url 地址
链接到网页
<Anchor des cription="baidu.com" url="http://www.baidu.com">
<Shape>
<Text string="baidu"/>
</Shape>
</Anchor>
保存为1.X3D
链接到X3D文件
<Anchor url="1.x3d">
<Shape>
<Appearance>
<Material diffuseColor="1 0 0" emissiveColor="0 1 0" specularColor="0 0 1"/>
</Appearance>
<Box size="1 1 1"/>
</Shape>
</Anchor>
Touch接触
TouchSensor接触感应
isActive 鼠标按下时为true
isOver 鼠标划过时发生事件
touchTime鼠标按下时发生时间事件
交互流程
改变文字
<Shape>
<Text DEF="text" string="hello"/>
</Shape>
<TouchSensor DEF="touchSensor"/>
<s cript DEF="s cript">
<field name="set_active" type="SFBool" accessType="inputOnly" />
<field name="string_changed" type="MFString" accessType="outputOnly" />
<![CDATA[javas cript:
function set_active()
{
string_changed = "touch";
}]]>
</s cript>
<ROUTE fromNode="touchSensor" fromField="isActive" toNode="s cript" toField="set_active" />
<ROUTE fromNode="s cript" fromField="string_changed" toNode="text" toField="string" />
划过便触发
<ROUTE fromNode="touchSensor" fromField="isOver" toNode="s cript" toField="set_active" />
<ROUTE fromNode="s cript" fromField="string_changed" toNode="text" toField="string" />
左右移动
按钮 TouchSensor放在中间表示只对某个物体有效
<Transform translation="-2 -2 0">
<TouchSensor DEF="touchSensor1"/>
<Shape>
<Text string="Left"/>
</Shape>
</Transform>
<Transform translation="2 -2 0">
<TouchSensor DEF="touchSensor2"/>
<Shape>
<Text string="Right"/>
</Shape>
</Transform>
移动体
<Transform DEF="M" >
<Shape>
<Appearance>
<ImageTexture url="2.jpg"/>
</Appearance>
<Box/>
</Shape>
</Transform>
<s cript DEF="s cript">
<field name="set_fraction1" type="SFBool" accessType="inputOnly" />
<field name="set_fraction2" type="SFBool" accessType="inputOnly" />
<field name="value_changed" type="SFVec3f" accessType="outputOnly" />
<![CDATA[javas cript:
function set_fraction1()
{
value_changed[0]-=0.2;
}
function set_fraction2()
{
value_changed[0]+=0.2;
}
]]>
</s cript>
<ROUTE fromNode="touchSensor1" fromField="isActive" toNode="s cript" toField="set_fraction1" />
<ROUTE fromNode="touchSensor2" fromField="isActive" toNode="s cript" toField="set_fraction2" />
<ROUTE fromNode="s cript" fromField="value_changed" toNode="M" toField="translation" />
陨石游戏
点击发生变化
<Transform DEF="transform">
<Shape>
<Appearance>
<ImageTexture url="3.jpg" />
</Appearance>
<Sphere radius="1" />
</Shape>
</Transform>
<TouchSensor DEF="touchSensor"/>
<s cript DEF="s cript">
<field name="set_fraction" type="SFBool" accessType="inputOnly" />
<field name="value_changed" type="SFVec3f" accessType="outputOnly" />
<![CDATA[javas cript:
function set_fraction()
{
value_changed[2] -= 10;
}]]>
</s cript>
<ROUTE fromNode="touchSensor" fromField="isActive" toNode="s cript" toField="set_fraction" />
<ROUTE fromNode="s cript" fromField="value_changed" toNode="transform" toField="translation" />
计分
<Transform translation="-2 2 0">
<Shape>
<Text DEF="text"/>
</Shape>
</Transform>
<TimeSensor DEF="Clock" cycleInterval="4" loop="true"/>
添加成员
<s cript DEF="s cript">
<field name="set_fraction" type="SFBool" accessType="inputOnly" />
<field name='set_fraction2' type='SFFloat' accessType='inputOnly'/>
<field name="value_changed" type="SFVec3f" accessType="outputOnly" />
<field name="string_changed" type="MFString" accessType="outputOnly" value="scores:0"/>
<field name="scores" type="SFInt32" accessType="outputOnly" value="0"/>
function set_fraction()
{
value_changed[2] -= 10;
scores+=10;
}
function set_fraction2()
{
string_changed="scores:"+scores;
}
<ROUTE fromNode="Clock" fromField="fraction_changed" toNode="s cript" toField="set_fraction2" />
<ROUTE fromNode="s cript" fromField="string_changed" toNode="text" toField="string" />
陨石会移动
时间
<TimeSensor DEF="Clock2" cycleInterval="4" loop="true"/>
成员
<field name='set_fraction3' type='SFFloat' accessType='inputOnly'/>
<field name="t" type="SFFloat" accessType="outputOnly" />
圆周运动
function set_fraction3() {
t+=0.1;
value_changed[0] =2*Math.sin(t);
value_changed[1] =2*Math.cos(t);
}
传递
<ROUTE fromNode="Clock2" fromField="fraction_changed" toNode="s cript" toField="set_fraction3" />
点文字也可以?移动位置
<Transform DEF="transform">
<TouchSensor DEF="touchSensor"/>
<Shape>
<Appearance>
<ImageTexture url="3.jpg" />
</Appearance>
<Sphere radius="1" />
</Shape>
</Transform>
改进:多个球,复杂的移动路径 |
|