commit 6bcd0b2b0160d63fd2aae98b90b683c735441262
parent f8774ae6ed1618b4b64d2a24e40a2cc33bcece83
Author: William Casarin <jb55@jb55.com>
Date: Fri, 8 May 2020 19:49:15 -0700
chess game
Diffstat:
25 files changed, 357 insertions(+), 119 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,7 +1,7 @@
NAME ?= polyadvent
BIN ?= $(NAME)
PREFIX ?= /usr/local
-DEFS= -DGLFW_INCLUDE_NONE
+DEFS= -DGLFW_INCLUDE_NONE -DDEBUG
# release build lol
# DEFS= -DGLFW_INCLUDE_NONE -DNDEBUG
diff --git a/etc/shaders/chess-piece.v.glsl b/etc/shaders/chess-piece.v.glsl
@@ -0,0 +1,18 @@
+
+#include profile
+
+in vec3 position;
+in vec3 normal;
+
+#include uniforms.glsl
+
+out shader_data {
+#include shadervars.glsl
+} data_out;
+
+void main()
+{
+ vec3 color = piece_color;
+#include standard_vtxos.glsl
+ gl_Position = mvp * v4_pos;
+}
diff --git a/etc/shaders/pbr.glsl b/etc/shaders/pbr.glsl
@@ -40,7 +40,7 @@ vec3 fresnel_schlick(float cos_theta, vec3 F0)
}
vec3 pbr(vec3 albedo, vec3 V, vec3 normal) {
- const float ao = 12.0;
+ const float ao = 15.0;
const float metallic = 0.6;
const float exposure = 0.05;
const float roughness = 0.6;
diff --git a/etc/shaders/shadervars.glsl b/etc/shaders/shadervars.glsl
@@ -5,3 +5,4 @@ vec3 position;
// ivec4 joint_indices;
// vec3 weights;
vec4 shadow_coord;
+vec3 piece_color;
diff --git a/etc/shaders/shadows.glsl b/etc/shaders/shadows.glsl
@@ -42,7 +42,7 @@ vec3 shadow_strength(vec4 position, vec4 normal, vec4 v_shadow_coord) {
&& shadow_sample.y < 1.0;
if (light_dir.z > 0.0 && in_shadow) {
- float factor = 1.0-abs(light_angle);
+ float factor = 1.0-abs(light_angle)*0.2;
// float factor = 1.0;
visibility = vec3(1.0)*factor;
// visibility = shadow_sample;
diff --git a/etc/shaders/standard_vtxos.glsl b/etc/shaders/standard_vtxos.glsl
@@ -4,6 +4,6 @@ vec4 v4_pos = vec4(position, 1.0);
data_out.normal = mat3(transpose(inverse(model))) * normal;
data_out.position = vec3(model * v4_pos);
-data_out.color_smooth = data_out.color = color;
+data_out.color_smooth = data_out.color = color + piece_color * 0.0000001;
data_out.shadow_coord = depth_mvp * v4_pos;
// TODO: move shadow coord calc from frag to here
diff --git a/etc/shaders/uniforms.glsl b/etc/shaders/uniforms.glsl
@@ -13,3 +13,5 @@ uniform mat4 normal_matrix;
uniform vec3 sun_color;
uniform vec3 camera_position;
uniform vec3 light_dir;
+
+uniform vec3 piece_color;
diff --git a/etc/shaders/vertex-color.glsl b/etc/shaders/vertex-color.glsl
@@ -10,6 +10,7 @@ out shader_data {
#include uniforms.glsl
+
void main()
{
#include standard_vtxos.glsl
diff --git a/main.c b/main.c
@@ -13,7 +13,6 @@
#include "quickhull.h"
#include "render.h"
#include "scene.h"
-#include "slab_geom.h"
#include "slab.h"
#include "terrain.h"
#include "uniform.h"
@@ -30,9 +29,11 @@ int main(void)
{
int nsamples;
- int seed = time(NULL);
+ /* int seed = time(NULL); */
+ /* int seed = 1588992474; */
+ int seed = 1589065328;
/* int seed = 42; */
- debug("seed %d\n", seed);
+ printf("seed %d\n", seed);
srand(seed);
struct game game;
@@ -43,7 +44,7 @@ int main(void)
int height = 480;
game_init(&game, width, height);
/* reset_scene(&game); */
- entity_test_scene(&game);
+ chess_scene(&game);
check_gl();
double last = hires_time_in_seconds();
diff --git a/src/chess.c b/src/chess.c
@@ -0,0 +1,234 @@
+
+#include "chess.h"
+
+#include "node.h"
+
+// v1------v0
+// | |
+// | |
+// | |
+// v2------v3
+
+static GLuint quad_indices[] = {0, 1, 2, 0, 2, 3};
+
+
+static GLfloat quad_normals[] = {
+ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, // front
+};
+
+static GLfloat quad_vertices[] = {
+ 0.5, 0.5, 0.5, -0.5, 0.5, 0.5, -0.5,-0.5, 0.5, 0.5,-0.5, 0.5, // v0-v1-v2-v3 front
+};
+
+
+static GLfloat quad_uvs[] =
+ {
+ 1.0, 1.0, // v0
+ 0.0, 1.0, // v1
+ 0.0, 0.0, // v2
+ 1.0, 0.0, // v3
+ };
+
+#define CELL_SIZE 10.0
+
+void make_grid(float *verts, float vert_capacity,
+ u32 *indices, float index_capacity,
+ float *normals, float normal_capacity,
+ float *colors, float color_capacity,
+ int width, int height)
+{
+ int c = 0;
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++, c++) {
+ int grid_ind = y * height + x;
+ int vind = grid_ind * ARRAY_SIZE(quad_vertices);
+ int iind = grid_ind * ARRAY_SIZE(quad_indices);
+ int i = 0;
+
+ for (i = 0; i < 4; i++) {
+ int nv = i*3;
+ assert(vind+2+nv < vert_capacity);
+ assert(vind+2+nv < color_capacity);
+ assert(vind+2+nv < normal_capacity);
+ verts[vind+0+nv] = (quad_vertices[0+nv] + x) * CELL_SIZE;
+ verts[vind+1+nv] = (quad_vertices[1+nv] + y) * CELL_SIZE;
+ verts[vind+2+nv] = quad_vertices[2+nv];
+
+ // recenter
+ verts[vind+0+nv] -= (width * CELL_SIZE)/2.0 - 0.5 * CELL_SIZE;
+ verts[vind+1+nv] -= (height * CELL_SIZE)/2.0 - 0.5 * CELL_SIZE;
+ verts[vind+2+nv] -= 0.5;
+
+ normals[vind+0+nv] = quad_normals[0+nv];
+ normals[vind+1+nv] = quad_normals[1+nv];
+ normals[vind+2+nv] = quad_normals[2+nv];
+
+ float checkers = (x ^ y) & 1;
+ colors[vind+0+nv] = checkers;
+ colors[vind+1+nv] = checkers;
+ colors[vind+2+nv] = checkers;
+ }
+
+ for (i = 0; i < 2; i++) {
+ int nv = i*3;
+ assert(iind+2+nv < index_capacity);
+ indices[iind+0+nv] = quad_indices[0+nv] + 4*c;
+ indices[iind+1+nv] = quad_indices[1+nv] + 4*c;
+ indices[iind+2+nv] = quad_indices[2+nv] + 4*c;
+ }
+ }
+ }
+}
+
+static void make_chessboard_geom(geometry_id *id)
+{
+ struct make_geometry mkgeom;
+ init_make_geometry(&mkgeom);
+
+ static float verts[12*8*8]; // array_size(quad) 12 * 8 * 8
+ static float colors[12*8*8]; // array_size(quad) 12 * 8 * 8
+ static float normals[12*8*8]; // array_size(quad) 12 * 8 * 8
+ static u32 indices[6*8*8]; // array_size(quad) 6 * 8 * 8
+
+ make_grid(verts, ARRAY_SIZE(verts),
+ indices, ARRAY_SIZE(indices),
+ normals, ARRAY_SIZE(normals),
+ colors, ARRAY_SIZE(colors),
+ 8, 8);
+
+ mkgeom.indices = indices;
+ mkgeom.vertices = verts;
+ mkgeom.normals = normals;
+ mkgeom.colors = colors;
+ mkgeom.num_indices = ARRAY_SIZE(indices);
+ mkgeom.num_verts = ARRAY_SIZE(verts)/3;
+ mkgeom.num_uv_components = 0;
+
+ init_id(id);
+ struct geometry *geom = new_geometry(id);
+ make_buffer_geometry(&mkgeom, geom);
+ check_gl();
+}
+
+static void position_piece(struct entity *piece, int x, int y)
+{
+ assert(x < 8);
+ assert(y < 8);
+
+ struct node *node = get_node(&piece->node_id);
+ struct model *model = get_model(&piece->model_id);
+ struct geometry *geom = get_geometry(&model->geom_id);
+ assert(node);
+
+ // reset to a1
+ node->pos[0] = -3.5 * CELL_SIZE;
+ node->pos[1] = -3.5 * CELL_SIZE;
+ node->pos[2] = 0.0;
+
+ node->pos[0] += x * CELL_SIZE;
+ node->pos[1] += y * CELL_SIZE;
+}
+
+static void setup_pieces(node_id *chessboard) {
+ struct model *pirate_officer;
+ get_static_model(model_pirate_officer, &pirate_officer);
+
+ // make pawn model
+ model_id pawn_model_id;
+ init_id(&pawn_model_id);
+ struct model *pawn_model = new_model(&pawn_model_id);
+ pawn_model->geom_id = pirate_officer->geom_id;
+ pawn_model->shader = CHESS_PIECE_PROGRAM;
+
+ // pawns
+ for (int i = 0; i < 16; i++) {
+ struct entity *pawn = new_entity(NULL);
+ struct node *pawn_node = get_node(&pawn->node_id);
+ pawn->model_id = pawn_model_id;
+ pawn->flags |= ENT_IS_WHITE | ENT_CASTS_SHADOWS;
+
+ node_scale(pawn_node, 5.0);
+ if (i >= 8) {
+ pawn->flags &= ~ENT_IS_WHITE;
+ node_rotate(pawn_node, V3(0.0,0.0,135.0));
+ }
+ node_attach(&pawn->node_id, chessboard);
+
+ position_piece(pawn, i % 8, i < 8 ? 1 : 6);
+ }
+
+ for (int i = 0; i < 4; i++) {
+ // rooks
+ struct entity *rook = new_entity(NULL);
+ struct model *rook_model;
+ struct node *rook_node = get_node(&rook->node_id);
+ rook->model_id = get_static_model(model_tower, &rook_model);
+ rook->flags |= ENT_CASTS_SHADOWS | ENT_IS_WHITE;
+ rook_model->shader = CHESS_PIECE_PROGRAM;
+ node_attach(&rook->node_id, chessboard);
+ /* node_rotate(rook_node, V3(0.0,0.0,20.0)); */
+ if (i >= 2) {
+ rook->flags &= ~ENT_IS_WHITE;
+ node_rotate(rook_node, V3(0.0,0.0,135.0));
+ }
+ position_piece(rook, i % 2 ? 0 : 7, i < 2 ? 0 : 7);
+ node_scale(rook_node, 0.25);
+ }
+
+
+}
+
+
+void chess_scene(struct game *game)
+{
+ struct entity *ent = new_entity(NULL);
+ struct node *node = get_node(&ent->node_id); assert(node);
+ struct entity *player = get_player(&game->test_resources);
+
+ ent->model_id = get_static_model(model_icosphere, NULL);
+ node_set_label(node, "sphere");
+
+ //
+ // setup chessboard
+ //
+ geometry_id chessboard_geom;
+ make_chessboard_geom(&chessboard_geom);
+
+ model_id chessboard_model_id;
+ init_id(&chessboard_model_id);
+
+ struct model *chessboard_model = new_model(&chessboard_model_id);
+ chessboard_model->shader = DEFAULT_PROGRAM;
+ chessboard_model->geom_id = chessboard_geom;
+
+ player->model_id = chessboard_model_id;
+ player->flags &= ~ENT_CASTS_SHADOWS;
+
+ //
+ // setup camera
+ //
+ struct spherical *coords = &game->test_resources.orbit_camera.coords;
+ coords->radius = 72.0;
+ coords->inclination = 0.5;
+ coords->azimuth = -7.86;
+
+ struct node *pnode = get_node(&player->node_id);
+ node_translate(pnode, V3(240.0, 252.0, 373.0));
+ pnode->orientation[2] = -0.005;
+ pnode->orientation[3] = -1.0;
+
+ node_id *cam_id = &game->test_resources.orbit_camera.node_id;
+ struct node *cam_node = get_node(cam_id); assert(cam_node);
+
+ setup_pieces(&player->node_id);
+
+ node_recalc(pnode);
+
+ //player 1284.539062 1111.104126 14.273574
+
+ // show terrain
+ //terrain_ent->flags |= ENT_INVISIBLE;
+
+ // show player
+ /* player->flags |= ENT_INVISIBLE; */
+}
diff --git a/src/chess.h b/src/chess.h
@@ -0,0 +1,9 @@
+
+#ifndef POLYADVENT_CHESS_H
+#define POLYADVENT_CHESS_H
+
+#include "game.h"
+
+void chess_scene(struct game *game);
+
+#endif /* POLYADVENT_CHESS_H */
diff --git a/src/entity.h b/src/entity.h
@@ -15,6 +15,7 @@ enum entity_flags {
ENT_INVISIBLE = 1 << 1,
ENT_CASTS_SHADOWS = 1 << 2,
ENT_ON_GROUND = 1 << 3,
+ ENT_IS_WHITE = 1 << 4,
};
struct entity {
diff --git a/src/game.c b/src/game.c
@@ -35,14 +35,6 @@ bool was_button_pressed_this_frame(struct game *game, SDL_GameControllerButton b
return is_button_down_on_frame(&game->input, button, game->frame);
}
-static void camera_update(struct node *node) {
- mat4 *persp = (float*)node->custom_update_data;
- mat4 *mat = (float*)node->mat;
-
- mat4_inverse(mat, mat);
- mat4_multiply(persp, mat, mat);
-}
-
struct entity *get_player(struct resources *res) {
struct entity *player = get_entity(&res->player_id);
assert(player);
@@ -103,7 +95,7 @@ void init_misc(struct game *game, int width, int height) {
game->quit = 0;
game->frame = 0;
- const double size = 5000.0;
+ const double size = 4000.0;
double scale = 0.03;
terrain->settings = (struct perlin_settings){
@@ -144,9 +136,9 @@ void init_misc(struct game *game, int width, int height) {
light_dir[1] = 0.8;
light_dir[2] = 0.8;
- res->sun_color[0] = 1.0;
- res->sun_color[1] = 0.9;
- res->sun_color[2] = 0.8;
+ res->piece_color[0] = 1.0;
+ res->piece_color[1] = 1.0;
+ res->piece_color[2] = 1.0;
res->sun_color[0] = 0.5;
res->sun_color[1] = 0.6;
diff --git a/src/game.h b/src/game.h
@@ -19,14 +19,6 @@
#define MAX_PROGRAMS 12
-enum program_type {
- DEFAULT_PROGRAM,
- TERRAIN_PROGRAM,
- UI_PROGRAM,
- SKYBOX_PROGRAM,
- NUM_PROGRAMS,
-};
-
/*
* Global data used by our render callback:
* NOTE: just for testing right now
@@ -51,6 +43,7 @@ struct resources {
GLint mvp;
GLint normal_matrix;
GLint sky_intensity;
+ GLint piece_color;
GLint sun_color;
GLint time;
GLint view_proj;
@@ -72,6 +65,7 @@ struct resources {
struct skybox skybox;
float sun_color[3];
+ float piece_color[3];
float test_mvp[MAT4_ELEMS];
float light_dir[3];
float light_intensity;
diff --git a/src/model.c b/src/model.c
@@ -20,7 +20,7 @@ static struct resource_manager dyn_modelman;
struct model *init_model(struct model *model) {
init_id(&model->geom_id);
- model->shading = SHADING_VERT_COLOR;
+ model->shader = DEFAULT_PROGRAM;
model->texture = 0;
model->nposes = 0;
for (u16 i = 0; i < ARRAY_SIZE(model->poses); i++) {
@@ -95,7 +95,7 @@ static struct model *load_static_model(enum static_model m)
}
// Load mesh
- debug("loading %s model with geom_id ", static_model_defs[m].file);
+ debug("loading %s model with geom_id\n", static_model_defs[m].file);
assert(m < NUM_STATIC_MODELS);
snprintf(path, 128, "data/models/%s.mdl", static_model_defs[m].file);
diff --git a/src/model.h b/src/model.h
@@ -17,16 +17,20 @@
typedef struct resource_id model_id;
-enum shading {
- SHADING_TERRAIN,
- SHADING_VERT_COLOR,
- SHADING_UI,
+enum program_type {
+ DEFAULT_PROGRAM,
+ TERRAIN_PROGRAM,
+ UI_PROGRAM,
+ SKYBOX_PROGRAM,
+ CHESS_PIECE_PROGRAM,
+ NUM_PROGRAMS,
};
+
struct model {
/* geometry_id geom_id; */
geometry_id geom_id;
- enum shading shading;
+ enum program_type shader;
struct pose poses[MAX_POSES]; // TODO: separate animated_model buffer?
int nposes;
u32 texture;
diff --git a/src/node.c b/src/node.c
@@ -213,6 +213,7 @@ int node_count(struct node *node)
return c;
}
+
void node_attach(struct resource_id *node_id, struct resource_id *to_id)
{
struct node *node = get_node(node_id);
diff --git a/src/node.h b/src/node.h
@@ -4,7 +4,7 @@
#include "resource.h"
-#define MAX_NODE_CHILDREN 4
+#define MAX_NODE_CHILDREN 20
enum node_flags {
NODE_IGNORE_RECALC = 1 << 0
diff --git a/src/render.c b/src/render.c
@@ -64,7 +64,7 @@ static const float bias_matrix[] = {
void
init_gl(struct resources *resources, int width, int height) {
- struct shader vertex, terrain_vertex, terrain_geom, fragment, fragment_smooth;
+ struct shader vertex, terrain_vertex, chess_piece_vertex, terrain_geom, fragment, fragment_smooth;
struct shader terrain_teval, terrain_tc;
float tmp_matrix[16];
int ok = 0;
@@ -80,24 +80,13 @@ init_gl(struct resources *resources, int width, int height) {
ok = make_shader(GL_VERTEX_SHADER, SHADER("vertex-color.glsl"), &vertex);
rtassert(ok, "vertex-color shader");
- ok = make_shader(GL_VERTEX_SHADER, SHADER("terrain.v.glsl"),
- &terrain_vertex);
+ ok = make_shader(GL_VERTEX_SHADER, SHADER("terrain.v.glsl"), &terrain_vertex);
rtassert(ok, "terrain vertex shader");
check_gl();
- /* ok = make_shader(GL_GEOMETRY_SHADER, SHADER("terrain.g.glsl"), */
- /* &terrain_geom); */
- /* assert(ok && "terrain geometry shader"); */
-
- /* ok = make_shader(GL_TESS_CONTROL_SHADER, SHADER("terrain.tc.glsl"), */
- /* &terrain_tc); */
- /* assert(ok && "terrain tessellation control shader"); */
- /* check_gl(); */
-
- /* ok = make_shader(GL_TESS_EVALUATION_SHADER, SHADER("terrain.te.glsl"), */
- /* &terrain_teval); */
- /* assert(ok && "terrain tessellation eval shader"); */
- /* check_gl(); */
+ ok = make_shader(GL_VERTEX_SHADER, SHADER("chess-piece.v.glsl"), &chess_piece_vertex);
+ rtassert(ok, "chess-piece vertex shader");
+ check_gl();
ok = make_shader(GL_FRAGMENT_SHADER, SHADER("main.f.glsl"), &fragment);
rtassert(ok, "default fragment shader");
@@ -110,17 +99,6 @@ init_gl(struct resources *resources, int width, int height) {
5000,
resources->proj_persp);
- /* Shader program */
- /* struct shader *terrain_shaders[] = */
- /* { &terrain_vertex, &fragment, &terrain_tc, &terrain_teval, */
- /* &terrain_geom }; */
-
- /* struct shader *terrain_shaders[] = */
- /* { &terrain_vertex, &fragment, &terrain_tc, &terrain_teval }; */
-
- /* struct shader *terrain_shaders[] = */
- /* { &terrain_vertex, &fragment, &terrain_geom }; */
-
struct shader *terrain_shaders[] =
{ &terrain_vertex, &fragment };
@@ -135,9 +113,15 @@ init_gl(struct resources *resources, int width, int height) {
rtassert(ok, "vertex-color program");
check_gl();
+ ok = make_program(&chess_piece_vertex, &fragment, &resources->programs[CHESS_PIECE_PROGRAM]);
+ rtassert(ok, "chess-piece program");
+ check_gl();
+
+ // Program variables
GLuint programs[] =
{ resources->programs[TERRAIN_PROGRAM].handle
, resources->programs[DEFAULT_PROGRAM].handle
+ , resources->programs[CHESS_PIECE_PROGRAM].handle
};
// uniforms shared between all shaders
@@ -149,6 +133,10 @@ init_gl(struct resources *resources, int width, int height) {
glGetUniformLocation(handle, "camera_position");
check_gl();
+ // TODO: more flexible uniforms
+ resources->uniforms.piece_color = glGetUniformLocation(handle, "piece_color");
+ check_gl();
+
/* resources->uniforms.depth_vp = */
/* glGetUniformLocation(handle, "depth_vp"); */
/* check_gl(); */
@@ -156,6 +144,10 @@ init_gl(struct resources *resources, int width, int height) {
resources->uniforms.depth_mvp =
glGetUniformLocation(handle, "depth_mvp");
check_gl();
+ resources->uniforms.camera_position =
+ glGetUniformLocation(handle, "camera_position");
+ check_gl();
+
resources->uniforms.light_intensity =
glGetUniformLocation(handle, "light_intensity");
@@ -214,6 +206,7 @@ init_gl(struct resources *resources, int width, int height) {
resources->vertex_attrs[va_color] =
(gpu_addr)glGetAttribLocation(resources->programs[DEFAULT_PROGRAM]
.handle, "color");
+
/* assert(resources->attributes.color != 0xFFFFFFFF); */
check_gl();
}
@@ -273,14 +266,6 @@ void render (struct game *game, struct render_config *config) {
struct gpu_program *current_program = NULL;
- struct gpu_program *terrain_program =
- &game->test_resources.programs[TERRAIN_PROGRAM];
-
- struct gpu_program *default_program =
- &game->test_resources.programs[DEFAULT_PROGRAM];
-
- /* mat4_multiply(view_proj, res->skybox.node.mat, mvp); */
-
mat4_inverse((float*)camera, view);
mat4_multiply(projection, view, view_proj);
@@ -303,6 +288,8 @@ void render (struct game *game, struct render_config *config) {
for (u32 i = 0; i < num_entities; ++i) {
struct entity *entity = &entities[i];
+ struct model *model = get_model(&entity->model_id);
+ assert(model);
if (entity->flags & ENT_INVISIBLE)
continue;
@@ -310,16 +297,22 @@ void render (struct game *game, struct render_config *config) {
if (config->is_depth_pass && !(entity->flags & ENT_CASTS_SHADOWS))
continue;
- // TODO this is a bit wonky, refactor this
- current_program = i == 0 ? terrain_program : default_program;
+ current_program = &game->test_resources.programs[model->shader];
+
glUseProgram(current_program->handle);
check_gl();
-
glUniform3f(res->uniforms.camera_position,
camera[M_X],
camera[M_Y],
camera[M_Z]);
+ check_gl();
+
+ if (entity->flags & ENT_IS_WHITE)
+ glUniform3f(res->uniforms.piece_color, 0.9f, 0.9f, 0.9f);
+ else
+ glUniform3f(res->uniforms.piece_color, 0.2f, 0.2f, 0.2f);
+ check_gl();
glUniform1i(res->uniforms.fog_on, res->fog_on);
check_gl();
@@ -359,8 +352,6 @@ void render (struct game *game, struct render_config *config) {
recalc_normals(res->uniforms.normal_matrix, model_view, normal_matrix);
check_gl();
- struct model *model = get_model(&entity->model_id);
- assert(model);
struct geometry *geo = get_geometry(&model->geom_id);
/* debug("geo node %s\n", node->label); */
assert(geo);
diff --git a/src/scene.h b/src/scene.h
@@ -8,5 +8,6 @@ void default_scene(struct game *);
void reset_scene(struct game *);
void entity_test_scene(struct game *);
void pbr_scene(struct game *);
+void chess_scene(struct game *);
#endif /* SCENE_H */
diff --git a/src/slab_geom.h b/src/slab_geom.h
@@ -1,18 +0,0 @@
-
-#ifndef SLAB_GEOM
-#define SLAB_GEOM
-
-#include "geometry.h"
-#include "slab.h"
-#include <stddef.h>
-
-struct geometry*
-slab_alloc_arrays(const struct slab *slab,
- struct geometry *geom,
- void* (*_realloc)(void*, size_t));
-
-void
-slab_free_arrays(struct geometry *geom,
- void (*_free)(void*));
-
-#endif // SLAB_GEOM
diff --git a/src/terrain.c b/src/terrain.c
@@ -64,7 +64,7 @@ void init_terrain(struct terrain *terrain, float size) {
assert(terrain->entity_id.index == 0);
- model->shading = SHADING_TERRAIN;
+ model->shader = TERRAIN_PROGRAM;
node_set_label(node, "terrain");
ent->flags &= ~ENT_CASTS_SHADOWS;
@@ -255,7 +255,7 @@ void create_terrain(struct terrain *terrain, float scale, int seed) {
// clamp height at edge
double d = distance_to_closest_edge(size, x, y);
- z *= d / (size/2.0);
+ z *= (d / (size/2.0)) * 2.0;
struct terrain_cell *cell =
index_terrain_cell(terrain, grid_x, grid_y);
diff --git a/src/ui.c b/src/ui.c
@@ -42,7 +42,7 @@ static void create_quad(geometry_id *id)
.normals = quad_normals,
.tex_coords = quad_uvs,
.num_indices = ARRAY_SIZE(quad_indices),
- .num_verts = ARRAY_SIZE(quad_vertices),
+ .num_verts = ARRAY_SIZE(quad_vertices)/3,
.num_uv_components = 2
};
init_id(id);
diff --git a/src/update.c b/src/update.c
@@ -89,13 +89,18 @@ static void movement(struct game *game, struct node *node, float speed_mult)
/* node_translate(node, V3(0, 0, -amt)); */
if (was_key_pressed_this_frame(game, SDL_SCANCODE_P)) {
- debug("%f %f %f ",
+ debug("player %f %f %f quat %f %f %f %f\n",
node->pos[0],
node->pos[1],
- node->pos[2]);
- node_recalc(node);
- grid_pos_debug(node->label, &game->terrain, node_world(node));
- /* mat4_print(node->mat); */
+ node->pos[2],
+ node->orientation[0],
+ node->orientation[1],
+ node->orientation[2],
+ node->orientation[3]
+ );
+ struct spherical *cam = &game->test_resources.orbit_camera.coords;
+ debug("camera settings radius %f inc %f azimuth %f\n",
+ cam->radius, cam->inclination, cam->azimuth);
}
}
@@ -182,7 +187,7 @@ void resize_fbos(struct entity *player, struct fbo *shadow_buffer,
}
// TODO: compute better bounds based
- const float factor = 5.5;
+ const float factor = 40.5;
struct model *model = get_model(&player->model_id); assert(model);
struct geometry *geom = get_geometry(&model->geom_id); assert(geom);
@@ -190,15 +195,15 @@ void resize_fbos(struct entity *player, struct fbo *shadow_buffer,
float left = geom->min[0] - factor;
float right = geom->max[0] + factor;
float bottom = geom->min[1] - factor;
- float top = geom->max[1] + factor/2.0;
+ float top = geom->max[1] + factor;
/* float left = -factor; */
/* float right = factor; */
/* float bottom = factor; */
/* float top = -factor; */
- const float near = -5.0;
- const float far = 5.0;
+ const float near = -50.0;
+ const float far = 50.0;
// default ortho screenspace projection
mat4_ortho(left, right, bottom, top, near, far, m4_ortho);
@@ -299,8 +304,8 @@ void orbit_update_from_mouse(struct orbit *camera, struct input *input,
node_recalc(target_node);
vec3_copy(node_world(target_node), target);
- assert(player_geom->max[2] != 0);
- vec3_add(target, V3(0.0, 0.0, player_geom->max[2]), target);
+ /* assert(player_geom->max[2] != 0); */
+ vec3_add(target, V3(0.0, 0.0, -15.0), target);
/* vec3_add(target, V3(0.0, 0.0, 10.0), target); */
float mx = 0.0, my = 0.0;
@@ -381,7 +386,7 @@ static void player_update(struct game *game, struct entity *player)
orbit_update_from_mouse(camera, &game->input, game->user_settings.mouse_sens,
player, game->dt);
- camera_keep_above_ground(&game->terrain, cam_node);
+ /* camera_keep_above_ground(&game->terrain, cam_node); */
// move player camera toward camera orientation
if (input_is_dragging(&game->input, SDL_BUTTON_RIGHT)) {
@@ -398,7 +403,8 @@ static void player_update(struct game *game, struct entity *player)
float pen;
vec3_copy(node_world(node), pos);
/* debug("node_world(player) %f %f %f\n", pos[0], pos[1], pos[2]); */
- struct tri *tri = collide_terrain(terrain, pos, move, &pen);
+ /* struct tri *tri = collide_terrain(terrain, pos, move, &pen); */
+ struct tri *tri = NULL;
/* node_translate(node, move); */
if (tri) {
@@ -416,14 +422,14 @@ static void player_update(struct game *game, struct entity *player)
}
else {
static int tric = 0;
- debug("%d no tri\n", tric++);
+ /* debug("%d no tri\n", tric++); */
}
- if (player->flags & ENT_ON_GROUND &&
- (was_key_pressed_this_frame(game, SDL_SCANCODE_SPACE) ||
- was_button_pressed_this_frame(game, SDL_CONTROLLER_BUTTON_X))) {
- entity_jump(player, 2.0);
- }
+ /* if (player->flags & ENT_ON_GROUND && */
+ /* (was_key_pressed_this_frame(game, SDL_SCANCODE_SPACE) || */
+ /* was_button_pressed_this_frame(game, SDL_CONTROLLER_BUTTON_X))) { */
+ /* entity_jump(player, 2.0); */
+ /* } */
/* debug("player velocity %f %f %f\n", */
/* player->velocity[0], */
@@ -433,7 +439,7 @@ static void player_update(struct game *game, struct entity *player)
/* if (player->flags & ENT_AT_REST) */
/* vec3_scale(player->velocity, 0.00001, player->velocity); */
- node_translate(node, player->velocity);
+ /* node_translate(node, player->velocity); */
node_recalc(node);
}
@@ -443,7 +449,7 @@ void update (struct game *game) {
static int toggle_fog = 0;
static int needs_terrain_update = 0;
struct resources *res = &game->test_resources;
- struct terrain *terrain = &game->terrain;
+ /* struct terrain *terrain = &game->terrain; */
struct node *root = get_node(&game->test_resources.root_id);
struct entity *player = get_player(res);
struct node *pnode = get_node(&player->node_id);
diff --git a/src/window.c b/src/window.c
@@ -11,7 +11,7 @@ void
handle_resize(struct game *game, int width, int height) {
/* printf("resizing %d %d\n", width, height); */
glViewport( 0, 0, width, height );
- mat4_perspective(75 /* fov */, (float)width / height, 0.1, 10000.0,
+ mat4_perspective(60 /* fov */, (float)width / height, 0.1, 10000.0,
game->test_resources.proj_persp);
resize_fbos(get_entity(&game->test_resources.player_id),