Files
wschod/game/src/entity/entity.h
T

61 lines
1.6 KiB
C

#pragma once
/* TODO: In the future, if entities are out of the tick radius, when
they reappear, calculate what would happen to them during the time
they were out of the radius. Useful for growing plants and
whatnot. */
#include <stdbool.h>
typedef struct Entity
{
enum { MESH_QUAD1, MESH_QUAD2, MESH_QUAD_X } mesh_type;
enum { ORIGIN_CENTER, ORIGIN_BOTTOM } origin;
enum { RENDER_NORMAL, RENDER_BILLBOARD_Y, RENDER_BILLBOARD } render_type;
bool visible;
bool dont_cull;
float cull_distance; /* 1 means as far as the terrain goes,
less than 1, for example 0.5, means
half as far as the terrain goes. */
bool wavy;
void *userdata;
void (*on_tick) (struct Entity *self);
bool tick_me_i_dont_care; /* Tick this entity regardless of the
distance and other
predicates. Useful for NPCs. */
vec3 position;
vec3 rotation;
vec3 scale;
/* Use RESPRG to get the int. */
unsigned int program;
/* Use RESTEX to get the int. */
unsigned int texture;
} Entity;
static inline void
entity_compute_aabb (Entity *e, vec3 out_min, vec3 out_max)
{
// The half extent is 1.0f, in that the mesh goes from -1 to 1.
vec3 half = { e->scale[0] * 1.0f, e->scale[1] * 1.0f, e->scale[2] * 1.0f };
out_min[0] = e->position[0] - half[0];
out_max[0] = e->position[0] + half[0];
if (e->origin == ORIGIN_BOTTOM)
{
out_min[1] = e->position[1];
out_max[1] = e->position[1] + 2.0f * half[1];
}
else
{
out_min[1] = e->position[1] - half[1];
out_max[1] = e->position[1] + half[1];
}
out_min[2] = e->position[2] - half[2];
out_max[2] = e->position[2] + half[2];
}