#VRML V2.0 utf8
	
	# ナビゲーション情報
	NavigationInfo {
	
	type "EXAMINE"
	
	}
	
	# 視点1
	Viewpoint {
	
	position 0 8 11
	orientation -1 0 0. 0.75
	description "bird"
	
	}
	
	# 背景
	Background {
	
	skyColor [
	
	0 0 1
	0.8 1 1
	0 0.7 0
	
	]
	skyAngle[ 1.4, 1.8, 3 ]
	
	}
	
	#地面
	Transform {
	
	translation 0 -0.05 0
	children [
	
	Shape {
	
	appearance Appearance {
	
	texture ImageTexture {
	
	url "field.jpg"
	
	}
	textureTransform TextureTransform {
	
	scale 3 3
	
	}
	material Material {
	
	diffuseColor 1 1 1
	
	}
	
	}
	geometry Box {
	
	size 10 0.1 10
	
	}
	
	}
	
	]
	
	}
	
	
	# 車
	DEF Car-Tf Transform {
	
	children [
	
	# ボディ
	Transform {
	
	translation 0 0.1 0
	rotation 1 0 0 -1.571
	scale 1 1 0.5
	children [
	
	Shape {
	
	appearance Appearance {
	
	material Material {
	
	diffuseColor 1 0 0
	
	}
	
	}
	geometry Cone {
	
	height 0.5
	bottomRadius 0.2
	
	}
	
	}
	
	]
	
	}
	# タイヤ
	Transform {
	
	translation 0.1 0.1 -0.15
	rotation 0 0 1 1.571
	children [
	
	DEF Tire-Sp Shape {
	
	appearance Appearance {
	
	material Material {
	
	diffuseColor 0 0 0
	
	}
	
	}
	geometry Cylinder {
	
	height 0.05
	radius 0.1
	
	}
	
	}
	
	]
	
	}
	Transform {
	
	translation -0.1 0.1 -0.15
	rotation 0 0 1 1.571
	children USE Tire-Sp
	
	}
	Transform {
	
	translation -0.2 0.1 0.25
	rotation 0 0 1 1.571
	children USE Tire-Sp
	
	}
	Transform {
	
	translation 0.2 0.1 0.25
	rotation 0 0 1 1.571
	children USE Tire-Sp
	
	}
	
	# 視点2
	Viewpoint {
	
	position 0 2 4
	orientation -1 0 0 0.5
	description "driver"
	
	}
	
	]
	
	}
	
	
	# 操作スイッチ
	DEF Console-Tf Transform {
	
	children [
	
	Transform {
	
	translation 0 -0.1 -0.5
	children [
	
	# 停止スイッチ
	Group {
	
	children [
	
	DEF Stop-ThS TouchSensor {}
	Shape {
	
	appearance Appearance {
	
	material Material {
	
	diffuseColor 1 1 0
	
	}
	
	}
	geometry Box {
	
	size 0.03 0.03 0.03
	
	}
	
	}
	
	]
	
	}
	# 前進スイッチ
	Transform {
	
	translation 0 0.06 0
	children [
	
	DEF F-ThS TouchSensor {}
	DEF Arrow-Sp Shape {
	
	appearance Appearance {
	
	material Material {
	
	diffuseColor 0 1 1
	
	}
	
	}
	geometry Cone {
	
	bottomRadius 0.025
	height 0.05
	
	}
	
	}
	
	]
	
	}
	# 後退スイッチ
	Transform {
	
	translation 0 -0.06 0
	children [
	
	DEF B-ThS TouchSensor {}
	Transform {
	
	rotation 0 0 1 3.141
	children USE Arrow-Sp
	
	}
	
	]
	
	}
	# 右ターンスイッチ
	Transform {
	
	translation 0.06 0 0
	children [
	
	DEF R-ThS TouchSensor {}
	Transform {
	
	rotation 0 0 1 -1.571
	children USE Arrow-Sp
	
	}
	
	]
	
	}
	# 左ターンスイッチ
	Transform {
	
	translation -0.06 0 0
	children [
	
	DEF L-ThS TouchSensor {}
	Transform {
	
	rotation 0 0 1 1.571
	children USE Arrow-Sp
	
	}
	
	]
	
	}
	
	]
	
	}
	
	]
	
	}
	
	# 操作スイッチ用近接度センサー
	DEF Console-PrS ProximitySensor {
	
	size 1000 1000 1000
	
	}
	
	ROUTE Console-PrS.position_changed TO Console-Tf.set_translation
	ROUTE Console-PrS.orientation_changed TO Console-Tf.set_rotation
	
	
	# タイムセンサー
	DEF TiS TimeSensor {
	
	loop TRUE
	
	}
	
	# スイッチ入力に従って車を動かすスクリプト
	DEF Sc Script {
	
	eventIn SFBool isActive_Stop
	eventIn SFBool isActive_Forward
	eventIn SFBool isActive_Back
	eventIn SFBool isActive_Right
	eventIn SFBool isActive_Left
	eventIn SFFloat set_fraction
	
	eventOut SFVec3f positionCar        # 車の位置
	eventOut SFRotation orientationCar  # 車の向き
	
	field SFVec3f moveVec 0 0 -1        # 車の移動ベクトル
	field SFVec3f initDirection 0 0 -1  # 車の向きの初期値(最初は向かって奥を向いている)
	field SFFloat moveSpeed 0           # 移動速度
	field SFFloat turnSpeed 0           # 回転速度
	field SFFloat oldF 0                # 前回イベント時の fraction_changed の値
	field SFBool isCortona FALSE        # 実行しているブラウザーが Cortona か否か
	url "javascript:
	
	
	function initialize () {
	
	
	positionCar = new SFVec3f (0, 0, 0);
	
	// 車の向きをy軸を中心とした回転に設定する。
	orientationCar = new SFRotation (0, 1, 0, 0);
	
	// 実行中のブラウザーが Cortona か調べる。
	isCortona = (Browser.getName() == 'Cortona VRML Client');
	
	
	}
	
	function isActive_Stop () {
	
	
	moveSpeed = 0;
	
	
	}
	
	function isActive_Forward () {
	
	
	moveSpeed = 1;
	
	
	}
	
	function isActive_Back () {
	
	
	moveSpeed = -1;
	
	
	}
	
	function isActive_Right (active) {
	
	
	// 右ターンスイッチが押されたならば turnSpeed を -1 に、離されたならば 0 にセットする。
		turnSpeed = -active;
	
	
	}
	
	function isActive_Left (active) {
	
	
	// 左ターンスイッチが押されたならば turnSpeed を 1 に、離されたならば 0 にセットする。
	turnSpeed = active;
	
	
	}
	
	function set_fraction (f) {
	
	
	// fraction の変化量を得る。
	var df = f - oldF;
	if ( df < 0 ) df++;
	oldF = f;
	
	// ブラウザーがCortonaならば、df にフレームレートの逆数を入れる。
	if ( isCortona ) {
	
	var fps = Browser.getCurrentFrameRate();
	if ( fps > 0.0 ) df = 1 / fps;
	
	}
	
	if ( turnSpeed != 0 ) {
	
	
	// 車の向きを変える。
		orientationCar.angle += turnSpeed * df;
	
	// 車の向きに従って移動ベクトルを回転させる。
		moveVec = orientationCar.multVec( initDirection );
	
	
	}
	
	if ( moveSpeed != 0 ) {
	
	
	// 車を移動させる。
	positionCar = moveVec.multiply( moveSpeed * df ).add( positionCar );
	
	
	}
	
	
	}
	
	"
	
	}
	
	# スイッチ入力をスクリプトに送る。
	ROUTE Stop-ThS.isActive TO Sc.isActive_Stop
	ROUTE F-ThS.isActive TO Sc.isActive_Forward
	ROUTE B-ThS.isActive TO Sc.isActive_Back
	ROUTE R-ThS.isActive TO Sc.isActive_Right
	ROUTE L-ThS.isActive TO Sc.isActive_Left
	
	# タイムセンサーの fraction_changed をスクリプトに送る。
	ROUTE TiS.fraction_changed TO Sc.set_fraction
	
	# 車の位置と向きをセットする。
	ROUTE Sc.positionCar TO Car-Tf.translation
	ROUTE Sc.orientationCar TO Car-Tf.rotation