Use print-object methods to better identify entities

This commit is contained in:
Renaud Casenave-Péré 2016-04-14 14:07:33 +02:00
parent faae6741be
commit 9ba6982892
4 changed files with 21 additions and 0 deletions

View file

@ -52,6 +52,10 @@
(with-slots (object-id) entity
(setf object-id (register-entity entity))))
(defmethod print-object ((entity entity) stream)
(print-unreadable-object (entity stream :identity t)
(format stream "~a: ~@<~{~:_~a~^ ~}~:>" (name entity) (all-components entity))))
(defclass component ()
((owner :initarg :owner :reader owner)
(activep :initarg :activep :initform t :accessor activep)

View file

@ -28,6 +28,12 @@
(with-slots (position direction) scene-object-component
(update-view camera position direction))))
(defmethod print-object ((camera camera-component) stream)
(with-slots (fovy aspect near far) camera
(print-unreadable-object (camera stream :type t)
(format stream "~@<~:_fovy = ~a ~:_aspect = ~a ~:_near = ~a ~:_far = ~a~:>"
fovy aspect near far))))
(defun update-view (camera position direction)
"Compute the world-to-view matrix from the position and the direction of the camera"
(setf (view camera) (m* (transpose (quat-to-mat4 direction)) (mtranslate (v- position)))))

View file

@ -45,6 +45,12 @@
(with-components ((node graph-node-component)) owner
(update-transform node position direction scale)))
(defmethod print-object ((obj scene-object-component) stream)
(with-accessors ((pos position-of) (dir direction-of) (scale scale-of)) obj
(print-unreadable-object (obj stream :type t)
(format stream "~@<~:_position = ~a ~:_direction = ~a ~:_scale = ~a~:>"
pos dir scale))))
(defun move (obj &key (dx 0.0) (dy 0.0) (dz 0.0))
(with-slots (position direction) obj
(setf position (v+ position (m* (quat-to-mat3 direction) (vec dx dy dz))))))

View file

@ -28,6 +28,11 @@
:reader raw-data
:documentation "The internal representation of the vector")))
(defmethod print-object ((v vect) stream)
(with-slots (array) v
(print-unreadable-object (v stream :type t)
(format stream "~a" array))))
(defclass int2 (vect)
((array :type (array fixnum (2)))))