Skip to content

Commit

Permalink
Add radius to polygon and offset to circle
Browse files Browse the repository at this point in the history
  • Loading branch information
borodust committed Apr 18, 2020
1 parent bae59a5 commit 2a1b571
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
30 changes: 18 additions & 12 deletions physics/2d/shape.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,24 @@
(defclass circular-shape (chipmunk-shape) ())


(defmethod initialize-instance ((this circular-shape) &rest args &key radius body universe)
(defmethod initialize-instance ((this circular-shape) &rest args
&key radius body universe offset)
(with-cp-vect (zero-vect)
(setf (zero-vect :x) (cp-float 0)
(zero-vect :y) (cp-float 0))
(setf (zero-vect :x) (cp-float (if offset (x offset) 0))
(zero-vect :y) (cp-float (if offset (y offset) 0)))
(apply #'call-next-method this
:handle (make-shape-handle (%cp:circle-shape-new (body-handle-or-static universe body)
(cp-float radius) zero-vect))
args)))


(defmethod simulation-engine-make-circle-shape ((engine chipmunk-engine) (universe universe)
(radius number) &key body substance)
(radius number) &key body substance offset)
(let ((shape (make-instance 'circular-shape
:universe universe
:radius radius
:substance substance
:offset offset
:body body)))
(add-space-shape universe shape)
shape))
Expand All @@ -164,7 +166,7 @@


(defmethod initialize-instance ((this polygon-shape) &rest args
&key points body universe)
&key points body universe radius)
(let ((point-count (length points)))
(c-with ((f-points %cp:vect :count point-count)
(f-transform %cp:transform))
Expand All @@ -184,17 +186,18 @@
point-count
(f-points &)
(f-transform &)
(cp-float 0.0001))))
(cp-float (or radius 0.0001)))))
args))))


(defmethod simulation-engine-make-polygon-shape ((engine chipmunk-engine) (universe universe)
points &key body substance)
points &key body substance radius)
(let ((shape (make-instance 'polygon-shape
:universe universe
:points points
:substance substance
:body body)))
:body body
:radius radius)))
(add-space-shape universe shape)
shape))

Expand All @@ -205,17 +208,18 @@


(defmethod initialize-instance ((this box-shape) &rest args
&key width height body universe &allow-other-keys)
&key width height body universe radius &allow-other-keys)
(apply #'call-next-method this
:handle (make-shape-handle (%cp:box-shape-new (body-handle-or-static universe body)
(cp-float width)
(cp-float height)
(cp-float 0)))
(cp-float (or radius 0))))
args))


(defmethod simulation-engine-make-box-shape ((engine chipmunk-engine) (universe universe)
(width number) (height number) &key body offset substance)
(width number) (height number)
&key body offset substance radius)
(if offset
(let ((ox (+ (- (/ width 2)) (x offset)))
(oy (+ (- (/ height 2)) (y offset))))
Expand All @@ -225,12 +229,14 @@
(vec2 (+ ox width) (+ oy height))
(vec2 (+ ox width) oy))
:body body
:substance substance))
:substance substance
:radius radius))
(let ((shape (make-instance 'box-shape
:universe universe
:substance substance
:width width
:height height
:radius radius
:body body)))
(add-space-shape universe shape)
shape)))
6 changes: 4 additions & 2 deletions physics/api.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
:substance prepared-substance))))


(defun make-box-shape (universe width height &key offset body substance)
(defun make-box-shape (universe width height &key offset body substance radius)
(make-shape-handle (%engine-of universe)
body
substance
Expand All @@ -292,10 +292,11 @@
width height
:body (%handle-of body)
:offset offset
:radius radius
:substance prepared-substance))))


(defun make-circle-shape (universe radius &key body substance)
(defun make-circle-shape (universe radius &key body substance offset)
(make-shape-handle (%engine-of universe)
body
substance
Expand All @@ -304,6 +305,7 @@
(%handle-of universe)
radius
:body (%handle-of body)
:offset offset
:substance prepared-substance))))


Expand Down
8 changes: 5 additions & 3 deletions physics/backend/backend.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@

(defgeneric simulation-engine-make-segment-shape (engine universe start end &key body substance))
(defgeneric simulation-engine-make-polyline-shape (engine universe points &key body substance))
(defgeneric simulation-engine-make-polygon-shape (engine universe points &key body substance))
(defgeneric simulation-engine-make-box-shape (engine universe width height &key offset body substance))
(defgeneric simulation-engine-make-circle-shape (engine universe radius &key body substance))
(defgeneric simulation-engine-make-polygon-shape (engine universe points
&key body substance radius))
(defgeneric simulation-engine-make-box-shape (engine universe width height
&key offset body substance radius))
(defgeneric simulation-engine-make-circle-shape (engine universe radius &key body substance offset))


;;;
Expand Down

0 comments on commit 2a1b571

Please sign in to comment.