@@ -17,6 +17,19 @@ using std::runtime_error;
1717using std::string;
1818using std::unique_ptr;
1919
20+ float DiceXCoords[3 ] = {9 .f , 134 .f , 259 .f };
21+ float DiceYCoords[2 ] = {3 .f , 142 .f };
22+ std::pair<float , float > lDieScreenLoc= make_pair(0 .7f , 0 .8f );
23+ std::pair<float , float > rDieScreenLoc= make_pair(0 .78f , 0 .8f );
24+
25+ #define DIE_SIDE_LENGTH 0 .06f
26+ #define DIE_SCREEN_SIDE_LENGTH 95 .f
27+
28+ #define EMPLACE_SQUARE_VERTEX (imXOff, imYOff, scXOff, scYOff ) \
29+ texCoordPair ({texTopLeft.first + imXOff, texTopLeft.second + imYOff}); \
30+ glVertex2d (screenTopLeft.first + scXOff, screenTopLeft.second + scYOff);
31+
32+
2033/* *
2134 * Construct a ViewElement covering a particular rectangle on screen.
2235 * @param rect The rectangle on screen that the view element occupies.
@@ -446,97 +459,55 @@ void drawTexturedCircle(std::pair<float, float> texCenter, float texRadius, std:
446459 glEnd ();
447460}
448461
462+ /* *
463+ * Draw a textured square oriented parallel to the ground
464+ * @param texTopLeft image coordinates of the top left side of our square texture
465+ * @param sideLength image domain side length (in pixels)
466+ * @param screenTopLeft GL coordinates for the top left of our square to render
467+ * @param screenSideLength GL image domain square side length
468+ */
449469void drawTexturedRectangle (std::pair<float , float > texTopLeft, float sideLength, std::pair<float , float > screenTopLeft, float screenSideLength) {
450470
451-
452-
453471 glBegin (GL_QUADS);
454472
455-
456-
457-
458- texCoordPair ({texTopLeft.first + 0 .0f , texTopLeft.second + 0 .0f });
459- glVertex2d (screenTopLeft.first + 0 .0f , screenTopLeft.second + 0 .0f );
460-
461- texCoordPair ({texTopLeft.first + sideLength, texTopLeft.second + 0 .0f });
462- glVertex2d (screenTopLeft.first + screenSideLength, screenTopLeft.second + 0 .0f );
463-
464-
465- texCoordPair ({texTopLeft.first + sideLength, texTopLeft.second + sideLength});
466- glVertex2d (screenTopLeft.first + screenSideLength, screenTopLeft.second + screenSideLength);
467-
468- texCoordPair ({texTopLeft.first + 0 .0f , texTopLeft.second + sideLength});
469- glVertex2d (screenTopLeft.first + 0 .0f , screenTopLeft.second + screenSideLength);
470-
471- /*
472- //redraw the image for reasons
473- texCoordPair({texTopLeft.first + sideLength, texTopLeft.second + sideLength});
474- glVertex2d(screenTopLeft.first + screenSideLength, screenTopLeft.second + screenSideLength);
475-
476- texCoordPair({texTopLeft.first + 0.0f, texTopLeft.second + sideLength});
477- glVertex2d(screenTopLeft.first + 0.0f, screenTopLeft.second + screenSideLength);
478-
479- texCoordPair({texTopLeft.first + sideLength, texTopLeft.second + 0.0f});
480- glVertex2d(screenTopLeft.first + screenSideLength, screenTopLeft.second + 0.0f);
481-
482- texCoordPair({texTopLeft.first + 0.0f, texTopLeft.second + 0.0f});
483- glVertex2d(screenTopLeft.first + 0.0f, screenTopLeft.second + 0.0f);
484-
485- */
486-
487-
473+ EMPLACE_SQUARE_VERTEX (0 .0f , 0 .0f , 0 .0f , 0 .0f )
474+ EMPLACE_SQUARE_VERTEX (sideLength, 0 .0f , screenSideLength, 0 .0f )
475+ EMPLACE_SQUARE_VERTEX (sideLength, sideLength, screenSideLength, screenSideLength)
476+ EMPLACE_SQUARE_VERTEX (0 .0f , sideLength, 0 .0f , screenSideLength)
488477
489478 glEnd ();
490479
491-
492-
493-
494-
495-
496480}
497481
482+ /* *
483+ * Draw both dice.
484+ * @param dice the dice data structure for the board
485+ */
498486void DrawingGameVisitor::visit (GameDice& dice) {
499487
500488 static const GLuint diceTextures = loadImageAsTexture (" resources/catan_dice_new.bmp" );
501489 glBindTexture (GL_TEXTURE_2D, diceTextures);
502490
503491 glColor3d (1.0 , 1.0 , 1.0 );
504- static const std::map<int , std::pair<float , float >> topLeftOffset = {
505- make_pair (1 , make_pair (9 .f , 3 .f )),
506- make_pair (2 , make_pair (134 .f , 3 .f )),
507- make_pair (3 , make_pair (259 .f , 3 .f )),
508- make_pair (4 , make_pair (9 .f , 142 .f )),
509- make_pair (5 , make_pair (134 .f , 142 .f )),
510- make_pair (6 , make_pair (259 .f , 142 .f ))
511- };
512-
513- drawTexturedRectangle (topLeftOffset.find (dice.getFirst ())->second , 95 .f ,
514- make_pair (.7f , .8f ), 0.06 );
492+ static std::map<int , std::pair<float , float >> topLeftOffset;
493+ // construct offset map
494+ for (int i = 1 ; i < 7 ; i++) {
515495
516-
517- drawTexturedRectangle (topLeftOffset.find (dice.getSecond ())->second , 95 .f ,
518- make_pair (.78f , .8f ), 0.06 );
519-
496+ // topLeftOffset.emplace(i, make_pair(DiceXCoords[(i-1)%3], DiceYCoords[i/4]));
497+ topLeftOffset.insert (make_pair (i, make_pair (DiceXCoords[(i-1 )%3 ], DiceYCoords[i/4 ])));
498+ }
520499
521500
522- // render all dice
523- // drawTexturedRectangle(make_pair(9.f, 3.f), 95.f, make_pair(.6f, .9f), 0.06);
524- // drawTexturedRectangle(make_pair(8.f, 4.f), 96.f, make_pair(.67f, .95f), 0.06);
525- // drawTexturedRectangle(make_pair(16.f, 8.f), 96.f, make_pair(.74f, .95f), 0.06);
526- // drawTexturedRectangle(make_pair(2.f, 8.f), 96.f, make_pair(.6f, .95f), 0.06);
527- // drawTexturedRectangle(make_pair(2.f, 8.f), 96.f, make_pair(.6f, .95f), 0.06);
528- // drawTexturedRectangle(make_pair(2.f, 8.f), 96.f, make_pair(.6f, .95f), 0.06);
501+ drawTexturedRectangle (topLeftOffset.find (dice.getFirst ())->second , DIE_SCREEN_SIDE_LENGTH,
502+ lDieScreenLoc, DIE_SIDE_LENGTH);
503+
529504
530- glBindTexture (GL_TEXTURE_2D, 0 );
531- // hardcoded 2 die for testing
532- // drawTexturedRectangle(make_pair(4.f, 8.f), 96.f, make_pair(.7f, .9f), 0.03);
505+ drawTexturedRectangle (topLeftOffset.find (dice.getSecond ())->second , DIE_SCREEN_SIDE_LENGTH,
506+ rDieScreenLoc, DIE_SIDE_LENGTH);
533507
534508
509+ glBindTexture (GL_TEXTURE_2D, 0 );
535510
536-
537-
538- // std::cout << dice.getFirst() << "\n";
539-
540511}
541512
542513/* *
0 commit comments