#include <stdio.h>
#include <stdlib.h>
+#include "client/frustum.h"
#include "client/object.h"
#include "client/scene.h"
-#define OBJECT_VERTEX_ATTRIBUTES 4
+#define OBJECT_VERTEX_ATTRIBUTES 5
static VertexAttribute vertex_attributes[OBJECT_VERTEX_ATTRIBUTES] = {
// position
.length = 3,
.size = sizeof(Vertex3DPosition),
},
+ // normal
+ {
+ .type = GL_FLOAT,
+ .length = 3,
+ .size = sizeof(Vertex3DNormal),
+ },
// textureIndex
{
.type = GL_FLOAT,
obj->meshes_count = 0;
obj->visible = true;
obj->wireframe = false;
- obj->box = (aabb3f32) {{0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}};
obj->frustum_culling = false;
+ obj->transparent = false;
+ obj->box = (aabb3f32) {{0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}};
obj->current_face = NULL;
obj->faces = array_create(sizeof(ObjectFace));
+ obj->on_render = NULL;
+ obj->extra = NULL;
return obj;
}
mat4x4_scale_aniso(obj->transform, obj->transform, obj->scale.x, obj->scale.y, obj->scale.z);
#pragma GCC diagnostic pop
}
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wpedantic"
-static bool inside_frustum(aabb3f32 box, mat4x4 MVP)
-{
- for (int x = 0; x <= 1; x++) {
- for (int y = 0; y <= 1; y++) {
- for (int z = 0; z <= 1; z++) {
- vec4 point = {x ? box.min.x : box.max.x, y ? box.min.y : box.max.y, z ? box.min.z : box.max.z, 1.0};
- vec4 point_NDC;
- mat4x4_mul_vec4(point_NDC, MVP, point);
-
- for (int j = 0; j < 3; j++) {
- float f = point_NDC[j];
-
- if (f > -1.0f && f > 1.0f)
- return true;
- }
- }
- }
- }
-
- return false;
-}
-#pragma GCC diagnostic pop
-
-void object_render(Object *obj, mat4x4 view_proj, GLint loc_MVP)
+bool object_before_render(Object *obj, f64 dtime)
{
+ if (obj->on_render)
+ obj->on_render(obj, dtime);
+
if (! obj->visible)
- return;
+ return false;
- mat4x4 MVP;
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wpedantic"
- mat4x4_mul(MVP, view_proj, obj->transform);
-#pragma GCC diagnostic pop
+ if (obj->frustum_culling) {
+ aabb3f32 box = {v3f32_add(obj->box.min, obj->pos), v3f32_add(obj->box.max, obj->pos), };
- if (obj->frustum_culling && ! inside_frustum(obj->box, MVP))
- return;
+ if (! frustum_is_visible(box))
+ return false;
+ }
- glUniformMatrix4fv(loc_MVP, 1, GL_FALSE, MVP[0]);
+ return true;
+}
+
+void object_render(Object *obj)
+{
+ glUniformMatrix4fv(scene.loc_model, 1, GL_FALSE, obj->transform[0]);
if (obj->wireframe)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);