ld33_umonster
view src/room.cc @ 6:3b4460b34d43
progress
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 23 Aug 2015 05:37:09 +0300 |
parents | 93ff21458a16 |
children |
line source
1 #include <stdio.h>
2 #include "opengl.h"
3 #include "room.h"
4 #include "game.h"
5 #include "object.h"
6 #include "scene.h"
7 #include "meshgen.h"
8 #include "revol.h"
10 static Scene scn;
12 static const vec2_t pillar_cp[] = {
13 {0.8, 10},
14 {1.2, 5.5},
15 {1, 0}
16 };
17 static const BezCurve pillar_curve = {
18 sizeof pillar_cp / sizeof *pillar_cp,
19 (vec2_t*)pillar_cp, 1.0
20 };
22 bool init_room()
23 {
24 Matrix4x4 xform;
26 // generate room
27 Mesh *mroom = new Mesh;
28 gen_box(mroom, ROOM_WIDTH, ROOM_HEIGHT, ROOM_LENGTH);
29 xform.set_translation(Vector3(0, ROOM_HEIGHT / 2.0, 0));
30 mroom->apply_xform(xform);
31 mroom->flip();
33 Object *oroom = new Object;
34 oroom->set_mesh(mroom);
35 oroom->mtl.diffuse = Vector3(0.5, 0.5, 0.5);
36 oroom->rop.cast_shadows = false;
37 scn.add_object(oroom);
39 for(int i=0; i<8; i++) {
40 float x = (i < 4 ? -1.0 : 1.0) * ROOM_WIDTH * 0.3;
41 float z = (float)(i % 4) * 12.5 - 12.5;
43 Mesh *mpillar = new Mesh;
44 gen_revol(mpillar, 16, 3, bezier_revol, bezier_revol_normal, (void*)&pillar_curve);
46 Mesh mtorus;
47 gen_torus(&mtorus, 1.0, 0.25, 16, 8);
48 Matrix4x4 xform;
49 xform.set_translation(Vector3(0, 0.1, 0));
50 mtorus.apply_xform(xform, Matrix4x4::identity);
51 mpillar->append(mtorus);
53 mpillar->texcoord_gen_cylinder();
55 Object *opillar = new Object;
56 opillar->set_mesh(mpillar);
57 opillar->mtl.diffuse = Vector3(0.6, 0.6, 0.6);
58 opillar->xform().set_translation(Vector3(x, 0.0, z));
60 scn.add_object(opillar);
61 }
62 return true;
63 }
65 void cleanup_room()
66 {
67 scn.clear();
68 }
70 void draw_room()
71 {
72 scn.draw();
73 }