#include "mesh.h"
#include "3dgfx.h"
-int load_mesh(struct g3d_mesh *mesh, const char *fname)
-{
- return -1; /* TODO */
-}
-
static struct {
struct g3d_vertex *varr;
const float *xform;
static int zsort_indexed_cmp(const void *aptr, const void *bptr)
{
- const int16_t *a = (const int16_t*)aptr;
- const int16_t *b = (const int16_t*)bptr;
+ const uint16_t *a = (const uint16_t*)aptr;
+ const uint16_t *b = (const uint16_t*)bptr;
const float *m = zsort_cls.xform;
{
int i, new_vcount, new_icount;
void *tmp;
- int16_t *iptr;
+ uint16_t *iptr;
if(ma->prim != mb->prim) {
fprintf(stderr, "append_mesh failed, primitive mismatch\n");
int i, j, nfaces, max_icount, idx;
int out_vcount = 0;
struct g3d_vertex *vin, *vout;
- int16_t *iout;
+ uint16_t *iout;
if(mesh->iarr) {
fprintf(stderr, "indexify_mesh failed: already indexed\n");
return 0;
}
+void normalize_mesh_normals(struct g3d_mesh *mesh)
+{
+ int i;
+ struct g3d_vertex *v = mesh->varr;
+
+ for(i=0; i<mesh->vcount; i++) {
+ float mag = sqrt(v->nx * v->nx + v->ny * v->ny + v->nz * v->nz);
+ float s = (mag == 0.0f) ? 1.0f : 1.0f / mag;
+ v->nx *= s;
+ v->ny *= s;
+ v->nz *= s;
+ ++v;
+ }
+}
+
int gen_plane_mesh(struct g3d_mesh *m, float width, float height, int usub, int vsub)
{
int i, j;
int nfaces, nverts, nidx, uverts, vverts;
float x, y, u, v, du, dv;
struct g3d_vertex *vptr;
- int16_t *iptr;
+ uint16_t *iptr;
if(usub < 1) usub = 1;
if(vsub < 1) vsub = 1;
int i;
struct g3d_mesh *m;
struct g3d_mesh tmpmesh;
- float xform[16];
static float rotface[][4] = {
{0, 0, 1, 0},
{90, 0, 1, 0},
g3d_load_identity();
g3d_rotate(rotface[i][0], rotface[i][1], rotface[i][2], rotface[i][3]);
g3d_translate(0, 0, sz / 2.0f);
- g3d_get_matrix(G3D_MODELVIEW, xform);
- apply_mesh_xform(m, xform);
+ apply_mesh_xform(m, g3d_get_matrix(G3D_MODELVIEW, 0));
if(i > 0) {
if(append_mesh(mesh, m) == -1) {
return -1;
int i, j;
int nfaces, uverts, vverts;
struct g3d_vertex *vptr;
- int16_t *iptr;
+ uint16_t *iptr;
mesh->prim = G3D_QUADS;
int chess = (i & 1) == (j & 1);
torusvec(&vptr->x, theta, phi, rad, ringrad);
+ vptr->w = 1.0f;
vptr->nx = (vptr->x - rcent[0]) / ringrad;
vptr->ny = (vptr->y - rcent[1]) / ringrad;