3dtoys/commonobj.c

71 lines
2.4 KiB
C
Raw Normal View History

#include "haloo3d/haloo3d.h"
#include "haloo3d/haloo3dex_gen.h"
#include "haloo3d/haloo3dex_obj.h"
#ifndef TREECOL
#define TREECOL 0xF070
#endif
#ifndef TREETRUNKCOL
#define TREETRUNKCOL 0xF950
#endif
#ifndef TREEBOTTOM
#define TREEBOTTOM -0.333
#endif
#ifndef TREETOPWIDTH
#define TREETOPWIDTH 1.0
#endif
#ifndef TREETRUNKWIDTH
#define TREETRUNKWIDTH 0.2
#endif
// Fill a face with a solid color given by the tex
void fastface(haloo3d_facei face, uint16_t tex, uint16_t v0, uint16_t v1,
uint16_t v2) {
face[0].texi = tex;
face[1].texi = tex;
face[2].texi = tex;
face[0].posi = v0;
face[1].posi = v1;
face[2].posi = v2;
}
// Generate a basic tree 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);
// clang-format off
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 = -TREETOPWIDTH, .y = TREEBOTTOM, .z = -TREETOPWIDTH, .w = 1});
uint16_t tree2 = haloo3d_obj_addvertex(tree,
(struct vec4){.x = TREETOPWIDTH, .y = TREEBOTTOM, .z = -TREETOPWIDTH, .w = 1});
uint16_t tree3 = haloo3d_obj_addvertex(tree,
(struct vec4){.x = 0, .y = TREEBOTTOM, .z = TREETOPWIDTH, .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});
// clang-format on
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);
}