ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/randlvl.C
Revision: 1.3
Committed: Mon Feb 7 08:16:31 2005 UTC (19 years, 4 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.2: +3 -2 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.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 root 1.2 tri->m = testmat2;
39 root 1.1 tri->set (t);
40    
41     return tri;
42     }
43    
44 root 1.3 static float myrand (float max)
45     {
46     return max * (float)rand () / (float)RAND_MAX;
47 root 1.1 }
48    
49     entity *RandomBuilding::draw (int cnt, int max_room, int max_cubes)
50     {
51     geometry_container *objs = new geometry_container;
52     for (int i = 0; i < cnt; ++i)
53     {
54     objs->add (mk_cube (
55     point (myrand (max_room), myrand (max_room), myrand (max_room)),
56     vec3 (1 + myrand (max_cubes), 1 + myrand (max_cubes), 1 + myrand (max_cubes))
57     ));
58     }
59    
60     return new entity (objs);
61     }