view tg.sh @ 28:91ad0fe957de

Redraw only when necessary Some rotation and movement code
author Josef "Jeff" Sipek <jeffpc@optonline.net>
date Sat, 03 Dec 2005 03:52:12 -0500
parents 72194bf15970
children d12f9450fa8f
line wrap: on
line source

./render&
sleep 0.5

IPIPE="/tmp/3de.in"
OPIPE="/tmp/3de.out"

ROT_ANGLE_DELTA="0.17453"
TRANS_DELTA="1.0"

CAM_X="1.0"
CAM_Y="1.0"
CAM_Z="0.0"
CAM_AX="0.0"
CAM_AY="0.0"
CAM_AZ="0.0"

REFRESH=1

echo "TRANSCAM 0 0 1" > $IPIPE
echo "TRANSCAM $CAM_X $CAM_Y $CAM_Z" > $IPIPE

while /bin/true; do
	if [ $REFRESH -eq 1 ]; then
		echo "CLEAR" > $IPIPE
		# the 4 walls
		cat tg/walls.scn > $IPIPE

		CDX=`echo "$CAM_AX*180/3.14159263" | bc`
		CDY=`echo "$CAM_AY*180/3.14159263" | bc`
		CDZ=`echo "$CAM_AZ*180/3.14159263" | bc`
		echo "TEXT 1 1 1 30 30 0 $CDX $CDY $CDZ" > $IPIPE
		echo "TEXT 1 1 1 30 50 0 $CAM_X $CAM_Y $CAM_Z" > $IPIPE
		echo "FLUSH" > $IPIPE
		REFRESH=0
	fi

	KEY=`./getline $OPIPE`

	if [ -n "$KEY" ]; then
		case $KEY in
			left)
				CAM_AZ=`echo "$CAM_AZ+$ROT_ANGLE_DELTA" | bc`
				echo "ROTCAM 0 0 $ROT_ANGLE_DELTA" > $IPIPE
				echo "got rotate left"
				REFRESH=1
				;;
			right)
				CAM_AZ=`echo "$CAM_AZ-$ROT_ANGLE_DELTA" | bc`
				echo "ROTCAM 0 0 -$ROT_ANGLE_DELTA" > $IPIPE
				echo "got rotate right"
				REFRESH=1
				;;
			up)
				CAM_AY=`echo "$CAM_AY+$ROT_ANGLE_DELTA" | bc`
				echo "ROTCAM 0 $ROT_ANGLE_DELTA 0" > $IPIPE
				echo "got rotate up"
				REFRESH=1
				;;
			down)
				CAM_AY=`echo "$CAM_AY-$ROT_ANGLE_DELTA" | bc`
				echo "ROTCAM 0 -$ROT_ANGLE_DELTA 0" > $IPIPE
				echo "got rotate down"
				REFRESH=1
				;;
			a)
				V2_HAT=`echo -e "0 0 $CAM_AZ\n0 0 0 1 0 0" | ./rotate | ./transform`
				V2_HAT=`echo "$V2_HAT 0 0 0 0 0 1" | ./cross`

				D_X=`echo $V2_HAT|awk '{print $1}'`
				D_X=`echo "$TRANS_DELTA*$D_X*-1" | bc`
				D_Y=`echo $V2_HAT|awk '{print $2}'`
				D_Y=`echo "$TRANS_DELTA*$D_Y*-1" | bc`
				
				CAM_X=`echo "$CAM_X+$D_X" | bc`
				CAM_Y=`echo "$CAM_Y+$D_Y" | bc`

				echo "got move left"
				echo "TRANSCAM $D_X $D_Y 0" > $IPIPE
				REFRESH=1
				;;
			d)
				V2_HAT=`echo -e "0 0 $CAM_AZ\n0 0 0 1 0 0" | ./rotate | ./transform`
				V2_HAT=`echo "$V2_HAT 0 0 0 0 0 1" | ./cross`

				D_X=`echo $V2_HAT|awk '{print $1}'`
				D_X=`echo "$TRANS_DELTA*$D_X" | bc`
				D_Y=`echo $V2_HAT|awk '{print $2}'`
				D_Y=`echo "$TRANS_DELTA*$D_Y" | bc`
				
				CAM_X=`echo "$CAM_X+$D_X" | bc`
				CAM_Y=`echo "$CAM_Y+$D_Y" | bc`
				
				echo "got move right"
				echo "TRANSCAM $D_X $D_Y 0" > $IPIPE
				REFRESH=1
				;;
			w)
				V2_HAT=`echo -e "0 0 $CAM_AZ\n0 0 0 1 0 0" | ./rotate | ./transform`

				D_X=`echo $V2_HAT|awk '{print $4}'`
				D_X=`echo "$TRANS_DELTA*$D_X" | bc`
				D_Y=`echo $V2_HAT|awk '{print $5}'`
				D_Y=`echo "$TRANS_DELTA*$D_Y" | bc`

				CAM_X=`echo "$CAM_X+$D_X" | bc`
				CAM_Y=`echo "$CAM_Y+$D_Y" | bc`
				
				echo "got move forward"
				echo "TRANSCAM $D_X $D_Y 0" > $IPIPE
				REFRESH=1
				;;
			s)
				V2_HAT=`echo -e "0 0 $CAM_AZ\n0 0 0 1 0 0" | ./rotate | ./transform`

				D_X=`echo $V2_HAT|awk '{print $4}'`
				D_X=`echo "$TRANS_DELTA*$D_X*-1" | bc`
				D_Y=`echo $V2_HAT|awk '{print $5}'`
				D_Y=`echo "$TRANS_DELTA*$D_Y*-1" | bc`

				CAM_X=`echo "$CAM_X+$D_X" | bc`
				CAM_Y=`echo "$CAM_Y+$D_Y" | bc`
				
				echo "got move backward"
				echo "TRANSCAM $D_X $D_Y 0" > $IPIPE
				REFRESH=1
				;;
		esac

	fi

	sleep 0.01
done