diffren/src/diffren_math.h
Kevin Trogant 7054c965a4 Initial commit
- Deferred renderer (forward)
- Loading models (temp)
- Started towards differentiation
2024-02-25 12:01:19 +01:00

83 lines
1.3 KiB
C

#ifndef DIFFREN_MATH_H
#define DIFFREN_MATH_H
/* Math definitions */
/* 3d float vector */
typedef union {
struct {
float x;
float y;
float z;
};
float e[3];
} V3;
/* 2d float vector */
typedef union {
struct {
float x;
float y;
};
float e[2];
} V2;
/* 4d float vector */
typedef union {
struct {
float x;
float y;
float z;
float w;
};
float e[4];
} V4;
/* 4x4 float matrix */
typedef union {
V4 columns[4];
float e[4 * 4];
} M4;
inline V3 V3Sub(V3 a, V3 b) {
V3 s;
for (int i = 0; i < 3; ++i)
s.e[i] = a.e[i] - b.e[i];
return s;
}
inline V3 V3Add(V3 a, V3 b) {
V3 s;
for (int i = 0; i < 3; ++i)
s.e[i] = a.e[i] + b.e[i];
return s;
}
inline V3 V3Cross(V3 a, V3 b) {
V3 r;
r.x = a.y * b.z - a.z * b.y;
r.y = a.z * b.x - a.x * b.z;
r.z = a.x * b.y - a.y * b.x;
return r;
}
inline float DegToRad(float deg) {
return deg * (3.1415926f / 180.f);
}
V3 V3Norm(V3 v);
M4 LookAt(V3 eye, V3 center, V3 up);
M4 Perspective(float y_fov, float aspect, float n, float f);
M4 M4Mul(M4 a, M4 b);
M4 M4Identity(void);
M4 M4Translate(float x, float y, float z);
M4 M4Rotate(float x, float y, float z, float angle);
#endif