package tiny_libs
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
From-scratch libraries for teaching: graphics, audio, compression, crypto, networking and more
Install
dune-project
Dependency
Authors
Maintainers
Sources
0.3.6.tar.gz
md5=7c636383d146d30ac6f2fa234a6253c8
sha512=c79f3823c5f8f57e5038eb640d487c61168b84aa07c61999d6622ef9fd0c890e2b03b4c6a7cdbbe9352a49e25dda00ac7bb14693cee8e3d7beeed251351a2af0
doc/src/tiny_libs.graphics_3d_geometry/Camera.ml.html
Source file Camera.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40(* Claude Code * * Copyright (C) 2026 Yoann Padioleau * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License * (LGPL) as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. *) (* See Camera.mli *) type t = { eye : Vec3.t; target : Vec3.t; up : Vec3.t; fov : float; ortho : float; near : float; far : float } (* the world's "up" *) let up_hint : Vec3.t = (0., 1., 0.) let basis ?(up = up_hint) ~(eye : Vec3.t) ~(target : Vec3.t) () : Vec3.t * Vec3.t * Vec3.t = let forward = Vec3.normalize (Vec3.sub target eye) in let right = Vec3.normalize (Vec3.cross forward up) in let up = Vec3.cross right forward in (right, up, forward) let view (camera : t) (point : Vec3.t) : Vec3.t = let right, up, forward = basis ~up:camera.up ~eye:camera.eye ~target:camera.target () in let relative = Vec3.sub point camera.eye in (Vec3.dot relative right, Vec3.dot relative up, Vec3.dot relative forward) let focal (camera : t) : float = 1. /. tan (camera.fov *. Float.pi /. 180. /. 2.) let ndc (camera : t) ~(aspect : float) ((x, y, z) : Vec3.t) : (float * float) option = if z < camera.near || z >= camera.far then None else if camera.ortho > 0. then (* no perspective at all: the depth is used to decide what is drawn * and what is in front, and for nothing else *) let h = camera.ortho /. 2. in Some (x /. aspect /. h, y /. h) else let f = focal camera in Some (f *. x /. aspect /. z, f *. y /. z)
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>