diff --git a/src/plugins/particle.lisp b/src/plugins/particle.lisp index fa1349e..3a768ae 100644 --- a/src/plugins/particle.lisp +++ b/src/plugins/particle.lisp @@ -52,28 +52,30 @@ ;;;; particle ============================================================ -(defclass particle () - ((pos :accessor pos :initarg :pos :initform (p! 0 0 0)) - (vel :accessor vel :initarg :vel :initform (p! 0 0 0)) - (is-alive? :accessor is-alive? :initarg :is-alive? :initform t) - (generation :accessor generation :initarg :generation :initform 1) - (life-span :accessor life-span :initarg :life-span :initform -1) ; -1 = immortal - (age :accessor age :initarg :age :initform 0) - - (points :accessor points :initarg :points :initform (make-array 0 :adjustable t :fill-pointer t)) -;; (behaviors :accessor behaviors :initarg :behaviors :initform (make-array 0 :adjustable t :fill-pointer t)) +(defclass-kons-9 particle () + ((pos (p! 0 0 0)) + (vel (p! 0 0 0)) + (is-alive? t) + (generation 1) + (life-span -1) ; -1 = immortal + (age 0) + + ;; size, color, alpha - (update-angle :accessor update-angle :initarg :update-angle :initform (range-float 0.0 0)) + (points (make-array 0 :adjustable t :fill-pointer t)) +;; (behaviors (make-array 0 :adjustable t :fill-pointer t)) + + (update-angle (range-float 0.0 0)) - (done-spawn? :accessor done-spawn? :initarg :done-spawn? :initform nil) - (mutate-spawns? :accessor mutate-spawns? :initarg :mutate-spawns? :initform nil) - (spawn-number-children :accessor spawn-number-children :initarg :spawn-number-children :initform (range-float 2 0)) - (spawn-angle :accessor spawn-angle :initarg :spawn-angle :initform (range-float 45.0 22.5)) - (spawn-life-span-factor :accessor spawn-life-span-factor :initarg :spawn-life-span-factor :initform (range-float 1.0 0)) - (spawn-velocity-factor :accessor spawn-velocity-factor :initarg :spawn-velocity-factor :initform (range-float 1.0 0)))) + (spawn-done? nil) + (spawn-mutate? nil) + (spawn-number-children (range-float 2 0)) + (spawn-angle (range-float 45.0 22.5)) + (spawn-life-span-factor (range-float 1.0 0)) + (spawn-velocity-factor (range-float 1.0 0)))) (defmethod copy-particle-data ((dst particle) (src particle)) - (setf (mutate-spawns? dst) (mutate-spawns? src)) + (setf (spawn-mutate? dst) (spawn-mutate? src)) (setf (update-angle dst) (range-duplicate (update-angle src))) (setf (spawn-number-children dst) (range-duplicate (spawn-number-children src))) (setf (spawn-angle dst) (range-duplicate (spawn-angle src))) @@ -127,16 +129,16 @@ :life-span (* (life-span ptcl) (range-value (spawn-life-span-factor ptcl)))))) (copy-particle-data child ptcl) ;transfer data - (when (mutate-spawns? ptcl) + (when (spawn-mutate? ptcl) (mutate-particle child 1.0)) child)) (defmethod do-spawn ((ptcl particle)) (if (and (not (= -1 (life-span ptcl))) (>= (age ptcl) (life-span ptcl)) - (not (done-spawn? ptcl))) + (not (spawn-done? ptcl))) (progn - (setf (done-spawn? ptcl) t) + (setf (spawn-done? ptcl) t) ;; spawn offspring (let ((children '())) (dotimes (i (round (range-value (spawn-number-children ptcl)))) diff --git a/test/demo-particle.lisp b/test/demo-particle.lisp index 06fe46b..6da336e 100644 --- a/test/demo-particle.lisp +++ b/test/demo-particle.lisp @@ -306,6 +306,48 @@ Dynamic particles growing from a superquadric with a gravity force field. ;;; for automated testing (update-scene *scene* 30) +#| +(Demo 13 particle) particle system attributes ================================== + +Create a row particle systems with varrying attributes. +|# + +(format t " particle-system 13...~%") (finish-output) + +(with-clear-scene + (defparameter *p-sys-1* (make-particle-system-from-point + (p! -8 0 0) 1 (p! 0 .2 0) (p! 0 .2 0) + 'particle + :life-span 5)) + (defparameter *p-sys-2* (make-particle-system-from-point + (p! -4 0 0) 1 (p! 0 .2 0) (p! 0 .2 0) + 'particle + :life-span 5 + :spawn-angle (range-float 10.0 5.0))) ;narrower branching + (defparameter *p-sys-3* (make-particle-system-from-point + (p! 0 0 0) 1 (p! 0 .2 0) (p! 0 .2 0) + 'particle + :life-span 5 + :spawn-velocity-factor (range-float .5 .2))) ;shorter branching + (defparameter *p-sys-4* (make-particle-system-from-point + (p! 4 0 0) 1 (p! 0 .2 0) (p! 0 .2 0) + 'particle + :life-span 5 + :update-angle (range-float 20.0 10.0))) ;twisty branches + (defparameter *p-sys-5* (make-particle-system-from-point + (p! 8 0 0) 1 (p! 0 .2 0) (p! 0 .2 0) + 'particle + :life-span 5 + :spawn-angle (range-float 5.0 2.5) ;very narrow branching + :update-angle (range-float 10.0 5.0))) ;twisty branches + (add-shapes *scene* (list *p-sys-1* *p-sys-2* *p-sys-3* *p-sys-4* *p-sys-5*)) + (add-motions *scene* (list *p-sys-1* *p-sys-2* *p-sys-3* *p-sys-4* *p-sys-5*))) + +;;; hold down space key in 3D view to run animation + +(update-scene *scene* 30) ;do update for batch testing + + #| END ============================================================================ |#