Skip to content

Instantly share code, notes, and snippets.

@skrat
Created August 19, 2014 10:42
Show Gist options
  • Save skrat/8c59d197f3c6acfbe22f to your computer and use it in GitHub Desktop.
Save skrat/8c59d197f3c6acfbe22f to your computer and use it in GitHub Desktop.
Orbiting camera
(defn camera
[x y]
(let [proj (js/mat4.perspective cam-proj
(/ js/Math.PI 4) (/ width height) 0.1 1000)
view (-> (js/mat4.identity cam-view)
(js/mat4.translate cam-view #js [0 0 (- camera-distance)])
(js/mat4.rotateX cam-view (/ y camera-speed))
(js/mat4.rotateY cam-view (/ x camera-speed))
(js/mat4.translate cam-view #js [0 (- (/ wall-height 2)) 0]))
viewr (js/mat3.fromMat4 cam-viewr view)]
{:proj proj
:view view
:viewr viewr
:inv-proj (js/mat4.invert cam-inv-proj proj)
:inv-view (js/mat4.invert cam-inv-view view)
:inv-viewr (js/mat3.invert cam-inv-viewr viewr)}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment