From 90dea0587522dc3c1a9af34191887f773de113ad Mon Sep 17 00:00:00 2001 From: FatalErr42O <58855799+FatalError42O@users.noreply.github.com> Date: Sun, 10 Sep 2023 15:27:15 -0700 Subject: [PATCH] staging commits --- README.md | 12 +- docs/index.html | 137 +++ docs/ldoc_new.css | 290 ++++++ docs/modules/bound2.html | 669 ++++++++++++++ docs/modules/bound3.html | 669 ++++++++++++++ docs/modules/bvh.html | 84 ++ docs/modules/color.html | 737 +++++++++++++++ docs/modules/constants.html | 125 +++ docs/modules/intersect.html | 84 ++ docs/modules/mat4.html | 1173 ++++++++++++++++++++++++ docs/modules/mesh.html | 84 ++ docs/modules/octree.html | 710 ++++++++++++++ docs/modules/quat.html | 1273 ++++++++++++++++++++++++++ docs/modules/simplex.html | 84 ++ docs/modules/utils.html | 557 +++++++++++ docs/modules/vec2.html | 1124 +++++++++++++++++++++++ docs/modules/vec3.html | 1032 +++++++++++++++++++++ docs/topics/readme.md.html | 85 ++ {doc => ldoc}/config.ld | 2 +- {doc => ldoc}/install_and_build_docs | 0 ldoc/windows_quick_generate.bat | 3 + modules/quat.lua | 13 +- 22 files changed, 8931 insertions(+), 16 deletions(-) create mode 100644 docs/index.html create mode 100644 docs/ldoc_new.css create mode 100644 docs/modules/bound2.html create mode 100644 docs/modules/bound3.html create mode 100644 docs/modules/bvh.html create mode 100644 docs/modules/color.html create mode 100644 docs/modules/constants.html create mode 100644 docs/modules/intersect.html create mode 100644 docs/modules/mat4.html create mode 100644 docs/modules/mesh.html create mode 100644 docs/modules/octree.html create mode 100644 docs/modules/quat.html create mode 100644 docs/modules/simplex.html create mode 100644 docs/modules/utils.html create mode 100644 docs/modules/vec2.html create mode 100644 docs/modules/vec3.html create mode 100644 docs/topics/readme.md.html rename {doc => ldoc}/config.ld (94%) rename {doc => ldoc}/install_and_build_docs (100%) create mode 100644 ldoc/windows_quick_generate.bat diff --git a/README.md b/README.md index 5eb580e..fc70063 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,12 @@ Cirno's Perfect Math Library ==== ### Adapated for Minetest For best memory performance: have luaJIT & it's FFI library (this should be built into luaJIT), and add MTUL-CPML to your trusted list (so it can `require()` call the FFI library) +also works if you disable mod security (DANGEROUS, NOT RECCOMENDED). Various useful bits of game math. 3D line intersections, ray casting, 2d/3d vectors, 4x4 matrices, quaternions, etc. -(originally) ntended to be used with LuaJIT and LÖVE (this is the backbone of LÖVE3D). +(originally) intended to be used with LuaJIT and LÖVE (this is the backbone of LÖVE3D). -Online documentation can be found [here](http://excessive.github.io/cpml/) or you can generate them yourself using `ldoc -c doc/config.ld -o index .` - -## Additionally adds to the API -`mat4:translate_local(out, a, t)` -does the same thing as `translate` only its far right column instead of bottom row (as that's what's needed for most local coordinate systems) -also: worth noting that "a" in both `translate` and `translate_local` can be an empty table, and it'll generate an identity matrix. Which is really -redundant code wise, not a fan of that. Probably will fix that at some point. ### TODO: -* Vec3s and Vec2s are not currently adapted for functionality with MT vectors (seperate classes) +* Vec3s and Vec2s are not currently adapted for functionality with MT vectors (seperate classes) \ No newline at end of file diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..d0eaa7e --- /dev/null +++ b/docs/index.html @@ -0,0 +1,137 @@ + + + + + CPML documentation + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ + +

A math library with (hopefully) everything you need for 2D/3D games

+ +

Modules

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
bound2A 2 component bounding box.
bound3A 3-component axis-aligned bounding box.
bvhBVH Tree
colorColor utilities
constantsVarious useful constants
intersectVarious geometric intersections
mat4double 4x4, 1-based, column major matrices
meshMesh utilities
octreeOctree
quatA quaternion and associated utilities.
simplexSimplex Noise
utilsVarious utility functions
vec2A 2 component vector.
vec3A 3 component vector.
+

Topics

+ + + + + +
readme.md
+ +
+
+
+generated by LDoc 1.5.0 +Last updated 2023-09-10 15:25:31 +
+
+ + diff --git a/docs/ldoc_new.css b/docs/ldoc_new.css new file mode 100644 index 0000000..13fef16 --- /dev/null +++ b/docs/ldoc_new.css @@ -0,0 +1,290 @@ +body { + color: #47555c; + font-size: 16px; + font-family: "Open Sans", sans-serif; + margin: 0; + background: #eff4ff; +} + +a:link { color: #008fee; } +a:visited { color: #008fee; } +a:hover { color: #22a7ff; } + +h1 { font-size:26px; font-weight: normal; } +h2 { font-size:22px; font-weight: normal; } +h3 { font-size:18px; font-weight: normal; } +h4 { font-size:16px; font-weight: bold; } + +hr { + height: 1px; + background: #c1cce4; + border: 0px; + margin: 15px 0; +} + +code, tt { + font-family: monospace; +} +span.parameter { + font-family: monospace; + font-weight: bold; + color: rgb(99, 115, 131); +} +span.parameter:after { + content:":"; +} +span.types:before { + content:"("; +} +span.types:after { + content:")"; +} +.type { + font-weight: bold; font-style:italic +} + +p.name { + font-family: "Andale Mono", monospace; +} + +#navigation { + float: left; + background-color: white; + border-right: 1px solid #d3dbec; + border-bottom: 1px solid #d3dbec; + + width: 14em; + vertical-align: top; + overflow: visible; +} + +#navigation br { + display: none; +} + +#navigation h1 { + background-color: white; + border-bottom: 1px solid #d3dbec; + padding: 15px; + margin-top: 0px; + margin-bottom: 0px; +} + +#navigation h2 { + font-size: 18px; + background-color: white; + border-bottom: 1px solid #d3dbec; + padding-left: 15px; + padding-right: 15px; + padding-top: 10px; + padding-bottom: 10px; + margin-top: 30px; + margin-bottom: 0px; +} + +#content h1 { + background-color: #2c3e67; + color: white; + padding: 15px; + margin: 0px; +} + +#content h2 { + background-color: #6c7ea7; + color: white; + padding: 15px; + padding-top: 15px; + padding-bottom: 15px; + margin-top: 0px; +} + +#content h2 a { + background-color: #6c7ea7; + color: white; + text-decoration: none; +} + +#content h2 a:hover { + text-decoration: underline; +} + +#content h3 { + font-style: italic; + padding-top: 15px; + padding-bottom: 4px; + margin-right: 15px; + margin-left: 15px; + margin-bottom: 5px; + border-bottom: solid 1px #bcd; +} + +#content h4 { + margin-right: 15px; + margin-left: 15px; + border-bottom: solid 1px #bcd; +} + +#content pre { + margin: 15px; +} + +pre { + background-color: rgb(50, 55, 68); + color: white; + border-radius: 3px; + /* border: 1px solid #C0C0C0; /* silver */ + padding: 15px; + overflow: auto; + font-family: "Andale Mono", monospace; +} + +#content ul pre.example { + margin-left: 0px; +} + +table.index { +/* border: 1px #00007f; */ +} +table.index td { text-align: left; vertical-align: top; } + +#navigation ul +{ + font-size:1em; + list-style-type: none; + margin: 1px 1px 10px 1px; +} + +#navigation li { + text-indent: -1em; + display: block; + margin: 3px 0px 0px 22px; +} + +#navigation li li a { + margin: 0px 3px 0px -1em; +} + +#content { + margin-left: 14em; +} + +#content p { + padding-left: 15px; + padding-right: 15px; +} + +#content table { + padding-left: 15px; + padding-right: 15px; + background-color: white; +} + +#content p, #content table, #content ol, #content ul, #content dl { + max-width: 900px; +} + +#about { + padding: 15px; + padding-left: 16em; + background-color: white; + border-top: 1px solid #d3dbec; + border-bottom: 1px solid #d3dbec; +} + +table.module_list, table.function_list { + border-width: 1px; + border-style: solid; + border-color: #cccccc; + border-collapse: collapse; + margin: 15px; +} +table.module_list td, table.function_list td { + border-width: 1px; + padding-left: 10px; + padding-right: 10px; + padding-top: 5px; + padding-bottom: 5px; + border: solid 1px rgb(193, 204, 228); +} +table.module_list td.name, table.function_list td.name { + background-color: white; min-width: 200px; border-right-width: 0px; +} +table.module_list td.summary, table.function_list td.summary { + background-color: white; width: 100%; border-left-width: 0px; +} + +dl.function { + margin-right: 15px; + margin-left: 15px; + border-bottom: solid 1px rgb(193, 204, 228); + border-left: solid 1px rgb(193, 204, 228); + border-right: solid 1px rgb(193, 204, 228); + background-color: white; +} + +dl.function dt { + color: rgb(99, 123, 188); + font-family: monospace; + border-top: solid 1px rgb(193, 204, 228); + padding: 15px; +} + +dl.function dd { + margin-left: 15px; + margin-right: 15px; + margin-top: 5px; + margin-bottom: 15px; +} + +#content dl.function dd h3 { + margin-top: 0px; + margin-left: 0px; + padding-left: 0px; + font-size: 16px; + color: rgb(128, 128, 128); + border-bottom: solid 1px #def; +} + +#content dl.function dd ul, #content dl.function dd ol { + padding: 0px; + padding-left: 15px; + list-style-type: none; +} + +ul.nowrap { + overflow:auto; + white-space:nowrap; +} + +.section-description { + padding-left: 15px; + padding-right: 15px; +} + +/* stop sublists from having initial vertical space */ +ul ul { margin-top: 0px; } +ol ul { margin-top: 0px; } +ol ol { margin-top: 0px; } +ul ol { margin-top: 0px; } + +/* make the target distinct; helps when we're navigating to a function */ +a:target + * { + background-color: #FF9; +} + + +/* styles for prettification of source */ +pre .comment { color: #bbccaa; } +pre .constant { color: #a8660d; } +pre .escape { color: #844631; } +pre .keyword { color: #ffc090; font-weight: bold; } +pre .library { color: #0e7c6b; } +pre .marker { color: #512b1e; background: #fedc56; font-weight: bold; } +pre .string { color: #8080ff; } +pre .number { color: #f8660d; } +pre .operator { color: #2239a8; font-weight: bold; } +pre .preprocessor, pre .prepro { color: #a33243; } +pre .global { color: #c040c0; } +pre .user-keyword { color: #800080; } +pre .prompt { color: #558817; } +pre .url { color: #272fc2; text-decoration: underline; } diff --git a/docs/modules/bound2.html b/docs/modules/bound2.html new file mode 100644 index 0000000..ceb5fad --- /dev/null +++ b/docs/modules/bound2.html @@ -0,0 +1,669 @@ + + + + + CPML documentation + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module bound2

+

A 2 component bounding box.

+

+ +

+ + +

Functions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
new (min, max)The public constructor.
clone (a)Clone a bound.
at (a, b)Construct a bound covering one or two points
extend (a, point)Extend bound to include point
extend_bound (a, bound)Extend bound to entirety of other bound
size (a)Get size of bounding box as a vector
with_size (a, new)Resize bounding box from minimum corner
radius (a)Get half-size of bounding box as a vector.
center (a)Get center of bounding box
with_center (a, new)Move bounding box to new center
with_size_centered (a, new)Resize bounding box from center
check (a)Convert possibly-invalid bounding box to valid one
inset (a, a)Shrink bounding box with fixed margin
outset (a, a)Expand bounding box with fixed margin
offset (a, offset)Offset bounding box
contains (a, point)Test if point in bound
to_string (a)Return a formatted string.
+ +
+
+ + +

Functions

+ +
+
+ + new (min, max) +
+
+ The public constructor. + + +

Parameters:

+
    +
  • min + Can be of two types:
    + vec2 min, minimum value for each component + nil Create bound at single point 0,0 +
  • +
  • max + vec2 + , maximum value for each component +
  • +
+ +

Returns:

+
    + + bound2 + out +
+ + + + +
+
+ + clone (a) +
+
+ Clone a bound. + + +

Parameters:

+
    +
  • a + bound2 + bound to be cloned +
  • +
+ +

Returns:

+
    + + bound2 + out +
+ + + + +
+
+ + at (a, b) +
+
+ Construct a bound covering one or two points + + +

Parameters:

+
    +
  • a + vec2 + Any vector +
  • +
  • b + vec2 + Any second vector (optional) +
  • +
+ +

Returns:

+
    + + vec2 + Minimum bound containing the given points +
+ + + + +
+
+ + extend (a, point) +
+
+ Extend bound to include point + + +

Parameters:

+
    +
  • a + bound2 + bound +
  • +
  • point + vec2 + to include +
  • +
+ +

Returns:

+
    + + bound2 + Bound covering current min, current max and new point +
+ + + + +
+
+ + extend_bound (a, bound) +
+
+ Extend bound to entirety of other bound + + +

Parameters:

+
    +
  • a + bound2 + bound +
  • +
  • bound + bound2 + to cover +
  • +
+ +

Returns:

+
    + + bound2 + Bound covering current min and max of each bound in the pair +
+ + + + +
+
+ + size (a) +
+
+ Get size of bounding box as a vector + + +

Parameters:

+
    +
  • a + bound2 + bound +
  • +
+ +

Returns:

+
    + + vec2 + Vector spanning min to max points +
+ + + + +
+
+ + with_size (a, new) +
+
+ Resize bounding box from minimum corner + + +

Parameters:

+
    +
  • a + bound2 + bound +
  • +
  • new + vec2 + size +
  • +
+ +

Returns:

+
    + + bound2 + resized bound +
+ + + + +
+
+ + radius (a) +
+
+ Get half-size of bounding box as a vector. A more correct term for this is probably "apothem" + + +

Parameters:

+
    +
  • a + bound2 + bound +
  • +
+ +

Returns:

+
    + + vec2 + Vector spanning center to max point +
+ + + + +
+
+ + center (a) +
+
+ Get center of bounding box + + +

Parameters:

+
    +
  • a + bound2 + bound +
  • +
+ +

Returns:

+
    + + bound2 + Point in center of bound +
+ + + + +
+
+ + with_center (a, new) +
+
+ Move bounding box to new center + + +

Parameters:

+
    +
  • a + bound2 + bound +
  • +
  • new + vec2 + center +
  • +
+ +

Returns:

+
    + + bound2 + Bound with same size as input but different center +
+ + + + +
+
+ + with_size_centered (a, new) +
+
+ Resize bounding box from center + + +

Parameters:

+
    +
  • a + bound2 + bound +
  • +
  • new + vec2 + size +
  • +
+ +

Returns:

+
    + + bound2 + resized bound +
+ + + + +
+
+ + check (a) +
+
+ Convert possibly-invalid bounding box to valid one + + +

Parameters:

+
    +
  • a + bound2 + bound +
  • +
+ +

Returns:

+
    + + bound2 + bound with all components corrected for min-max property +
+ + + + +
+
+ + inset (a, a) +
+
+ Shrink bounding box with fixed margin + + +

Parameters:

+
    +
  • a + vec2 + margin +
  • +
  • a + vec2 + margin +
  • +
+ +

Returns:

+
    + + bound2 + bound with margin subtracted from all edges. May not be valid, consider calling check() +
+ + + + +
+
+ + outset (a, a) +
+
+ Expand bounding box with fixed margin + + +

Parameters:

+
    +
  • a + vec2 + margin +
  • +
  • a + vec2 + margin +
  • +
+ +

Returns:

+
    + + bound2 + bound with margin added to all edges. May not be valid, consider calling check() +
+ + + + +
+
+ + offset (a, offset) +
+
+ Offset bounding box + + +

Parameters:

+
    +
  • a + bound2 + bound +
  • +
  • offset + vec2 + + + +
  • +
+ +

Returns:

+
    + + bound2 + bound with same size, but position moved by offset +
+ + + + +
+
+ + contains (a, point) +
+
+ Test if point in bound + + +

Parameters:

+
    +
  • a + bound2 + bound +
  • +
  • point + vec2 + to test +
  • +
+ +

Returns:

+
    + + boolean + true if point in bounding box +
+ + + + +
+
+ + to_string (a) +
+
+ Return a formatted string. + + +

Parameters:

+
    +
  • a + bound2 + bound to be turned into a string +
  • +
+ +

Returns:

+
    + + string + formatted +
+ + + + +
+
+ + +
+
+
+generated by LDoc 1.5.0 +Last updated 2023-09-10 15:25:31 +
+
+ + diff --git a/docs/modules/bound3.html b/docs/modules/bound3.html new file mode 100644 index 0000000..bdcc4b4 --- /dev/null +++ b/docs/modules/bound3.html @@ -0,0 +1,669 @@ + + + + + CPML documentation + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module bound3

+

A 3-component axis-aligned bounding box.

+

+ +

+ + +

Functions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
new (min, max)The public constructor.
clone (a)Clone a bound.
at (a, b)Construct a bound covering one or two points
extend (a, point)Extend bound to include point
extend_bound (a, bound)Extend bound to entirety of other bound
size (a)Get size of bounding box as a vector
with_size (a, new)Resize bounding box from minimum corner
radius (a)Get half-size of bounding box as a vector.
center (a)Get center of bounding box
with_center (a, new)Move bounding box to new center
with_size_centered (a, new)Resize bounding box from center
check (a)Convert possibly-invalid bounding box to valid one
inset (a, a)Shrink bounding box with fixed margin
outset (a, a)Expand bounding box with fixed margin
offset (a, offset)Offset bounding box
contains (a, point)Test if point in bound
to_string (a)Return a formatted string.
+ +
+
+ + +

Functions

+ +
+
+ + new (min, max) +
+
+ The public constructor. + + +

Parameters:

+
    +
  • min + Can be of two types:
    + vec3 min, minimum value for each component + nil Create bound at single point 0,0,0 +
  • +
  • max + vec3 + , maximum value for each component +
  • +
+ +

Returns:

+
    + + bound3 + out +
+ + + + +
+
+ + clone (a) +
+
+ Clone a bound. + + +

Parameters:

+
    +
  • a + bound3 + bound to be cloned +
  • +
+ +

Returns:

+
    + + bound3 + out +
+ + + + +
+
+ + at (a, b) +
+
+ Construct a bound covering one or two points + + +

Parameters:

+
    +
  • a + vec3 + Any vector +
  • +
  • b + vec3 + Any second vector (optional) +
  • +
+ +

Returns:

+
    + + vec3 + Minimum bound containing the given points +
+ + + + +
+
+ + extend (a, point) +
+
+ Extend bound to include point + + +

Parameters:

+
    +
  • a + bound3 + bound +
  • +
  • point + vec3 + to include +
  • +
+ +

Returns:

+
    + + bound3 + Bound covering current min, current max and new point +
+ + + + +
+
+ + extend_bound (a, bound) +
+
+ Extend bound to entirety of other bound + + +

Parameters:

+
    +
  • a + bound3 + bound +
  • +
  • bound + bound3 + to cover +
  • +
+ +

Returns:

+
    + + bound3 + Bound covering current min and max of each bound in the pair +
+ + + + +
+
+ + size (a) +
+
+ Get size of bounding box as a vector + + +

Parameters:

+
    +
  • a + bound3 + bound +
  • +
+ +

Returns:

+
    + + vec3 + Vector spanning min to max points +
+ + + + +
+
+ + with_size (a, new) +
+
+ Resize bounding box from minimum corner + + +

Parameters:

+
    +
  • a + bound3 + bound +
  • +
  • new + vec3 + size +
  • +
+ +

Returns:

+
    + + bound3 + resized bound +
+ + + + +
+
+ + radius (a) +
+
+ Get half-size of bounding box as a vector. A more correct term for this is probably "apothem" + + +

Parameters:

+
    +
  • a + bound3 + bound +
  • +
+ +

Returns:

+
    + + vec3 + Vector spanning center to max point +
+ + + + +
+
+ + center (a) +
+
+ Get center of bounding box + + +

Parameters:

+
    +
  • a + bound3 + bound +
  • +
+ +

Returns:

+
    + + bound3 + Point in center of bound +
+ + + + +
+
+ + with_center (a, new) +
+
+ Move bounding box to new center + + +

Parameters:

+
    +
  • a + bound3 + bound +
  • +
  • new + vec3 + center +
  • +
+ +

Returns:

+
    + + bound3 + Bound with same size as input but different center +
+ + + + +
+
+ + with_size_centered (a, new) +
+
+ Resize bounding box from center + + +

Parameters:

+
    +
  • a + bound3 + bound +
  • +
  • new + vec3 + size +
  • +
+ +

Returns:

+
    + + bound3 + resized bound +
+ + + + +
+
+ + check (a) +
+
+ Convert possibly-invalid bounding box to valid one + + +

Parameters:

+
    +
  • a + bound3 + bound +
  • +
+ +

Returns:

+
    + + bound3 + bound with all components corrected for min-max property +
+ + + + +
+
+ + inset (a, a) +
+
+ Shrink bounding box with fixed margin + + +

Parameters:

+
    +
  • a + vec3 + margin +
  • +
  • a + vec3 + margin +
  • +
+ +

Returns:

+
    + + bound3 + bound with margin subtracted from all edges. May not be valid, consider calling check() +
+ + + + +
+
+ + outset (a, a) +
+
+ Expand bounding box with fixed margin + + +

Parameters:

+
    +
  • a + vec3 + margin +
  • +
  • a + vec3 + margin +
  • +
+ +

Returns:

+
    + + bound3 + bound with margin added to all edges. May not be valid, consider calling check() +
+ + + + +
+
+ + offset (a, offset) +
+
+ Offset bounding box + + +

Parameters:

+
    +
  • a + bound3 + bound +
  • +
  • offset + vec3 + + + +
  • +
+ +

Returns:

+
    + + bound3 + bound with same size, but position moved by offset +
+ + + + +
+
+ + contains (a, point) +
+
+ Test if point in bound + + +

Parameters:

+
    +
  • a + bound3 + bound +
  • +
  • point + vec3 + to test +
  • +
+ +

Returns:

+
    + + boolean + true if point in bounding box +
+ + + + +
+
+ + to_string (a) +
+
+ Return a formatted string. + + +

Parameters:

+
    +
  • a + bound3 + bound to be turned into a string +
  • +
+ +

Returns:

+
    + + string + formatted +
+ + + + +
+
+ + +
+
+
+generated by LDoc 1.5.0 +Last updated 2023-09-10 15:25:31 +
+
+ + diff --git a/docs/modules/bvh.html b/docs/modules/bvh.html new file mode 100644 index 0000000..d07e692 --- /dev/null +++ b/docs/modules/bvh.html @@ -0,0 +1,84 @@ + + + + + CPML documentation + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module bvh

+

BVH Tree

+

+ +

+ + + +
+
+ + + + +
+
+
+generated by LDoc 1.5.0 +Last updated 2023-09-10 15:25:31 +
+
+ + diff --git a/docs/modules/color.html b/docs/modules/color.html new file mode 100644 index 0000000..34232d7 --- /dev/null +++ b/docs/modules/color.html @@ -0,0 +1,737 @@ + + + + + CPML documentation + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module color

+

Color utilities

+

+ +

+ + +

Functions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
new (x, g, b, a)The public constructor.
from_hsv (h, s, v)Convert hue,saturation,value to color object.
from_hsva (h, s, v, a)Convert hue,saturation,value to color object.
invert (to)Invert a color.
lighten (to, amount)Lighten a color by a component-wise fixed amount (alpha unchanged)
lerp (at, at, s)Interpolate between two colors.
unpack (to)Unpack a color into individual components in 0-1.
as_255 (to)Unpack a color into individual components in 0-255.
darken (to, amount)Darken a color by a component-wise fixed amount (alpha unchanged)
multiply (to, to)Multiply a color's components by a value (alpha unchanged)
opacity (to, to)Multiply a color's alpha by a value
hue (to, to)Set a color's hue (saturation, value, alpha unchanged)
saturation (to, to)Set a color's saturation (hue, value, alpha unchanged)
value (to, to)Set a color's value (saturation, hue, alpha unchanged)
is_color (to)Check if color is valid
to_string (a)Return a formatted string.
+

Fields

+ + + + + + + + + +
hsv_to_color_tableConvert hue,saturation,value table to color object.
color_to_hsv_tableConvert color to hue,saturation,value table
+ +
+
+ + +

Functions

+ +
+
+ + new (x, g, b, a) +
+
+ The public constructor. + + +

Parameters:

+
    +
  • x + Can be of three types:
    + number red component 0-1 + table {r, g, b, a} + nil for {0,0,0,0} +
  • +
  • g + number + Green component 0-1 +
  • +
  • b + number + Blue component 0-1 +
  • +
  • a + number + Alpha component 0-1 +
  • +
+ +

Returns:

+
    + + color + out +
+ + + + +
+
+ + from_hsv (h, s, v) +
+
+ Convert hue,saturation,value to color object. + + +

Parameters:

+
    +
  • h + number + hue 0-1 +
  • +
  • s + number + saturation 0-1 +
  • +
  • v + number + value 0-1 +
  • +
+ +

Returns:

+
    + + color + out +
+ + + + +
+
+ + from_hsva (h, s, v, a) +
+
+ Convert hue,saturation,value to color object. + + +

Parameters:

+
    +
  • h + number + hue 0-1 +
  • +
  • s + number + saturation 0-1 +
  • +
  • v + number + value 0-1 +
  • +
  • a + number + alpha 0-1 +
  • +
+ +

Returns:

+
    + + color + out +
+ + + + +
+
+ + invert (to) +
+
+ Invert a color. + + +

Parameters:

+
    +
  • to + color + invert +
  • +
+ +

Returns:

+
    + + color + out +
+ + + + +
+
+ + lighten (to, amount) +
+
+ Lighten a color by a component-wise fixed amount (alpha unchanged) + + +

Parameters:

+
    +
  • to + color + lighten +
  • +
  • amount + number + to increase each component by, 0-1 scale +
  • +
+ +

Returns:

+
    + + color + out +
+ + + + +
+
+ + lerp (at, at, s) +
+
+ Interpolate between two colors. + + +

Parameters:

+
    +
  • at + color + end +
  • +
  • at + color + end +
  • +
  • s + number + in 0-1 progress between the two colors +
  • +
+ +

Returns:

+
    + + color + out +
+ + + + +
+
+ + unpack (to) +
+
+ Unpack a color into individual components in 0-1. + + +

Parameters:

+
    +
  • to + color + unpack +
  • +
+ +

Returns:

+
    +
  1. + number + r in 0-1
  2. +
  3. + number + g in 0-1
  4. +
  5. + number + b in 0-1
  6. +
  7. + number + a in 0-1
  8. +
+ + + + +
+
+ + as_255 (to) +
+
+ Unpack a color into individual components in 0-255. + + +

Parameters:

+
    +
  • to + color + unpack +
  • +
+ +

Returns:

+
    +
  1. + number + r in 0-255
  2. +
  3. + number + g in 0-255
  4. +
  5. + number + b in 0-255
  6. +
  7. + number + a in 0-255
  8. +
+ + + + +
+
+ + darken (to, amount) +
+
+ Darken a color by a component-wise fixed amount (alpha unchanged) + + +

Parameters:

+
    +
  • to + color + darken +
  • +
  • amount + number + to decrease each component by, 0-1 scale +
  • +
+ +

Returns:

+
    + + color + out +
+ + + + +
+
+ + multiply (to, to) +
+
+ Multiply a color's components by a value (alpha unchanged) + + +

Parameters:

+
    +
  • to + number + multiply each component by +
  • +
  • to + number + multiply each component by +
  • +
+ +

Returns:

+
    + + color + out +
+ + + + +
+
+ + opacity (to, to) +
+
+ Multiply a color's alpha by a value + + +

Parameters:

+
    +
  • to + number + multiply alpha by +
  • +
  • to + number + multiply alpha by +
  • +
+ +

Returns:

+
    + + color + out +
+ + + + +
+
+ + hue (to, to) +
+
+ Set a color's hue (saturation, value, alpha unchanged) + + +

Parameters:

+
    +
  • to + hue + set 0-1 +
  • +
  • to + hue + set 0-1 +
  • +
+ +

Returns:

+
    + + color + out +
+ + + + +
+
+ + saturation (to, to) +
+
+ Set a color's saturation (hue, value, alpha unchanged) + + +

Parameters:

+ + +

Returns:

+
    + + color + out +
+ + + + +
+
+ + value (to, to) +
+
+ Set a color's value (saturation, hue, alpha unchanged) + + +

Parameters:

+
    +
  • to + value + set 0-1 +
  • +
  • to + value + set 0-1 +
  • +
+ +

Returns:

+
    + + color + out +
+ + + + +
+
+ + is_color (to) +
+
+ Check if color is valid + + +

Parameters:

+
    +
  • to + color + test +
  • +
+ +

Returns:

+
    + + boolean + is color +
+ + + + +
+
+ + to_string (a) +
+
+ Return a formatted string. + + +

Parameters:

+
    +
  • a + color + color to be turned into a string +
  • +
+ +

Returns:

+
    + + string + formatted +
+ + + + +
+
+

Fields

+ +
+
+ + hsv_to_color_table +
+
+ Convert hue,saturation,value table to color object. + + +
    +
  • hsva + table + {hue 0-1, saturation 0-1, value 0-1, alpha 0-1} +
  • +
+ + + + + +
+
+ + color_to_hsv_table +
+
+ Convert color to hue,saturation,value table + + +
    +
  • in + color + + + +
  • +
+ + + + + +
+
+ + +
+
+
+generated by LDoc 1.5.0 +Last updated 2023-09-10 15:25:31 +
+
+ + diff --git a/docs/modules/constants.html b/docs/modules/constants.html new file mode 100644 index 0000000..3594813 --- /dev/null +++ b/docs/modules/constants.html @@ -0,0 +1,125 @@ + + + + + CPML documentation + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module constants

+

Various useful constants

+

+ +

+ + +

Tables

+ + + + + +
constantsConstants
+ +
+
+ + +

Tables

+ +
+
+ + constants +
+
+ Constants + + +

Fields:

+
    +
  • FLT_EPSILON + Floating point precision breaks down +
  • +
  • DBL_EPSILON + Double-precise floating point precision breaks down +
  • +
  • DOT_THRESHOLD + Close enough to 1 for interpolations to occur +
  • +
+ + + + + +
+
+ + +
+
+
+generated by LDoc 1.5.0 +Last updated 2023-09-10 15:25:31 +
+
+ + diff --git a/docs/modules/intersect.html b/docs/modules/intersect.html new file mode 100644 index 0000000..c3c06f0 --- /dev/null +++ b/docs/modules/intersect.html @@ -0,0 +1,84 @@ + + + + + CPML documentation + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module intersect

+

Various geometric intersections

+

+ +

+ + + +
+
+ + + + +
+
+
+generated by LDoc 1.5.0 +Last updated 2023-09-10 15:25:31 +
+
+ + diff --git a/docs/modules/mat4.html b/docs/modules/mat4.html new file mode 100644 index 0000000..bc97db6 --- /dev/null +++ b/docs/modules/mat4.html @@ -0,0 +1,1173 @@ + + + + + CPML documentation + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module mat4

+

double 4x4, 1-based, column major matrices

+

+ +

+ + +

Functions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
new (a)The public constructor.
identity (a)Create an identity matrix.
from_angle_axis (angle, axis)Create a matrix from an angle/axis pair.
from_quaternion (q)Create a matrix from a quaternion.
from_direction (direction, up)Create a matrix from a direction/up pair.
from_transform (trans, rot, scale)Create a matrix from a transform.
from_ortho (left, right, top, bottom, near, far)Create matrix from orthogonal.
from_perspective (fovy, aspect, near, far)Create matrix from perspective.
clone (a)Clone a matrix.
mul (out, or, right)Multiply N matrices.
mul_vec3_perspective (out, a, b)Multiply a matrix and a vec3, with perspective division.
mul_vec4 (out, a, b)Multiply a matrix and a vec4.
invert (out, a)Invert a matrix.
scale (out, a, s)Scale a matrix.
rotate (out, a, angle, axis)Rotate a matrix.
translate (out, a, t)Translate a matrix.
shear (out, a, yx, zx, xy, zy, xz, yz)Shear a matrix.
reflect (Matrix, Matrix, position, normal)Reflect a matrix across a plane.
look_at (out, eye, center, up)Transform matrix to look at a point.
target (out, eye, center, up)Transform matrix to target a point.
transpose (out, a)Transpose a matrix.
project (obj, mvp, viewport)Project a point into screen space
unproject (win, mvp, viewport)Unproject a point from screen space to world space.
is_mat4 (a)Return a boolean showing if a table is or is not a mat4.
vec2.has_nan (a)Return whether any component is NaN
to_string (a)Return a formatted string.
to_vec4s (a)Convert a matrix to row vec4s.
to_vec4s_cols (a)Convert a matrix to col vec4s.
+ +
+
+ + +

Functions

+ +
+
+ + new (a) +
+
+ The public constructor. + + +

Parameters:

+
    +
  • a + Can be of four types:
    + table Length 16 (4x4 matrix) + table Length 9 (3x3 matrix) + table Length 4 (4 vec4s) + nil +
  • +
+ +

Returns:

+
    + + mat4 + out +
+ + + + +
+
+ + identity (a) +
+
+ Create an identity matrix. + + +

Parameters:

+
    +
  • a + mat4 + Matrix to overwrite +
  • +
+ +

Returns:

+
    + + mat4 + out +
+ + + + +
+
+ + from_angle_axis (angle, axis) +
+
+ Create a matrix from an angle/axis pair. + + +

Parameters:

+
    +
  • angle + number + Angle of rotation +
  • +
  • axis + vec3 + Axis of rotation +
  • +
+ +

Returns:

+
    + + mat4 + out +
+ + + + +
+
+ + from_quaternion (q) +
+
+ Create a matrix from a quaternion. + + +

Parameters:

+
    +
  • q + quat + Rotation quaternion +
  • +
+ +

Returns:

+
    + + mat4 + out +
+ + + + +
+
+ + from_direction (direction, up) +
+
+ Create a matrix from a direction/up pair. + + +

Parameters:

+
    +
  • direction + vec3 + Vector direction +
  • +
  • up + vec3 + Up direction +
  • +
+ +

Returns:

+
    + + mat4 + out +
+ + + + +
+
+ + from_transform (trans, rot, scale) +
+
+ Create a matrix from a transform. + + +

Parameters:

+
    +
  • trans + vec3 + Translation vector +
  • +
  • rot + quat + Rotation quaternion +
  • +
  • scale + vec3 + Scale vector +
  • +
+ +

Returns:

+
    + + mat4 + out +
+ + + + +
+
+ + from_ortho (left, right, top, bottom, near, far) +
+
+ Create matrix from orthogonal. + + +

Parameters:

+
    +
  • left + number + + + +
  • +
  • right + number + + + +
  • +
  • top + number + + + +
  • +
  • bottom + number + + + +
  • +
  • near + number + + + +
  • +
  • far + number + + + +
  • +
+ +

Returns:

+
    + + mat4 + out +
+ + + + +
+
+ + from_perspective (fovy, aspect, near, far) +
+
+ Create matrix from perspective. + + +

Parameters:

+
    +
  • fovy + number + Field of view +
  • +
  • aspect + number + Aspect ratio +
  • +
  • near + number + Near plane +
  • +
  • far + number + Far plane +
  • +
+ +

Returns:

+
    + + mat4 + out +
+ + + + +
+
+ + clone (a) +
+
+ Clone a matrix. + + +

Parameters:

+
    +
  • a + mat4 + Matrix to clone +
  • +
+ +

Returns:

+
    + + mat4 + out +
+ + + + +
+
+ + mul (out, or, right) +
+
+ Multiply N matrices. + + +

Parameters:

+
    +
  • out + mat4 + Matrix to store the result +
  • +
  • or + mat4 + {mat4, ...} left hand operand(s) +
  • +
  • right + mat4 + hand operand if a is not table +
  • +
+ +

Returns:

+
    + + mat4 + out multiplied matrix result +
+ + + + +
+
+ + mul_vec3_perspective (out, a, b) +
+
+ Multiply a matrix and a vec3, with perspective division. + This function uses an implicit 1 for the fourth component. + + +

Parameters:

+
    +
  • out + vec3 + vec3 to store the result +
  • +
  • a + mat4 + Left hand operand +
  • +
  • b + vec3 + Right hand operand +
  • +
+ +

Returns:

+
    + + vec3 + out +
+ + + + +
+
+ + mul_vec4 (out, a, b) +
+
+ Multiply a matrix and a vec4. + + +

Parameters:

+
    +
  • out + table + table to store the result +
  • +
  • a + mat4 + Left hand operand +
  • +
  • b + table + Right hand operand +
  • +
+ +

Returns:

+
    + + vec4 + out +
+ + + + +
+
+ + invert (out, a) +
+
+ Invert a matrix. + + +

Parameters:

+
    +
  • out + mat4 + Matrix to store the result +
  • +
  • a + mat4 + Matrix to invert +
  • +
+ +

Returns:

+
    + + mat4 + out +
+ + + + +
+
+ + scale (out, a, s) +
+
+ Scale a matrix. + + +

Parameters:

+
    +
  • out + mat4 + Matrix to store the result +
  • +
  • a + mat4 + Matrix to scale +
  • +
  • s + vec3 + Scalar +
  • +
+ +

Returns:

+
    + + mat4 + out +
+ + + + +
+
+ + rotate (out, a, angle, axis) +
+
+ Rotate a matrix. + + +

Parameters:

+
    +
  • out + mat4 + Matrix to store the result +
  • +
  • a + mat4 + Matrix to rotate +
  • +
  • angle + number + Angle to rotate by (in radians) +
  • +
  • axis + vec3 + Axis to rotate on +
  • +
+ +

Returns:

+
    + + mat4 + out +
+ + + + +
+
+ + translate (out, a, t) +
+
+ Translate a matrix. + + +

Parameters:

+
    +
  • out + mat4 + Matrix to store the result +
  • +
  • a + mat4 + Matrix to translate +
  • +
  • t + vec3 + Translation vector +
  • +
+ +

Returns:

+
    + + mat4 + out +
+ + + + +
+
+ + shear (out, a, yx, zx, xy, zy, xz, yz) +
+
+ Shear a matrix. + + +

Parameters:

+
    +
  • out + mat4 + Matrix to store the result +
  • +
  • a + mat4 + Matrix to translate +
  • +
  • yx + number + + + +
  • +
  • zx + number + + + +
  • +
  • xy + number + + + +
  • +
  • zy + number + + + +
  • +
  • xz + number + + + +
  • +
  • yz + number + + + +
  • +
+ +

Returns:

+
    + + mat4 + out +
+ + + + +
+
+ + reflect (Matrix, Matrix, position, normal) +
+
+ Reflect a matrix across a plane. + + +

Parameters:

+
    +
  • Matrix + a + to reflect +
  • +
  • Matrix + a + to reflect +
  • +
  • position + vec3 + A point on the plane +
  • +
  • normal + vec3 + The (normalized!) normal vector of the plane +
  • +
+ + + + + +
+
+ + look_at (out, eye, center, up) +
+
+ Transform matrix to look at a point. + + +

Parameters:

+
    +
  • out + mat4 + Matrix to store result +
  • +
  • eye + vec3 + Location of viewer's view plane +
  • +
  • center + vec3 + Location of object to view +
  • +
  • up + vec3 + Up direction +
  • +
+ +

Returns:

+
    + + mat4 + out +
+ + + + +
+
+ + target (out, eye, center, up) +
+
+ Transform matrix to target a point. + + +

Parameters:

+
    +
  • out + mat4 + Matrix to store result +
  • +
  • eye + vec3 + Location of viewer's view plane +
  • +
  • center + vec3 + Location of object to view +
  • +
  • up + vec3 + Up direction +
  • +
+ +

Returns:

+
    + + mat4 + out +
+ + + + +
+
+ + transpose (out, a) +
+
+ Transpose a matrix. + + +

Parameters:

+
    +
  • out + mat4 + Matrix to store the result +
  • +
  • a + mat4 + Matrix to transpose +
  • +
+ +

Returns:

+
    + + mat4 + out +
+ + + + +
+
+ + project (obj, mvp, viewport) +
+
+ Project a point into screen space + + +

Parameters:

+
    +
  • obj + vec3 + Object position in world space +
  • +
  • mvp + mat4 + Projection matrix +
  • +
  • viewport + table + XYWH of viewport +
  • +
+ +

Returns:

+
    + + vec3 + win +
+ + + + +
+
+ + unproject (win, mvp, viewport) +
+
+ Unproject a point from screen space to world space. + + +

Parameters:

+
    +
  • win + vec3 + Object position in screen space +
  • +
  • mvp + mat4 + Projection matrix +
  • +
  • viewport + table + XYWH of viewport +
  • +
+ +

Returns:

+
    + + vec3 + obj +
+ + + + +
+
+ + is_mat4 (a) +
+
+ Return a boolean showing if a table is or is not a mat4. + + +

Parameters:

+
    +
  • a + mat4 + Matrix to be tested +
  • +
+ +

Returns:

+
    + + boolean + is_mat4 +
+ + + + +
+
+ + vec2.has_nan (a) +
+
+ Return whether any component is NaN + + +

Parameters:

+
    +
  • a + mat4 + Matrix to be tested +
  • +
+ +

Returns:

+
    + + boolean + if any component is NaN +
+ + + + +
+
+ + to_string (a) +
+
+ Return a formatted string. + + +

Parameters:

+
    +
  • a + mat4 + Matrix to be turned into a string +
  • +
+ +

Returns:

+
    + + string + formatted +
+ + + + +
+
+ + to_vec4s (a) +
+
+ Convert a matrix to row vec4s. + + +

Parameters:

+
    +
  • a + mat4 + Matrix to be converted +
  • +
+ +

Returns:

+
    + + table + vec4s +
+ + + + +
+
+ + to_vec4s_cols (a) +
+
+ Convert a matrix to col vec4s. + + +

Parameters:

+
    +
  • a + mat4 + Matrix to be converted +
  • +
+ +

Returns:

+
    + + table + vec4s +
+ + + + +
+
+ + +
+
+
+generated by LDoc 1.5.0 +Last updated 2023-09-10 15:25:31 +
+
+ + diff --git a/docs/modules/mesh.html b/docs/modules/mesh.html new file mode 100644 index 0000000..5505e00 --- /dev/null +++ b/docs/modules/mesh.html @@ -0,0 +1,84 @@ + + + + + CPML documentation + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module mesh

+

Mesh utilities

+

+ +

+ + + +
+
+ + + + +
+
+
+generated by LDoc 1.5.0 +Last updated 2023-09-10 15:25:31 +
+
+ + diff --git a/docs/modules/octree.html b/docs/modules/octree.html new file mode 100644 index 0000000..aa7cf00 --- /dev/null +++ b/docs/modules/octree.html @@ -0,0 +1,710 @@ + + + + + CPML documentation + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module octree

+

Octree

+

+ +

+ + +

Functions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Octree:add (obj, objBounds)Add an object.
Octree:remove (obj)Remove an object.
Octree:is_colliding (checkBounds)Check if the specified bounds intersect with anything in the tree.
Octree:get_colliding (checkBounds)Returns an array of objects that intersect with the specified bounds, if any.
Octree:cast_ray (ray, func, out)Cast a ray through the node and its children
Octree:draw_bounds (cube)Draws node boundaries visually for debugging.
Octree:draw_objects (cube, filter)Draws the bounds of all objects in the tree visually for debugging.
Octree:grow (direction)Grow the octree to fit in all objects.
Octree:shrink ()Shrink the octree if possible, else leave it the same.
OctreeNode:add (obj, objBounds)Add an object.
OctreeNode:remove (obj)Remove an object.
OctreeNode:is_colliding (checkBounds)Check if the specified bounds intersect with anything in the tree.
OctreeNode:get_colliding (checkBounds, results)Returns an array of objects that intersect with the specified bounds, if any.
OctreeNode:cast_ray (ray, func, out, depth)Cast a ray through the node and its children
OctreeNode:set_children (childOctrees)Set the 8 children of this octree.
OctreeNode:shrink_if_possible (minLength)We can shrink the octree if: + - This node is >= double minLength in length + - All objects in the root node are within one octant + - This node doesn't have children, or does but 7/8 children are empty + We can also shrink it if there are no objects left at all!
OctreeNode:set_values (baseLength, minSize, looseness, center)Set values for this node.
OctreeNode:split ()Splits the octree into eight children.
OctreeNode:merge ()Merge all children into this node - the opposite of Split.
OctreeNode:best_fit_child (objBounds)Find which child node this object would be most likely to fit in.
OctreeNode:should_merge ()Checks if there are few enough objects in this node and its children that the children should all be merged into this.
OctreeNode:has_any_objects ()Checks if this node or anything below it has something in it.
+ +
+
+ + +

Functions

+ +
+
+ + Octree:add (obj, objBounds) +
+
+ Add an object. + + +

Parameters:

+
    +
  • obj + Object to add +
  • +
  • objBounds + 3D bounding box around the object +
  • +
+ + + + + +
+
+ + Octree:remove (obj) +
+
+ Remove an object. Makes the assumption that the object only exists once in the tree. + + +

Parameters:

+
    +
  • obj + Object to remove +
  • +
+ +

Returns:

+
    + + bool True if the object was removed successfully +
+ + + + +
+
+ + Octree:is_colliding (checkBounds) +
+
+ Check if the specified bounds intersect with anything in the tree. See also: get_colliding. + + +

Parameters:

+
    +
  • checkBounds + bounds to check +
  • +
+ +

Returns:

+
    + + bool True if there was a collision +
+ + + + +
+
+ + Octree:get_colliding (checkBounds) +
+
+ Returns an array of objects that intersect with the specified bounds, if any. Otherwise returns an empty array. See also: is_colliding. + + +

Parameters:

+
    +
  • checkBounds + bounds to check +
  • +
+ +

Returns:

+
    + + table Objects that intersect with the specified bounds +
+ + + + +
+
+ + Octree:cast_ray (ray, func, out) +
+
+ Cast a ray through the node and its children + + +

Parameters:

+
    +
  • ray + Ray with a position and a direction +
  • +
  • func + Function to execute on any objects within child nodes +
  • +
  • out + Table to store results of func in +
  • +
+ +

Returns:

+
    + + boolean True if an intersect detected +
+ + + + +
+
+ + Octree:draw_bounds (cube) +
+
+ Draws node boundaries visually for debugging. + + +

Parameters:

+
    +
  • cube + + + +
  • +
+ + + + + +
+
+ + Octree:draw_objects (cube, filter) +
+
+ Draws the bounds of all objects in the tree visually for debugging. + + +

Parameters:

+
    +
  • cube + + + +
  • +
  • filter + + + +
  • +
+ + + + + +
+
+ + Octree:grow (direction) +
+
+ Grow the octree to fit in all objects. + + +

Parameters:

+
    +
  • direction + Direction to grow +
  • +
+ + + + + +
+
+ + Octree:shrink () +
+
+ Shrink the octree if possible, else leave it the same. + + + + + + + +
+
+ + OctreeNode:add (obj, objBounds) +
+
+ Add an object. + + +

Parameters:

+
    +
  • obj + Object to add +
  • +
  • objBounds + 3D bounding box around the object +
  • +
+ +

Returns:

+
    + + boolean True if the object fits entirely within this node +
+ + + + +
+
+ + OctreeNode:remove (obj) +
+
+ Remove an object. Makes the assumption that the object only exists once in the tree. + + +

Parameters:

+
    +
  • obj + Object to remove +
  • +
+ +

Returns:

+
    + + boolean True if the object was removed successfully +
+ + + + +
+
+ + OctreeNode:is_colliding (checkBounds) +
+
+ Check if the specified bounds intersect with anything in the tree. See also: get_colliding. + + +

Parameters:

+
    +
  • checkBounds + Bounds to check +
  • +
+ +

Returns:

+
    + + boolean True if there was a collision +
+ + + + +
+
+ + OctreeNode:get_colliding (checkBounds, results) +
+
+ Returns an array of objects that intersect with the specified bounds, if any. Otherwise returns an empty array. See also: is_colliding. + + +

Parameters:

+
    +
  • checkBounds + Bounds to check. Passing by ref as it improve performance with structs +
  • +
  • results + List results +
  • +
+ +

Returns:

+
    + + table Objects that intersect with the specified bounds +
+ + + + +
+
+ + OctreeNode:cast_ray (ray, func, out, depth) +
+
+ Cast a ray through the node and its children + + +

Parameters:

+
    +
  • ray + Ray with a position and a direction +
  • +
  • func + Function to execute on any objects within child nodes +
  • +
  • out + Table to store results of func in +
  • +
  • depth + (used internally) +
  • +
+ +

Returns:

+
    + + boolean True if an intersect is detected +
+ + + + +
+
+ + OctreeNode:set_children (childOctrees) +
+
+ Set the 8 children of this octree. + + +

Parameters:

+
    +
  • childOctrees + The 8 new child nodes +
  • +
+ + + + + +
+
+ + OctreeNode:shrink_if_possible (minLength) +
+
+ We can shrink the octree if: + - This node is >= double minLength in length + - All objects in the root node are within one octant + - This node doesn't have children, or does but 7/8 children are empty + We can also shrink it if there are no objects left at all! + + +

Parameters:

+
    +
  • minLength + Minimum dimensions of a node in this octree +
  • +
+ +

Returns:

+
    + + table The new root, or the existing one if we didn't shrink +
+ + + + +
+
+ + OctreeNode:set_values (baseLength, minSize, looseness, center) +
+
+ Set values for this node. + + +

Parameters:

+
    +
  • baseLength + Length of this node, not taking looseness into account +
  • +
  • minSize + Minimum size of nodes in this octree +
  • +
  • looseness + Multiplier for baseLengthVal to get the actual size +
  • +
  • center + Centre position of this node +
  • +
+ + + + + +
+
+ + OctreeNode:split () +
+
+ Splits the octree into eight children. + + + + + + + +
+
+ + OctreeNode:merge () +
+
+ Merge all children into this node - the opposite of Split. + Note: We only have to check one level down since a merge will never happen if the children already have children, + since THAT won't happen unless there are already too many objects to merge. + + + + + + + +
+
+ + OctreeNode:best_fit_child (objBounds) +
+
+ Find which child node this object would be most likely to fit in. + + +

Parameters:

+
    +
  • objBounds + The object's bounds +
  • +
+ +

Returns:

+
    + + number One of the eight child octants +
+ + + + +
+
+ + OctreeNode:should_merge () +
+
+ Checks if there are few enough objects in this node and its children that the children should all be merged into this. + + + +

Returns:

+
    + + boolean True there are less or the same abount of objects in this and its children than numObjectsAllowed +
+ + + + +
+
+ + OctreeNode:has_any_objects () +
+
+ Checks if this node or anything below it has something in it. + + + +

Returns:

+
    + + boolean True if this node or any of its children, grandchildren etc have something in the +
+ + + + +
+
+ + +
+
+
+generated by LDoc 1.5.0 +Last updated 2023-09-10 15:25:31 +
+
+ + diff --git a/docs/modules/quat.html b/docs/modules/quat.html new file mode 100644 index 0000000..97a0603 --- /dev/null +++ b/docs/modules/quat.html @@ -0,0 +1,1273 @@ + + + + + CPML documentation + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module quat

+

A quaternion and associated utilities.

+

+ +

+ + +

Functions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
new (x, y, z, w)The public constructor.
from_angle_axis (angle, axis, y, z)Create a quaternion from an angle/axis pair.
from_direction (normal, up)Create a quaternion from a normal/up vector pair.
clone (a)Clone a quaternion.
add (a, b)Add two quaternions.
sub (a, b)Subtract a quaternion from another.
mul (a, b)Multiply two quaternions.
mul_vec3 (a, b)Multiply a quaternion and a vec3.
pow (a, s)Raise a normalized quaternion to a scalar power.
normalize (a)Normalize a quaternion.
dot (a, b)Get the dot product of two quaternions.
len (a)Return the length of a quaternion.
len2 (a)Return the squared length of a quaternion.
scale (a, s)Multiply a quaternion by a scalar.
rotate (angle, axis, y, z)Alias of fromangleaxis.
conjugate (a)Return the conjugate of a quaternion.
inverse (a)Return the inverse of a quaternion.
reciprocal (a)Return the reciprocal of a quaternion.
lerp (a, b, s)Lerp between two quaternions.
slerp (a, b, s)Slerp between two quaternions.
unpack (a)Unpack a quaternion into individual components.
is_quat (a)Return a boolean showing if a table is or is not a quat.
is_zero (a)Return a boolean showing if a table is or is not a zero quat.
is_real (a)Return a boolean showing if a table is or is not a real quat.
is_imaginary (a)Return a boolean showing if a table is or is not an imaginary quat.
has_nan (a)Return whether any component is NaN
to_angle_axis_unpack (a, vec3)Convert a quaternion into an angle plus axis components.
to_angle_axis (a, vec3)Convert a quaternion into an angle/axis pair.
to_euler_angles_unpack (a)Convert a quaternion into euler angle components
to_euler_angles (a)Convert a quaternion into euler angles
to_vec3 (a)Convert a quaternion into a vec3.
to_string (a)Return a formatted string.
to_euler (a)Convert a quaternion to an Euler angle
+

Tables

+ + + + + +
quatConstants
+ +
+
+ + +

Functions

+ +
+
+ + new (x, y, z, w) +
+
+ The public constructor. + + +

Parameters:

+
    +
  • x + Can be of two types:
    + number x X component + table {x, y, z, w} or {x=x, y=y, z=z, w=w} +
  • +
  • y + number + Y component +
  • +
  • z + number + Z component +
  • +
  • w + number + W component +
  • +
+ +

Returns:

+
    + + quat + out +
+ + + + +
+
+ + from_angle_axis (angle, axis, y, z) +
+
+ Create a quaternion from an angle/axis pair. + + +

Parameters:

+
    +
  • angle + number + Angle (in radians) +
  • +
  • axis + /x -- Can be of two types, a vec3 axis, or the x component of that axis +
  • +
  • y + axis -- y component of axis (optional, only if x component param used) +
  • +
  • z + axis -- z component of axis (optional, only if x component param used) +
  • +
+ +

Returns:

+
    + + quat + out +
+ + + + +
+
+ + from_direction (normal, up) +
+
+ Create a quaternion from a normal/up vector pair. + + +

Parameters:

+
    +
  • normal + vec3 + + + +
  • +
  • up + vec3 + (optional) +
  • +
+ +

Returns:

+
    + + quat + out +
+ + + + +
+
+ + clone (a) +
+
+ Clone a quaternion. + + +

Parameters:

+
    +
  • a + quat + Quaternion to clone +
  • +
+ +

Returns:

+
    + + quat + out +
+ + + + +
+
+ + add (a, b) +
+
+ Add two quaternions. + + +

Parameters:

+
    +
  • a + quat + Left hand operand +
  • +
  • b + quat + Right hand operand +
  • +
+ +

Returns:

+
    + + quat + out +
+ + + + +
+
+ + sub (a, b) +
+
+ Subtract a quaternion from another. + + +

Parameters:

+
    +
  • a + quat + Left hand operand +
  • +
  • b + quat + Right hand operand +
  • +
+ +

Returns:

+
    + + quat + out +
+ + + + +
+
+ + mul (a, b) +
+
+ Multiply two quaternions. + + +

Parameters:

+
    +
  • a + quat + Left hand operand +
  • +
  • b + quat + Right hand operand +
  • +
+ +

Returns:

+
    + + quat + quaternion equivalent to "apply b, then a" +
+ + + + +
+
+ + mul_vec3 (a, b) +
+
+ Multiply a quaternion and a vec3. + + +

Parameters:

+
    +
  • a + quat + Left hand operand +
  • +
  • b + vec3 + Right hand operand +
  • +
+ +

Returns:

+
    + + vec3 + out +
+ + + + +
+
+ + pow (a, s) +
+
+ Raise a normalized quaternion to a scalar power. + + +

Parameters:

+
    +
  • a + quat + Left hand operand (should be a unit quaternion) +
  • +
  • s + number + Right hand operand +
  • +
+ +

Returns:

+
    + + quat + out +
+ + + + +
+
+ + normalize (a) +
+
+ Normalize a quaternion. + + +

Parameters:

+
    +
  • a + quat + Quaternion to normalize +
  • +
+ +

Returns:

+
    + + quat + out +
+ + + + +
+
+ + dot (a, b) +
+
+ Get the dot product of two quaternions. + + +

Parameters:

+
    +
  • a + quat + Left hand operand +
  • +
  • b + quat + Right hand operand +
  • +
+ +

Returns:

+
    + + number + dot +
+ + + + +
+
+ + len (a) +
+
+ Return the length of a quaternion. + + +

Parameters:

+
    +
  • a + quat + Quaternion to get length of +
  • +
+ +

Returns:

+
    + + number + len +
+ + + + +
+
+ + len2 (a) +
+
+ Return the squared length of a quaternion. + + +

Parameters:

+
    +
  • a + quat + Quaternion to get length of +
  • +
+ +

Returns:

+
    + + number + len +
+ + + + +
+
+ + scale (a, s) +
+
+ Multiply a quaternion by a scalar. + + +

Parameters:

+
    +
  • a + quat + Left hand operand +
  • +
  • s + number + Right hand operand +
  • +
+ +

Returns:

+
    + + quat + out +
+ + + + +
+
+ + rotate (angle, axis, y, z) +
+
+ Alias of fromangleaxis. + + +

Parameters:

+
    +
  • angle + number + Angle (in radians) +
  • +
  • axis + /x -- Can be of two types, a vec3 axis, or the x component of that axis +
  • +
  • y + axis -- y component of axis (optional, only if x component param used) +
  • +
  • z + axis -- z component of axis (optional, only if x component param used) +
  • +
+ +

Returns:

+
    + + quat + out +
+ + + + +
+
+ + conjugate (a) +
+
+ Return the conjugate of a quaternion. + + +

Parameters:

+
    +
  • a + quat + Quaternion to conjugate +
  • +
+ +

Returns:

+
    + + quat + out +
+ + + + +
+
+ + inverse (a) +
+
+ Return the inverse of a quaternion. + + +

Parameters:

+
    +
  • a + quat + Quaternion to invert +
  • +
+ +

Returns:

+
    + + quat + out +
+ + + + +
+
+ + reciprocal (a) +
+
+ Return the reciprocal of a quaternion. + + +

Parameters:

+
    +
  • a + quat + Quaternion to reciprocate +
  • +
+ +

Returns:

+
    + + quat + out +
+ + + + +
+
+ + lerp (a, b, s) +
+
+ Lerp between two quaternions. + + +

Parameters:

+
    +
  • a + quat + Left hand operand +
  • +
  • b + quat + Right hand operand +
  • +
  • s + number + Step value +
  • +
+ +

Returns:

+
    + + quat + out +
+ + + + +
+
+ + slerp (a, b, s) +
+
+ Slerp between two quaternions. + + +

Parameters:

+
    +
  • a + quat + Left hand operand +
  • +
  • b + quat + Right hand operand +
  • +
  • s + number + Step value +
  • +
+ +

Returns:

+
    + + quat + out +
+ + + + +
+
+ + unpack (a) +
+
+ Unpack a quaternion into individual components. + + +

Parameters:

+
    +
  • a + quat + Quaternion to unpack +
  • +
+ +

Returns:

+
    +
  1. + number + x
  2. +
  3. + number + y
  4. +
  5. + number + z
  6. +
  7. + number + w
  8. +
+ + + + +
+
+ + is_quat (a) +
+
+ Return a boolean showing if a table is or is not a quat. + + +

Parameters:

+
    +
  • a + quat + Quaternion to be tested +
  • +
+ +

Returns:

+
    + + boolean + is_quat +
+ + + + +
+
+ + is_zero (a) +
+
+ Return a boolean showing if a table is or is not a zero quat. + + +

Parameters:

+
    +
  • a + quat + Quaternion to be tested +
  • +
+ +

Returns:

+
    + + boolean + is_zero +
+ + + + +
+
+ + is_real (a) +
+
+ Return a boolean showing if a table is or is not a real quat. + + +

Parameters:

+
    +
  • a + quat + Quaternion to be tested +
  • +
+ +

Returns:

+
    + + boolean + is_real +
+ + + + +
+
+ + is_imaginary (a) +
+
+ Return a boolean showing if a table is or is not an imaginary quat. + + +

Parameters:

+
    +
  • a + quat + Quaternion to be tested +
  • +
+ +

Returns:

+
    + + boolean + is_imaginary +
+ + + + +
+
+ + has_nan (a) +
+
+ Return whether any component is NaN + + +

Parameters:

+
    +
  • a + quat + Quaternion to be tested +
  • +
+ +

Returns:

+
    + + boolean + if x,y,z, or w is NaN +
+ + + + +
+
+ + to_angle_axis_unpack (a, vec3) +
+
+ Convert a quaternion into an angle plus axis components. + + +

Parameters:

+
    +
  • a + quat + Quaternion to convert +
  • +
  • vec3 + identityAxis + of axis to use on identity/degenerate quaternions (optional, default returns 0,0,0,1) +
  • +
+ +

Returns:

+
    +
  1. + number + angle
  2. +
  3. + x + axis-x
  4. +
  5. + y + axis-y
  6. +
  7. + z + axis-z
  8. +
+ + + + +
+
+ + to_angle_axis (a, vec3) +
+
+ Convert a quaternion into an angle/axis pair. + + +

Parameters:

+
    +
  • a + quat + Quaternion to convert +
  • +
  • vec3 + identityAxis + of axis to use on identity/degenerate quaternions (optional, default returns 0,vec3(0,0,1)) +
  • +
+ +

Returns:

+
    +
  1. + number + angle
  2. +
  3. + vec3 + axis
  4. +
+ + + + +
+
+ + to_euler_angles_unpack (a) +
+
+ Convert a quaternion into euler angle components + + +

Parameters:

+
    +
  • a + quat + Quaternion to convert +
  • +
+ +

Returns:

+
    +
  1. + roll + + +
  2. +
  3. + pitch + + +
  4. +
  5. + yaw + no idea if this shit really works, very well could not...
  6. +
+ + + + +
+
+ + to_euler_angles (a) +
+
+ Convert a quaternion into euler angles + + +

Parameters:

+
    +
  • a + quat + Quaternion to convert +
  • +
+ +

Returns:

+
    + + result + a {roll, pitch, yaw} table +
+ + + + +
+
+ + to_vec3 (a) +
+
+ Convert a quaternion into a vec3. + + +

Parameters:

+
    +
  • a + quat + Quaternion to convert +
  • +
+ +

Returns:

+
    + + vec3 + out +
+ + + + +
+
+ + to_string (a) +
+
+ Return a formatted string. + + +

Parameters:

+
    +
  • a + quat + Quaternion to be turned into a string +
  • +
+ +

Returns:

+
    + + string + formatted +
+ + + + +
+
+ + to_euler (a) +
+
+ Convert a quaternion to an Euler angle + + +

Parameters:

+
    +
  • a + quat + Quaternion to convert +
  • +
+ +

Returns:

+
    + + vec3 + euler angle in radians +
+ + + + +
+
+

Tables

+ +
+
+ + quat +
+
+ Constants + + +

Fields:

+
    +
  • unit + Unit quaternion +
  • +
  • zero + Empty quaternion +
  • +
+ + + + + +
+
+ + +
+
+
+generated by LDoc 1.5.0 +Last updated 2023-09-10 15:25:31 +
+
+ + diff --git a/docs/modules/simplex.html b/docs/modules/simplex.html new file mode 100644 index 0000000..e742b1f --- /dev/null +++ b/docs/modules/simplex.html @@ -0,0 +1,84 @@ + + + + + CPML documentation + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module simplex

+

Simplex Noise

+

+ +

+ + + +
+
+ + + + +
+
+
+generated by LDoc 1.5.0 +Last updated 2023-09-10 15:25:31 +
+
+ + diff --git a/docs/modules/utils.html b/docs/modules/utils.html new file mode 100644 index 0000000..59b88c9 --- /dev/null +++ b/docs/modules/utils.html @@ -0,0 +1,557 @@ + + + + + CPML documentation + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module utils

+

Various utility functions

+

+ +

+ + +

Functions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
clamp (value, min, max)Clamps a value within the specified range.
deadzone (value, size)Returns value if it is equal or greater than |size|, or 0.
threshold (value, threshold)Check if value is equal or greater than threshold.
tolerance (value, threshold)Check if value is equal or less than threshold.
map (value, min_in, max_in, min_out, max_out)Scales a value from one range to another.
lerp (low, high, progress)Linear interpolation.
decay (low, high, rate, dt)Exponential decay
smoothstep (progress, low, high)Hermite interpolation.
wrap (value, limit)Wrap value around if it exceeds limit.
is_pot (value)Check if a value is a power-of-two.
sign (value)Get the sign of a number + returns 1 for positive values, -1 for negative and 0 for zero.
+

Fields

+ + + + + + + + + +
roundRound number at a given precision.
is_nanCheck if a value is NaN + Returns true if a number is not a valid number
+ +
+
+ + +

Functions

+ +
+
+ + clamp (value, min, max) +
+
+ Clamps a value within the specified range. + + +

Parameters:

+
    +
  • value + Input value +
  • +
  • min + Minimum output value +
  • +
  • max + Maximum output value +
  • +
+ +

Returns:

+
    + + number +
+ + + + +
+
+ + deadzone (value, size) +
+
+ Returns value if it is equal or greater than |size|, or 0. + + +

Parameters:

+
    +
  • value + + + +
  • +
  • size + + + +
  • +
+ +

Returns:

+
    + + number +
+ + + + +
+
+ + threshold (value, threshold) +
+
+ Check if value is equal or greater than threshold. + + +

Parameters:

+
    +
  • value + + + +
  • +
  • threshold + + + +
  • +
+ +

Returns:

+
    + + boolean +
+ + + + +
+
+ + tolerance (value, threshold) +
+
+ Check if value is equal or less than threshold. + + +

Parameters:

+
    +
  • value + + + +
  • +
  • threshold + + + +
  • +
+ +

Returns:

+
    + + boolean +
+ + + + +
+
+ + map (value, min_in, max_in, min_out, max_out) +
+
+ Scales a value from one range to another. + + +

Parameters:

+
    +
  • value + Input value +
  • +
  • min_in + Minimum input value +
  • +
  • max_in + Maximum input value +
  • +
  • min_out + Minimum output value +
  • +
  • max_out + Maximum output value +
  • +
+ +

Returns:

+
    + + number +
+ + + + +
+
+ + lerp (low, high, progress) +
+
+ Linear interpolation. + Performs linear interpolation between 0 and 1 when low < progress < high. + + +

Parameters:

+
    +
  • low + value to return when progress is 0 +
  • +
  • high + value to return when progress is 1 +
  • +
  • progress + (0-1) +
  • +
+ +

Returns:

+
    + + number +
+ + + + +
+
+ + decay (low, high, rate, dt) +
+
+ Exponential decay + + +

Parameters:

+
    +
  • low + initial value +
  • +
  • high + target value +
  • +
  • rate + portion of the original value remaining per second +
  • +
  • dt + time delta +
  • +
+ +

Returns:

+
    + + number +
+ + + + +
+
+ + smoothstep (progress, low, high) +
+
+ Hermite interpolation. + Performs smooth Hermite interpolation between 0 and 1 when low < progress < high. + + +

Parameters:

+
    +
  • progress + (0-1) +
  • +
  • low + value to return when progress is 0 +
  • +
  • high + value to return when progress is 1 +
  • +
+ +

Returns:

+
    + + number +
+ + + + +
+
+ + wrap (value, limit) +
+
+ Wrap value around if it exceeds limit. + + +

Parameters:

+
    +
  • value + + + +
  • +
  • limit + + + +
  • +
+ +

Returns:

+
    + + number +
+ + + + +
+
+ + is_pot (value) +
+
+ Check if a value is a power-of-two. + Returns true if a number is a valid power-of-two, otherwise false. + + +

Parameters:

+
    +
  • value + + + +
  • +
+ +

Returns:

+
    + + boolean +
+ + + + +
+
+ + sign (value) +
+
+ Get the sign of a number + returns 1 for positive values, -1 for negative and 0 for zero. + + +

Parameters:

+
    +
  • value + + + +
  • +
+ +

Returns:

+
    + + number +
+ + + + +
+
+

Fields

+ +
+
+ + round +
+
+ Round number at a given precision. + Truncates value at precision points after the decimal (whole number if + left unspecified). + + +
    +
  • value + + + +
  • +
  • precision + + + +
  • +
+ + + + + +
+
+ + is_nan +
+
+ Check if a value is NaN + Returns true if a number is not a valid number + + +
    +
  • value + + + +
  • +
+ + + + + +
+
+ + +
+
+
+generated by LDoc 1.5.0 +Last updated 2023-09-10 15:25:31 +
+
+ + diff --git a/docs/modules/vec2.html b/docs/modules/vec2.html new file mode 100644 index 0000000..8a3def9 --- /dev/null +++ b/docs/modules/vec2.html @@ -0,0 +1,1124 @@ + + + + + CPML documentation + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module vec2

+

A 2 component vector.

+

+ +

+ + +

Functions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
new (x, y)The public constructor.
from_cartesian (radius, theta)Convert point from polar to cartesian.
clone (a)Clone a vector.
add (a, b)Add two vectors.
sub (a, b)Subtract one vector from another.
mul (a, b)Multiply a vector by another vector.
div (a, b)Divide a vector by another vector.
normalize (a)Get the normal of a vector.
trim (a, len)Trim a vector to a given length.
cross (a, b)Get the cross product of two vectors.
dot (a, b)Get the dot product of two vectors.
len (a)Get the length of a vector.
len2 (a)Get the squared length of a vector.
dist (a, b)Get the distance between two vectors.
dist2 (a, b)Get the squared distance between two vectors.
scale (a, b)Scale a vector by a scalar.
rotate (a, phi)Rotate a vector.
perpendicular (a)Get the perpendicular vector of a vector.
angle_to (a, b)Signed angle from one vector to another.
angle_between (a, b)Unsigned angle between two vectors.
lerp (a, b, s)Lerp between two vectors.
unpack (a)Unpack a vector into individual components.
component_min (a, b)Return the component-wise minimum of two vectors.
component_max (a, b)Return the component-wise maximum of two vectors.
is_vec2 (a)Return a boolean showing if a table is or is not a vec2.
is_zero (a)Return a boolean showing if a table is or is not a zero vec2.
has_nan (a)Return whether either value is NaN
to_polar (a)Convert point from cartesian to polar.
to_string (a)Return a formatted string.
+

Tables

+ + + + + +
vec2Constants
+ +
+
+ + +

Functions

+ +
+
+ + new (x, y) +
+
+ The public constructor. + + +

Parameters:

+
    +
  • x + Can be of three types:
    + number X component + table {x, y} or {x = x, y = y} + scalar to fill the vector eg. {x, x} +
  • +
  • y + number + Y component +
  • +
+ +

Returns:

+
    + + vec2 + out +
+ + + + +
+
+ + from_cartesian (radius, theta) +
+
+ Convert point from polar to cartesian. + + +

Parameters:

+
    +
  • radius + number + Radius of the point +
  • +
  • theta + number + Angle of the point (in radians) +
  • +
+ +

Returns:

+
    + + vec2 + out +
+ + + + +
+
+ + clone (a) +
+
+ Clone a vector. + + +

Parameters:

+
    +
  • a + vec2 + Vector to be cloned +
  • +
+ +

Returns:

+
    + + vec2 + out +
+ + + + +
+
+ + add (a, b) +
+
+ Add two vectors. + + +

Parameters:

+
    +
  • a + vec2 + Left hand operand +
  • +
  • b + vec2 + Right hand operand +
  • +
+ +

Returns:

+
    + + vec2 + out +
+ + + + +
+
+ + sub (a, b) +
+
+ Subtract one vector from another. + Order: If a and b are positions, computes the direction and distance from b + to a. + + +

Parameters:

+
    +
  • a + vec2 + Left hand operand +
  • +
  • b + vec2 + Right hand operand +
  • +
+ +

Returns:

+
    + + vec2 + out +
+ + + + +
+
+ + mul (a, b) +
+
+ Multiply a vector by another vector. + Component-size multiplication not matrix multiplication. + + +

Parameters:

+
    +
  • a + vec2 + Left hand operand +
  • +
  • b + vec2 + Right hand operand +
  • +
+ +

Returns:

+
    + + vec2 + out +
+ + + + +
+
+ + div (a, b) +
+
+ Divide a vector by another vector. + Component-size inv multiplication. Like a non-uniform scale(). + + +

Parameters:

+
    +
  • a + vec2 + Left hand operand +
  • +
  • b + vec2 + Right hand operand +
  • +
+ +

Returns:

+
    + + vec2 + out +
+ + + + +
+
+ + normalize (a) +
+
+ Get the normal of a vector. + + +

Parameters:

+
    +
  • a + vec2 + Vector to normalize +
  • +
+ +

Returns:

+
    + + vec2 + out +
+ + + + +
+
+ + trim (a, len) +
+
+ Trim a vector to a given length. + + +

Parameters:

+
    +
  • a + vec2 + Vector to be trimmed +
  • +
  • len + number + Length to trim the vector to +
  • +
+ +

Returns:

+
    + + vec2 + out +
+ + + + +
+
+ + cross (a, b) +
+
+ Get the cross product of two vectors. + Order: Positive if a is clockwise from b. Magnitude is the area spanned by + the parallelograms that a and b span. + + +

Parameters:

+
    +
  • a + vec2 + Left hand operand +
  • +
  • b + vec2 + Right hand operand +
  • +
+ +

Returns:

+
    + + number + magnitude +
+ + + + +
+
+ + dot (a, b) +
+
+ Get the dot product of two vectors. + + +

Parameters:

+
    +
  • a + vec2 + Left hand operand +
  • +
  • b + vec2 + Right hand operand +
  • +
+ +

Returns:

+
    + + number + dot +
+ + + + +
+
+ + len (a) +
+
+ Get the length of a vector. + + +

Parameters:

+
    +
  • a + vec2 + Vector to get the length of +
  • +
+ +

Returns:

+
    + + number + len +
+ + + + +
+
+ + len2 (a) +
+
+ Get the squared length of a vector. + + +

Parameters:

+
    +
  • a + vec2 + Vector to get the squared length of +
  • +
+ +

Returns:

+
    + + number + len +
+ + + + +
+
+ + dist (a, b) +
+
+ Get the distance between two vectors. + + +

Parameters:

+
    +
  • a + vec2 + Left hand operand +
  • +
  • b + vec2 + Right hand operand +
  • +
+ +

Returns:

+
    + + number + dist +
+ + + + +
+
+ + dist2 (a, b) +
+
+ Get the squared distance between two vectors. + + +

Parameters:

+
    +
  • a + vec2 + Left hand operand +
  • +
  • b + vec2 + Right hand operand +
  • +
+ +

Returns:

+
    + + number + dist +
+ + + + +
+
+ + scale (a, b) +
+
+ Scale a vector by a scalar. + + +

Parameters:

+
    +
  • a + vec2 + Left hand operand +
  • +
  • b + number + Right hand operand +
  • +
+ +

Returns:

+
    + + vec2 + out +
+ + + + +
+
+ + rotate (a, phi) +
+
+ Rotate a vector. + + +

Parameters:

+
    +
  • a + vec2 + Vector to rotate +
  • +
  • phi + number + Angle to rotate vector by (in radians) +
  • +
+ +

Returns:

+
    + + vec2 + out +
+ + + + +
+
+ + perpendicular (a) +
+
+ Get the perpendicular vector of a vector. + + +

Parameters:

+
    +
  • a + vec2 + Vector to get perpendicular axes from +
  • +
+ +

Returns:

+
    + + vec2 + out +
+ + + + +
+
+ + angle_to (a, b) +
+
+ Signed angle from one vector to another. + Rotations from +x to +y are positive. + + +

Parameters:

+
    +
  • a + vec2 + Vector +
  • +
  • b + vec2 + Vector +
  • +
+ +

Returns:

+
    + + number + angle in (-pi, pi] +
+ + + + +
+
+ + angle_between (a, b) +
+
+ Unsigned angle between two vectors. + Directionless and thus commutative. + + +

Parameters:

+
    +
  • a + vec2 + Vector +
  • +
  • b + vec2 + Vector +
  • +
+ +

Returns:

+
    + + number + angle in [0, pi] +
+ + + + +
+
+ + lerp (a, b, s) +
+
+ Lerp between two vectors. + + +

Parameters:

+
    +
  • a + vec2 + Left hand operand +
  • +
  • b + vec2 + Right hand operand +
  • +
  • s + number + Step value +
  • +
+ +

Returns:

+
    + + vec2 + out +
+ + + + +
+
+ + unpack (a) +
+
+ Unpack a vector into individual components. + + +

Parameters:

+
    +
  • a + vec2 + Vector to unpack +
  • +
+ +

Returns:

+
    +
  1. + number + x
  2. +
  3. + number + y
  4. +
+ + + + +
+
+ + component_min (a, b) +
+
+ Return the component-wise minimum of two vectors. + + +

Parameters:

+
    +
  • a + vec2 + Left hand operand +
  • +
  • b + vec2 + Right hand operand +
  • +
+ +

Returns:

+
    + + vec2 + A vector where each component is the lesser value for that component between the two given vectors. +
+ + + + +
+
+ + component_max (a, b) +
+
+ Return the component-wise maximum of two vectors. + + +

Parameters:

+
    +
  • a + vec2 + Left hand operand +
  • +
  • b + vec2 + Right hand operand +
  • +
+ +

Returns:

+
    + + vec2 + A vector where each component is the lesser value for that component between the two given vectors. +
+ + + + +
+
+ + is_vec2 (a) +
+
+ Return a boolean showing if a table is or is not a vec2. + + +

Parameters:

+
    +
  • a + vec2 + Vector to be tested +
  • +
+ +

Returns:

+
    + + boolean + is_vec2 +
+ + + + +
+
+ + is_zero (a) +
+
+ Return a boolean showing if a table is or is not a zero vec2. + + +

Parameters:

+
    +
  • a + vec2 + Vector to be tested +
  • +
+ +

Returns:

+
    + + boolean + is_zero +
+ + + + +
+
+ + has_nan (a) +
+
+ Return whether either value is NaN + + +

Parameters:

+
    +
  • a + vec2 + Vector to be tested +
  • +
+ +

Returns:

+
    + + boolean + if x or y is nan +
+ + + + +
+
+ + to_polar (a) +
+
+ Convert point from cartesian to polar. + + +

Parameters:

+
    +
  • a + vec2 + Vector to convert +
  • +
+ +

Returns:

+
    +
  1. + number + radius
  2. +
  3. + number + theta
  4. +
+ + + + +
+
+ + to_string (a) +
+
+ Return a formatted string. + + +

Parameters:

+
    +
  • a + vec2 + Vector to be turned into a string +
  • +
+ +

Returns:

+
    + + string + formatted +
+ + + + +
+
+

Tables

+ +
+
+ + vec2 +
+
+ Constants + + +

Fields:

+
    +
  • unit_x + X axis of rotation +
  • +
  • unit_y + Y axis of rotation +
  • +
  • zero + Empty vector +
  • +
+ + + + + +
+
+ + +
+
+
+generated by LDoc 1.5.0 +Last updated 2023-09-10 15:25:31 +
+
+ + diff --git a/docs/modules/vec3.html b/docs/modules/vec3.html new file mode 100644 index 0000000..61796f0 --- /dev/null +++ b/docs/modules/vec3.html @@ -0,0 +1,1032 @@ + + + + + CPML documentation + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module vec3

+

A 3 component vector.

+

+ +

+ + +

Functions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
new (x, y, z)The public constructor.
clone (a)Clone a vector.
add (a, b)Add two vectors.
sub (a, b)Subtract one vector from another.
mul (a, b)Multiply a vector by another vector.
div (a, b)Divide a vector by another.
normalize (a)Scale a vector to unit length (1).
normalize_len (a)Scale a vector to unit length (1), and return the input length.
trim (a, len)Trim a vector to a given length
cross (a, b)Get the cross product of two vectors.
dot (a, b)Get the dot product of two vectors.
len (a)Get the length of a vector.
len2 (a)Get the squared length of a vector.
dist (a, b)Get the distance between two vectors.
dist2 (a, b)Get the squared distance between two vectors.
scale (a, b)Scale a vector by a scalar.
rotate (a, phi, axis)Rotate vector about an axis.
perpendicular (a)Get the perpendicular vector of a vector.
lerp (a, b, s)Lerp between two vectors.
unpack (a)Unpack a vector into individual components.
component_min (a, b)Return the component-wise minimum of two vectors.
component_max (a, b)Return the component-wise maximum of two vectors.
is_vec3 (a)Return a boolean showing if a table is or is not a vec3.
is_zero (a)Return a boolean showing if a table is or is not a zero vec3.
has_nan (a)Return whether any component is NaN
to_string (a)Return a formatted string.
+

Tables

+ + + + + +
vec3Constants
+ +
+
+ + +

Functions

+ +
+
+ + new (x, y, z) +
+
+ The public constructor. + + +

Parameters:

+
    +
  • x + Can be of three types:
    + number X component + table {x, y, z} or {x=x, y=y, z=z} + scalar To fill the vector eg. {x, x, x} +
  • +
  • y + number + Y component +
  • +
  • z + number + Z component +
  • +
+ +

Returns:

+
    + + vec3 + out +
+ + + + +
+
+ + clone (a) +
+
+ Clone a vector. + + +

Parameters:

+
    +
  • a + vec3 + Vector to be cloned +
  • +
+ +

Returns:

+
    + + vec3 + out +
+ + + + +
+
+ + add (a, b) +
+
+ Add two vectors. + + +

Parameters:

+
    +
  • a + vec3 + Left hand operand +
  • +
  • b + vec3 + Right hand operand +
  • +
+ +

Returns:

+
    + + vec3 + out +
+ + + + +
+
+ + sub (a, b) +
+
+ Subtract one vector from another. + Order: If a and b are positions, computes the direction and distance from b + to a. + + +

Parameters:

+
    +
  • a + vec3 + Left hand operand +
  • +
  • b + vec3 + Right hand operand +
  • +
+ +

Returns:

+
    + + vec3 + out +
+ + + + +
+
+ + mul (a, b) +
+
+ Multiply a vector by another vector. + Component-wise multiplication not matrix multiplication. + + +

Parameters:

+
    +
  • a + vec3 + Left hand operand +
  • +
  • b + vec3 + Right hand operand +
  • +
+ +

Returns:

+
    + + vec3 + out +
+ + + + +
+
+ + div (a, b) +
+
+ Divide a vector by another. + Component-wise inv multiplication. Like a non-uniform scale(). + + +

Parameters:

+
    +
  • a + vec3 + Left hand operand +
  • +
  • b + vec3 + Right hand operand +
  • +
+ +

Returns:

+
    + + vec3 + out +
+ + + + +
+
+ + normalize (a) +
+
+ Scale a vector to unit length (1). + + +

Parameters:

+
    +
  • a + vec3 + vector to normalize +
  • +
+ +

Returns:

+
    + + vec3 + out +
+ + + + +
+
+ + normalize_len (a) +
+
+ Scale a vector to unit length (1), and return the input length. + + +

Parameters:

+
    +
  • a + vec3 + vector to normalize +
  • +
+ +

Returns:

+
    +
  1. + vec3 + out
  2. +
  3. + number + input vector length
  4. +
+ + + + +
+
+ + trim (a, len) +
+
+ Trim a vector to a given length + + +

Parameters:

+
    +
  • a + vec3 + vector to be trimmed +
  • +
  • len + number + Length to trim the vector to +
  • +
+ +

Returns:

+
    + + vec3 + out +
+ + + + +
+
+ + cross (a, b) +
+
+ Get the cross product of two vectors. + Resulting direction is right-hand rule normal of plane defined by a and b. + Magnitude is the area spanned by the parallelograms that a and b span. + Order: Direction determined by right-hand rule. + + +

Parameters:

+
    +
  • a + vec3 + Left hand operand +
  • +
  • b + vec3 + Right hand operand +
  • +
+ +

Returns:

+
    + + vec3 + out +
+ + + + +
+
+ + dot (a, b) +
+
+ Get the dot product of two vectors. + + +

Parameters:

+
    +
  • a + vec3 + Left hand operand +
  • +
  • b + vec3 + Right hand operand +
  • +
+ +

Returns:

+
    + + number + dot +
+ + + + +
+
+ + len (a) +
+
+ Get the length of a vector. + + +

Parameters:

+
    +
  • a + vec3 + Vector to get the length of +
  • +
+ +

Returns:

+
    + + number + len +
+ + + + +
+
+ + len2 (a) +
+
+ Get the squared length of a vector. + + +

Parameters:

+
    +
  • a + vec3 + Vector to get the squared length of +
  • +
+ +

Returns:

+
    + + number + len +
+ + + + +
+
+ + dist (a, b) +
+
+ Get the distance between two vectors. + + +

Parameters:

+
    +
  • a + vec3 + Left hand operand +
  • +
  • b + vec3 + Right hand operand +
  • +
+ +

Returns:

+
    + + number + dist +
+ + + + +
+
+ + dist2 (a, b) +
+
+ Get the squared distance between two vectors. + + +

Parameters:

+
    +
  • a + vec3 + Left hand operand +
  • +
  • b + vec3 + Right hand operand +
  • +
+ +

Returns:

+
    + + number + dist +
+ + + + +
+
+ + scale (a, b) +
+
+ Scale a vector by a scalar. + + +

Parameters:

+
    +
  • a + vec3 + Left hand operand +
  • +
  • b + number + Right hand operand +
  • +
+ +

Returns:

+
    + + vec3 + out +
+ + + + +
+
+ + rotate (a, phi, axis) +
+
+ Rotate vector about an axis. + + +

Parameters:

+
    +
  • a + vec3 + Vector to rotate +
  • +
  • phi + number + Angle to rotate vector by (in radians) +
  • +
  • axis + vec3 + Axis to rotate by +
  • +
+ +

Returns:

+
    + + vec3 + out +
+ + + + +
+
+ + perpendicular (a) +
+
+ Get the perpendicular vector of a vector. + + +

Parameters:

+
    +
  • a + vec3 + Vector to get perpendicular axes from +
  • +
+ +

Returns:

+
    + + vec3 + out +
+ + + + +
+
+ + lerp (a, b, s) +
+
+ Lerp between two vectors. + + +

Parameters:

+
    +
  • a + vec3 + Left hand operand +
  • +
  • b + vec3 + Right hand operand +
  • +
  • s + number + Step value +
  • +
+ +

Returns:

+
    + + vec3 + out +
+ + + + +
+
+ + unpack (a) +
+
+ Unpack a vector into individual components. + + +

Parameters:

+
    +
  • a + vec3 + Vector to unpack +
  • +
+ +

Returns:

+
    +
  1. + number + x
  2. +
  3. + number + y
  4. +
  5. + number + z
  6. +
+ + + + +
+
+ + component_min (a, b) +
+
+ Return the component-wise minimum of two vectors. + + +

Parameters:

+
    +
  • a + vec3 + Left hand operand +
  • +
  • b + vec3 + Right hand operand +
  • +
+ +

Returns:

+
    + + vec3 + A vector where each component is the lesser value for that component between the two given vectors. +
+ + + + +
+
+ + component_max (a, b) +
+
+ Return the component-wise maximum of two vectors. + + +

Parameters:

+
    +
  • a + vec3 + Left hand operand +
  • +
  • b + vec3 + Right hand operand +
  • +
+ +

Returns:

+
    + + vec3 + A vector where each component is the lesser value for that component between the two given vectors. +
+ + + + +
+
+ + is_vec3 (a) +
+
+ Return a boolean showing if a table is or is not a vec3. + + +

Parameters:

+
    +
  • a + vec3 + Vector to be tested +
  • +
+ +

Returns:

+
    + + boolean + is_vec3 +
+ + + + +
+
+ + is_zero (a) +
+
+ Return a boolean showing if a table is or is not a zero vec3. + + +

Parameters:

+
    +
  • a + vec3 + Vector to be tested +
  • +
+ +

Returns:

+
    + + boolean + is_zero +
+ + + + +
+
+ + has_nan (a) +
+
+ Return whether any component is NaN + + +

Parameters:

+
    +
  • a + vec3 + Vector to be tested +
  • +
+ +

Returns:

+
    + + boolean + if x,y, or z are nan +
+ + + + +
+
+ + to_string (a) +
+
+ Return a formatted string. + + +

Parameters:

+
    +
  • a + vec3 + Vector to be turned into a string +
  • +
+ +

Returns:

+
    + + string + formatted +
+ + + + +
+
+

Tables

+ +
+
+ + vec3 +
+
+ Constants + + +

Fields:

+
    +
  • unit_x + X axis of rotation +
  • +
  • unit_y + Y axis of rotation +
  • +
  • unit_z + Z axis of rotation +
  • +
  • zero + Empty vector +
  • +
+ + + + + +
+
+ + +
+
+
+generated by LDoc 1.5.0 +Last updated 2023-09-10 15:25:31 +
+
+ + diff --git a/docs/topics/readme.md.html b/docs/topics/readme.md.html new file mode 100644 index 0000000..a691dc1 --- /dev/null +++ b/docs/topics/readme.md.html @@ -0,0 +1,85 @@ + + + + + CPML documentation + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ + +

Cirno's Perfect Math Library

+

Adapated for Minetest

+

For best memory performance: have luaJIT & it's FFI library (this should be built into luaJIT), and add MTUL-CPML to your trusted list (so it can require() call the FFI library) +also works if you disable mod security (DANGEROUS, NOT RECCOMENDED).

+ +

Various useful bits of game math. 3D line intersections, ray casting, 2d/3d vectors, 4x4 matrices, quaternions, etc.

+ +

(originally) intended to be used with LuaJIT and LÖVE (this is the backbone of LÖVE3D).

+ + +

TODO:

+

* Vec3s and Vec2s are not currently adapted for functionality with MT vectors (seperate classes)

+ + +
+
+
+generated by LDoc 1.5.0 +Last updated 2023-09-10 15:25:31 +
+
+ + diff --git a/doc/config.ld b/ldoc/config.ld similarity index 94% rename from doc/config.ld rename to ldoc/config.ld index c1a87fc..5cd140b 100644 --- a/doc/config.ld +++ b/ldoc/config.ld @@ -7,6 +7,6 @@ file = { "../init.lua", "../modules" } -dir='./out' +dir='../docs' readme='../README.md' style='!new' diff --git a/doc/install_and_build_docs b/ldoc/install_and_build_docs similarity index 100% rename from doc/install_and_build_docs rename to ldoc/install_and_build_docs diff --git a/ldoc/windows_quick_generate.bat b/ldoc/windows_quick_generate.bat new file mode 100644 index 0000000..a025533 --- /dev/null +++ b/ldoc/windows_quick_generate.bat @@ -0,0 +1,3 @@ +# literally just so I dont have to open powershell every time. +@echo off +ldoc . \ No newline at end of file diff --git a/modules/quat.lua b/modules/quat.lua index 3c1d401..ce3b526 100644 --- a/modules/quat.lua +++ b/modules/quat.lua @@ -428,27 +428,28 @@ end -- @treturn roll -- @treturn pitch -- @treturn yaw +--no idea if this shit really works, very well could not... function quat.to_euler_angles_unpack(q) -- roll (x-axis rotation) local sinr_cosp = 2 * (q.w * q.x + q.y * q.z) local cosr_cosp = 1 - 2 * (q.x * q.x + q.y * q.y) - local roll = math.atan2(sinr_cosp, cosr_cosp) + local pitch = math.atan2(sinr_cosp, cosr_cosp) -- pitch (y-axis rotation) local sinp = 2 * (q.w * q.y - q.z * q.x) - local pitch + local yaw if math.abs(sinp) >= 1 then - pitch = math.pi / 2 * ((sinp > 0) and 1 or -1) -- Use 90 degrees if out of range + yaw = math.pi / 2 * ((sinp > 0) and 1 or -1) -- Use 90 degrees if out of range else - pitch = math.asin(sinp) + yaw = math.asin(sinp) end -- yaw (z-axis rotation) local siny_cosp = 2 * (q.w * q.z + q.x * q.y) local cosy_cosp = 1 - 2 * (q.y * q.y + q.z * q.z) - local yaw = math.atan2(siny_cosp, cosy_cosp) + local roll = math.atan2(siny_cosp, cosy_cosp) - return roll, pitch, yaw + return pitch, yaw, roll end --- Convert a quaternion into euler angles