#VRML V2.0 utf8
# VRML/Java Seminar WS 1997/98
# Norbert Schoepke
# *** Hier definieren wir uns ein Auto!
# ********************************
PROTO Auto [ exposedField SFVec3f pos 0 0 0, # die Position,
exposedField SFRotation rot 1 0 0 0, # Orientierung,
exposedField SFColor col 1 0 0 # Farbe und
field SFString name "Auto"] { # ein Name
Transform {
translation IS pos
rotation IS rot
children [
Shape { # die Karosserie
appearance Appearance {
material Material { diffuseColor IS col }
}
geometry IndexedFaceSet {
convex FALSE
coord Coordinate {
point [ 2.0 0.2 -0.8, -2.0 0.2 -0.8,
-2.0 0.8 -0.8, -1.5 0.8 -0.8,
-1.0 1.4 -0.8, 0.5 1.4 -0.8,
1.0 0.8 -0.8, 2.0 0.8 -0.8,
2.0 0.2 0.8, -2.0 0.2 0.8,
-2.0 0.8 0.8, -1.5 0.8 0.8,
-1.0 1.4 0.8, 0.5 1.4 0.8,
1.0 0.8 0.8, 2.0 0.8 0.8 ]
}
coordIndex [ 0 7 15 8 -1, 7 6 14 15 -1,
6 5 13 14 -1, 5 4 12 13 -1,
4 3 11 12 -1, 3 2 10 11 -1, 2 1 9 10 -1,
1 0 8 9 -1,
0 1 2 3 4 5 6 7 -1, 15 14 13 12 11 10 9 8, -1 ]
}
}
Transform {
rotation 1 0 0 -1.57
translation 1.3 0.3 0.7
children [
DEF rad Shape { # Ein Rad...
appearance Appearance {
material Material { diffuseColor 0.2 0.2 0.2 }
}
geometry Cylinder { radius 0.3, height 0.28 }
}
]
}
Transform { # ...und noch drei
rotation 1 0 0 -1.57 # Raeder. Da ver-
translation 1.3 0.3 -0.7 # wenden wir doch
children USE rad # gleich noch mal
} # das erste Rad!
Transform {
rotation 1 0 0 -1.57
translation -1.3 0.3 0.7
children USE rad
}
Transform {
rotation 1 0 0 -1.57
translation -1.3 0.3 -0.7
children USE rad
}
Viewpoint { # Mittendrin statt
orientation 0 1 0 -1.57 # nur dabei - so
position 0.2 1.2 0.0 # sieht der Fahrer
description IS name # die Sache!
}
]
}
}
# *** auch die Pfosten konstruieren wir als Prototyp
# *******************
# Zunaechst die Zylinder-Stuecke, aus der
# wir die Pfosten zusammensetzen:
PROTO Segment [ exposedField SFVec3f pos 0 0 0, # Position
exposedField SFColor col 1 0 0 ] { # und Farbe
Transform {
translation IS pos
children Shape {
appearance Appearance {
material Material { diffuseColor IS col }
}
geometry Cylinder { radius 0.1, height 0.2 }
}
}
}
PROTO Pfosten [ exposedField SFVec3f pos 0 0 0 ] {
Transform {
translation IS pos
children [
Segment { pos 0.0 0.1 0.0, col 1.0 0.0 0.0 } # rot,
Segment { pos 0.0 0.3 0.0, col 1.0 1.0 1.0 } # weiss,
Segment { pos 0.0 0.5 0.0, col 1.0 0.0 0.0 } # rot,
Segment { pos 0.0 0.7 0.0, col 1.0 1.0 1.0 } # weiss und
Segment { pos 0.0 0.9 0.0, col 1.0 0.0 0.0 } # nochmal rot
]
}
}
# *** so, jetzt koennen wir die Welt zusammensetzen
# ********************
Background { skyColor 1 1 1 } # weisser Himmel
Viewpoint { # zunaechst sieht
orientation 0.26 -0.93 -0.25 -1.63 # man die VRML-Welt
position 13.8 6.3 0.0 # aus der Vogel-
description "Uebersicht" # perspektive
}
Shape { # eine quadratische
appearance Appearance { # Flaeche als
material Material { diffuseColor 0.8 0.8 0.8 } # Strasse
}
geometry Box { size 20.0 0.01 20.0 }
}
Pfosten { pos -9.0 0.0 0.0 } # Einige Pfosten
Pfosten { pos -8.9 0.0 1.6 } # bringen etwas
Pfosten { pos -8.5 0.0 3.0 } # Perspektive in
Pfosten { pos -7.8 0.0 4.5 } # die VRML-Welt.
Pfosten { pos -6.9 0.0 5.8 }
Pfosten { pos -5.8 0.0 6.9 }
Pfosten { pos -4.5 0.0 7.8 }
Pfosten { pos -3.0 0.0 8.5 }
Pfosten { pos -1.6 0.0 8.9 }
Pfosten { pos 0.0 0.0 9.0 }
Pfosten { pos -6.0 0.0 0.0 }
Pfosten { pos -5.7 0.0 1.9 }
Pfosten { pos -4.9 0.0 3.5 }
Pfosten { pos -3.5 0.0 4.9 }
Pfosten { pos -1.9 0.0 5.7 }
Pfosten { pos 0.0 0.0 6.0 }
Pfosten { pos -6.0 0.0 -1.2 }
Pfosten { pos -4.8 0.0 -2.4 }
Pfosten { pos -3.6 0.0 -3.6 }
Pfosten { pos -2.4 0.0 -4.8 }
Pfosten { pos -1.2 0.0 -6.0 }
Pfosten { pos 0.0 0.0 -4.8 }
Pfosten { pos 1.2 0.0 -3.6 }
Auto { # Hier parkt das
pos -0.4 0.0 -3.4 # blaue Auto...
rot 0 1 0 -0.79
col 0 0 1
name "Blaues Auto"
}
Auto { # Hier parkt das
pos -1.9 0.0 -1.9 # gelbe Auto...
rot 0 1 0 -0.79
col 1 1 0
name "Gelbes Auto"
}
Auto { # ...und hier
pos -3.4 0.0 -0.4 # das gruene.
rot 0 1 0 -0.79
col 0 1 0
name "Gruenes Auto"
}
DEF rotesAuto Transform { # Das rote Auto
children Auto { pos 0.0 0.0 7.5 name "Rote Auto"} # erhaelt einen
} # Transform-Node...
DEF rotInt OrientationInterpolator { # ...damit es auf
key [ 0.00 0.33 0.66 1.00 ] # diesem Rundkurs
keyValue [ 0 1 0 0.00, 0 1 0 2.09, # fahren kann.
0 1 0 4.19, 0 1 0 0.00 ]
}
DEF timer TimeSensor { # Hier tickt die
loop TRUE # Uhr, die unsere
cycleInterval 20 # Animation
} # steuert.
# So, jetzt muessen wir noch alles richtig verdrahten, damit sich auch
# etwas bewegt:
# die Zeit vom Timer zum Interpolator
ROUTE timer.fraction_changed TO rotInt.set_fraction
# und die Rotation vom Interpolatior zum Transform-Node
ROUTE rotInt.value_changed TO rotesAuto.set_rotation
# Fertig!