#include "util.h" #include "entity.h" #include "randlvl.h" #include using namespace std; typedef vector < vertex_t2f_n3f_v3f > triangles; void add_tri (triangles& t, point ap, point bp, point cp, tex2 uv1, tex2 uv2, tex2 uv3) { vec3 nv = normalize (cross (vec3 (cp.x - bp.x, cp.y - bp.y, cp.z - bp.z), vec3 (ap.x - bp.x, ap.y - bp.y, ap.z - bp.z))); t.push_back (vertex_t2f_n3f_v3f (ap, nv, uv1)); t.push_back (vertex_t2f_n3f_v3f (bp, nv, uv2)); t.push_back (vertex_t2f_n3f_v3f (cp, nv, uv3)); } void add_quad (triangles& t, point p1, point p2, point p3, point p4) { add_tri (t, p1, p2, p3, tex2 (0, 0), tex2 (0, 1), tex2 (1, 1)); add_tri (t, p1, p3, p4, tex2 (0, 0), tex2 (1, 1), tex2 (1, 0)); } geometry_triangles* mk_cube (point p, vec3 v) { triangles t; add_quad (t, p , p + vec3 (v.x, 0, 0) , p + vec3 (v.x, 0, v.z), p + vec3 (0, 0, v.z)); add_quad (t, p + vec3 (0, 0, v.z), p + vec3 (0, v.y, v.z), p + vec3 (0, v.y, 0) , p); add_quad (t, p + vec3 (0, 0, v.z), p + vec3 (v.x, 0, v.z), p + v , p + vec3(0, v.y, v.z)); add_quad (t, p + vec3 (0, v.y, 0), p + vec3 (0, v.y, v.z), p + v , p + vec3(v.x, v.y, 0)); add_quad (t, p , p + vec3 (0, v.y, 0) , p + vec3 (v.x, v.y, 0), p + vec3(v.x, 0, 0)); add_quad (t, p + v , p + vec3 (v.x, 0, v.z), p + vec3 (v.x, 0, 0) , p + vec3(v.x, v.y, 0)); geometry_triangles *tri = new geometry_triangles; tri->m = testmat; tri->set (t); return tri; } int myrand (float max) { return (max * rand () / RAND_MAX); } entity *RandomBuilding::draw (int cnt, int max_room, int max_cubes) { geometry_container *objs = new geometry_container; for (int i = 0; i < cnt; ++i) { objs->add (mk_cube ( point (myrand (max_room), myrand (max_room), myrand (max_room)), vec3 (1 + myrand (max_cubes), 1 + myrand (max_cubes), 1 + myrand (max_cubes)) )); } return new entity (objs); }