Gabriel Pariat
3 years ago
12 changed files with 247 additions and 98 deletions
Binary file not shown.
@ -0,0 +1,95 @@ |
|||||||
|
(defpackage #:camera |
||||||
|
(:use #:cl) |
||||||
|
(:import-from #:sb-cga #:vec #:normalize #:cross-product #:vec+ #:vec* #:vec-) |
||||||
|
(:import-from #:kit.math #:deg-to-rad #:look-at) |
||||||
|
(:export #:get-view-matrix |
||||||
|
#:move-left |
||||||
|
#:move-right |
||||||
|
#:move-backward |
||||||
|
#:move-forward |
||||||
|
#:process-mouse-movement |
||||||
|
#:process-mouse-scroll |
||||||
|
#:make-camera |
||||||
|
#:*zoom*)) |
||||||
|
|
||||||
|
(in-package #:camera) |
||||||
|
|
||||||
|
(defparameter *position* nil) |
||||||
|
(defparameter *front* nil) |
||||||
|
(defparameter *up* nil) |
||||||
|
(defparameter *right* nil) |
||||||
|
(defparameter *world-up* nil) |
||||||
|
(defparameter *yaw* nil) |
||||||
|
(defparameter *pitch* nil) |
||||||
|
(defparameter *mouvement-speed* 2.5) |
||||||
|
(defparameter *mouse-sensitivity* 0.1) |
||||||
|
(defparameter *zoom* 45.0) |
||||||
|
|
||||||
|
(defun get-view-matrix () |
||||||
|
(look-at *position* (vec+ *position* *front*) *up*)) |
||||||
|
|
||||||
|
(defun move-left (delta-time) |
||||||
|
(setf *position* |
||||||
|
(vec- *position* |
||||||
|
(vec* *right* |
||||||
|
(* *mouvement-speed* |
||||||
|
(coerce delta-time 'single-float)))))) |
||||||
|
|
||||||
|
(defun move-right (delta-time) |
||||||
|
(setf *position* |
||||||
|
(vec+ *position* |
||||||
|
(vec* *right* |
||||||
|
(* *mouvement-speed* |
||||||
|
(coerce delta-time 'single-float)))))) |
||||||
|
|
||||||
|
(defun move-backward (delta-time) |
||||||
|
(setf *position* |
||||||
|
(vec- *position* |
||||||
|
(vec* *front* |
||||||
|
(* *mouvement-speed* |
||||||
|
(coerce delta-time 'single-float)))))) |
||||||
|
|
||||||
|
(defun move-forward (delta-time) |
||||||
|
(setf *position* |
||||||
|
(vec+ *position* |
||||||
|
(vec* *front* |
||||||
|
(* *mouvement-speed* |
||||||
|
(coerce delta-time 'single-float)))))) |
||||||
|
|
||||||
|
(defun front-vector (yaw pitch) |
||||||
|
(normalize (vec (coerce (* (cos (deg-to-rad yaw)) (cos (deg-to-rad pitch))) 'single-float) |
||||||
|
(coerce (sin (deg-to-rad pitch)) 'single-float) |
||||||
|
(coerce (* (sin (deg-to-rad yaw)) (cos (deg-to-rad pitch))) 'single-float)))) |
||||||
|
|
||||||
|
(defun right-vector (front world-up) |
||||||
|
(normalize (cross-product front world-up))) |
||||||
|
|
||||||
|
(defun up-vector (right front) |
||||||
|
(normalize (cross-product right front))) |
||||||
|
|
||||||
|
(defun process-mouse-movement (xoffset yoffset &optional (constrain-pitch t)) |
||||||
|
(incf *yaw* (* xoffset *mouse-sensitivity*)) |
||||||
|
(setf *pitch* (let ((pitch (+ *pitch* (* yoffset *mouse-sensitivity*)))) |
||||||
|
(if constrain-pitch (min (max pitch -89.0) 89.0) pitch))) |
||||||
|
(setf *front* (front-vector *yaw* *pitch*)) |
||||||
|
(setf *right* (right-vector *front* *world-up*)) |
||||||
|
(setf *up* (up-vector *right* *front*))) |
||||||
|
|
||||||
|
(defmethod process-mouse-scroll (yoffset) |
||||||
|
(setf *zoom* (max (min (- *zoom* yoffset) 45.0) 1.0))) |
||||||
|
|
||||||
|
(defun make-camera (&optional |
||||||
|
(position (vec 0.0 0.0 0.0)) |
||||||
|
(world-up (vec 0.0 1.0 0.0)) |
||||||
|
(yaw -90.0) |
||||||
|
(pitch 0.0)) |
||||||
|
(let* ((front (front-vector yaw pitch)) |
||||||
|
(right (right-vector front world-up)) |
||||||
|
(up (up-vector right front))) |
||||||
|
(setf *position* position) |
||||||
|
(setf *world-up* world-up) |
||||||
|
(setf *yaw* yaw) |
||||||
|
(setf *pitch* pitch) |
||||||
|
(setf *front* front) |
||||||
|
(setf *right* right) |
||||||
|
(setf *up* up))) |
@ -1,12 +0,0 @@ |
|||||||
#version 330 core |
|
||||||
out vec4 FragColor; |
|
||||||
|
|
||||||
in vec3 ourColor; |
|
||||||
in vec2 TexCoord; |
|
||||||
|
|
||||||
uniform sampler2D ourTexture; |
|
||||||
|
|
||||||
void main() |
|
||||||
{ |
|
||||||
FragColor = texture(ourTexture, TexCoord); |
|
||||||
} |
|
@ -1,14 +0,0 @@ |
|||||||
#version 330 core |
|
||||||
layout (location = 0) in vec3 aPos; |
|
||||||
layout (location = 1) in vec3 aColor; |
|
||||||
layout (location = 2) in vec2 aTexCoord; |
|
||||||
|
|
||||||
out vec3 ourColor; |
|
||||||
out vec2 TexCoord; |
|
||||||
|
|
||||||
void main() |
|
||||||
{ |
|
||||||
gl_Position = vec4(aPos, 1.0); |
|
||||||
ourColor = aColor; |
|
||||||
TexCoord = aTexCoord; |
|
||||||
} |
|
After Width: | Height: | Size: 58 KiB |
After Width: | Height: | Size: 181 KiB |
After Width: | Height: | Size: 413 KiB |
Loading…
Reference in new issue