ULK_vector update to v1.1; ULK_matrix update to v1.1.1

ULK_vector changelog:
	- added ULK_vector_3d_slerp
	- removed all functions calling malloc/free/realloc to make library more usable

ULK_matrix changelog:
	- removed all functions calling malloc/free/realloc to make library more usable
This commit is contained in:
Captain4LK 2020-06-13 14:08:21 +02:00
parent 9df628626c
commit 938414dd77
5 changed files with 100 additions and 329 deletions

View File

@ -26,5 +26,5 @@ Just grab the header file and the corresponding c source file and add them to yo
|library|version|category|description|
|---|---|---|---|
|[ULK_vector](include/ULK_vector.h)|1.0|math|simple vector math library with support for 2,3 and 4 dimensional vectors|
|[ULK_matrix](include/ULK_matrix.h)|1.01|math|simple matrix math library with support for 2x2,2x3,3x3 and 4x4 matrix, needs ULK_vector to work|
|[ULK_vector](include/ULK_vector.h)|1.1|math|simple vector math library with support for 2,3 and 4 dimensional vectors|
|[ULK_matrix](include/ULK_matrix.h)|1.1.1|math|simple matrix math library with support for 2x2,2x3,3x3 and 4x4 matrix, needs ULK_vector to work|

View File

@ -1,5 +1,15 @@
/*
*/
/*
LICENSE OPTION A: 3-clause BSD
LICENSE OPTION A: 3-clause BSD
Copyright (C) 2020 Captain4LK (Lukas Holzbeierlein)
@ -13,7 +23,7 @@
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
LICENSE OPTION B: Public Domain CC0
LICENSE OPTION B: Public Domain CC0
just credit the original creator of gl-matrix as stated below.
*/
@ -32,6 +42,25 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
-----------------------------------------
1. Add ULK_matrix.c and ULK_vector.c to your source files.
2. Add ULK_matrix.h to your include files.
3. Edit ULK_matrix.c, l.44 to match the path to ULK_matrix.h.
4. Edit ULK_vector.c, l.43 to match the path to ULK_vector.h.
Linker options: None, unless your plattform treats math.h as a library, then add -lm (eg. Linux).
*/
#ifndef _ULK_MATRIX_H_
#define _ULK_MATRIX_H_
@ -48,16 +77,13 @@ typedef float ULK_matrix_4x4[16];
void ULK_matrix_2x2_add(ULK_matrix_2x2 out, const ULK_matrix_2x2 a, const ULK_matrix_2x2 b);
void ULK_matrix_2x2_adjoint(ULK_matrix_2x2 out, const ULK_matrix_2x2 in);
ULK_matrix_2x2 *ULK_matrix_2x2_clone(const ULK_matrix_2x2 in);
void ULK_matrix_2x2_copy(ULK_matrix_2x2 dst, const ULK_matrix_2x2 src);
ULK_matrix_2x2 *ULK_matrix_2x2_create();
float ULK_matrix_2x2_determinant(const ULK_matrix_2x2 in);
int ULK_matrix_2x2_equals(const ULK_matrix_2x2 a, const ULK_matrix_2x2 b);
int ULK_matrix_2x2_exact_equals(const ULK_matrix_2x2 a, const ULK_matrix_2x2 b);
float ULK_matrix_2x2_frob(const ULK_matrix_2x2 in);
void ULK_matrix_2x2_from_rotation(ULK_matrix_2x2 out, float rad);
void ULK_matrix_2x2_from_scaling(ULK_matrix_2x2 out, const ULK_vector_2d scaling);
ULK_matrix_2x2 *ULK_matrix_2x2_from_values(float m00, float m01, float m10, float m11);
void ULK_matrix_2x2_identity(ULK_matrix_2x2 out);
void ULK_matrix_2x2_invert(ULK_matrix_2x2 out, const ULK_matrix_2x2 in);
void ULK_matrix_2x2_LDU(ULK_matrix_2x2 L, ULK_matrix_2x2 D, ULK_matrix_2x2 U, const ULK_matrix_2x2 in);
@ -70,9 +96,7 @@ void ULK_matrix_2x2_subtract(ULK_matrix_2x2 out, const ULK_matrix_2x2 a, const U
void ULK_matrix_2x2_transpose(ULK_matrix_2x2 out, const ULK_matrix_2x2 in);
void ULK_matrix_2x3_add(ULK_matrix_2x3 out, const ULK_matrix_2x3 a, const ULK_matrix_2x3 b);
ULK_matrix_2x3 *ULK_matrix_2x3_clone(const ULK_matrix_2x3 in);
void ULK_matrix_2x3_copy(ULK_matrix_2x3 dst, const ULK_matrix_2x3 src);
ULK_matrix_2x3 *ULK_matrix_2x3_create();
float ULK_matrix_2x3_determinant(const ULK_matrix_2x3 in);
int ULK_matrix_2x3_equals(const ULK_matrix_2x3 a, const ULK_matrix_2x3 b);
int ULK_matrix_2x3_exact_equals(const ULK_matrix_2x3 a, const ULK_matrix_2x3 b);
@ -80,7 +104,6 @@ float ULK_matrix_2x3_frob(const ULK_matrix_2x3 in);
void ULK_matrix_2x3_from_rotation(ULK_matrix_2x3 out, float rad);
void ULK_matrix_2x3_from_scaling(ULK_matrix_2x3 out, const ULK_vector_2d scaling);
void ULK_matrix_2x3_from_translation(ULK_matrix_2x3 out, const ULK_vector_2d translation);
ULK_matrix_2x3 *ULK_matrix_2x3_from_values(float a, float b, float c, float d, float tx, float ty);
void ULK_matrix_2x3_identity(ULK_matrix_2x3 out);
void ULK_matrix_2x3_invert(ULK_matrix_2x3 out, const ULK_matrix_2x3 in);
void ULK_matrix_2x3_multiply(ULK_matrix_2x3 out, const ULK_matrix_2x3 a, const ULK_matrix_2x3 b);
@ -93,9 +116,7 @@ void ULK_matrix_2x3_translate(ULK_matrix_2x3 out, const ULK_matrix_2x3 in, const
void ULK_matrix_3x3_add(ULK_matrix_3x3 out, const ULK_matrix_3x3 a, const ULK_matrix_3x3 b);
void ULK_matrix_3x3_adjoint(ULK_matrix_3x3 out, const ULK_matrix_3x3 in);
ULK_matrix_3x3 *ULK_matrix_3x3_clone(const ULK_matrix_3x3 in);
void ULK_matrix_3x3_copy(ULK_matrix_3x3 out, const ULK_matrix_3x3 in);
ULK_matrix_3x3 *ULK_matrix_3x3_create();
float ULK_matrix_3x3_determinant(const ULK_matrix_3x3 in);
int ULK_matrix_3x3_equals(const ULK_matrix_3x3 a, const ULK_matrix_3x3 b);
int ULK_matrix_3x3_exact_equals(const ULK_matrix_3x3 a, const ULK_matrix_3x3 b);
@ -105,7 +126,6 @@ void ULK_matrix_3x3_from_matrix_4x4(ULK_matrix_3x3 out, const ULK_matrix_4x4 in)
void ULK_matrix_3x3_from_rotation(ULK_matrix_3x3 out, float rad);
void ULK_matrix_3x3_from_scaling(ULK_matrix_3x3 out, const ULK_vector_2d scaling);
void ULK_matrix_3x3_from_translation(ULK_matrix_3x3 out, const ULK_vector_2d translation);
ULK_matrix_3x3 *ULK_matrix_3x3_from_values(float m00, float m01, float m02, float m10, float m11, float m12, float m20, float m21, float m22);
void ULK_matrix_3x3_identity(ULK_matrix_3x3 out);
void ULK_matrix_3x3_invert(ULK_matrix_3x3 out, const ULK_matrix_3x3 in);
void ULK_matrix_3x3_multiply(ULK_matrix_3x3 out, const ULK_matrix_3x3 a, const ULK_matrix_3x3 b);
@ -121,9 +141,7 @@ void ULK_matrix_3x3_transpose(ULK_matrix_3x3 out, const ULK_matrix_3x3 in);
void ULK_matrix_4x4_add(ULK_matrix_4x4 out, const ULK_matrix_4x4 a, const ULK_matrix_4x4 b);
void ULK_matrix_4x4_adjoint(ULK_matrix_4x4 out, const ULK_matrix_4x4 in);
ULK_matrix_4x4 *ULK_matrix_4x4_clone(const ULK_matrix_4x4 in);
void ULK_matrix_4x4_copy(ULK_matrix_4x4 out, const ULK_matrix_4x4 in);
ULK_matrix_4x4 *ULK_matrix_4x4_create();
float ULK_matrix_4x4_determinant(const ULK_matrix_4x4 in);
int ULK_matrix_4x4_equals(const ULK_matrix_4x4 a, const ULK_matrix_4x4 b);
int ULK_matrix_4x4_exact_equals(const ULK_matrix_4x4 a, const ULK_matrix_4x4 b);
@ -131,7 +149,6 @@ float ULK_matrix_4x4_frob(const ULK_matrix_4x4 in);
void ULK_matrix_4x4_from_rotation(ULK_matrix_4x4 out, float rad, const ULK_vector_3d axis);
void ULK_matrix_4x4_from_scaling(ULK_matrix_4x4 out, const ULK_vector_3d scaling);
void ULK_matrix_4x4_fom_translation(ULK_matrix_4x4 out, const ULK_vector_3d translation);
ULK_matrix_4x4 *ULK_matrix_4x4_from_values(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23, float m30, float m31, float m32, float m33);
void ULK_matrix_4x4_from_xrotation(ULK_matrix_4x4 out, float rad);
void ULK_matrix_4x4_from_yrotation(ULK_matrix_4x4 out, float rad);
void ULK_matrix_4x4_from_zrotation(ULK_matrix_4x4 out, float rad);

View File

@ -1,5 +1,15 @@
/*
*/
/*
LICENSE OPTION A: 3-clause BSD
LICENSE OPTION A: 3-clause BSD
Copyright (C) 2020 Captain4LK (Lukas Holzbeierlein)
@ -13,7 +23,7 @@
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
LICENSE OPTION B: Public Domain CC0
LICENSE OPTION B: Public Domain CC0
just credit the original creator of gl-matrix as stated below.
*/
@ -32,6 +42,23 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
-----------------------------------------
1. Add ULK_vector.c to your source files.
2. Add ULK_vector.h to your include files.
3. Edit ULK_vector.c, l.43 to match the path to ULK_vector.h
Linker options: None, unless your plattform treats math.h as a library, then add -lm (eg. Linux).
*/
#ifndef _ULK_VECTOR_H_
#define _ULK_VECTOR_H_
@ -47,9 +74,7 @@ typedef float ULK_vector_4d[4];
void ULK_vector_2d_add(ULK_vector_2d out, const ULK_vector_2d a, const ULK_vector_2d b);
float ULK_vector_2d_angle(const ULK_vector_2d a, const ULK_vector_2d b);
void ULK_vector_2d_ceil(ULK_vector_2d out, const ULK_vector_2d in);
ULK_vector_2d *ULK_vector_2d_clone(const ULK_vector_2d in);
void ULK_vector_2d_copy(ULK_vector_2d dst, const ULK_vector_2d src);
ULK_vector_2d *ULK_vector_2d_create();
void ULK_vector_2d_cross(ULK_vector_3d out, const ULK_vector_2d a, const ULK_vector_2d b);
float ULK_vector_2d_distance(const ULK_vector_2d a, const ULK_vector_2d b);
void ULK_vector_2d_divide(ULK_vector_2d out, const ULK_vector_2d a, const ULK_vector_2d b);
@ -57,7 +82,6 @@ float ULK_vector_2d_dot(const ULK_vector_2d a, const ULK_vector_2d b);
int ULK_vector_2d_equals(const ULK_vector_2d a, const ULK_vector_2d b);
int ULK_vector_2d_exact_equals(const ULK_vector_2d a, const ULK_vector_2d b);
void ULK_vector_2d_floor(ULK_vector_2d out, const ULK_vector_2d in);
ULK_vector_2d *ULK_vector_2d_from_values(float x, float y);
void ULK_vector_2d_invert(ULK_vector_2d out, const ULK_vector_2d in);
float ULK_vector_2d_length(const ULK_vector_2d in);
void ULK_vector_2d_lerp(ULK_vector_2d out, const ULK_vector_2d a, const ULK_vector_2d b, float t);
@ -79,9 +103,7 @@ void ULK_vector_3d_add(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vecto
float ULK_vector_3d_angle(const ULK_vector_3d a, const ULK_vector_3d b);
void ULK_vector_3d_bezier(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b, const ULK_vector_3d c, const ULK_vector_3d d, const float t);
void ULK_vector_3d_ceil(ULK_vector_3d out, const ULK_vector_3d in);
ULK_vector_3d *ULK_vector_3d_clone(const ULK_vector_3d in);
void ULK_vector_3d_copy(ULK_vector_3d dst, const ULK_vector_3d src);
ULK_vector_3d *ULK_vector_3d_create();
void ULK_vector_3d_cross(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b);
float ULK_vector_3d_distance(const ULK_vector_3d a, const ULK_vector_3d b);
void ULK_vector_3d_divide(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b);
@ -89,7 +111,6 @@ float ULK_vector_3d_dot(const ULK_vector_3d a, const ULK_vector_3d b);
int ULK_vector_3d_equals(const ULK_vector_3d a, const ULK_vector_3d b);
int ULK_vector_3d_exact_equals(const ULK_vector_3d a, const ULK_vector_3d b);
void ULK_vector_3d_floor(ULK_vector_3d out, const ULK_vector_3d in);
ULK_vector_3d *ULK_vector_3d_from_values(float x, float y, float z);
void ULK_vector_3d_hermite(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b, const ULK_vector_3d c, const ULK_vector_3d d, float t);
void ULK_vector_3d_inverse(ULK_vector_3d out, const ULK_vector_3d in);
float ULK_vector_3d_length(const ULK_vector_3d in);
@ -105,6 +126,7 @@ void ULK_vector_3d_rotate_z(ULK_vector_3d out, const ULK_vector_3d in, const ULK
void ULK_vector_3d_round(ULK_vector_3d out, const ULK_vector_3d in);
void ULK_vector_3d_scale(ULK_vector_3d out, const ULK_vector_3d in, float scale);
void ULK_vector_3d_set(ULK_vector_3d out, float x, float y, float z);
void ULK_vector_3d_slerp(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b, float t);
float ULK_vector_3d_squared_distance(const ULK_vector_3d a, const ULK_vector_3d b);
float ULK_vector_3d_squared_length(const ULK_vector_3d in);
void ULK_vector_3d_subtract(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b);
@ -112,9 +134,7 @@ void ULK_vector_3d_zero(ULK_vector_3d out);
void ULK_vector_4d_add(ULK_vector_4d out, const ULK_vector_4d a, const ULK_vector_4d b);
void ULK_vector_4d_ceil(ULK_vector_4d out, const ULK_vector_4d in);
ULK_vector_4d *ULK_vector_4d_clone(const ULK_vector_4d in);
void ULK_vector_4d_copy(ULK_vector_4d out, const ULK_vector_4d in);
ULK_vector_4d *ULK_vector_4d_create();
void ULK_vector_4d_cross(ULK_vector_4d out, const ULK_vector_4d a, const ULK_vector_4d b, const ULK_vector_4d c);
float ULK_vector_4d_distance(const ULK_vector_4d a, const ULK_vector_4d b);
void ULK_vector_4d_divide(ULK_vector_4d out, const ULK_vector_4d a, const ULK_vector_4d b);
@ -122,7 +142,6 @@ float ULK_vector_4d_dot(const ULK_vector_4d a, const ULK_vector_4d b);
int ULK_vector_4d_equals(const ULK_vector_4d a, const ULK_vector_4d b);
int ULK_vector_4d_exact_equals(const ULK_vector_4d a, const ULK_vector_4d b);
void ULK_vector_4d_floor(ULK_vector_4d out, const ULK_vector_4d in);
ULK_vector_4d *ULK_vector_4d_from_values(float x, float y, float z, float w);
void ULK_vector_4d_inverse(ULK_vector_4d out, const ULK_vector_4d in);
float ULK_vector_4d_length(const ULK_vector_4d in);
void ULK_vector_4d_lerp(ULK_vector_4d out, const ULK_vector_4d a, const ULK_vector_4d b, float t);

View File

@ -1,5 +1,5 @@
/*
LICENSE OPTION A: 3-clause BSD
LICENSE OPTION A: 3-clause BSD
Copyright (C) 2020 Captain4LK (Lukas Holzbeierlein)
@ -13,7 +13,7 @@
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
LICENSE OPTION B: Public Domain CC0
LICENSE OPTION B: Public Domain CC0
just credit the original creator of gl-matrix as stated below.
*/
@ -32,6 +32,15 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
Changelog:
v1.1:
- added ULK_vector_*d_transform_matrix_*x*()
v1.1.1:
- removed all functions allocating memory to make library more usable
*/
#include "../include/ULK_matrix.h"
#define EPSILON 0.000001f
@ -56,18 +65,6 @@ void ULK_matrix_2x2_adjoint(ULK_matrix_2x2 out, const ULK_matrix_2x2 in)
out[3] = in0;
}
ULK_matrix_2x2 *ULK_matrix_2x2_clone(const ULK_matrix_2x2 in)
{
ULK_matrix_2x2 *out = malloc(sizeof(ULK_matrix_2x2));
*out[0] = in[0];
*out[1] = in[1];
*out[2] = in[2];
*out[3] = in[3];
return out;
}
void ULK_matrix_2x2_copy(ULK_matrix_2x2 dst, const ULK_matrix_2x2 src)
{
dst[0] = src[0];
@ -76,18 +73,6 @@ void ULK_matrix_2x2_copy(ULK_matrix_2x2 dst, const ULK_matrix_2x2 src)
dst[3] = src[3];
}
ULK_matrix_2x2 *ULK_matrix_2x2_create()
{
ULK_matrix_2x2 *out = malloc(sizeof(ULK_matrix_2x2));
*out[0] = 1.0f;
*out[1] = 0.0f;
*out[2] = 0.0f;
*out[3] = 1.0f;
return out;
}
float ULK_matrix_2x2_determinant(const ULK_matrix_2x2 in)
{
return in[0]*in[3]-in[2]*in[1];
@ -127,18 +112,6 @@ void ULK_matrix_2x2_from_scaling(ULK_matrix_2x2 out, const ULK_vector_2d scaling
out[3] = scaling[1];
}
ULK_matrix_2x2 *ULK_matrix_2x2_from_values(float m00, float m01, float m10, float m11)
{
ULK_matrix_2x2 *out = malloc(sizeof(ULK_matrix_2x2));
*out[0] = m00;
*out[1] = m01;
*out[2] = m10;
*out[3] = m11;
return out;
}
void ULK_matrix_2x2_identity(ULK_matrix_2x2 out)
{
out[0] = 1.0f;
@ -257,20 +230,6 @@ void ULK_matrix_2x3_add(ULK_matrix_2x3 out, const ULK_matrix_2x3 a, const ULK_ma
out[5] = a[5]+b[5];
}
ULK_matrix_2x3 *ULK_matrix_2x3_clone(const ULK_matrix_2x3 in)
{
ULK_matrix_2x3 *out = malloc(sizeof(ULK_matrix_2x3));
*out[0] = in[0];
*out[1] = in[1];
*out[2] = in[2];
*out[3] = in[3];
*out[4] = in[4];
*out[5] = in[5];
return out;
}
void ULK_matrix_2x3_copy(ULK_matrix_2x3 dst, const ULK_matrix_2x3 src)
{
dst[0] = src[0];
@ -281,20 +240,6 @@ void ULK_matrix_2x3_copy(ULK_matrix_2x3 dst, const ULK_matrix_2x3 src)
dst[5] = src[5];
}
ULK_matrix_2x3 *ULK_matrix_2x3_create()
{
ULK_matrix_2x3 *out = malloc(sizeof(ULK_matrix_2x3));
*out[0] = 1.0f;
*out[1] = 0.0f;
*out[2] = 0.0f;
*out[3] = 1.0f;
*out[4] = 0.0f;
*out[5] = 0.0f;
return out;
}
float ULK_matrix_2x3_determinant(const ULK_matrix_2x3 in)
{
return in[0]*in[3]-in[1]*in[2];
@ -348,20 +293,6 @@ void ULK_matrix_2x3_from_translation(ULK_matrix_2x3 out, const ULK_vector_2d tra
out[5] = translation[1];
}
ULK_matrix_2x3 *ULK_matrix_2x3_from_values(float a, float b, float c, float d, float tx, float ty)
{
ULK_matrix_2x3 *out = malloc(sizeof(ULK_matrix_2x3));
*out[0] = a;
*out[1] = b;
*out[2] = c;
*out[3] = d;
*out[4] = tx;
*out[5] = ty;
return out;
}
void ULK_matrix_2x3_identity(ULK_matrix_2x3 out)
{
out[0] = 1.0f;
@ -519,23 +450,6 @@ void ULK_matrix_3x3_adjoint(ULK_matrix_3x3 out, const ULK_matrix_3x3 in)
out[8] = in00*in11-in01*in10;
}
ULK_matrix_3x3 *ULK_matrix_3x3_clone(const ULK_matrix_3x3 in)
{
ULK_matrix_3x3 *out = malloc(sizeof(ULK_matrix_3x3));
*out[0] = in[0];
*out[1] = in[1];
*out[2] = in[2];
*out[3] = in[3];
*out[4] = in[4];
*out[5] = in[5];
*out[6] = in[6];
*out[7] = in[7];
*out[8] = in[8];
return out;
}
void ULK_matrix_3x3_copy(ULK_matrix_3x3 out, const ULK_matrix_3x3 in)
{
out[0] = in[0];
@ -549,23 +463,6 @@ void ULK_matrix_3x3_copy(ULK_matrix_3x3 out, const ULK_matrix_3x3 in)
out[8] = in[8];
}
ULK_matrix_3x3 *ULK_matrix_3x3_create()
{
ULK_matrix_3x3 *out = malloc(sizeof(ULK_matrix_3x3));
*out[0] = 1.0f;
*out[1] = 0.0f;
*out[2] = 0.0f;
*out[3] = 0.0f;
*out[4] = 1.0f;
*out[5] = 0.0f;
*out[6] = 0.0f;
*out[7] = 0.0f;
*out[8] = 1.0f;
return out;
}
float ULK_matrix_3x3_determinant(const ULK_matrix_3x3 in)
{
return in[0]*(in[8]*in[4]-in[5]*in[7])+in[1]*(-in[8]*in[3]+in[5]*in[6])+in[2]*(in[7]*in[3]-in[4]*in[6]);
@ -670,23 +567,6 @@ void ULK_matrix_3x3_from_translation(ULK_matrix_3x3 out, const ULK_vector_2d tra
out[8] = 1.0f;
}
ULK_matrix_3x3 *ULK_matrix_3x3_from_values(float m00, float m01, float m02, float m10, float m11, float m12, float m20, float m21, float m22)
{
ULK_matrix_3x3 *out = malloc(sizeof(ULK_matrix_3x3));
*out[0] = m00;
*out[1] = m01;
*out[2] = m02;
*out[3] = m10;
*out[4] = m11;
*out[5] = m12;
*out[6] = m20;
*out[7] = m21;
*out[8] = m22;
return out;
}
void ULK_matrix_3x3_identity(ULK_matrix_3x3 out)
{
out[0] = 1.0f;
@ -990,30 +870,6 @@ void ULK_matrix_4x4_adjoint(ULK_matrix_4x4 out, const ULK_matrix_4x4 in)
out[15] = in00*(in11*in22-in12*in21)-in10*(in01*in22-in02*in21)+in20*(in01*in12-in02*in11);
}
ULK_matrix_4x4 *ULK_matrix_4x4_clone(const ULK_matrix_4x4 in)
{
ULK_matrix_4x4 *out = malloc(sizeof(ULK_matrix_4x4));
*out[0] = in[0];
*out[1] = in[1];
*out[2] = in[2];
*out[3] = in[3];
*out[4] = in[4];
*out[5] = in[5];
*out[6] = in[6];
*out[7] = in[7];
*out[8] = in[8];
*out[9] = in[9];
*out[10] = in[10];
*out[11] = in[11];
*out[12] = in[12];
*out[13] = in[13];
*out[14] = in[14];
*out[15] = in[15];
return out;
}
void ULK_matrix_4x4_copy(ULK_matrix_4x4 out, const ULK_matrix_4x4 in)
{
out[0] = in[0];
@ -1034,30 +890,6 @@ void ULK_matrix_4x4_copy(ULK_matrix_4x4 out, const ULK_matrix_4x4 in)
out[15] = in[15];
}
ULK_matrix_4x4 *ULK_matrix_4x4_create()
{
ULK_matrix_4x4 *out = malloc(sizeof(ULK_matrix_4x4));
*out[0] = 1.0f;
*out[1] = 0.0f;
*out[2] = 0.0f;
*out[3] = 0.0f;
*out[4] = 0.0f;
*out[5] = 1.0f;
*out[6] = 0.0f;
*out[7] = 0.0f;
*out[8] = 0.0f;
*out[9] = 0.0f;
*out[10] = 1.0f;
*out[11] = 0.0f;
*out[12] = 0.0f;
*out[13] = 0.0f;
*out[14] = 0.0f;
*out[15] = 1.0f;
return out;
}
float ULK_matrix_4x4_determinant(const ULK_matrix_4x4 in)
{
float b00 = in[0]*in[5]-in[1]*in[4];
@ -1194,30 +1026,6 @@ void ULK_matrix_4x4_fom_translation(ULK_matrix_4x4 out, const ULK_vector_3d tran
out[15] = 1.0f;
}
ULK_matrix_4x4 *ULK_matrix_4x4_from_values(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23, float m30, float m31, float m32, float m33)
{
ULK_matrix_4x4 *out = malloc(sizeof(ULK_matrix_4x4));
*out[0] = m00;
*out[1] = m01;
*out[2] = m02;
*out[3] = m03;
*out[4] = m10;
*out[5] = m11;
*out[6] = m12;
*out[7] = m13;
*out[8] = m20;
*out[9] = m21;
*out[10] = m22;
*out[11] = m23;
*out[12] = m30;
*out[13] = m31;
*out[14] = m32;
*out[15] = m33;
return out;
}
void ULK_matrix_4x4_from_xrotation(ULK_matrix_4x4 out, float rad)
{
float s = sinf(rad);

View File

@ -1,5 +1,5 @@
/*
LICENSE OPTION A: 3-clause BSD
LICENSE OPTION A: 3-clause BSD
Copyright (C) 2020 Captain4LK (Lukas Holzbeierlein)
@ -13,7 +13,7 @@
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
LICENSE OPTION B: Public Domain CC0
LICENSE OPTION B: Public Domain CC0
just credit the original creator of gl-matrix as stated below.
*/
@ -32,6 +32,14 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
Changelog:
v1.1:
- added ULK_vector_3d_slerp
- removed all functions allocating memory to make library more usable
*/
#include "../include/ULK_vector.h"
#define EPSILON 0.000001f
@ -61,31 +69,12 @@ void ULK_vector_2d_ceil(ULK_vector_2d out, const ULK_vector_2d in)
out[1] = ceilf(in[1]);
}
ULK_vector_2d *ULK_vector_2d_clone(const ULK_vector_2d in)
{
ULK_vector_2d *out = malloc(sizeof(ULK_vector_2d));
*out[0] = in[0];
*out[1] = in[1];
return out;
}
void ULK_vector_2d_copy(ULK_vector_2d dst, const ULK_vector_2d src)
{
dst[0] = src[0];
dst[1] = src[1];
}
ULK_vector_2d *ULK_vector_2d_create()
{
ULK_vector_2d *out = malloc(sizeof(ULK_vector_2d));
*out[0] = 0.0f;
*out[1] = 0.0f;
return out;
}
void ULK_vector_2d_cross(ULK_vector_3d out, const ULK_vector_2d a, const ULK_vector_2d b)
{
float z = a[0]*b[1]-a[1]*b[0];
@ -129,15 +118,6 @@ void ULK_vector_2d_floor(ULK_vector_2d out, const ULK_vector_2d in)
out[1] = floorf(in[1]);
}
ULK_vector_2d *ULK_vector_2d_from_values(float x, float y)
{
ULK_vector_2d *out = malloc(sizeof(ULK_vector_2d));
*out[0] = x;
*out[1] = y;
return out;
}
void ULK_vector_2d_invert(ULK_vector_2d out, const ULK_vector_2d in)
{
out[0] = 1.0f/in[0];
@ -302,17 +282,6 @@ void ULK_vector_3d_ceil(ULK_vector_3d out, const ULK_vector_3d in)
out[2] = ceilf(in[2]);
}
ULK_vector_3d *ULK_vector_3d_clone(const ULK_vector_3d in)
{
ULK_vector_3d *out = malloc(sizeof(ULK_vector_3d));
*out[0] = in[0];
*out[1] = in[1];
*out[2] = in[2];
return out;
}
void ULK_vector_3d_copy(ULK_vector_3d dst, const ULK_vector_3d src)
{
dst[0] = src[0];
@ -320,17 +289,6 @@ void ULK_vector_3d_copy(ULK_vector_3d dst, const ULK_vector_3d src)
dst[2] = src[2];
}
ULK_vector_3d *ULK_vector_3d_create()
{
ULK_vector_3d *out = malloc(sizeof(ULK_vector_3d));
*out[0] = 0.0f;
*out[1] = 0.0f;
*out[2] = 0.0f;
return out;
}
void ULK_vector_3d_cross(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b)
{
float a0 = a[0];
@ -383,17 +341,6 @@ void ULK_vector_3d_floor(ULK_vector_3d out, const ULK_vector_3d in)
out[2] = floorf(in[2]);
}
ULK_vector_3d *ULK_vector_3d_from_values(float x, float y, float z)
{
ULK_vector_3d *out = malloc(sizeof(ULK_vector_3d));
*out[0] = x;
*out[1] = y;
*out[2] = z;
return out;
}
void ULK_vector_3d_hermite(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b, const ULK_vector_3d c, const ULK_vector_3d d, float t)
{
float factor0 = t*t*(2*t-3)+1;
@ -546,6 +493,18 @@ void ULK_vector_3d_set(ULK_vector_3d out, float x, float y, float z)
out[2] = z;
}
void ULK_vector_3d_slerp(ULK_vector_3d out, const ULK_vector_3d a, const ULK_vector_3d b, float t)
{
float angle = acosf(MIN(MAX(ULK_vector_3d_dot(a,b),-1.0f),1.0f));
float sin_total = sinf(angle);
float ratio_a = sinf((1.0f-t)*angle)/sin_total;
float ratio_b = sinf(t*angle)/sin_total;
out[0] = ratio_a*a[0]+ratio_b*b[0];
out[1] = ratio_a*a[1]+ratio_b*b[1];
out[2] = ratio_a*a[2]+ratio_b*b[2];
}
float ULK_vector_3d_squared_distance(const ULK_vector_3d a, const ULK_vector_3d b)
{
float x = b[0]-a[0];
@ -590,18 +549,6 @@ void ULK_vector_4d_ceil(ULK_vector_4d out, const ULK_vector_4d in)
out[3] = ceilf(in[3]);
}
ULK_vector_4d *ULK_vector_4d_clone(const ULK_vector_4d in)
{
ULK_vector_4d *out = malloc(sizeof(ULK_vector_4d));
*out[0] = in[0];
*out[1] = in[1];
*out[2] = in[2];
*out[3] = in[3];
return out;
}
void ULK_vector_4d_copy(ULK_vector_4d out, const ULK_vector_4d in)
{
out[0] = in[0];
@ -610,18 +557,6 @@ void ULK_vector_4d_copy(ULK_vector_4d out, const ULK_vector_4d in)
out[3] = in[3];
}
ULK_vector_4d *ULK_vector_4d_create()
{
ULK_vector_4d *out = malloc(sizeof(ULK_vector_4d));
*out[0] = 0.0f;
*out[1] = 0.0f;
*out[2] = 0.0f;
*out[3] = 0.0f;
return out;
}
void ULK_vector_4d_cross(ULK_vector_4d out, const ULK_vector_4d a, const ULK_vector_4d b, const ULK_vector_4d c)
{
float A = b[0]*c[1]-b[1]*c[0];
@ -682,18 +617,6 @@ void ULK_vector_4d_floor(ULK_vector_4d out, const ULK_vector_4d in)
out[3] = floorf(in[3]);
}
ULK_vector_4d *ULK_vector_4d_from_values(float x, float y, float z, float w)
{
ULK_vector_4d *out = malloc(sizeof(ULK_vector_4d));
*out[0] = x;
*out[1] = y;
*out[2] = z;
*out[3] = w;
return out;
}
void ULK_vector_4d_inverse(ULK_vector_4d out, const ULK_vector_4d in)
{
out[0] = 1.0f/in[0];
@ -840,3 +763,7 @@ void ULK_vector_4d_zero(ULK_vector_4d out)
out[2] = 0.0f;
out[3] = 0.0f;
}
#undef EPSILON
#undef MAX
#undef MIN