more changes

This commit is contained in:
treeform 2023-05-11 22:15:07 -07:00
parent 6e2906d989
commit 8ff93d903a
2 changed files with 49 additions and 11 deletions

View file

@ -1,6 +1,6 @@
<img src="docs/banner.png">
# VMath - 2d and 3d vector math.
# VMath - 2D and 3D vector math.
`nimble install vmath`
@ -10,6 +10,8 @@
This library has no dependencies other than the Nim standard library.
Supports c, cpp and js backend.
## About
Your one stop shop for vector math routines for 2d and 3d graphics.

View file

@ -1,22 +1,20 @@
##[
This library has no dependencies other than the Nim standard libarary.
Your one stop shop for vector math routines for 2d and 3d graphics.
* Pure Nim with no dependencies.
* Very similar to GLSL Shader Language with extra stuff.
* Extensively benchmarked.
====== =========== ===================================================
====== =========== =================================================
Type Constructor Description
====== =========== ===================================================
BVec# bvec# a vector of booleans
IVec# ivec# a vector of signed integers
UVec# uvec# a vector of unsigned integers
Vec# vec# a vector of single-precision floating-point numbers
DVec# dvec# a vector of double-precision floating-point numbers
====== =========== ===================================================
====== =========== =================================================
BVec# bvec# vector of booleans
IVec# ivec# vector of signed integers
UVec# uvec# vector of unsigned integers
Vec# vec# vector of single-precision floating-point numbers
DVec# dvec# vector of double-precision floating-point numbers
====== =========== =================================================
You can use these constructors to make them:
@ -438,10 +436,12 @@ proc fixAngle*[T: SomeFloat](angle: T): T =
proc angleBetween*[T: SomeFloat](a, b: T): T =
## Angle between angle a and angle b.
## All angles assume radians.
fixAngle(b - a)
proc turnAngle*[T: SomeFloat](a, b, speed: T): T =
## Move from angle a to angle b with step of v.
## All angles assume radians.
var
turn = fixAngle(b - a)
if abs(turn) < speed:
@ -1285,7 +1285,12 @@ proc translate*[T](v: GVec3[T]): GMat4[T] =
)
proc rotate*[T](angle: T): GMat3[T] =
<<<<<<< 6e2906d9898fffe4edf18d77c10b32f09bcf8233
## Create a 2d rotation matrix by an angle.
=======
## Create a 2D rotation matrix by an angle.
## All angles assume radians.
>>>>>>> more changes
let
sin = sin(angle)
cos = cos(angle)
@ -1303,6 +1308,10 @@ proc rotationOnly*[T](a: GMat4[T]): GMat4[T] {.inline.} =
proc rotateX*[T](angle: T): GMat4[T] =
## Return a rotation matrix around X with angle.
<<<<<<< 6e2906d9898fffe4edf18d77c10b32f09bcf8233
=======
## All angles assume radians.
>>>>>>> more changes
result[0, 0] = 1
result[0, 1] = 0
result[0, 2] = 0
@ -1325,6 +1334,10 @@ proc rotateX*[T](angle: T): GMat4[T] =
proc rotateY*[T](angle: T): GMat4[T] =
## Return a rotation matrix around Y with angle.
<<<<<<< 6e2906d9898fffe4edf18d77c10b32f09bcf8233
=======
## All angles assume radians.
>>>>>>> more changes
result[0, 0] = cos(angle)
result[0, 1] = 0
result[0, 2] = sin(angle)
@ -1347,6 +1360,10 @@ proc rotateY*[T](angle: T): GMat4[T] =
proc rotateZ*[T](angle: T): GMat4[T] =
## Return a rotation matrix around Z with angle.
<<<<<<< 6e2906d9898fffe4edf18d77c10b32f09bcf8233
=======
## All angles assume radians.
>>>>>>> more changes
result[0, 0] = cos(angle)
result[0, 1] = -sin(angle)
result[0, 2] = 0
@ -1372,6 +1389,10 @@ proc toAngles*[T](a: GVec3[T]): GVec3[T] =
## pitch (x rotation)
## yaw (y rotation)
## roll (z rotation) - always 0 in vector case
<<<<<<< 6e2906d9898fffe4edf18d77c10b32f09bcf8233
=======
## All angles assume radians.
>>>>>>> more changes
if a == gvec3[T](T(0), T(0), T(0)):
return
let
@ -1385,6 +1406,10 @@ proc toAngles*[T](origin, target: GVec3[T]): GVec3[T] =
## pitch (x rotation)
## yaw (y rotation)
## roll (z rotation) - always 0 in vector case
<<<<<<< 6e2906d9898fffe4edf18d77c10b32f09bcf8233
=======
## All angles assume radians.
>>>>>>> more changes
toAngles(target - origin)
proc toAngles*[T](m: GMat4[T]): GVec3[T] =
@ -1393,6 +1418,10 @@ proc toAngles*[T](m: GMat4[T]): GVec3[T] =
## yaw (y rotation)
## roll (z rotation)
## Assumes matrix has not been scaled.
<<<<<<< 6e2906d9898fffe4edf18d77c10b32f09bcf8233
=======
## All angles assume radians.
>>>>>>> more changes
result.x = arcsin(m[2,1])
if result.x > PI/2:
# Degenerate case over north pole.
@ -1407,6 +1436,10 @@ proc toAngles*[T](m: GMat4[T]): GVec3[T] =
proc fromAngles*[T](a: GVec3[T]): GMat4[T] =
## Takes a vector containing Euler angles and returns a matrix.
<<<<<<< 6e2906d9898fffe4edf18d77c10b32f09bcf8233
=======
## All angles assume radians.
>>>>>>> more changes
rotateY(a.y) * rotateX(a.x) * rotateZ(a.z)
proc frustum*[T](left, right, bottom, top, near, far: T): GMat4[T] =
@ -1742,7 +1775,10 @@ proc rotate*[T](angle: T, axis: GVec3[T]): GMat4[T] =
## Return a rotation matrix with axis and angle.
fromAxisAngle(axis, angle).mat4()
<<<<<<< 6e2906d9898fffe4edf18d77c10b32f09bcf8233
=======
>>>>>>> more changes
when defined(release):
{.pop.}
{.pop.}