tavli
changeset 2:893192aea099
board keeps objects instead of raw meshes
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 22 Jun 2015 05:15:39 +0300 |
parents | 3fcd7b4d631f |
children | 94aff2ff1934 |
files | src/board.cc src/board.h src/object.cc |
diffstat | 3 files changed, 28 insertions(+), 16 deletions(-) [+] |
line diff
1.1 --- a/src/board.cc Mon Jun 22 05:05:37 2015 +0300 1.2 +++ b/src/board.cc Mon Jun 22 05:15:39 2015 +0300 1.3 @@ -5,7 +5,7 @@ 1.4 1.5 Board::Board() 1.6 { 1.7 - puck_mesh = 0; 1.8 + puck_obj = 0; 1.9 clear(); 1.10 } 1.11 1.12 @@ -25,13 +25,13 @@ 1.13 1.14 void Board::destroy() 1.15 { 1.16 - for(size_t i=0; i<board_meshes.size(); i++) { 1.17 - delete board_meshes[i]; 1.18 + for(size_t i=0; i<obj.size(); i++) { 1.19 + delete obj[i]; 1.20 } 1.21 - board_meshes.clear(); 1.22 + obj.clear(); 1.23 1.24 - delete puck_mesh; 1.25 - puck_mesh = 0; 1.26 + delete puck_obj; 1.27 + puck_obj = 0; 1.28 } 1.29 1.30 void Board::clear() 1.31 @@ -41,8 +41,8 @@ 1.32 1.33 void Board::draw() const 1.34 { 1.35 - for(size_t i=0; i<board_meshes.size(); i++) { 1.36 - board_meshes[i]->draw(); 1.37 + for(size_t i=0; i<obj.size(); i++) { 1.38 + obj[i]->draw(); 1.39 } 1.40 } 1.41 1.42 @@ -59,12 +59,19 @@ 1.43 { 1.44 Matrix4x4 xform; 1.45 1.46 + obj.clear(); 1.47 + 1.48 // generate bottom 1.49 Mesh *bottom = new Mesh; 1.50 gen_box(bottom, HSIZE, BOT_THICKNESS, HSIZE * 2.0); 1.51 xform.set_translation(Vector3(0, -BOT_THICKNESS / 2.0, 0)); 1.52 bottom->apply_xform(xform); 1.53 1.54 + Object *obottom = new Object; 1.55 + obottom->set_mesh(bottom); 1.56 + obj.push_back(obottom); 1.57 + 1.58 + 1.59 // generate the 4 sides 1.60 Mesh *sides = new Mesh; 1.61 gen_box(sides, WALL_THICKNESS, WALL_HEIGHT, VSIZE + WALL_THICKNESS * 2); 1.62 @@ -94,6 +101,11 @@ 1.63 sides->append(tmp); 1.64 tmp.clear(); 1.65 1.66 + Object *osides = new Object; 1.67 + osides->set_mesh(sides); 1.68 + obj.push_back(osides); 1.69 + 1.70 + 1.71 // generate the hinges 1.72 Mesh *hinges = new Mesh; 1.73 gen_cylinder(hinges, HINGE_RAD, HINGE_HEIGHT, 10, 1, 1); 1.74 @@ -108,10 +120,10 @@ 1.75 1.76 hinges->append(tmp); 1.77 1.78 + Object *ohinges = new Object; 1.79 + ohinges->set_mesh(hinges); 1.80 + obj.push_back(ohinges); 1.81 1.82 - board_meshes.clear(); 1.83 - board_meshes.push_back(bottom); 1.84 - board_meshes.push_back(sides); 1.85 - board_meshes.push_back(hinges); 1.86 + 1.87 return true; 1.88 }
2.1 --- a/src/board.h Mon Jun 22 05:05:37 2015 +0300 2.2 +++ b/src/board.h Mon Jun 22 05:15:39 2015 +0300 2.3 @@ -2,7 +2,7 @@ 2.4 #define BOARD_H_ 2.5 2.6 #include <vector> 2.7 -#include "mesh.h" 2.8 +#include "object.h" 2.9 2.10 #define NUM_SLOTS 24 2.11 #define MAX_PUCKS 30 2.12 @@ -12,8 +12,8 @@ 2.13 class Board { 2.14 private: 2.15 int slots[NUM_SLOTS][MAX_PUCKS]; 2.16 - std::vector<Mesh*> board_meshes; 2.17 - Mesh *puck_mesh; 2.18 + std::vector<Object*> obj; 2.19 + Object *puck_obj; 2.20 2.21 bool generate(); 2.22