dunger now saves player start position and cell size
[vrlugburz] / src / mesh.c
index 149fbe7..dbafcbd 100644 (file)
@@ -3,9 +3,7 @@
 #include <stddef.h>
 #include <string.h>
 #include <float.h>
-#define GL_GLEXT_PROTOTYPES 1
-#include <GL/gl.h>
-#include <GL/glext.h>
+#include "opengl.h"
 #include "mesh.h"
 
 static int update_mesh_vbo(struct mesh *m);
@@ -41,6 +39,34 @@ void clear_mesh(struct mesh *m)
        m->bbvalid = m->vbovalid = 0;
 }
 
+int copy_mesh(struct mesh *dest, struct mesh *src)
+{
+       init_mesh(dest);
+
+       if(src->max_verts && !(dest->varr = malloc(src->max_verts * sizeof *dest->varr))) {
+               return -1;
+       }
+       if(src->max_idx && !(dest->iarr = malloc(src->max_idx * sizeof *dest->iarr))) {
+               free(dest->varr);
+               dest->varr = 0;
+               return -1;
+       }
+
+       dest->num_verts = src->num_verts;
+       dest->max_verts = src->max_verts;
+       if(dest->varr) {
+               memcpy(dest->varr, src->varr, src->num_verts * sizeof *dest->varr);
+       }
+
+       dest->num_idx = src->num_idx;
+       dest->max_idx = src->max_idx;
+       if(dest->iarr) {
+               memcpy(dest->iarr, src->iarr, src->num_idx * sizeof *dest->iarr);
+       }
+
+       return 0;
+}
+
 void init_meshgroup(struct meshgroup *mg)
 {
        memset(mg, 0, sizeof *mg);
@@ -335,3 +361,17 @@ static int update_meshgroup_vbo(struct meshgroup *mg)
        free(iarr);
        return 0;
 }
+
+void xform_mesh(struct mesh *mesh, float *mat)
+{
+       int i;
+
+       mesh->vbovalid = 0;
+       mesh->bbvalid = 0;
+
+       for(i=0; i<mesh->num_verts; i++) {
+               cgm_vmul_v3m4(&mesh->varr[i].pos, mat);
+               cgm_vmul_v3m3(&mesh->varr[i].norm, mat);
+               cgm_vmul_v3m3(&mesh->varr[i].tang, mat);
+       }
+}