# HG changeset patch # User John Tsiombikas # Date 1440274677 -10800 # Node ID bed0e207acb641adf9a2bc292915a192096341c8 # Parent 4a6683050e2950918fcdf685faa9f52a360e6494 improved gen_box diff -r 4a6683050e29 -r bed0e207acb6 src/meshgen.cc --- a/src/meshgen.cc Sat Aug 22 07:15:00 2015 +0300 +++ b/src/meshgen.cc Sat Aug 22 23:17:57 2015 +0300 @@ -394,8 +394,41 @@ } } -// ----- heightmap ------ +// ----- box ------ +void gen_box(Mesh *mesh, float xsz, float ysz, float zsz, int usub, int vsub) +{ + static const float face_angles[][2] = { + {0, 0}, + {M_PI / 2.0, 0}, + {M_PI, 0}, + {3.0 * M_PI / 2.0, 0}, + {0, M_PI / 2.0}, + {0, -M_PI / 2.0} + }; + if(usub < 1) usub = 1; + if(vsub < 1) vsub = 1; + + mesh->clear(); + + for(int i=0; i<6; i++) { + Matrix4x4 xform; + Mesh m; + + gen_plane(&m, 1, 1, usub, vsub); + xform.rotate(Vector3(face_angles[i][1], face_angles[i][0], 0)); + xform.translate(Vector3(0, 0, 0.5)); + m.apply_xform(xform); + + mesh->append(m); + } + + Matrix4x4 scale; + scale.set_scaling(Vector3(xsz, ysz, zsz)); + mesh->apply_xform(scale, Matrix4x4::identity); +} + +/* void gen_box(Mesh *mesh, float xsz, float ysz, float zsz) { mesh->clear(); @@ -485,6 +518,7 @@ } } } +*/ static inline Vector3 rev_vert(float u, float v, Vector2 (*rf)(float, float, void*), void *cls) { diff -r 4a6683050e29 -r bed0e207acb6 src/meshgen.h --- a/src/meshgen.h Sat Aug 22 07:15:00 2015 +0300 +++ b/src/meshgen.h Sat Aug 22 23:17:57 2015 +0300 @@ -10,7 +10,7 @@ void gen_cone(Mesh *mesh, float rad, float height, int usub, int vsub, int capsub = 0, float urange = 1.0, float vrange = 1.0); void gen_plane(Mesh *mesh, float width, float height, int usub = 1, int vsub = 1); void gen_heightmap(Mesh *mesh, float width, float height, int usub, int vsub, float (*hf)(float, float, void*), void *hfdata = 0); -void gen_box(Mesh *mesh, float xsz, float ysz, float zsz); +void gen_box(Mesh *mesh, float xsz, float ysz, float zsz, int usub = 1, int vsub = 1); void gen_revol(Mesh *mesh, int usub, int vsub, Vector2 (*rfunc)(float, float, void*), void *cls = 0); void gen_revol(Mesh *mesh, int usub, int vsub, Vector2 (*rfunc)(float, float, void*), Vector2 (*nfunc)(float, float, void*), void *cls);