terrain working - no culling
[demo] / src / meshgen.cc
index ff7906d..ddcd571 100644 (file)
@@ -119,7 +119,7 @@ void gen_geosphere(Mesh *mesh, float rad, int subdiv, bool hemi)
        for(int i=0; i<num_verts; i++) {
                mesh->indices[i] = i;
        }
-       mesh->update_vertex_data();
+       mesh->invalidate();
 }
 
 // ------ heightfield ------
@@ -165,9 +165,9 @@ void gen_heightfield(Mesh *mesh, float xsz, float ysz, float height, int usub,
        float dv = 1.0 / (float)num_vvertices;
 
        for(int i=0; i<num_vvertices; i++) {
-               float v = (float)i / (float)num_vvertices;
+               float v = 1 - (float)i / (float)(num_vvertices - 1);
                for(int j=0; j<num_uvertices; j++) {
-                       float u = (float)j / (float)num_uvertices;
+                       float u = (float)j / (float)(num_uvertices - 1);
                        Vec3 vtx = hfield_vertex(u, v, calc_height(u, v, ptr), xsz, ysz, height);
 
                        /* calculating normal with forward differences:
@@ -179,7 +179,7 @@ void gen_heightfield(Mesh *mesh, float xsz, float ysz, float height, int usub,
                        Vec3 bitangent = hfield_vertex(u, v + dv, calc_height(u, v + dv, ptr),
                                        xsz, ysz, height) - vtx;
 
-                       Vec3 normal = normalize(cross(tangent, bitangent));
+                       Vec3 normal = normalize(cross(bitangent, tangent));
 
                        mesh->vertices[vidx] = vtx;
                        mesh->normals[vidx] = normal;
@@ -202,7 +202,6 @@ void gen_heightfield(Mesh *mesh, float xsz, float ysz, float height, int usub,
                        int c = d + 1;
 
                        /* 1st triangle */
-
                        *iptr++ = a;
                        *iptr++ = b;
                        *iptr++ = c;
@@ -214,5 +213,5 @@ void gen_heightfield(Mesh *mesh, float xsz, float ysz, float height, int usub,
                        *iptr++ = a;
                }
        }
-       mesh->update_vertex_data();
+       mesh->invalidate();
 }