Tree model test
This commit is contained in:
parent
ccc017c647
commit
a2d38044f0
2
haloo3d
2
haloo3d
@ -1 +1 @@
|
|||||||
Subproject commit 46a3dd12d7f3f7d2a204fe4c5efa3cb5336bb187
|
Subproject commit d5cd80d67cacec466968aa846883e2dd10db3a38
|
65
terrain.c
65
terrain.c
@ -36,13 +36,17 @@
|
|||||||
#define INIT_NEARCLIP 0.01
|
#define INIT_NEARCLIP 0.01
|
||||||
#define INIT_FARCLIP 100.0
|
#define INIT_FARCLIP 100.0
|
||||||
|
|
||||||
#define MAXCHUNKPERFRAME 5
|
#define MAXCHUNKPERFRAME 50
|
||||||
|
|
||||||
// Generation consts / things for looks
|
// Generation consts / things for looks
|
||||||
#define LANDCOL 0xF6D2 // 0xF4E1
|
#define LANDCOL 0xF6D2 // 0xF4E1
|
||||||
#define SEACOL 0xF28D // 0xF26C
|
#define SEACOL 0xF28D // 0xF26C
|
||||||
#define LANDHEIGHT 4.0
|
#define LANDHEIGHT 4.0
|
||||||
#define SKYCOL 0xF97F // 0xF77F
|
#define SKYCOL 0xF97F // 0xF77F
|
||||||
|
#define TREECOL 0xF070
|
||||||
|
#define TREETRUNKCOL 0xF950
|
||||||
|
#define TREEBOTTOM -0.333
|
||||||
|
#define TREETRUNKWIDTH 0.2
|
||||||
#define SEATRANS 0.75
|
#define SEATRANS 0.75
|
||||||
#define INIT_LIGHTPITCH MPI_2 * 1.65
|
#define INIT_LIGHTPITCH MPI_2 * 1.65
|
||||||
#define INIT_LIGHTYAW MPI_2 * 0.65
|
#define INIT_LIGHTYAW MPI_2 * 0.65
|
||||||
@ -55,7 +59,7 @@
|
|||||||
#define INIT_CAMPITCH MPI_2 * 1.3 // MPI_2 * 1.6 // 1.575
|
#define INIT_CAMPITCH MPI_2 * 1.3 // MPI_2 * 1.6 // 1.575
|
||||||
#define INIT_PLAYERHEIGHT 0.65
|
#define INIT_PLAYERHEIGHT 0.65
|
||||||
#define INIT_PLAYERSPEED \
|
#define INIT_PLAYERSPEED \
|
||||||
{ .x = 0, .y = 0, .z = -4.5 }
|
{ .x = 0, .y = 0, .z = -1.5 }
|
||||||
|
|
||||||
#define RANDF() ((float)rand() / RAND_MAX)
|
#define RANDF() ((float)rand() / RAND_MAX)
|
||||||
|
|
||||||
@ -63,6 +67,7 @@
|
|||||||
int fps = 60;
|
int fps = 60;
|
||||||
|
|
||||||
#define PALETTEKEY "palette"
|
#define PALETTEKEY "palette"
|
||||||
|
#define TREEKEY "tree"
|
||||||
|
|
||||||
void fastface(haloo3d_facei face, uint16_t tex, uint16_t v0, uint16_t v1,
|
void fastface(haloo3d_facei face, uint16_t tex, uint16_t v0, uint16_t v1,
|
||||||
uint16_t v2) {
|
uint16_t v2) {
|
||||||
@ -76,8 +81,49 @@ void fastface(haloo3d_facei face, uint16_t tex, uint16_t v0, uint16_t v1,
|
|||||||
|
|
||||||
static int gen_terrain_seed = 0;
|
static int gen_terrain_seed = 0;
|
||||||
|
|
||||||
void gen_terrain(struct vec3i pos, haloo3d_obj *model) {
|
void gen_tree_model(haloo3d_obj *tree) {
|
||||||
|
haloo3d_obj_resetfixed(tree, 12, 24);
|
||||||
|
struct vec3 treecol = haloo3d_gen_paletteuv(TREECOL);
|
||||||
|
int treeuv = haloo3d_obj_addvtexture(tree, treecol);
|
||||||
|
struct vec3 trunkcol = haloo3d_gen_paletteuv(TREETRUNKCOL);
|
||||||
|
int trunkuv = haloo3d_obj_addvtexture(tree, trunkcol);
|
||||||
|
uint16_t top = haloo3d_obj_addvertex(
|
||||||
|
tree, (struct vec4){.x = 0, .y = 1, .z = 0, .w = 1});
|
||||||
|
uint16_t tree1 = haloo3d_obj_addvertex(
|
||||||
|
tree, (struct vec4){.x = -1, .y = TREEBOTTOM, .z = -1, .w = 1});
|
||||||
|
uint16_t tree2 = haloo3d_obj_addvertex(
|
||||||
|
tree, (struct vec4){.x = 1, .y = TREEBOTTOM, .z = -1, .w = 1});
|
||||||
|
uint16_t tree3 = haloo3d_obj_addvertex(
|
||||||
|
tree, (struct vec4){.x = 0, .y = TREEBOTTOM, .z = 1, .w = 1});
|
||||||
|
uint16_t trunk1 = haloo3d_obj_addvertex(
|
||||||
|
tree, (struct vec4){
|
||||||
|
.x = -TREETRUNKWIDTH, .y = -1, .z = -TREETRUNKWIDTH, .w = 1});
|
||||||
|
uint16_t trunk2 = haloo3d_obj_addvertex(
|
||||||
|
tree, (struct vec4){
|
||||||
|
.x = TREETRUNKWIDTH, .y = -1, .z = -TREETRUNKWIDTH, .w = 1});
|
||||||
|
uint16_t trunk3 = haloo3d_obj_addvertex(
|
||||||
|
tree, (struct vec4){.x = 0, .y = -1, .z = TREETRUNKWIDTH, .w = 1});
|
||||||
|
|
||||||
|
haloo3d_facei face;
|
||||||
|
fastface(face, treeuv, top, tree1, tree3);
|
||||||
|
haloo3d_obj_addface(tree, face);
|
||||||
|
fastface(face, treeuv, top, tree3, tree2);
|
||||||
|
haloo3d_obj_addface(tree, face);
|
||||||
|
fastface(face, treeuv, top, tree2, tree1);
|
||||||
|
haloo3d_obj_addface(tree, face);
|
||||||
|
fastface(face, trunkuv, top, trunk1, trunk3);
|
||||||
|
haloo3d_obj_addface(tree, face);
|
||||||
|
fastface(face, trunkuv, top, trunk3, trunk2);
|
||||||
|
haloo3d_obj_addface(tree, face);
|
||||||
|
fastface(face, trunkuv, top, trunk2, trunk1);
|
||||||
|
haloo3d_obj_addface(tree, face);
|
||||||
|
haloo3d_obj_shrinktofit(tree);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gen_terrain(struct vec3i pos, haloo3d_obj *model,
|
||||||
|
haloo3d_easystore *storage) {
|
||||||
eprintf("Generating terrain at %d,%d\n", pos.x, pos.z);
|
eprintf("Generating terrain at %d,%d\n", pos.x, pos.z);
|
||||||
|
haloo3d_obj *tree = haloo3d_easystore_getobj(storage, TREEKEY);
|
||||||
// Don't allow the model to have more than some amount of faces/vertices.
|
// Don't allow the model to have more than some amount of faces/vertices.
|
||||||
haloo3d_obj_resetfixed(model, CHUNKVSIZE * CHUNKVSIZE * 4,
|
haloo3d_obj_resetfixed(model, CHUNKVSIZE * CHUNKVSIZE * 4,
|
||||||
CHUNKVSIZE * CHUNKVSIZE * 4);
|
CHUNKVSIZE * CHUNKVSIZE * 4);
|
||||||
@ -94,7 +140,7 @@ void gen_terrain(struct vec3i pos, haloo3d_obj *model) {
|
|||||||
for (int x = 0; x < CHUNKVSIZE; x++) {
|
for (int x = 0; x < CHUNKVSIZE; x++) {
|
||||||
// clang-format off
|
// clang-format off
|
||||||
haloo3d_obj_addvertex(model,
|
haloo3d_obj_addvertex(model,
|
||||||
(struct vec4){.x = x, .y = fnlGetNoise2D(&ns, noisex + x, noisey + z), .z = -z });
|
(struct vec4){.x = x, .y = fnlGetNoise2D(&ns, noisex + x, noisey + z), .z = -z, .w = 1 });
|
||||||
//(struct vec4){.x = x, .y = 2 * RANDF() - 1, .z = -z});
|
//(struct vec4){.x = x, .y = 2 * RANDF() - 1, .z = -z});
|
||||||
// clang-format on
|
// clang-format on
|
||||||
}
|
}
|
||||||
@ -113,6 +159,12 @@ void gen_terrain(struct vec3i pos, haloo3d_obj *model) {
|
|||||||
fastface(face, landuv, br, tr, tl);
|
fastface(face, landuv, br, tr, tl);
|
||||||
haloo3d_obj_addface(model, face);
|
haloo3d_obj_addface(model, face);
|
||||||
}
|
}
|
||||||
|
haloo3d_obj_addobj(model, tree,
|
||||||
|
(struct vec3){.x = CHUNKSIZE / 2.0,
|
||||||
|
.y = LANDHEIGHT,
|
||||||
|
.z = CHUNKSIZE / 2.0},
|
||||||
|
(struct vec3)DEFAULTLOOK, (struct vec3)DEFAULTUP,
|
||||||
|
(struct vec3){.x = 1.0, .y = 1.0, .z = 1.0});
|
||||||
haloo3d_obj_shrinktofit(model);
|
haloo3d_obj_shrinktofit(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +179,7 @@ void gen_chunk(render_context *ctx, tecs *ecs, struct vec3i pos) {
|
|||||||
sprintf(garbage.dynmodel, "e%d", id);
|
sprintf(garbage.dynmodel, "e%d", id);
|
||||||
haloo3d_obj *model =
|
haloo3d_obj *model =
|
||||||
haloo3d_easystore_addobj(&ecs->storage, garbage.dynmodel);
|
haloo3d_easystore_addobj(&ecs->storage, garbage.dynmodel);
|
||||||
gen_terrain(pos, model);
|
gen_terrain(pos, model, &ecs->storage);
|
||||||
ECS_SETCOMPONENT(ecs, id, ecs_playergarbage) garbage;
|
ECS_SETCOMPONENT(ecs, id, ecs_playergarbage) garbage;
|
||||||
ECS_SETCOMPONENT(ecs, id, ecs_chunk){.pos = pos};
|
ECS_SETCOMPONENT(ecs, id, ecs_chunk){.pos = pos};
|
||||||
ECS_SETCOMPONENT(ecs, id,
|
ECS_SETCOMPONENT(ecs, id,
|
||||||
@ -501,6 +553,7 @@ int main() { // int argc, char **argv) {
|
|||||||
context.farclip = INIT_FARCLIP;
|
context.farclip = INIT_FARCLIP;
|
||||||
context.fov = INIT_FOV;
|
context.fov = INIT_FOV;
|
||||||
haloo3d_trirender_init(&context.rendersettings);
|
haloo3d_trirender_init(&context.rendersettings);
|
||||||
|
// context.rendersettings.flags &= ~H3DR_PCT;
|
||||||
// context.rendersettings.flags &= ~H3DR_DITHERPIX;
|
// context.rendersettings.flags &= ~H3DR_DITHERPIX;
|
||||||
// context.rendersettings.flags |= H3DR_DITHERTRI;
|
// context.rendersettings.flags |= H3DR_DITHERTRI;
|
||||||
context.rendersettings.ditherclose = INIT_DITHERSTART;
|
context.rendersettings.ditherclose = INIT_DITHERSTART;
|
||||||
@ -522,6 +575,8 @@ int main() { // int argc, char **argv) {
|
|||||||
haloo3d_easystore_init(&ecs.storage);
|
haloo3d_easystore_init(&ecs.storage);
|
||||||
haloo3d_fb *palettetex = haloo3d_easystore_addtex(&ecs.storage, PALETTEKEY);
|
haloo3d_fb *palettetex = haloo3d_easystore_addtex(&ecs.storage, PALETTEKEY);
|
||||||
haloo3d_gen_palettetex(palettetex);
|
haloo3d_gen_palettetex(palettetex);
|
||||||
|
haloo3d_obj *treemodel = haloo3d_easystore_addobj(&ecs.storage, TREEKEY);
|
||||||
|
gen_tree_model(treemodel);
|
||||||
|
|
||||||
eprintf("Setup ECS system + obj/tex storage (%d bytes)\n", tecs_size);
|
eprintf("Setup ECS system + obj/tex storage (%d bytes)\n", tecs_size);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user