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.physics_3d/Sweep3d.ml.html
Source file Sweep3d.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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56(* 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. *) let gap (p : Vec3.t) (h : Hitbox3d.placed) : float = match h.shape with | Hitbox3d.Sphere r -> Float.max 0. (Vec3.length (Vec3.sub p h.pos) -. r) | Hitbox3d.Box _ -> Vec3.length (Vec3.sub p (Collide3d.closest_on_box h p)) | Hitbox3d.Capsule (_, r) -> Float.max 0. (Vec3.length (Vec3.sub p (Collide3d.closest_on_segment (Hitbox3d.segment h) p)) -. r) | Hitbox3d.Plane (n, d) -> Float.max 0. (Vec3.dot n p -. d) let reach (h : Hitbox3d.placed) : float = match h.shape with | Hitbox3d.Sphere r -> r | Hitbox3d.Box half -> Vec3.length half | Hitbox3d.Capsule (half, r) -> half +. r | Hitbox3d.Plane _ -> infinity (* touching, for the start of a step: within this of the surface *) let touching = 1e-4 (* the depth the sweep stops at: a millimetre into the obstacle, so that * the next step's contact finds it (a sphere stopped exactly at the * surface would be touching nothing, and go on) -- well within the * solver's slop, so the solver does not push it out *) let overlap = 1e-3 let sphere ~(radius : float) ~(from : Vec3.t) ~(motion : Vec3.t) ?(moving = ((0., 0., 0.), (0., 0., 0.))) (h : Hitbox3d.placed) : float option = let shift, turn = moving in let at (t : float) : Hitbox3d.placed = { h with pos = Vec3.add h.pos (Vec3.scale t shift); orientation = Quat.turned_by ~spin:turn ~dt:t h.orientation } in let clearance t = gap (Vec3.add from (Vec3.scale t motion)) (at t) -. radius in (* the fastest the clearance can shrink, per unit of the step: the * relative motion, and the obstacle's farthest point swinging round *) let closing = Vec3.length (Vec3.sub motion shift) +. if Vec3.length turn = 0. then 0. else Vec3.length turn *. reach h in if clearance 0. <= touching || closing = 0. || Float.is_nan closing || closing = infinity then None else let rec advance t n = let c = clearance t in if c <= -.overlap +. 1e-9 then Some t else if n = 0 then Some t (* nearly there, in 64 steps: close enough *) else let t = t +. ((c +. overlap) /. closing) in if t > 1. then None else advance t (n - 1) in advance 0. 64
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>