walk.nas 3.07 KB
Newer Older
lm's avatar
lm committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
var sin = func(a) { math.sin(a * math.pi / 180.0) }
var cos = func(a) { math.cos(a * math.pi / 180.0) }
var posx= 0;
var posy= 0;
var posz= 0;

 setlistener("sim/walker/walking", func {
	walk();
 });

var main_loop = func {
	if (getprop ("sim/walker/outside") == 0) {
		setprop ("sim/walker/latitude-deg" , (getprop ("position/latitude-deg")));
		setprop ("sim/walker/longitude-deg" , (getprop ("position/longitude-deg")));
		setprop ("sim/walker/altitude-ft" , (getprop ("position/altitude-ft")));
		setprop ("sim/walker/roll-deg" , (getprop ("orientation/roll-deg")));
		setprop ("sim/walker/pitch-deg" , (getprop ("orientation/pitch-deg")));
		setprop ("sim/walker/heading-deg" , (getprop ("orientation/heading-deg")));
	}
  settimer(main_loop, 0.008)
}
var walk = func {


				if (getprop ("sim/current-view/view-number") == view.indexof("Walk View")) {
				if (getprop ("devices/status/mice/mouse/mode") == 2){


					if (getprop ("sim/walker/outside") == 1) {
						ext_mov();
					} else {
						int_mov();
					}
		}
	}
}

var ext_mov = func {
	speed = getprop ("sim/walker/speed");
	head = getprop ("sim/current-view/heading-offset-deg");
	posy = getprop ("sim/walker/latitude-deg");
	posx = getprop ("sim/walker/longitude-deg");
	posz1 = getprop ("sim/walker/altitude-ft");
	posx1 = posx - speed*sin(head);
	if (posy < 0 ) {
		# southern hemisphere
		posy1 = posy + (speed+0.000001*sin(posy))*cos(head);
#		print ("south");
		} else {
		# northern hemisphere
#		print ("north");
		posy1 = posy + (speed-0.000001*sin(posy))*cos(head);
		}
#	print (head,"  ",speed,"  ",speed+0.0000001*sin(posy));
#	print (cos(head),"  ",sin(head));
#	print (posy,"  ",speed+0.000001*sin(posy));
	posz2 = geo.elevation (posy1,posx1);

	if ((posz2 * 3.28084) < (posz1+10)) {
		interpolate ("sim/walker/latitude-deg", posy1,0.25,0.3);
#		print (posy);
		interpolate ("sim/walker/longitude-deg", posx1,0.25,0.3);
#		print (posx);

#		print (posz1," ", posz2 * 3.28084);
		if ((posz1+0.4) > (posz2 * 3.28084) or (posz1-0.4) < posz2 * 3.28084) {
			interpolate ("sim/walker/altitude-ft", posz2 * 3.28084 ,0.25,0.3);
		}
	}
if (getprop ("sim/walker/walking") == 1) {
	settimer(ext_mov, 0.25);
	}
}
var get_out = func {
	if (getprop ("sim/current-view/view-number") == view.indexof("Walk View")) {
		posx = getprop ("position/longitude-deg");
		posy = getprop ("sim/walker/latitude-deg");
		head = getprop ("orientation/heading-deg");
		posy1  = posy + (0.000001*sin(posy))*sin(head);

		setprop ("sim/walker/heading-deg", 0);
		setprop ("sim/walker/outside", 1);
		setprop ("sim/current-view/x-offset-m", 0);
		setprop ("sim/current-view/y-offset-m", 1.87);
		setprop ("sim/current-view/z-offset-m", 0);
		setprop ("sim/current-view/roll-offset-deg", 0);
	}
}	

var get_in = func {
	if (getprop ("sim/current-view/view-number") == view.indexof("Walk View")) {
		setprop ("sim/walker/outside", 0);
		setprop ("sim/current-view/x-offset-m", 0.35);
		setprop ("sim/current-view/y-offset-m", 1.5);
		setprop ("sim/current-view/z-offset-m", 2.295);
		setprop ("sim/current-view/roll-offset-deg", 0);
	}
}
var int_mov = func {
print ("Not yet implemented");
}