Skip to content

Commit

Permalink
Fix camera perspective setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinmera committed Jan 2, 2025
1 parent 2299d86 commit 57f94d6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
16 changes: 10 additions & 6 deletions camera.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
(defgeneric focal-point (camera))
(defgeneric screen-area (thing camera))

(defmethod activate ((camera camera))
(setf (camera (scene +main+)) camera))

(defmethod width ((camera camera))
(* 2 (vx (bsize camera))))

Expand All @@ -30,14 +33,16 @@
(defmethod (setf near-plane) :around (val (camera camera))
(when (/= val (near-plane camera))
(call-next-method)
(let ((bsize (bsize camera)))
(setup-perspective camera (max 1 (vx bsize)) (max 1 (vy bsize))))))
(setup-perspective camera T T)))

(defmethod (setf far-plane) :around (val (camera camera))
(when (/= val (far-plane camera))
(call-next-method)
(let ((bsize (bsize camera)))
(setup-perspective camera (max 1 (vx bsize)) (max 1 (vy bsize))))))
(setup-perspective camera T T)))

(defmethod setup-perspective ((camera camera) (w (eql T)) (h (eql T)))
(let ((bsize (bsize camera)))
(setup-perspective camera (max 1 (* 2 (vx bsize))) (max 1 (* 2 (vy bsize))))))

(defmethod setup-perspective :before ((camera camera) w h)
(reset-matrix *projection-matrix*))
Expand Down Expand Up @@ -143,8 +148,7 @@
(defmethod (setf fov) :around (val (camera 3d-camera))
(when (/= (fov camera) val)
(call-next-method)
(let ((bsize (bsize camera)))
(setup-perspective camera (max 1 (vx bsize)) (max 1 (vy bsize))))))
(setup-perspective camera T T)))

(defmethod setup-perspective ((camera 3d-camera) width height)
(perspective-projection (fov camera) (/ (max 1 width) (max 1 height)) (near-plane camera) (far-plane camera))
Expand Down
3 changes: 3 additions & 0 deletions scene.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
(unless (camera scene)
(setf (camera scene) camera)))

(defmethod (setf camera) :after ((camera camera) (scene scene))
(setup-perspective camera T T))

(defmethod unit (name (scene scene))
(gethash name (name-map scene)))

Expand Down

0 comments on commit 57f94d6

Please sign in to comment.