sources ::= main.c \
engine/asset.c \
+ engine/geometry.c \
engine/logger.c \
engine/performance.c \
engine/render.c \
--- /dev/null
+#include <stddef.h>
+
+#include "geometry.h"
+
+Transform identity() {
+ return (Transform) { .a1 = 1.0f, .a2 = 0.0f, .a3 = 0.0f, .a4 = 0.0f,
+ .b1 = 0.0f, .b2 = 1.0f, .b3 = 0.0f, .b4 = 0.0f,
+ .c1 = 0.0f, .c2 = 0.0f, .c3 = 1.0f, .c4 = 0.0f,
+ .d1 = 0.0f, .d2 = 0.0f, .d3 = 0.0f, .d4 = 1.0f };
+}
+
+void multiply(Transform* transform, Transform by) {
+ GLfloat* a = (GLfloat*) &by;
+ GLfloat* b = (GLfloat*) transform;
+
+ for (size_t row = 0; row < 4; ++row) {
+ for (size_t col = 0; col < 4; ++col) {
+ b[(row * 4) + col] =
+ a[(row * 4) + 0] * b[(0 * 4) + col]
+ + a[(row * 4) + 1] * b[(1 * 4) + col]
+ + a[(row * 4) + 2] * b[(2 * 4) + col]
+ + a[(row * 4) + 3] * b[(3 * 4) + col];
+ }
+ }
+}
+
+void translate(Transform* transform, Vector3D vec) {
+ multiply(transform, (Transform) { .a1 = 1.0f, .a2 = 0.0f, .a3 = 0.0f, .a4 = vec.x,
+ .b1 = 0.0f, .b2 = 1.0f, .b3 = 0.0f, .b4 = vec.y,
+ .c1 = 0.0f, .c2 = 0.0f, .c3 = 1.0f, .c4 = vec.z,
+ .d1 = 0.0f, .d2 = 0.0f, .d3 = 0.0f, .d4 = 1.0f });
+}
+
+Vector3D translationOf(Transform transform) {
+ return (Vector3D) { transform.a4, transform.b4, transform.c4 };
+}
#ifndef GEOMETRY_H_
#define GEOMETRY_H_
+#include <GL/gl.h>
+
typedef struct Vector3D Vector3D;
+typedef struct Transform Transform;
struct Vector3D {
float x;
float z;
};
+struct Transform {
+ GLfloat a1, a2, a3, a4;
+ GLfloat b1, b2, b3, b4;
+ GLfloat c1, c2, c3, c4;
+ GLfloat d1, d2, d3, d4;
+};
+
+Transform identity();
+void translate(Transform* transform, Vector3D vec);
+Vector3D translationOf(Transform transform);
+
#endif
#include "engine/logger.h"
+#include "geometry.h"
#include "scene.h"
Scene* currentScene = NULL;
-Transform identity() {
- return (Transform) { .a1 = 1.0f, .a2 = 0.0f, .a3 = 0.0f, .a4 = 0.0f,
- .b1 = 0.0f, .b2 = 1.0f, .b3 = 0.0f, .b4 = 0.0f,
- .c1 = 0.0f, .c2 = 0.0f, .c3 = 1.0f, .c4 = 0.0f,
- .d1 = 0.0f, .d2 = 0.0f, .d3 = 0.0f, .d4 = 1.0f };
-}
-
-void multiply(Transform* transform, Transform by) {
- GLfloat* a = (GLfloat*) &by;
- GLfloat* b = (GLfloat*) transform;
-
- for (size_t row = 0; row < 4; ++row) {
- for (size_t col = 0; col < 4; ++col) {
- b[(row * 4) + col] =
- a[(row * 4) + 0] * b[(0 * 4) + col]
- + a[(row * 4) + 1] * b[(1 * 4) + col]
- + a[(row * 4) + 2] * b[(2 * 4) + col]
- + a[(row * 4) + 3] * b[(3 * 4) + col];
- }
- }
-}
-
-void translate(Transform* transform, Vector3D vec) {
- multiply(transform, (Transform) { .a1 = 1.0f, .a2 = 0.0f, .a3 = 0.0f, .a4 = vec.x,
- .b1 = 0.0f, .b2 = 1.0f, .b3 = 0.0f, .b4 = vec.y,
- .c1 = 0.0f, .c2 = 0.0f, .c3 = 1.0f, .c4 = vec.z,
- .d1 = 0.0f, .d2 = 0.0f, .d3 = 0.0f, .d4 = 1.0f });
-}
-
-Vector3D translationOf(Transform transform) {
- return (Vector3D) { transform.a4, transform.b4, transform.c4 };
-}
-
Scene* newScene() {
Scene* scene = malloc(sizeof(Scene));
*scene = (Scene) { .parent = NULL,
#include "asset.h"
typedef struct Scene Scene;
-typedef struct Transform Transform;
-
-struct Transform {
- GLfloat a1, a2, a3, a4;
- GLfloat b1, b2, b3, b4;
- GLfloat c1, c2, c3, c4;
- GLfloat d1, d2, d3, d4;
-};
struct Scene {
Scene* parent;
Scene* currentScene;
-Transform identity();
-void translate(Transform* transform, Vector3D vec);
-Vector3D translationOf(Transform transform);
-
Scene* newScene();
void insertChildScene(Scene* scene, Scene* newChild);
void reparentScene(Scene* scene, Scene* newParent);
#include <GL/gl.h>
-#include "engine/geometry.h"
#include "engine/scene.h"
Scene* playerCharacter;