ld33_umonster

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