cleaning up and normalizing api
This commit is contained in:
parent
a29f16e697
commit
4114069f01
|
@ -79,8 +79,9 @@
|
||||||
|
|
||||||
(defparameter *rear-thruster-vertices*
|
(defparameter *rear-thruster-vertices*
|
||||||
(make-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-points *3pyramid-points* (vector 0 0 0.5)) (vector 4 1 1.01))
|
||||||
(transform-points (translate-triangle (rotate-triangle *3pyramid-points* (make-rotation-matrix 0 0 0)) (vector 0 0 0.5)) '(4 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 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))
|
; '( (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))
|
2))
|
||||||
; '((0.0 0.5 0.0) (-2.0 -0.5 0.0) (2.0 -0.5 0.0)
|
; '((0.0 0.5 0.0) (-2.0 -0.5 0.0) (2.0 -0.5 0.0)
|
||||||
|
|
32
math.lisp
32
math.lisp
|
@ -23,13 +23,13 @@
|
||||||
|
|
||||||
|
|
||||||
;; returns a real lisp 2d array: args in radians
|
;; returns a real lisp 2d array: args in radians
|
||||||
(defun make-rotation-matrix (xa ya za)
|
(defun make-rotation-matrix (xyz)
|
||||||
(let ((sxa (sin xa))
|
(let ((sxa (sin (aref xyz 0))) ;x
|
||||||
(cxa (cos xa))
|
(cxa (cos (aref xyz 0))) ;x
|
||||||
(sya (sin ya))
|
(sya (sin (aref xyz 1))) ;y
|
||||||
(cya (cos ya))
|
(cya (cos (aref xyz 1))) ;y
|
||||||
(sza (sin za))
|
(sza (sin (aref xyz 2))) ;z
|
||||||
(cza (cos za)))
|
(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)))
|
(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 (* cya sza) (+ (* cxa cza) (* sxa sya sza)) (+ (- (* sxa cza)) (* cxa sya sza)))
|
||||||
(list (- sya) (* sxa cya) (* cxa cya))))))
|
(list (- sya) (* sxa cya) (* cxa cya))))))
|
||||||
|
@ -48,13 +48,21 @@
|
||||||
result))
|
result))
|
||||||
|
|
||||||
|
|
||||||
(defun translate-triangle (tri position)
|
(defun translate-points (tri position)
|
||||||
(make-array (length tri) :initial-contents
|
(make-array (length tri) :initial-contents
|
||||||
(loop for v across tri collecting (translate-point position v))))
|
(loop for v across tri collecting (translate-point position v))))
|
||||||
|
|
||||||
(defun rotate-triangle (tri m)
|
(defun rotate-triangle (points m)
|
||||||
(make-array (length tri) :initial-contents
|
; (if (not (vectorp (aref m 0)))
|
||||||
(loop for v across tri collecting (rotate* m v))))
|
; (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)
|
(defun scale-vector (v a)
|
||||||
(make-array (length v) :initial-contents (loop for i across v collecting (* i 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
|
(make-array (length points) :initial-contents
|
||||||
(loop for v across points collecting
|
(loop for v across points collecting
|
||||||
(make-array 3 :initial-contents
|
(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
|
; 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)
|
; e.x. (scale-vector (8 4 2)) -> (1 .5 .25)
|
||||||
|
|
|
@ -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 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))))))
|
(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*
|
(defparameter *ship-model*
|
||||||
(make-model-3pyramid ;*3pyramid-flat-points*
|
(make-model-3pyramid ;*3pyramid-flat-points*
|
||||||
(transform-points
|
(transform-points
|
||||||
(rotate-triangle *3pyramid-flat-points* (make-rotation-matrix 0 0 0))
|
(rotate-points *3pyramid-flat-points* (make-rotation-matrix (vector 0 0 0)))
|
||||||
'(4 1 3))
|
(vector 4 1 3))
|
||||||
:face-colors '((196 196 196) (196 196 196) (196 196 196) (32 32 32))))
|
:face-colors '((196 196 196) (196 196 196) (196 196 196) (32 32 32))))
|
||||||
|
|
||||||
;(defparameter *ship-model*
|
;(defparameter *ship-model*
|
||||||
|
|
Loading…
Reference in New Issue