# HG changeset patch # User John Tsiombikas # Date 1435784499 -10800 # Node ID c3fbf9616dbdebeaff015b6eab7beeddbff77f1b # Parent 111c1a9bca2915e13ebe869bac2672884a1df242 slot bounds, and ray testing diff -r 111c1a9bca29 -r c3fbf9616dbd src/board.cc --- a/src/board.cc Mon Jun 29 21:55:36 2015 +0300 +++ b/src/board.cc Thu Jul 02 00:01:39 2015 +0300 @@ -19,6 +19,8 @@ #define PIECE_RAD (0.45 * HSIZE / 5.0) #define BOARD_OFFSET (HSIZE / 2.0 + WALL_THICKNESS + HINGE_RAD * 0.25) #define PIECES_PER_LAYER 5 +#define SLOT_WIDTH (HSIZE / 5.0) +#define SLOT_HEIGHT (VSIZE * 0.4) static const vec2_t piece_cp[] = { @@ -66,11 +68,37 @@ } } +Quad::Quad() +{ +} + +Quad::Quad(const Vector3 &v0, const Vector3 &v1, const Vector3 &v2, const Vector3 &v3) + : tri0(v0, v1, v2), tri1(v0, v2, v3) +{ +} + +bool Quad::intersect(const Ray &ray, HitPoint *hit) const +{ + return tri0.intersect(ray, hit) || tri1.intersect(ray, hit); +} Board::Board() { piece_obj = 0; clear(); + + for(int i=0; i= NUM_SLOTS / 2; + + float z0 = top_side ? -PIECE_RAD : PIECE_RAD; + float z1 = top_side ? SLOT_HEIGHT : -SLOT_HEIGHT; + + slotbb[i] = Quad(p + Vector3(-SLOT_WIDTH / 2.0, 0, z0), + p + Vector3(SLOT_WIDTH / 2.0, 0, z0), + p + Vector3(SLOT_WIDTH / 2.0, 0, z1), + p + Vector3(-SLOT_WIDTH / 2.0, 0, z1)); + } } Board::~Board() @@ -163,13 +191,23 @@ pos.y = (layer + 0.5) * PIECE_HEIGHT; pos.z = (-VSIZE * 0.5 + PIECE_RAD + PIECE_RAD * 2.0 * layer_level); - if(top_side) { + if(!top_side) { pos.z = -pos.z; } return pos; } +int Board::slot_hit(const Ray &ray) const +{ + for(int i=0; iset_shader(piece_sdr); piece_obj->draw(); } + + // draw the slot bounds + /* + static const float pal[][3] = { + {1, 0, 0}, + {0, 1, 0}, + {0, 0, 1}, + {1, 1, 0}, + {0, 1, 1}, + {1, 0, 1} + }; + int idx = dbg_int % NUM_SLOTS; + if(idx >= 0) { + glUseProgram(0); + + glPushAttrib(GL_ENABLE_BIT); + glDisable(GL_LIGHTING); + glDisable(GL_CULL_FACE); + glDisable(GL_DEPTH_TEST); + + glBegin(GL_TRIANGLES); + glColor3fv(pal[idx % (sizeof pal / sizeof *pal)]); + glVertex3f(slotbb[idx].tri0.v[0].x, slotbb[idx].tri0.v[0].y, slotbb[idx].tri0.v[0].z); + glVertex3f(slotbb[idx].tri0.v[1].x, slotbb[idx].tri0.v[1].y, slotbb[idx].tri0.v[1].z); + glVertex3f(slotbb[idx].tri0.v[2].x, slotbb[idx].tri0.v[2].y, slotbb[idx].tri0.v[2].z); + glVertex3f(slotbb[idx].tri1.v[0].x, slotbb[idx].tri1.v[0].y, slotbb[idx].tri1.v[0].z); + glVertex3f(slotbb[idx].tri1.v[1].x, slotbb[idx].tri1.v[1].y, slotbb[idx].tri1.v[1].z); + glVertex3f(slotbb[idx].tri1.v[2].x, slotbb[idx].tri1.v[2].y, slotbb[idx].tri1.v[2].z); + glEnd(); + + glPopAttrib(); + } + */ + // TODO slot highlighting } diff -r 111c1a9bca29 -r c3fbf9616dbd src/board.h --- a/src/board.h Mon Jun 29 21:55:36 2015 +0300 +++ b/src/board.h Thu Jul 02 00:01:39 2015 +0300 @@ -3,6 +3,7 @@ #include #include "object.h" +#include "mesh.h" #include "image.h" #define NUM_SLOTS 20 @@ -24,11 +25,22 @@ void move_to(int slot, int level, bool anim = true); }; +// for slot bounds +class Quad { +public: + Triangle tri0, tri1; + + Quad(); + Quad(const Vector3 &v0, const Vector3 &v1, const Vector3 &v2, const Vector3 &v3); + + bool intersect(const Ray &ray, HitPoint *hit = 0) const; +}; class Board { private: Piece pieces[MAX_PIECES]; int hist[NUM_SLOTS + 1]; + Quad slotbb[NUM_SLOTS]; std::vector obj; Object *piece_obj; @@ -53,6 +65,8 @@ Vector3 piece_pos(int slot, int level = 0) const; + int slot_hit(const Ray &ray) const; + void draw() const; }; diff -r 111c1a9bca29 -r c3fbf9616dbd src/game.cc --- a/src/game.cc Mon Jun 29 21:55:36 2015 +0300 +++ b/src/game.cc Thu Jul 02 00:01:39 2015 +0300 @@ -17,6 +17,7 @@ unsigned int sdr_shadow, sdr_shadow_notex; unsigned int sdr_unlit; bool wireframe; +int dbg_int; static Board board; @@ -252,6 +253,18 @@ opt.shadows = !opt.shadows; redisplay(); break; + + case '=': + dbg_int++; + printf("dbg_int: %d\n", dbg_int); + redisplay(); + break; + + case '-': + dbg_int--; + printf("dbg_int: %d\n", dbg_int); + redisplay(); + break; } } } diff -r 111c1a9bca29 -r c3fbf9616dbd src/game.h --- a/src/game.h Mon Jun 29 21:55:36 2015 +0300 +++ b/src/game.h Thu Jul 02 00:01:39 2015 +0300 @@ -8,6 +8,7 @@ extern unsigned long cur_time; extern bool wireframe; +extern int dbg_int; bool game_init(); void game_cleanup();