Debian Codegraph @

tests/data/switches_and_transforms_2.x3dv

raw
1 #X3D V3.2 utf8
2 PROFILE Interchange
3
4 # Transform, Switch, and Transform inside a Switch...
5 # Test of Transform fields optimization with Switch.whichChoice optimization
6 # (when they all change through events).
7 #
8 # Keys 1,2,3,4 change switches whichChoice values.
9 # Horizontal arrow should always move only horizontally,
10 # vertical arrow --- only vertically.
11 #
12 # (Transforms of both left arrows are deliberately the different nodes,
13 # to test the harder case --- see Castle Game Engine vrmlscene.pas
14 # Transform optimization for details.)
15
16 PROTO ArrowVertical [ ] {
17 Shape {
18 geometry Extrusion {
19 spine [ 0 0 0, 0 1.5 0, 0 1.5 0 , 0 4.5 0, 0 4.5 0, 0 6 0 ]
20 scale [ 0 0 , 1 1 , 0.75 0.75, 0.75 0.75, 1 1 , 0 0 ]
21 }
22 appearance Appearance { material Material { } }
23 }
24 }
25
26 PROTO ArrowHorizontal [ ] {
27 Transform {
28 rotation 0 0 1 1.5707963268
29 center 0 3 0 # to rotate around arrow center
30 children ArrowVertical { }
31 }
32 }
33
34 DEF Left Transform {
35 translation -4 0 0
36 children DEF LeftSwitch Switch {
37 whichChoice 1
38 children [
39 DEF LeftHoriz Transform {
40 children ArrowHorizontal { }
41 }
42 DEF LeftVert Transform {
43 children ArrowVertical { }
44 }
45 ]
46 }
47 }
48
49 DEF Right Transform {
50 translation 4 0 0
51 children DEF RightSwitch Switch {
52 whichChoice 0
53 children [
54 DEF RightHoriz Transform {
55 children ArrowHorizontal { }
56 }
57 DEF RightVert Transform {
58 children ArrowVertical { }
59 }
60 ]
61 }
62 }
63
64 # animate left horiz arrow --------------------------------------------------
65
66 DEF TimerLeftHoriz TimeSensor { loop TRUE }
67 DEF InterpLeftHoriz PositionInterpolator {
68 key [ 0 0.5 1 ]
69 keyValue [ -0.5 0 0, 0.5 0 0, -0.5 0 0 ]
70 }
71 ROUTE TimerLeftHoriz.fraction_changed TO InterpLeftHoriz.set_fraction
72 ROUTE InterpLeftHoriz.value_changed TO LeftHoriz.translation
73
74 # animate right horiz arrow --------------------------------------------------
75
76 DEF TimerRightHoriz TimeSensor { loop TRUE }
77 DEF InterpRightHoriz PositionInterpolator {
78 key [ 0 0.5 1 ]
79 keyValue [ -0.5 0 0, 0.5 0 0, -0.5 0 0 ]
80 }
81 ROUTE TimerRightHoriz.fraction_changed TO InterpRightHoriz.set_fraction
82 ROUTE InterpRightHoriz.value_changed TO RightHoriz.translation
83
84 # animate left vert arrow --------------------------------------------------
85
86 DEF TimerLeftVert TimeSensor { loop TRUE }
87 DEF InterpLeftVert PositionInterpolator {
88 key [ 0 0.5 1 ]
89 keyValue [ 0 -0.5 0, 0 0.5 0, 0 -0.5 0 ]
90 }
91 ROUTE TimerLeftVert.fraction_changed TO InterpLeftVert.set_fraction
92 ROUTE InterpLeftVert.value_changed TO LeftVert.translation
93
94 # animate right vert arrow --------------------------------------------------
95
96 DEF TimerRightVert TimeSensor { loop TRUE }
97 DEF InterpRightVert PositionInterpolator {
98 key [ 0 0.5 1 ]
99 keyValue [ 0 -0.5 0, 0 0.5 0, 0 -0.5 0 ]
100 }
101 ROUTE TimerRightVert.fraction_changed TO InterpRightVert.set_fraction
102 ROUTE InterpRightVert.value_changed TO RightVert.translation
103
104 # Script with key sensor to change switches values ---------------------------
105
106 DEF Scr Script {
107 inputOutput SFInt32 leftChoice 0
108 inputOutput SFInt32 rightChoice 0
109 inputOnly SFString keyPress
110 url "castlescript:
111
112 function keyPress(value, time)
113 when(value = '1', leftChoice := 0);
114 when(value = '2', leftChoice := 1);
115 when(value = '3', rightChoice := 0);
116 when(value = '4', rightChoice := 1)
117 "
118 }
119 DEF K KeySensor { }
120 ROUTE K.keyPress TO Scr.keyPress
121 ROUTE Scr.leftChoice TO LeftSwitch.whichChoice
122 ROUTE Scr.rightChoice TO RightSwitch.whichChoice