-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added spring and player classes. Apperenly fixed the no disabling of …
…physics objects issue somewhere along the way.
- Loading branch information
Showing
7 changed files
with
102 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,19 @@ | ||
(in-package #:clode) | ||
|
||
(defclass spring () | ||
()) | ||
|
||
(defclass physics-player () | ||
((head :initform nil | ||
:initarg :head | ||
:reader head) | ||
(legs :initform nil | ||
:initarg :legs | ||
:reader legs) | ||
(up :initform '(0 1 0) | ||
:initarg :up | ||
:reader up-vector) | ||
(direction :initform '(1 0 0) | ||
:initarg :direction | ||
:reader direction-vector) | ||
(max-speed :initform 1 | ||
:initarg :max-speed | ||
:accessor max-speed))) | ||
((body :initform (error "You must pass a physics-body to a physics-player object!") | ||
:initarg :body | ||
:reader body))) | ||
|
||
|
||
(defmethod initialize-instance :after ((this physics-player) &key) | ||
|
||
(let ((pbody (clode::pointer (clode::body this)))) | ||
|
||
(clode:body-set-max-angular-speed pbody 0) | ||
(clode::body-set-kinematic pbody) | ||
(clode:Body-Set-Auto-Disable-Flag pbody 0) | ||
(clode:Body-Set-Angular-Damping pbody 0) | ||
(clode:Body-Set-linear-Damping pbody 0))) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
(in-package #:clode) | ||
|
||
|
||
(defclass physics-spring (physics-ray) | ||
((springiness :initform 1 | ||
:initarg :springiness | ||
:accessor springiness) | ||
(damping :initform .1 | ||
:initarg :damping | ||
:accessor damping))) | ||
|
||
|
||
|
||
|
||
|
||
(defmethod close-callback ((this physics-spring) (that physics-object)) | ||
|
||
(let* ((o1 (geometry this)) | ||
(o2 (geometry that)) | ||
(b1 (geom-get-body o1)) | ||
(b2 (geom-get-body o2))) | ||
|
||
(with-foreign-object (contact '(:struct dContact) *physics-max-contacts*) | ||
(let ((gg (foreign-slot-pointer contact '(:struct ode::dContact) 'ode::geom))) | ||
|
||
|
||
(let ((num-contacts (collide o1 o2 *physics-max-contacts* gg (foreign-type-size '(:struct ode::dContact))))) | ||
(unless (zerop num-contacts) | ||
|
||
(let ((distance (abs (foreign-slot-value gg '(:struct ode::dContactGeom) 'ode::depth)))) | ||
|
||
;;(format t "CLODE:ray-callback b1 = ~A~%" distance) | ||
(multiple-value-bind (start dir) (Ray-Get this) | ||
;;(format t "spring dir: ~A start: ~A~%" dir start) | ||
|
||
|
||
(let* ((vel (body-get-linear-vel b1)) | ||
(len (ray-length this)) | ||
(x (+ (* (- 1 (damping this)) (aref vel 1)) | ||
(* (springiness this) (abs (- (abs distance) len)))))) | ||
;; (normal-dir (sb-cga:dot-product (apply #'clinch:make-vector | ||
;; (subseq (map 'list (lambda (x) | ||
;; (coerce x 'single-float)) | ||
;; dir) 0 3)) | ||
;; (apply #'clinch:make-vector | ||
;; (subseq (map 'list (lambda (x) | ||
;; (coerce x 'single-float)) | ||
;; vel) 0 3))))) | ||
|
||
(clode:body-set-linear-vel b1 (aref vel 0) x (aref vel 2))))))))))) | ||
|
||
|
||
(defmethod close-callback ((this physics-object) (that physics-ray)) | ||
(close-callback that this)) |