;;/* ;; nii.c ;; Nate Robins 1997 ;; ;; Network Integration Incorporated logo. ;; ;; */ (in-package :common-lisp-user) (defpackage :nii (:use :common-lisp #-SBCL :ext #+SBCL :sb-ext :gl :ffi-glue) (:export :start)) (in-package :nii) (defvar *window* nil) (defparameter n_vertices #(#(-17f0 17f0 6f0) #(-17f0 -17f0 6f0) #(-5f0 -17f0 6f0) #(-5f0 -7f0 6f0) #(5f0 -17f0 6f0) #(17f0 -17f0 6f0) #(17f0 9f0 6f0) #(5f0 9f0 6f0) #(5f0 7f0 6f0) #(-5f0 17f0 6f0) #(-17f0 17f0 -6f0) #(-17f0 -17f0 -6f0) #(-5f0 -17f0 -6f0) #(-5f0 -7f0 -6f0) #(5f0 -17f0 -6f0) #(17f0 -17f0 -6f0) #(17f0 9f0 -6f0) #(5f0 9f0 -6f0) #(5f0 7f0 -6f0) #(-5f0 17f0 -6f0) #(6f0 8f0 6f0) #(6f0 -16f0 6f0) #(16f0 -16f0 6f0) #(16f0 8f0 6f0) #(6f0 8f0 -6f0) #(6f0 -16f0 -6f0) #(16f0 -16f0 -6f0) #(16f0 8f0 -6f0))) (dotimes (i (length n_vertices)) (setf (svref n_vertices i) (convert-array-to-pointer 'single-float (svref n_vertices i)))) (defparameter n_vindices #(#(0 1 2) #(0 2 9) #(9 3 8) #(8 3 4) ;; /* back */ #(10 12 11) #(10 19 12) #(19 18 13) #(18 14 13) #(0 9 19) ;/* top left */ #(0 19 10) #(19 9 8) ;/* top slant */ #(8 18 19) #(8 7 17) ;/* small step */ #(17 18 8) #(17 7 6) ;/* below cube */ #(17 6 16) #(6 5 15) ;/* top right */ #(16 6 15) #(5 14 15) ;/* bottom right */ #(5 4 14) #(4 3 13) ;/* bottom slant */ #(4 13 14) #(2 12 13) ;/* step */ #(2 13 3) #(2 11 12) ;/* bottom left */ #(2 1 11) #(1 0 10) ;/* left */) #(1 10 11) #(7 4 20) ;/* hollow front */ #(20 4 21) #(21 4 5) #(21 5 22) #(22 5 6) #(6 23 22) #(7 23 6) #(7 20 23) #(17 24 14) ;/* hollow back */ #(24 25 14) #(25 15 14) #(25 26 15) #(26 16 15) #(16 26 27) #(17 16 27) #(17 27 24) #(20 24 23) ;/* hollow top */ #(24 27 23) #(23 27 26) ;/* hollow right */ #(23 26 22) #(20 21 25) ;/* hollow left */ #(20 25 24) #(25 21 22) ;/* hollow bottom */ #(25 22 26))) (defparameter n_normals #(#(0f0 0f0 1f0) #(0f0 0f0 1f0) #(0f0 0f0 1f0) #(0f0 0f0 1f0) #(0f0 0f0 -1f0) #(0f0 0f0 -1f0) #(0f0 0f0 -1f0) #(0f0 0f0 -1f0) #(0f0 1f0 0f0) #(0f0 1f0 0f0) #(0.7071f0 0.7071f0 0f0) #(0.7071f0 0.7071f0 0f0) #(-1f0 0f0 0f0) #(-1f0 0f0 0f0) #(0f0 1f0 0f0) #(0f0 1f0 0f0) #(1f0 0f0 0f0) #(1f0 0f0 0f0) #(0f0 -1f0 0f0) #(0f0 -1f0 0f0) #(-0.7071f0 -0.7071f0 0f0) #(-0.7071f0 -0.7071f0 0f0) #(1f0 0f0 0f0) #(1f0 0f0 0f0) #(0f0 -1f0 0f0) #(0f0 -1f0 0f0) #(-1f0 0f0 0f0) #(-1f0 0f0 0f0) #(0f0 0f0 1f0) #(0f0 0f0 1f0) #(0f0 0f0 1f0) #(0f0 0f0 1f0) #(0f0 0f0 1f0) #(0f0 0f0 1f0) #(0f0 0f0 1f0) #(0f0 0f0 1f0) #(0f0 0f0 -1f0) #(0f0 0f0 -1f0) #(0f0 0f0 -1f0) #(0f0 0f0 -1f0) #(0f0 0f0 -1f0) #(0f0 0f0 -1f0) #(0f0 0f0 -1f0) #(0f0 0f0 -1f0) #(0f0 -1f0 0f0) #(0f0 -1f0 0f0) #(-1f0 0f0 0f0) #(-1f0 0f0 0f0) #(1f0 0f0 0f0) #(1f0 0f0 0f0) #(0f0 1f0 0f0) #(0f0 1f0 0f0))) (dotimes (i (length n_normals)) (setf (svref n_normals i) (convert-array-to-pointer 'single-float (svref n_normals i)))) (defparameter n_numtriangles 52) (defparameter c_vertices #(#(-6f0 3f0 6f0) #(-6f0 -3f0 6f0) #(6f0 -3f0 6f0) #(6f0 3f0 6f0) #(-6f0 3f0 -6f0) #(-6f0 -3f0 -6f0) #(6f0 -3f0 -6f0) #(6f0 3f0 -6f0))) (dotimes (i (length c_vertices)) (setf (svref c_vertices i) (convert-array-to-pointer 'single-float (svref c_vertices i)))) (defparameter c_vindices #(#(0 1 2) #(0 2 3) #(0 3 7) #(0 7 4) #(3 2 6) #(3 6 7) #(7 6 5) #(7 5 4) #(6 2 1) #(6 1 5) #(4 5 1) #(4 1 0))) (defparameter c_normals #(#(0f0 0f0 1f0 ) #(0f0 0f0 1f0) #(0f0 1f0 0f0) #(0f0 1f0 0f0) #(1f0 0f0 0f0) #(1f0 0f0 0f0) #(0f0 0f0 -1f0) #(0f0 0f0 -1f0) #(0f0 -1f0 0f0) #(0f0 -1f0 0f0) #(-1f0 0f0 0f0) #(-1f0 0f0 0f0))) (dotimes (i (length c_normals)) (setf (svref c_normals i) (convert-array-to-pointer 'single-float (svref c_normals i)))) (defparameter c_numtriangles 12) (defparameter spin_x -30f0) (defparameter spin_y 25f0) (defparameter spin_c 0f0) (def-callback reshape (void (width int) (height int)) (glViewport 0 0 width height) (glMatrixMode GL_PROJECTION) (glLoadIdentity) (gluPerspective 60.0d0 (coerce (/ width height) 'double-float) 1d0 1200d0) (glMatrixMode GL_MODELVIEW) (glLoadIdentity) (gluLookAt 0d0 0d0 60d0 0d0 0d0 0d0 0d0 1d0 0d0) (glLightfv GL_LIGHT0 GL_POSITION (convert-array-to-pointer 'single-float #(0f0 1f0 1f0 0f0))) (glClearColor 1f0 1f0 1f0 1f0) (glEnable GL_LIGHTING) (glEnable GL_LIGHT0) (glEnable GL_DEPTH_TEST) (glEnable GL_CULL_FACE) (glEnable GL_COLOR_MATERIAL) (glShadeModel GL_SMOOTH)) (def-callback display (void) (glClear (+ GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT)) (glPushMatrix) (glRotatef spin_y 1f0 0f0 0f0) (glRotatef spin_x 0f0 1f0 0f0) (glColor3ub 165 163 160) (glBegin GL_TRIANGLES) (dotimes (i n_numtriangles) (glNormal3fv (aref n_normals i)) (glVertex3fv (aref n_vertices (aref (aref n_vindices i) 0))) (glVertex3fv (aref n_vertices (aref (aref n_vindices i) 1))) (glVertex3fv (aref n_vertices (aref (aref n_vindices i) 2)))) (glend) (glColor3ub 0 90 107) (glTranslatef 11.0 14.0 0.0) (glRotatef spin_c 0.0 1.0 0.0) (glBegin GL_TRIANGLES) (dotimes (i c_numtriangles) (glNormal3fv (aref c_normals i)) (glVertex3fv (aref c_vertices (aref (aref c_vindices i) 0))) (glVertex3fv (aref c_vertices (aref (aref c_vindices i) 1))) (glVertex3fv (aref c_vertices (aref (aref c_vindices i) 2)))) (glEnd) (glPopMatrix) (glutSwapBuffers)) (def-callback idle (void) (incf spin_c) (when (> spin_c 360) (decf spin_c 360)) (glutPostRedisplay)) (let ((old_x 50) (old_y 50) (old_width 320) (old_height 320)) (defun swap-fullscreen () (if (< (glutGet GLUT_WINDOW_WIDTH) (glutGet GLUT_SCREEN_WIDTH)) (progn (setq old_x (glutGet GLUT_WINDOW_X) old_y (glutGet GLUT_WINDOW_Y) old_width (glutGet GLUT_WINDOW_WIDTH) old_height (glutGet GLUT_WINDOW_HEIGHT)) (glutFullScreen)) (progn (glutPositionWindow old_x old_y) (glutReshapeWindow old_width old_height))) (glutPostRedisplay))) (let ((toggle nil)) (def-callback keyboard (void (key int) (x int) (y int)) (declare (ignorable key x y)) (case (code-char key) (#\Tab (swap-fullscreen)) (#\Escape (glutDestroyWindow *window*) (throw :exit-nii nil)) (#\Space (setq toggle (not toggle)) (if toggle (glutIdleFunc nil) (glutIdleFunc (callback idle))))))) (let ((old_x 0) (old_y 0)) (def-callback mouse (void (button int) (state int) (x int) (y int)) (declare (ignorable button state x y)) (setq old_x x old_y y) (glutPostRedisplay)) (def-callback motion (void (x int) (y int)) (setq spin_x (float (- x old_x)) spin_y (float (- y old_y))) (glutPostRedisplay))) (def-callback visibility (void (state int)) (if (= state GLUT_VISIBLE) (glutIdleFunc (callback idle)) (glutIdleFunc nil))) (defun start () (glutInitDisplayMode (+ GLUT_RGB GLUT_DEPTH GLUT_DOUBLE)) (glutInitWindowPosition 50 50) (glutInitWindowSize 640 480) (setq *window* (glutCreateWindow "Network Integration")) (glutVisibilityFunc (callback visibility)) (glutKeyboardFunc (callback keyboard)) (glutDisplayFunc (callback display)) (glutReshapeFunc (callback reshape)) (glutMotionFunc (callback motion)) (glutMouseFunc (callback mouse)) (glutIdleFunc (callback idle)) (catch :exit-nii (glutMainLoop)) (ignore-errors (glutMainLoopEvent)) (format t "Done~%"))