Permalink
Browse files

cleaning up and normalizing api

  • Loading branch information...
1 parent a29f16e commit 4114069f01fe36e46b5d1d3df4e255f2138d45a9 @dballard committed Jun 21, 2012
Showing with 28 additions and 18 deletions.
  1. +3 −2 engine.lisp
  2. +20 −12 math.lisp
  3. +5 −4 model.lisp
View
@@ -79,8 +79,9 @@
(defparameter *rear-thruster-vertices*
(make-thruster-vertices
- '( (0.0 0.5 0.0) (-2.0 -0.5 0.0) (2.0 -0.5 0.0) (0.0 0.0 0.0))
- (transform-points (translate-triangle (rotate-triangle *3pyramid-points* (make-rotation-matrix 0 0 0)) (vector 0 0 0.5)) '(4 1 1.5))
+ (transform-points (translate-points *3pyramid-points* (vector 0 0 0.5)) (vector 4 1 1.01))
+ ;'( (0.0 0.5 0.0) (-2.0 -0.5 0.0) (2.0 -0.5 0.0) (0.0 0.0 0.0))
+ (transform-points (translate-points (rotate-points *3pyramid-points* (make-rotation-matrix (vector 0 0 0))) (vector 0 0 0.5)) (vector 14 1 1.5))
; '( (0.0 0.5 0.0) (-2.0 -0.5 0.0) (2.0 -0.5 0.0) (0.0 0.0 1.5))
2))
; '((0.0 0.5 0.0) (-2.0 -0.5 0.0) (2.0 -0.5 0.0)
View
@@ -23,13 +23,13 @@
;; returns a real lisp 2d array: args in radians
-(defun make-rotation-matrix (xa ya za)
- (let ((sxa (sin xa))
- (cxa (cos xa))
- (sya (sin ya))
- (cya (cos ya))
- (sza (sin za))
- (cza (cos za)))
+(defun make-rotation-matrix (xyz)
+ (let ((sxa (sin (aref xyz 0))) ;x
+ (cxa (cos (aref xyz 0))) ;x
+ (sya (sin (aref xyz 1))) ;y
+ (cya (cos (aref xyz 1))) ;y
+ (sza (sin (aref xyz 2))) ;z
+ (cza (cos (aref xyz 2)))) ;z
(make-array '(3 3) :initial-contents (list (list (* cya cza) (+ (- (* cxa sza)) (* sxa sya cza)) (+ (* sxa sza) (* cxa sya cza)))
(list (* cya sza) (+ (* cxa cza) (* sxa sya sza)) (+ (- (* sxa cza)) (* cxa sya sza)))
(list (- sya) (* sxa cya) (* cxa cya))))))
@@ -48,13 +48,21 @@
result))
-(defun translate-triangle (tri position)
+(defun translate-points (tri position)
(make-array (length tri) :initial-contents
(loop for v across tri collecting (translate-point position v))))
-(defun rotate-triangle (tri m)
- (make-array (length tri) :initial-contents
- (loop for v across tri collecting (rotate* m v))))
+(defun rotate-triangle (points m)
+; (if (not (vectorp (aref m 0)))
+; (rotate-triangle points (make-rotation-matrix m)))
+ (make-array (length points) :initial-contents
+ (loop for v across points collecting (rotate* m v))))
+
+(defun rotate-points (points m)
+; (if (not (vectorp (aref m 0)))
+; (rotate-points points (make-rotation-matrix m)))
+ (make-array (length points) :initial-contents (loop for tri across points collecting (rotate* m tri))))
+
(defun scale-vector (v a)
(make-array (length v) :initial-contents (loop for i across v collecting (* i a))))
@@ -68,7 +76,7 @@
(make-array (length points) :initial-contents
(loop for v across points collecting
(make-array 3 :initial-contents
- (list (* (aref v 0) (first xyz)) (* (aref v 1) (second xyz)) (* (aref v 2) (third xyz)))))))
+ (list (* (aref v 0) (aref xyz 0)) (* (aref v 1) (aref xyz 1)) (* (aref v 2) (aref xyz 2)))))))
; returns a vector with all elemts scaled to biggest 1 which is scaled to 1
; e.x. (scale-vector (8 4 2)) -> (1 .5 .25)
View
@@ -102,14 +102,15 @@
(make-2d-array 4 3 '((0 0 0) (1 1 1) (2 2 2) (3 3 3)))
(make-2d-array 4 3 '((0 1 3) (0 2 1) (0 3 2) (1 2 3))))))
-(defun rotate-points (points m)
- (loop for tri in points collecting (rotate-triangle (make-array (length tri) :initial-contents tri) m)))
+
+
+
(defparameter *ship-model*
(make-model-3pyramid ;*3pyramid-flat-points*
(transform-points
- (rotate-triangle *3pyramid-flat-points* (make-rotation-matrix 0 0 0))
- '(4 1 3))
+ (rotate-points *3pyramid-flat-points* (make-rotation-matrix (vector 0 0 0)))
+ (vector 4 1 3))
:face-colors '((196 196 196) (196 196 196) (196 196 196) (32 32 32))))
;(defparameter *ship-model*

0 comments on commit 4114069

Please sign in to comment.