camera

frustumclj

orbit-controlcljs

ortho

perspective

print-cameraclj

print-projectionclj

camera

Arguments
[][eyeX eyeY eyeZ centerX centerY centerZ upX upY upZ]
Docstring

Sets the position of the camera through setting the eye position, the center of the scene, and which axis is facing upward. Moving the eye position and the direction it is pointing (the center of the scene) allows the images to be seen from different angles. The version without any parameters sets the camera to the default position, pointing to the center of the display window with the Y axis as up. The default values are:

  • eyeX - (/ (width) 2.0)
  • eyeY - (/ (height) 2.0)
  • eyeZ - (/ (/ (height) 2.0) (tan (/ (* Math/PI 60.0) 360.0)))
  • centerX - (/ (width) 2.0)
  • centerY - (/ (height) 2.0)
  • centerZ - 0
  • upX - 0
  • upY - 1
  • upZ - 0

Similar to gluLookAt() in OpenGL, but it first clears the current camera settings.

Works only inside sketch functions?
Yes
Original Processing method
camera()
Original p5js method
camera()
Example
(q/background 255)
; set camera in point [200, 200, 200]
; the camera looks in direction of point [0, 0, 0]
; \"up\" vector is [0, 0, -1]
(q/camera 200 200 200 0 0 0 0 0 -1)
; draw a box of size 100 at the [0, 0, 0] point
(q/stroke-weight 2)
(q/stroke 0)
(q/fill 127)
(q/box 100)
; draw red X axis
(q/stroke 255 0 0)
(q/line 0 0 0 100 0 0)
; draw green Y axis
(q/stroke 0 255 0)
(q/line 0 0 0 0 100 0)
; draw blue Z axis
(q/stroke 0 0 255)
(q/line 0 0 0 0 0 100)
try example

frustumclj

Arguments
[left right bottom top near far]
Docstring

Sets a perspective matrix defined through the parameters. Works like glFrustum, except it wipes out the current perspective matrix rather than multiplying itself with it. https://en.wikipedia.org/wiki/Frustum

Works only inside sketch functions?
Yes
Original Processing method
frustum()
Original p5js method
None.
Example
clojure specific
  • (q/background 255)
    ; set camera in point [200, 200, 200]
    ; the camera looks in direction of point [0, 0, 0]
    ; \"up\" vector is [0, 0, -1]
    (q/camera 200 200 200 0 0 0 0 0 -1)
    (comment
      "set camera to show only part of the scene according to following condition")
    ; between -100 and 100 left to right
    ; between -100 and 100 top to bottm
    ; between 300 and 350 points in front
    (q/frustum -100 100 -100 100 300 350)
    ; draw box, it will appear cut as we frustum 
    ; limits to 300-350 region in fron of camera
    (q/stroke-weight 2)
    (q/stroke 0)
    (q/fill 127)
    (q/box 100)
    ; draw red X axis
    (q/stroke 255 0 0)
    (q/line 0 0 0 100 0 0)
    ; draw green Y axis
    (q/stroke 0 255 0)
    (q/line 0 0 0 0 100 0)
    ; draw blue Z axis
    (q/stroke 0 0 255)
    (q/line 0 0 0 0 0 100)

orbit-controlcljs

Arguments
[]
Docstring

Allows the camera to orbit around a target using mouse.

Works only inside sketch functions?
Yes
Original Processing method
None.
Original p5js method
orbitControl()
Example
clojurescript specific
  • (q/orbit-control)
    (q/background 255)
    (q/fill 0 127 127)
    (q/box 200)
    (comment "rotate camera around box using mouse")
    try example

ortho

Arguments
[][left right bottom top][left right bottom top near far]
Docstring

Sets an orthographic projection and defines a parallel clipping volume. All objects with the same dimension appear the same size, regardless of whether they are near or far from the camera. The parameters to this function specify the clipping volume where left and right are the minimum and maximum x values, top and bottom are the minimum and maximum y values, and near and far are the minimum and maximum z values. If no parameters are given, the default is used: (ortho 0 width 0 height -10 10)

Works only inside sketch functions?
Yes
Original Processing method
ortho()
Original p5js method
ortho()
Example
(q/background 240)
; flip between ortho and perspective camera every frame
; enable ortho camera
; in ortho all figures will look the same regardless distance
(comment
  "in perspective (default) all figures will look smaller the farther they are")
(if (even? (q/frame-count)) (q/ortho) (q/perspective))
; set camera to look from [300, 0, 300] at point [100, 0, 0]
(q/camera 300 0 300 100 0 0 0 0 -1)
(q/fill 0 127 127)
; draw 3 boxes with x coordinates 0, 100 and 200
(doseq [x [0 100 200]]
  (q/with-translation [x 0 0]
    (q/box 50)))
try example
(q/background 240)
; set camera to look from [400, 100, 200] at point [100, 0, 0]
(q/camera 400 100 200 100 0 0 0 0 -1)
; in ortho all figures will look the same regardless distance
(q/ortho)
; draw 3 boxes with x coordinates 0, 100 and 200
(q/fill 0 127 127)
(doseq [x [0 100 200]]
  (q/with-translation [x 0 0]
    (q/box 50)))
try example

perspective

Arguments
[][fovy aspect z-near z-far]
Docstring

Sets a perspective projection applying foreshortening, making distant objects appear smaller than closer ones. The parameters define a viewing volume with the shape of truncated pyramid. Objects near to the front of the volume appear their actual size, while farther objects appear smaller. This projection simulates the perspective of the world more accurately than orthographic projection. The version of perspective without parameters sets the default perspective and the version with four parameters allows the programmer to set the area precisely. The default values are: perspective(PI/3.0, width/height, cameraZ/10.0, cameraZ*10.0) where cameraZ is ((height/2.0) / tan(PI*60.0/360.0))

Works only inside sketch functions?
Yes
Original Processing method
perspective()
Original p5js method
perspective()
Example
(q/background 240)
; flip between ortho and perspective camera every frame
; enable ortho camera
; in ortho all figures will look the same regardless distance
(comment
  "in perspective (default) all figures will look smaller the farther they are")
(if (even? (q/frame-count)) (q/ortho) (q/perspective))
; set camera to look from [300, 0, 300] at point [100, 0, 0]
(q/camera 300 0 300 100 0 0 0 0 -1)
(q/fill 0 127 127)
; draw 3 boxes with x coordinates 0, 100 and 200
(doseq [x [0 100 200]]
  (q/with-translation [x 0 0]
    (q/box 50)))
try example
(q/background 240)
; set camera to look from [400, 100, 200] at point [100, 0, 0]
(q/camera 400 100 200 100 0 0 0 0 -1)
(comment
  "in perspective (default) all figures will look smaller the farther they are")
(q/perspective)
; draw 3  boxes with x coordinates 0, 100 and 200
(q/fill 0 127 127)
(doseq [x [0 100 200]]
  (q/with-translation [x 0 0]
    (q/box 50)))
try example