aboutsummaryrefslogtreecommitdiff
path: root/src/linear.h
blob: 3733c700b2231fafff64eb742f1c614adb8f57c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 * This file is part of mverse
 * Copyright (C) 2022  juanvalencia.xyz

 * mverse is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef __LINEAR__
#define __LINEAR__

#ifndef M_PI
#define M_PI (3.14159265358979323846)
#endif

typedef struct {
    float matrix[4][4];
} Mat4;

typedef struct {
    float vector[3];
} Vec3;

Mat4 linearTranslatev(Vec3 translate_vector);
Mat4 linearRotatev(float degree, Vec3 rotation_axis);
Mat4 linearScalev(Vec3 scale_vector);
Mat4 linearTranslate(float translate_x, float translate_y, float translate_z);
Mat4 linearScale(float scale_x, float scale_y, float scale_z);
Mat4 linearRotate(float degree, float rotate_x, float rotate_y, float rotate_z);
Mat4 linearPerspective(float FoV, float ratio, float near, float far);
Mat4 linearOrtho(float left, float right, float bottom, float top, float near, float far);
Mat4 linearLookAt(Vec3 position, Vec3 target, Vec3 up);

Mat4 linearMat4Fill(float value);
Mat4 linearMat4Identity(float value);
Mat4 linearMat4Mul(Mat4 x1, Mat4 x2);
Mat4 linearMat4Muln(int n, ...);
Mat4 linearMat4Transpose(Mat4 x);
Mat4 linearMat4Inv(Mat4 x); //TODO
Mat4 linearMat4Add(Mat4 x1, Mat4 x2);
float linearMat4Det(Mat4 x); //TODO

Vec3 linearVec3(float x, float y, float z);
Vec3 linearVec3Normalize(Vec3 vector);
Vec3 linearVec3Add(Vec3 vector1, Vec3 vector2);
Vec3 linearVec3ScalarMulp(Vec3 vector, float scalar);
Vec3 linearVec3CrossProduct(Vec3 vector1, Vec3 vector2);
float linearVec3DotProduct(Vec3 vector1, Vec3 vector2);
#endif
Feel free to download, copy and edit any repo