more restructuring of code into logical files and moving functions into

classes
This commit is contained in:
Dan Ballard 2011-07-30 13:09:37 -07:00
parent c64e191879
commit dd65cc83b0
5 changed files with 60 additions and 41 deletions

View File

@ -8,7 +8,9 @@
:components ((:file "package")
(:file "util")
(:file "math")
(:file "graphics")
(:file "model")
(:file "phsyics")
(:file "objects")
(:file "flight-sim")))

View File

@ -5,10 +5,6 @@
;;; "flight-sim" goes here. Hacks and glory await!
(defclass game-object ()
((model :initarg :model :accessor model :initform (make-instance 'model))
(body :initarg :body :accessor body :inotform (make-instance 'body))))
(defclass engine-object (game-object)
((active :initarg :active :reader active :initform nil)
@ -102,44 +98,7 @@
(defparameter *num-frames* 0)
(defun draw-triangle (tri colors)
(declare (type shape-vector tri))
(declare (type shape-vector colors))
(gl:with-primitive :triangles
(let ((c (aref colors 0)))
(gl:color (aref c 0) (aref c 1) (aref c 2)))
(let ((v (aref tri 0)))
(gl:vertex (aref v 0) (aref v 1) (aref v 2)))
(let ((c (aref colors 1)))
(gl:color (aref c 0) (aref c 1) (aref c 2)))
(let ((v (aref tri 1)))
(gl:vertex (aref v 0) (aref v 1) (aref v 2)))
(let ((c (aref colors 2)))
(gl:color (aref c 0) (aref c 1) (aref c 2)))
(let ((v (aref tri 2)))
(gl:vertex (aref v 0) (aref v 1) (aref v 2)))))
(defun draw-entity (entity)
(gl:translate (aref (coords (motion entity)) 0) (aref (coords (motion entity)) 1) (aref (coords (motion entity)) 2))
(gl:rotate (aref (angles entity) 0) 1 0 0)
(gl:rotate (aref (angles entity) 1) 0 1 0)
(gl:rotate (aref (angles entity) 2) 0 0 1)
(loop for i from 0 to (1- (length (faces (model entity)))) do
(draw-triangle (get-vertecies (aref (faces (model entity)) i) (vertices (model entity)))
(get-vertecies (aref (face-colors (model entity)) i) (colors (model entity))))))
(defgeneric object-draw (object))
(defmethod object-draw :before ((object game-object))
(gl:push-matrix))
(defmethod object-draw :after ((object game-object))
(gl:pop-matrix))
(defmethod object-draw ((object game-object))
(draw-entity object))
(defmethod object-draw ((object powered-object))
(draw-entity object)

25
graphics.lisp Normal file
View File

@ -0,0 +1,25 @@
(in-package #:flight-sim)
(defun draw-triangle (tri colors)
(declare (type shape-vector tri))
(declare (type shape-vector colors))
(gl:with-primitive :triangles
(let ((c (aref colors 0)))
(gl:color (aref c 0) (aref c 1) (aref c 2)))
(let ((v (aref tri 0)))
(gl:vertex (aref v 0) (aref v 1) (aref v 2)))
(let ((c (aref colors 1)))
(gl:color (aref c 0) (aref c 1) (aref c 2)))
(let ((v (aref tri 1)))
(gl:vertex (aref v 0) (aref v 1) (aref v 2)))
(let ((c (aref colors 2)))
(gl:color (aref c 0) (aref c 1) (aref c 2)))
(let ((v (aref tri 2)))
(gl:vertex (aref v 0) (aref v 1) (aref v 2)))))
;(defun draw-entity (entity)
(defgeneric draw (object))

View File

@ -6,6 +6,14 @@
(colors :initarg :colors :reader colors :initform (vector) :type shape-vector)
(face-colors :initarg :face-colors :accessor face-colors :initform (vector) :type shape-ref-vector)))
(defmethod draw ((model model))
(loop for i from 0 to (1- (length (faces model))) do
(draw-triangle (get-vertecies (aref (faces model) i) (vertices model))
(get-vertecies (aref (face-colors model) i) (colors model)))))
(defclass animated-model ()
((start-time :initarg :start-time :accessor start-time :initform 0.0)))
(defmethod scale-colors ((model model))
(let ((colors (colors model)))
(loop for i from 0 to (1- (length colors)) do

25
objects.lisp Normal file
View File

@ -0,0 +1,25 @@
(in-package #:flight-sim)
(defclass game-object ()
((model :initarg :model :accessor model :initform (make-instance 'model))
(body :initarg :body :accessor body :initform (make-instance 'body))
(attachments :initarg :attachments :accessor attachments :initform '())
(active-attachments :initarg :active-attachments :accessor active-attachments :initform '())))
(defmethod draw :before ((object game-object))
(gl:push-matrix)
(gl:translate (aref (coords (motion entity)) 0) (aref (coords (motion entity)) 1) (aref (coords (motion entity)) 2))
(gl:rotate (aref (angles entity) 0) 1 0 0)
(gl:rotate (aref (angles entity) 1) 0 1 0)
(gl:rotate (aref (angles entity) 2) 0 0 1))
(defmethod draw :after ((object game-object))
(gl:pop-matrix))
(defmethod draw ((object game-object))
(draw (model object)))