Skip to content

Commit

Permalink
Try to copy camera properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinmera committed Jan 3, 2025
1 parent c9237ce commit e6d5300
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions camera.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
(far-plane :initarg :far-plane :initform 10000.0f0 :accessor far-plane)
(bsize :initform (vec2 0 0) :accessor bsize)))

(define-transfer camera location near-plane far-plane bsize)

(defgeneric project-view (camera))
(defgeneric setup-perspective (camera width height))
(defgeneric map-visible (function camera container))
Expand Down Expand Up @@ -112,6 +114,8 @@
((zoom :initarg :zoom :initform 1.0 :accessor zoom)
(target :initarg :target :initform (vec 0 0 200) :accessor target)))

(define-transfer sidescroll-camera zoom target)

(defmethod project-view ((camera sidescroll-camera))
(let* ((z (zoom camera))
(v (vxy_ (bsize camera))))
Expand Down Expand Up @@ -145,6 +149,8 @@
:faces (u16-vec 0 1 2 2 3 0 4 5 6 6 7 4))
:accessor frustum)))

(define-transfer 3d-camera fov frustum)

(defmethod (setf fov) :around (val (camera 3d-camera))
(when (/= (fov camera) val)
(call-next-method)
Expand Down Expand Up @@ -262,6 +268,8 @@
((target :initarg :target :initform (vec3 0) :accessor target)
(up :initarg :up :initform +vy3+ :accessor up)))

(define-transfer target-camera target up)

(defmethod project-view ((camera target-camera))
(let ((matrix (meye 4))
(loc (vec3))
Expand All @@ -279,6 +287,8 @@
((rotation :initform (quat) :accessor rotation)
(radius :initform 1.0 :initarg :radius :accessor radius)))

(define-transfer pivot-camera rotation radius)

(defmethod initialize-instance :after ((camera pivot-camera) &key)
(setf (rotation camera) (rotation camera)))

Expand Down Expand Up @@ -311,6 +321,8 @@
(x-acceleration :initarg :x-acceleration :initform 0.01 :accessor x-acceleration)
(y-acceleration :initarg :y-acceleration :initform 0.01 :accessor y-acceleration)))

(define-transfer fps-camera rotation x-acceleration y-acceleration)

(defmethod project-view ((camera fps-camera))
(reset-matrix (view-matrix))
(rotate +vx+ (vx (rotation camera)) (view-matrix))
Expand All @@ -335,6 +347,8 @@
(defclass freeroam-camera (fps-camera)
((move-speed :initarg :move-speed :initform 1.0 :accessor move-speed)))

(define-transfer freeroam-camera move-speed)

(define-handler (freeroam-camera tick :after) ()
(let* ((loc (location freeroam-camera))
(rot (rotation freeroam-camera))
Expand Down Expand Up @@ -367,3 +381,9 @@
(when (or (retained :middle)
(retained :left-control))
(do-fps-movement editor-camera old-pos pos)))

(defmethod (setf camera) :around ((camera editor-camera) scene)
(let ((old (camera scene)))
(prog1 (call-next-method)
(when (typep old 'camera)
(<- camera old)))))

0 comments on commit e6d5300

Please sign in to comment.