发布网友 发布时间:2022-04-25 15:06
共2个回答
热心网友 时间:2023-10-11 00:51
Script执行语句写完要加分号!
TimeSensor节点enabled域是控制是否有效的,并不会停止运算,所以当再次enabled时,所得的fraction_changed是原先的。
要想得到暂停的效果,可以将TimeSensor的startTime+暂停的时间,这样得到的就是暂停时的fraction。
请看:
#VRML V2.0 utf8
Transform {
translation 2.5 0.0 0.0
children [
Shape{
appearance Appearance {
material Material {
diffuseColor 0.0 0.8 0.8
}
}
geometry Box {
size 5.0 0.1 2.0
}
}]}
DEF ball Transform {
children [
Shape {
appearance Appearance {
material Material {
diffuseColor 1.0 0.0 0.0
}
}
geometry Sphere {
radius 0.5
}
}
]}
Transform {
translation -3.3 -1.0 0.0
children [
Shape {
appearance Appearance {
material Material {
diffuseColor 1 1 0
}}
geometry Text {
string [ "Stop"]
fontStyle FontStyle {
family "SANS"
size 0.5}
}}
Transform {
translation 0.2 0.0 -1.0
children [
DEF anniu Shape {
appearance Appearance {
material Material {
diffuseColor .61 .61 .61
specularColor .39 .39 .39
ambientIntensity .25
shininess .11
}}
geometry Box {
size 1.5 0.8 0.1}}
DEF touch1 TouchSensor {}]}]}
Transform {
translation -3.3 0.9 0.0
children [
Shape {
appearance Appearance {
material Material {
diffuseColor 0 1 0
}}
geometry Text {
string ["Play"]
fontStyle FontStyle {
family "SANS"
size 0.5}}}
Transform {
translation 0.2 0.2 -1.0
children [
Shape {
appearance Appearance {
material Material {
diffuseColor .61 .61 .61
specularColor .39 .39 .39
ambientIntensity .25
shininess .11
}}
geometry Box {
size 1.5 0.8 0.1}}
DEF touch2 TouchSensor {}]}]}
DEF clock TimeSensor {
cycleInterval 6
loop TRUE
enabled FALSE
}
DEF path1 Script {
eventIn SFBool input
eventOut SFBool output
url "vrmlscript:
function input (bool)
{
if(bool)
output=!bool;}"
}
DEF path2 Script {
eventIn SFBool input
eventOut SFBool output
url "vrmlscript:
function input (bool)
{
if(bool)
output=bool;}"
}
DEF path3 Script{
eventIn SFFloat set_fraction
eventIn SFTime t1time
eventIn SFTime t2time
field SFFloat n 0.0
eventOut SFTime n1
eventOut SFTime n2
eventOut SFVec3f value_changed
field SFNode clock USE clock
url "vrmlscript:
function t1time(){
n1=t1time;
clock.stopTime = t1time;
}
function t2time(){
n2=t2time;
if(clock.enabled){
clock.stopTime = clock.startTime;
clock.startTime += n2-n1;
}else{
clock.enabled = true;
clock.startTime = t2time;
}
}
function set_fraction(fra){
// n=((n2-n1)%6)/6 ;
// if(0<=n<=1-fra)
// fra=fra+n ;
// else
// fra=fra-Math.abs(1-n) ;
value_changed[0]=5*fra ;
value_changed[1]=Math.sin(fra*4*3.14) ;
value_changed[2]=0;}
"}
#ROUTE touch1.isActive TO path1.input
#ROUTE path1.output TO clock.enabled
#ROUTE touch2.isActive TO path2.input
#ROUTE path2.output TO clock.enabled
ROUTE touch1.touchTime TO path3.t1time
ROUTE touch2.touchTime TO path3.t2time
ROUTE clock.fraction_changed TO path3.set_fraction
ROUTE path3.value_changed TO ball.translation
参考资料:http://hi.baidu.com/saintdomdong
热心网友 时间:2023-10-11 00:51
其实这个问题我也想知道,,期待高人。。。。