Skip to content

Commit

Permalink
Added freeze-transform and demo
Browse files Browse the repository at this point in the history
  • Loading branch information
kaveh808 committed Sep 3, 2022
1 parent 79498ba commit 7ff3015
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/kernel/matrix.lisp
Expand Up @@ -310,6 +310,6 @@
(p-set! point tx ty tz))))

(defun transform-points! (points matrix)
(mapc #'(lambda (p) (transform-point! p matrix)) points)
points)
(loop for p across points
do (transform-point! p matrix)))

4 changes: 4 additions & 0 deletions src/kernel/point-cloud.lisp
Expand Up @@ -23,6 +23,10 @@
(defun make-point-cloud (points)
(make-instance 'point-cloud :points points))

(defmethod freeze-transform ((p-cloud point-cloud))
(transform-points! (points p-cloud) (transform-matrix (transform p-cloud)))
(reset-transform (transform p-cloud)))

;;; point generator functions --------------------------------------------------

(defun make-line-points (p1 p2 num-segments)
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/polyhedron.lisp
Expand Up @@ -309,7 +309,7 @@
:name name
:mesh-type mesh-type)))

(defun make-cut-cube-polyhedron (side &key (name nil) (mesh-type 'polyhedron))
(defun make-cut-cube (side &key (name nil) (mesh-type 'polyhedron))
(let ((r (* side 0.5))
(-r (* side -0.5))
(b (* side 0.3)))
Expand Down
34 changes: 34 additions & 0 deletions test/demo-kernel.lisp
Expand Up @@ -722,6 +722,40 @@ Display shape bounds, face-normals, and axes.
(setf (show-bounds? sphere) t)
(add-shapes *scene* (list circle sphere icos))))

#|
(Demo 21 kernel) freezing shapes ===============================================
Freeze a shape by transforming its points.
|#
(progn
(defparameter *cube* (make-cube 2.0))
(with-clear-scene
(add-shapes *scene* (list
(translate-by
(make-group
(list (rotate-by
(make-group
(list
(translate-by
*cube*
(p! 2.5 0 0))))
(p! 0 45 0))))
(p! 0 2 0))))
(setf (show-axis *cube*) 3.0)))

#|
Hints:
- Press 1 to turn off shaded view so you can see cube axis better.
- Press 7 to turn off global axes display.
Local freezing: transforms a point-based shape's points by its transform matrix
and resets the transform.
|#
(progn
(format t "~%~%Before freeze: ~a~%" (points *cube*))
(freeze-transform *cube*)
(format t "After freeze: ~a~%" (points *cube*)))

#|
END ============================================================================
|#

0 comments on commit 7ff3015

Please sign in to comment.