dbf_amiga

annotate src/room.cc @ 0:87dfe0e10235

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