changeset 12:43c7ce2fc334

New utility: getline Skeleton of TG; renders the walls and listens for key presses
author jsipek@huey.fsl.cs.sunysb.edu
date Thu, 24 Nov 2005 04:39:25 -0400
parents 55b7e6aba0ef
children 51e9b6b85edd
files Makefile getline.c render.c tg.sh tg/walls.scn
diffstat 5 files changed, 68 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Thu Nov 24 03:59:14 2005 -0400
+++ b/Makefile	Thu Nov 24 04:39:25 2005 -0400
@@ -1,4 +1,4 @@
-all: render transform rotate
+all: render transform rotate getline
 
 render: render.c
 	gcc render.c -o render -I/usr/X11R6/include/ -L/usr/X11R6/lib -lX11 -lXi -lXmu -lglut -lGL -lGLU -g -Wall -lrt
@@ -9,5 +9,8 @@
 rotate: rotate.c
 	gcc -o rotate rotate.c -Wall -g -lm
 
+getline: getline.c
+	gcc -o getline getline.c -Wall -g
+
 clean:
-	rm -f rotate render transform *~ *.o a.out
+	rm -f getline rotate render transform *~ *.o a.out
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/getline.c	Thu Nov 24 04:39:25 2005 -0400
@@ -0,0 +1,20 @@
+#include <unistd.h>
+#include <fcntl.h>
+
+int main(int argc, char** argv)
+{
+	char c;
+	int fd;
+
+	if (argc < 2)
+		write(2, "error", 5);
+
+	if ((fd = open(argv[1], O_RDONLY | O_NONBLOCK)) == -1)
+		write(2, "error", 5);
+
+	while((read(fd, &c, 1) == 1) && (c != '\n'))
+		write(1, &c, 1);
+
+	return 0;
+}
+
--- a/render.c	Thu Nov 24 03:59:14 2005 -0400
+++ b/render.c	Thu Nov 24 04:39:25 2005 -0400
@@ -128,13 +128,12 @@
 
 		ptr += r;
 	} while(1);
-
+#if 0
 	if (strlen(buf)) {
 		printf("buf = \"%s\"\n", buf);
 		fflush(stdout);
 	}
-
-fprintf(stderr,"displaying...%s.\n",buf);
+#endif
 	if (!strncmp(buf, "CLEAR", 5)) {
 		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 	} else if (!strncmp(buf, "FLUSH", 5)) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tg.sh	Thu Nov 24 04:39:25 2005 -0400
@@ -0,0 +1,35 @@
+./render&
+sleep 0.5
+
+IPIPE="/tmp/3de.in"
+OPIPE="/tmp/3de.out"
+
+while /bin/true; do
+	echo "CLEAR" > $IPIPE
+
+	# the 4 walls
+	cat tg/walls.scn > $IPIPE
+
+	KEY=`./getline $OPIPE`
+
+	if [ -n "$KEY" ]; then
+		case $KEY in
+			left)
+				echo "got left"
+				;;
+			right)
+				echo "got right"
+				;;
+			up)
+				echo "got up"
+				;;
+			down)
+				echo "got down"
+				;;
+		esac
+
+	fi
+
+	echo "FLUSH" > $IPIPE
+	sleep 0.01
+done
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tg/walls.scn	Thu Nov 24 04:39:25 2005 -0400
@@ -0,0 +1,6 @@
+POLY 1 0 0 0 0 0 1 0 0 0 0 2 1 0 0 30 0 2 1 0 0 30 0 0
+POLY 0 1 1 0 30 0 0 1 1 30 30 0 0 1 1 30 30 2 0 1 1 0 30 2
+POLY 1 0 1 0 0 0 1 0 1 30 0 0 1 0 1 30 30 0 1 0 1 0 30 0
+POLY 1 1 0 0 0 2 1 1 0 0 30 2 1 1 0 30 30 2 1 1 0 30 0 2
+POLY 0 0 1 0 0 0 0 0 1 0 30 0 0 0 1 0 30 2 0 0 1 0 0 2
+POLY 0 1 0 30 0 0 0 1 0 30 0 2 0 1 0 30 30 2 0 1 0 30 30 0