vrml文件:route&java.wrl代码如下:
#VRML V2.0 utf8Viewpoint
{
position 0 0 15
orientation 0 0 1 0
fieldOfView 0.8
}Background
{
skyColor
[
0 0 0.2,
0.1 0.1 0.8,
0.7 0.8 0.9
]
skyAngle
[ 1.0 1.57 ]
groundColor
[
0.0 0.0 0.0,
0.5 0.4 0.3,
0.3 0.3 0.3
]
groundAngle
[ 1.57 1.0]
}DEF ball Transform
{
children
[
DEF switch TouchSensor
{
}
Shape
{
appearance Appearance
{
material Material
{
diffuseColor 1 0 0
emissiveColor 0 0 0
shininess 0.2
specularColor 0 0 0
transparency 0.0
}
texture NULL
textureTransform NULL
}
geometry Sphere { }
}
]
}DEF time TimeSensor
{
cycleInterval 5
loop TRUE
}DEF position1 PositionInterpolator
{
key [ 0 1 ]
keyValue
[
-10 0 0,
10 0 0
]
} DEF position2 PositionInterpolator
{
key [ 0 0.5 1 ]
keyValue
[
-10 0 0
0 2 10
10 0 0
]
}DEF changePath Script
{
url "route.class"
field SFBool status FALSE
field SFNode position1 USE position1
field SFNode position2 USE position2
field SFNode ball USE ball
eventIn SFBool onChange
}ROUTE time.fraction_changed TO position1.set_fraction
ROUTE time.fraction_changed TO position2.set_fraction
ROUTE switch.isActive TO changePath.onChangejava文件:route.java的代码如下:
import vrml.*;
import vrml.node.*;
import vrml.field.*;public class route extends Script{
private SFBool status;
Browser myBrowser;
Node position1;
Node position2;
Node ball;
public void initialize(){
myBrowser = getBrowser();
status = (SFBool)getField("status1");
position1 = (Node)((SFNode)getField("position1")).getValue();
position2 = (Node)((SFNode)getField("position2")).getValue();
ball = (Node)((SFNode)getField("ball")).getValue();
myBrowser.addRoute(position1, "value_changed", ball,"translation");
}
public void processEvent( Event e ){
ConstSFBool value = (ConstSFBool)e.getValue();
if( value.getValue() ){
if( status.getValue() ){
myBrowser.deleteRoute(position2,"value_changed", ball, "translation");
myBrowser.addRoute(position1, "value_chanegd", ball, "translation");
}
else{
myBrowser.deleteRoute(position1,"value_changed", ball, "translation");
myBrowser.addRoute(position2, "value_chanegd", ball, "translation");
}
}
status.setValue(!status.getValue());
}
}
我没有分,所以只能给1分,希望高手们不吝赐教,不甚感激。在此先谢过了。
#VRML V2.0 utf8Viewpoint
{
position 0 0 15
orientation 0 0 1 0
fieldOfView 0.8
}Background
{
skyColor
[
0 0 0.2,
0.1 0.1 0.8,
0.7 0.8 0.9
]
skyAngle
[ 1.0 1.57 ]
groundColor
[
0.0 0.0 0.0,
0.5 0.4 0.3,
0.3 0.3 0.3
]
groundAngle
[ 1.57 1.0]
}DEF ball Transform
{
children
[
DEF switch TouchSensor
{
}
Shape
{
appearance Appearance
{
material Material
{
diffuseColor 1 0 0
emissiveColor 0 0 0
shininess 0.2
specularColor 0 0 0
transparency 0.0
}
texture NULL
textureTransform NULL
}
geometry Sphere { }
}
]
}DEF time TimeSensor
{
cycleInterval 5
loop TRUE
}DEF position1 PositionInterpolator
{
key [ 0 1 ]
keyValue
[
-10 0 0,
10 0 0
]
} DEF position2 PositionInterpolator
{
key [ 0 0.5 1 ]
keyValue
[
-10 0 0
0 2 10
10 0 0
]
}DEF changePath Script
{
url "route.class"
field SFBool status FALSE
field SFNode position1 USE position1
field SFNode position2 USE position2
field SFNode ball USE ball
eventIn SFBool onChange
}ROUTE time.fraction_changed TO position1.set_fraction
ROUTE time.fraction_changed TO position2.set_fraction
ROUTE switch.isActive TO changePath.onChangejava文件:route.java的代码如下:
import vrml.*;
import vrml.node.*;
import vrml.field.*;public class route extends Script{
private SFBool status;
Browser myBrowser;
Node position1;
Node position2;
Node ball;
public void initialize(){
myBrowser = getBrowser();
status = (SFBool)getField("status1");
position1 = (Node)((SFNode)getField("position1")).getValue();
position2 = (Node)((SFNode)getField("position2")).getValue();
ball = (Node)((SFNode)getField("ball")).getValue();
myBrowser.addRoute(position1, "value_changed", ball,"translation");
}
public void processEvent( Event e ){
ConstSFBool value = (ConstSFBool)e.getValue();
if( value.getValue() ){
if( status.getValue() ){
myBrowser.deleteRoute(position2,"value_changed", ball, "translation");
myBrowser.addRoute(position1, "value_chanegd", ball, "translation");
}
else{
myBrowser.deleteRoute(position1,"value_changed", ball, "translation");
myBrowser.addRoute(position2, "value_chanegd", ball, "translation");
}
}
status.setValue(!status.getValue());
}
}
我没有分,所以只能给1分,希望高手们不吝赐教,不甚感激。在此先谢过了。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货