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