ld33_umonster

diff src/meshgen.cc @ 1:bed0e207acb6

improved gen_box
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 22 Aug 2015 23:17:57 +0300
parents 4a6683050e29
children 35349df5392d
line diff
     1.1 --- a/src/meshgen.cc	Sat Aug 22 07:15:00 2015 +0300
     1.2 +++ b/src/meshgen.cc	Sat Aug 22 23:17:57 2015 +0300
     1.3 @@ -394,8 +394,41 @@
     1.4  	}
     1.5  }
     1.6  
     1.7 -// ----- heightmap ------
     1.8 +// ----- box ------
     1.9 +void gen_box(Mesh *mesh, float xsz, float ysz, float zsz, int usub, int vsub)
    1.10 +{
    1.11 +	static const float face_angles[][2] = {
    1.12 +		{0, 0},
    1.13 +		{M_PI / 2.0, 0},
    1.14 +		{M_PI, 0},
    1.15 +		{3.0 * M_PI / 2.0, 0},
    1.16 +		{0, M_PI / 2.0},
    1.17 +		{0, -M_PI / 2.0}
    1.18 +	};
    1.19  
    1.20 +	if(usub < 1) usub = 1;
    1.21 +	if(vsub < 1) vsub = 1;
    1.22 +
    1.23 +	mesh->clear();
    1.24 +
    1.25 +	for(int i=0; i<6; i++) {
    1.26 +		Matrix4x4 xform;
    1.27 +		Mesh m;
    1.28 +
    1.29 +		gen_plane(&m, 1, 1, usub, vsub);
    1.30 +		xform.rotate(Vector3(face_angles[i][1], face_angles[i][0], 0));
    1.31 +		xform.translate(Vector3(0, 0, 0.5));
    1.32 +		m.apply_xform(xform);
    1.33 +
    1.34 +		mesh->append(m);
    1.35 +	}
    1.36 +
    1.37 +	Matrix4x4 scale;
    1.38 +	scale.set_scaling(Vector3(xsz, ysz, zsz));
    1.39 +	mesh->apply_xform(scale, Matrix4x4::identity);
    1.40 +}
    1.41 +
    1.42 +/*
    1.43  void gen_box(Mesh *mesh, float xsz, float ysz, float zsz)
    1.44  {
    1.45  	mesh->clear();
    1.46 @@ -485,6 +518,7 @@
    1.47  		}
    1.48  	}
    1.49  }
    1.50 +*/
    1.51  
    1.52  static inline Vector3 rev_vert(float u, float v, Vector2 (*rf)(float, float, void*), void *cls)
    1.53  {