source

vrml

VRML 2.0 Tutorial--button3.wrl Source

#VRML V2.0 utf8

WorldInfo {
	title "button3: Linked to another shape"
	info "
		File:          button3.wrl
		Version:       1.1
		Revisions:     1.0 June 22, 1996 -- initial cut
                     	1.1 February 16, 1997 -- updated to Final Spec
		Description:   Button drives a cube's behavior
		Requirements:  A VRML2.0 capable browser
		Author:        Matt Leonard
                     mattl@pobox.com
                     http://www.pobox.com/~mattl
		Copyright:     This file is copyright 1996 Matt Leonard
		Tabstop:       4
	" # info
} # WorldInfo

NavigationInfo {
	type "EXAMINE"
} # NavigationInfo

DEF VIEW_1 Viewpoint {
	position 0.2 1.0 1
	orientation 1 0 0 -0.6
	description "Looking down from the front"
} # VIEW_1

DEF BASE Transform {
	translation 0 0 0
	scale 2 1 1

	children [
		Shape {
			geometry Cylinder {
				radius 0.1
				height 0.05
			} # Cylinder
		} # Shape
	] # children
} # BASE

DEF BUTTON Transform {
	translation 0 0 0
	scale 2 1 1

	children [
		DEF SWITCH Switch {
			whichChoice 0
			choice [
				DEF POPPED Transform {
					translation 0 0.026 0
					children [
						Shape {
							geometry Cylinder {
								radius 0.07
								height 0.04
							} # Cylinder

							appearance Appearance {
								material Material {
									# green
									diffuseColor 0 255 0
								} # material
							} # appearance
						} # Shape
					] # children
				} # POPPED

				DEF PUSHED Transform {
					translation 0 0.026 0
					children [
						Shape {
							geometry Cylinder {
								radius .07
								height .005
							} # Cylinder

							appearance Appearance {
								material Material {
									# red
									diffuseColor 255 0 0
								} # material
							} # appearance
						} # Shape
					] # children
				} # PUSHED
			] # choice
		} # SWITCH

		DEF ON_OFF TouchSensor {
		} # ON_OFF

		DEF TIME_SOURCE_UP TimeSensor {
			cycleInterval 5
		} # TIME_SOURCE_UP

		DEF TIME_SOURCE_DOWN TimeSensor {
			cycleInterval 5
		} # TIME_SOURCE_DOWN

	] # children
} # BUTTON

DEF MOVING_BOX Transform {
	translation 0.5 0 0
	scale 1 1 1

	children [
		Shape {
			geometry DEF BOX Box {
				size 0.1 0.1 0.1
			} # Box

			appearance Appearance {
				material Material {
					diffuseColor 0 0 255
				} # material
			} # appearance
		} # Shape

		DEF BOX_POSITION_UP PositionInterpolator {
			key [ 0 0.5 1]
			keyValue [ 0.5 0.0 0.0, 0.5 0.1 0.0, 0.5 0.2 0.0 ]
		} # BOX_POSITION_UP

		DEF BOX_POSITION_DOWN PositionInterpolator {
			key [ 0 0.5 1]
			keyValue [ 0.5 0.2 0.0, 0.5 0.1 0.0, 0.5 0.0 0.0 ]
		} # BOX_POSITION_DOWN

	] # children

} # MOVING_BOX

DEF PUSH_SCRIPT Script {
	eventIn SFTime pushButton
	eventOut SFInt32 push_pop
	eventOut SFTime start_up
	eventOut SFTime start_down
	url "vrmlscript:
	function pushButton(inTime) {
		if (push_pop == 1) {
			push_pop = 0;
			start_down = inTime;
		} else {
			push_pop = 1;
			start_up = inTime;
		}
	}" # url
} # PUSH_SCRIPT

# routing to push/pop button
ROUTE ON_OFF.touchTime TO PUSH_SCRIPT.pushButton
ROUTE PUSH_SCRIPT.push_pop TO SWITCH.whichChoice

# routing to move box down on button pop
ROUTE PUSH_SCRIPT.start_down TO TIME_SOURCE_DOWN.startTime
ROUTE TIME_SOURCE_DOWN.fraction_changed TO BOX_POSITION_DOWN.set_fraction
ROUTE BOX_POSITION_DOWN.value_changed TO MOVING_BOX.translation

# routing to move box up on button push
ROUTE PUSH_SCRIPT.start_up TO TIME_SOURCE_UP.startTime
ROUTE TIME_SOURCE_UP.fraction_changed TO BOX_POSITION_UP.set_fraction
ROUTE BOX_POSITION_UP.value_changed TO MOVING_BOX.translation

-- Back to Tutorial --

vrml navbar