Revision: 80
http://svn.sourceforge.net/mactel-linux/?rev=80&view=rev
Author: ludov
Date: 2006-12-09 14:11:54 -0800 (Sat, 09 Dec 2006)
Log Message:
-----------
new files from
http://www.boichat.ch/nicolas/macbook-tools/hdaps-gl-0.0.5-a.tar.bz2
Added Paths:
-----------
trunk/tools/hdaps-gl/
trunk/tools/hdaps-gl/Makefile
trunk/tools/hdaps-gl/hdaps-gl.c
Added: trunk/tools/hdaps-gl/Makefile
===================================================================
--- trunk/tools/hdaps-gl/Makefile (rev 0)
+++ trunk/tools/hdaps-gl/Makefile 2006-12-09 22:11:54 UTC (rev 80)
@@ -0,0 +1,16 @@
+# Makefile for hdaps-gl
+
+LIBDIR = -L/usr/X11R6/lib
+CFLAGS = -O2 -W -Wall -Wshadow -Waggregate-return -Wbad-function-cast \
+ -Wpointer-arith -Wmissing-prototypes -Wmissing-declarations \
+ -Wcast-align -Wdisabled-optimization -Wstrict-prototypes \
+ -Wcast-qual -Wwrite-strings -Wredundant-decls
+LIBRARIES = -lglut -lGL -lGLU -lm
+
+all: hdaps-gl
+
+hdaps-gl: hdaps-gl.c
+ $(CC) $(CFLAGS) $(LIBDIR) $(LIBRARIES) -o hdaps-gl hdaps-gl.c
+
+clean:
+ rm -f hdaps-gl *.o
Added: trunk/tools/hdaps-gl/hdaps-gl.c
===================================================================
--- trunk/tools/hdaps-gl/hdaps-gl.c (rev 0)
+++ trunk/tools/hdaps-gl/hdaps-gl.c 2006-12-09 22:11:54 UTC (rev 80)
@@ -0,0 +1,282 @@
+/*
+ * hdaps-gl.c - GL-based laptop model that rotates in real-time via hdaps
+ *
+ * This code was created by Jeff Molofee '99.
+ *
+ * And then ported to Linux/GLUT by Richard Campbell '99.
+ *
+ * This tutrial was combined with Jesper Juhl's ibm_hdaps_userspace.c
+ * to rotate the cube according to the laptop position.
+ *
+ * Cube replaced by simple laptop by Petschge <[EMAIL PROTECTED]>.
+ *
+ * And then updated by Robert Love <[EMAIL PROTECTED]>.
+ */
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <GL/glut.h>
+#include <GL/gl.h>
+#include <GL/glu.h>
+
+#define UPDATE_THRESHOLD 4
+#define SLEEP_INTERVAL 50000 /* microseconds */
+#define SYSFS_POSITION_FILE "/sys/devices/platform/applesmc/position"
+#define BUF_LEN 32
+#define WIDTH 640
+#define HEIGHT 480
+
+static int val_x;
+static int val_y;
+static int val_z;
+static int rest_x;
+static int rest_y;
+static int rest_z;
+
+/*
+ * read_position - read the (x,y) position pair from hdaps.
+ *
+ * We open and close the file on every invocation, which is lame but due to
+ * several features of sysfs files:
+ *
+ * (a) Sysfs files are seekable.
+ * (b) Seeking to zero and then rereading does not seem to work.
+ *
+ * If I were king--and I will be one day--I would of made sysfs files
+ * nonseekable and only able to return full-size reads.
+ */
+static int read_position (int *x, int *y, int* z)
+{
+ char buf[BUF_LEN];
+ int fd, ret;
+
+ fd = open (SYSFS_POSITION_FILE, O_RDONLY);
+ if (fd < 0) {
+ perror ("open " SYSFS_POSITION_FILE);
+ return fd;
+ }
+
+ ret = read (fd, buf, BUF_LEN);
+ if (ret < 0) {
+ perror ("read");
+ goto out;
+ } else if (ret == 0) {
+ fprintf (stderr, "error: unexpectedly read zero!\n");
+ ret = 1;
+ goto out;
+ }
+ ret = 0;
+
+ if (sscanf (buf, "(%d,%d,%d)\n", x, y, z) != 3)
+ ret = 1;
+
+out:
+ if (close (fd))
+ perror ("close");
+
+ return ret;
+}
+
+static void resize_scene (int width, int height)
+{
+ if (height == 0)
+ height = 1;
+ glViewport (0, 0, width, height);
+ glMatrixMode (GL_PROJECTION);
+ glLoadIdentity ();
+ gluPerspective (45.0f, (GLfloat)width / (GLfloat)height, 0.1f, 100.0f);
+ glMatrixMode (GL_MODELVIEW);
+}
+
+static void draw_scene (void)
+{
+ glClear (GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
+ glPushMatrix ();
+
+ glRotated (val_x / 255.0 * 90.0, 0.0f, 0.0f, 1.0f);
+ glRotated (val_y / 255.0 * 90.0, 1.0f, 0.0f, 0.0f);
+ //glRotated (val_y / 2.0, 1.0f, 0.0f, 0.0f);
+
+ glBegin (GL_QUADS); // start drawing the laptop.
+
+ // top of body
+ glColor3d (0.0f, 0.0f, 0.0f);
+ glVertex3d (1.0f, 0.0f, 1.6f);
+ glVertex3d (-1.0f, 0.0f, 1.6f);
+ glVertex3d (-1.0f, 0.0f, 0.0f);
+ glVertex3d (1.0f, 0.0f, 0.0f);
+
+ //printf("%d\n", val_z);
+ // trackpoint
+ if (val_z > 0)
+ glColor3d (1.0f, 0.0f, 0.0f);
+ else
+ glColor3d (0.0f, 1.0f, 0.0f);
+ glVertex3d (0.05f, (float)abs(val_z)/50.0f, 0.80f);
+ glVertex3d (0.05f, 0.01f, 0.80f);
+ glVertex3d (-0.05f, 0.01f, 0.80f);
+ glVertex3d (-0.05f, (float)abs(val_z)/50.0f, 0.80f);
+
+ // bottom of body
+ glColor3d (0.0f, 0.0f, 0.0f);
+ glVertex3d (1.0f, -0.1f, -0.1f);
+ glVertex3d (-1.0f, -0.1f, -0.1f);
+ glVertex3d (-1.0f, -0.1f, 1.6f);
+ glVertex3d (1.0f, -0.1f, 1.6f);
+
+ // front of body
+ glColor3d (0.0f, 0.0f, 0.0f);
+ glVertex3d (1.0f, 0.0f, 1.6f);
+ glVertex3d (-1.0f, 0.0f, 1.6f);
+ glVertex3d (-1.0f, -0.1f, 1.6f);
+ glVertex3d (1.0f, -0.1f, 1.6f);
+
+ // left of body
+ glColor3d (0.0f, 0.0f, 0.0f);
+ glVertex3d (-1.0f, 0.0f, 1.6f);
+ glVertex3d (-1.0f, 0.0f, 0.0f);
+ glVertex3d (-1.0f, -0.1f, 0.0f);
+ glVertex3d (-1.0f, -0.1f, 1.6f);
+
+ // Right of body
+ glColor3d (0.0f, 0.0f, 0.0f);
+ glVertex3d (1.0f, 0.0f, 0.0f);
+ glVertex3d (1.0f, 0.0f, 1.6f);
+ glVertex3d (1.0f, -0.1f, 1.6f);
+ glVertex3d (1.0f, -0.1f, 0.0f);
+
+ // top of screen
+ glColor3d (0.0f, 0.0f, 0.0f);
+ glVertex3d (1.0f, 1.6f, -0.1f);
+ glVertex3d (-1.0f, 1.6f, -0.1f);
+ glVertex3d (-1.0f, 1.6f, 0.0f);
+ glVertex3d (1.0f, 1.6f, 0.0f);
+
+ // front of screen
+ glColor3d (0.0f, 0.0f, 0.0f);
+ glVertex3d (1.0f, 1.6f, 0.0f);
+ glVertex3d (-1.0f, 1.6f, 0.0f);
+ glVertex3d (-1.0f, 0.0f, 0.0f);
+ glVertex3d (1.0f, 0.0f, 0.0f);
+
+ // screen
+ glColor3d (0.0f, 0.0f, 1.0f);
+ glVertex3d (0.9f, 1.5f, 0.01f);
+ glVertex3d (-0.9f, 1.5f, 0.01f);
+ glVertex3d (-0.9f, 0.1f, 0.01f);
+ glVertex3d (0.9f, 0.1f, 0.01f);
+
+ // back of screen
+ glColor3d (0.0f, 0.0f, 0.0f);
+ glVertex3d (1.0f, -0.1f, -0.1f);
+ glVertex3d (-1.0f, -0.1f, -0.1f);
+ glVertex3d (-1.0f, 1.6f, -0.1f);
+ glVertex3d (1.0f, 1.6f, -0.1f);
+
+ // left of screen
+ glColor3d (0.0f, 0.0f, 0.0f);
+ glVertex3d (-1.0f, 1.6f, 0.0f);
+ glVertex3d (-1.0f, 1.6f, -0.1f);
+ glVertex3d (-1.0f, -0.1f, -0.1f);
+ glVertex3d (-1.0f, -0.1f, 0.0f);
+
+ // Right of screen
+ glColor3d (0.0f, 0.0f, 0.0f);
+ glVertex3d (1.0f, 1.6f, -0.1f);
+ glVertex3d (1.0f, 1.6f, 0.0f);
+ glVertex3d (1.0f, -0.1f, 0.0f);
+ glVertex3d (1.0f, -0.1f, -0.1f);
+
+ glEnd ();
+ glPopMatrix ();
+ glutSwapBuffers ();
+}
+
+static void update_scene (void)
+{
+ int ret, x, y, z, do_update = 0;
+
+ ret = read_position (&x, &y, &z);
+ if (ret)
+ return;
+ //exit(EXIT_FAILURE);
+
+ x -= rest_x;
+ y -= rest_y;
+ z -= rest_z;
+
+ /* only update if we surpass our threshold, to minimize jitter ... */
+ if (abs (x - val_x) > UPDATE_THRESHOLD) {
+ val_x = x;
+ do_update = 1;
+ }
+ if (abs (y - val_y) > UPDATE_THRESHOLD) {
+ val_y = y;
+ do_update = 1;
+ }
+ if (abs (z - val_z) > UPDATE_THRESHOLD) {
+ val_z = z;
+ do_update = 1;
+ }
+
+ /* ... or, if we are within our threshold of zero, reset to zero */
+ if (abs (x) < UPDATE_THRESHOLD) {
+ val_x = 0;
+ do_update = 1;
+ }
+ if (abs (y) < UPDATE_THRESHOLD) {
+ val_y = 0;
+ do_update = 1;
+ }
+
+ if (do_update)
+ draw_scene ();
+
+ usleep (SLEEP_INTERVAL);
+}
+
+int main (int argc, char *argv[])
+{
+ int ret;
+
+ ret = read_position (&rest_x, &rest_y, &rest_z);
+ if (ret)
+ return 1;
+
+ glutInit (&argc, argv);
+ glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
+ glutInitWindowSize (WIDTH, HEIGHT);
+ glutInitWindowPosition (0, 0);
+ glutCreateWindow ("IBM Accelerometer Demo");
+ glutDisplayFunc (&update_scene);
+ glutIdleFunc (&update_scene);
+ glutReshapeFunc (&resize_scene);
+
+ glClearColor (0.5f, 0.5f, 0.5f, 0.0f);
+ glClearDepth (1.0); // Enables Clearing Of The Depth Buffer
+ glDepthFunc (GL_LESS); // The Type Of Depth Test To Do
+ glEnable (GL_DEPTH_TEST); // Enables Depth Testing
+ glShadeModel (GL_SMOOTH); // Enables Smooth Color Shading
+
+ glMatrixMode (GL_PROJECTION);
+ glLoadIdentity ();
+ gluPerspective (45.0f, (GLfloat)WIDTH / (GLfloat)HEIGHT, 0.1f, 100.0f);
+
+ glMatrixMode (GL_MODELVIEW);
+ glLoadIdentity ();
+ glTranslated (0.0, -0.5, -4.0);
+
+ draw_scene ();
+
+ /* Start Event Processing Engine */
+ glutMainLoop ();
+
+ return 0;
+}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Mactel-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mactel-linux-devel