]> git.lizzy.rs Git - shadowclad.git/blob - src/engine/geometry.h
Add copyright and license notices in source code
[shadowclad.git] / src / engine / geometry.h
1 /**
2  * Copyright 2018-2020 Iwo 'Outfrost' Bujkiewicz
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8
9 #ifndef ENGINE_GEOMETRY_H_
10 #define ENGINE_GEOMETRY_H_
11
12 #include <GL/gl.h>
13
14 typedef struct Vector Vector;
15 typedef struct Transform Transform;
16
17 struct Vector {
18         float x;
19         float y;
20         float z;
21 };
22
23 struct Transform {
24         GLfloat a1, a2, a3, a4;
25         GLfloat b1, b2, b3, b4;
26         GLfloat c1, c2, c3, c4;
27         GLfloat d1, d2, d3, d4;
28 };
29
30 static const float TAU = 6.28318530718f;
31
32 Transform identity();
33 Transform multiply(Transform t1, Transform t2);
34 void translate(Transform* transform, Vector vec);
35 void rotate(Transform* transform, Vector axis, float angle);
36 Vector addVectors(Vector v1, Vector v2);
37 Vector subtractVectors(Vector v1, Vector v2);
38 Vector crossProduct(Vector v1, Vector v2);
39 float dotProduct(Vector v1, Vector v2);
40 Vector scaleVector(Vector vec, float scale);
41 Vector growVectorNoFlip(Vector vec, float amount);
42 Vector clampMagnitude(Vector vec, float maxMagnitude);
43 float magnitude(Vector vec);
44 Vector applyTransform(Transform transform, Vector vec);
45 Vector translationOf(Transform transform);
46 Vector normalized(Vector vec);
47
48 #endif // ENGINE_GEOMETRY_H_