ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/randlvl.C
Revision: 1.2
Committed: Mon Feb 7 07:37:00 2005 UTC (19 years, 4 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.1: +1 -1 lines
Log Message:
some new material

File Contents

# Content
1 #include "util.h"
2 #include "entity.h"
3 #include "randlvl.h"
4 #include <vector>
5
6 using namespace std;
7
8 typedef vector < vertex_t2f_n3f_v3f > triangles;
9
10 void add_tri (triangles& t, point ap, point bp, point cp, tex2 uv1, tex2 uv2, tex2 uv3)
11 {
12 vec3 nv = normalize (cross (vec3 (cp.x - bp.x, cp.y - bp.y, cp.z - bp.z),
13 vec3 (ap.x - bp.x, ap.y - bp.y, ap.z - bp.z)));
14
15 t.push_back (vertex_t2f_n3f_v3f (ap, nv, uv1));
16 t.push_back (vertex_t2f_n3f_v3f (bp, nv, uv2));
17 t.push_back (vertex_t2f_n3f_v3f (cp, nv, uv3));
18 }
19
20 void add_quad (triangles& t, point p1, point p2, point p3, point p4)
21 {
22 add_tri (t, p1, p2, p3, tex2 (0, 0), tex2 (0, 1), tex2 (1, 1));
23 add_tri (t, p1, p3, p4, tex2 (0, 0), tex2 (1, 1), tex2 (1, 0));
24 }
25
26 geometry_triangles* mk_cube (point p, vec3 v)
27 {
28 triangles t;
29
30 add_quad (t, p , p + vec3 (v.x, 0, 0) , p + vec3 (v.x, 0, v.z), p + vec3 (0, 0, v.z));
31 add_quad (t, p + vec3 (0, 0, v.z), p + vec3 (0, v.y, v.z), p + vec3 (0, v.y, 0) , p);
32 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));
33 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));
34 add_quad (t, p , p + vec3 (0, v.y, 0) , p + vec3 (v.x, v.y, 0), p + vec3(v.x, 0, 0));
35 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));
36
37 geometry_triangles *tri = new geometry_triangles;
38 tri->m = testmat2;
39 tri->set (t);
40
41 return tri;
42 }
43
44 int myrand (float max) {
45 return (max * rand () / RAND_MAX);
46 }
47
48 entity *RandomBuilding::draw (int cnt, int max_room, int max_cubes)
49 {
50 geometry_container *objs = new geometry_container;
51 for (int i = 0; i < cnt; ++i)
52 {
53 objs->add (mk_cube (
54 point (myrand (max_room), myrand (max_room), myrand (max_room)),
55 vec3 (1 + myrand (max_cubes), 1 + myrand (max_cubes), 1 + myrand (max_cubes))
56 ));
57 }
58
59 return new entity (objs);
60 }