Skip to content

Commit 3955171

Browse files
committed
Merge branch 'master' into DevCardUImerger
2 parents 4d1889a + 6f9d658 commit 3955171

File tree

2 files changed

+41
-69
lines changed

2 files changed

+41
-69
lines changed

include/GameView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class GameController;
1818
class ViewElement;
1919
class GameView;
2020

21+
2122
/**
2223
* An element that is drawn on screen and can receive inputs from the user. These all occupy a rectangular area on screen
2324
* and can choose to handle clicks from the user that are inside their area.

src/GameView.cpp

Lines changed: 40 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ using std::runtime_error;
1717
using std::string;
1818
using 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.
@@ -471,97 +484,55 @@ void drawTexturedCircle(std::pair<float, float> texCenter, float texRadius, std:
471484
glEnd();
472485
}
473486

487+
/**
488+
* Draw a textured square oriented parallel to the ground
489+
* @param texTopLeft image coordinates of the top left side of our square texture
490+
* @param sideLength image domain side length (in pixels)
491+
* @param screenTopLeft GL coordinates for the top left of our square to render
492+
* @param screenSideLength GL image domain square side length
493+
*/
474494
void drawTexturedRectangle(std::pair<float, float> texTopLeft, float sideLength, std::pair<float, float> screenTopLeft, float screenSideLength) {
475495

476-
477-
478496
glBegin(GL_QUADS);
479497

480-
481-
482-
483-
texCoordPair({texTopLeft.first + 0.0f, texTopLeft.second + 0.0f});
484-
glVertex2d(screenTopLeft.first + 0.0f, screenTopLeft.second + 0.0f);
485-
486-
texCoordPair({texTopLeft.first + sideLength, texTopLeft.second + 0.0f});
487-
glVertex2d(screenTopLeft.first + screenSideLength, screenTopLeft.second + 0.0f);
488-
489-
490-
texCoordPair({texTopLeft.first + sideLength, texTopLeft.second + sideLength});
491-
glVertex2d(screenTopLeft.first + screenSideLength, screenTopLeft.second + screenSideLength);
492-
493-
texCoordPair({texTopLeft.first + 0.0f, texTopLeft.second + sideLength});
494-
glVertex2d(screenTopLeft.first + 0.0f, screenTopLeft.second + screenSideLength);
495-
496-
/*
497-
//redraw the image for reasons
498-
texCoordPair({texTopLeft.first + sideLength, texTopLeft.second + sideLength});
499-
glVertex2d(screenTopLeft.first + screenSideLength, screenTopLeft.second + screenSideLength);
500-
501-
texCoordPair({texTopLeft.first + 0.0f, texTopLeft.second + sideLength});
502-
glVertex2d(screenTopLeft.first + 0.0f, screenTopLeft.second + screenSideLength);
503-
504-
texCoordPair({texTopLeft.first + sideLength, texTopLeft.second + 0.0f});
505-
glVertex2d(screenTopLeft.first + screenSideLength, screenTopLeft.second + 0.0f);
506-
507-
texCoordPair({texTopLeft.first + 0.0f, texTopLeft.second + 0.0f});
508-
glVertex2d(screenTopLeft.first + 0.0f, screenTopLeft.second + 0.0f);
509-
510-
*/
511-
512-
498+
EMPLACE_SQUARE_VERTEX(0.0f, 0.0f, 0.0f, 0.0f)
499+
EMPLACE_SQUARE_VERTEX(sideLength, 0.0f, screenSideLength, 0.0f)
500+
EMPLACE_SQUARE_VERTEX(sideLength, sideLength, screenSideLength, screenSideLength)
501+
EMPLACE_SQUARE_VERTEX(0.0f, sideLength, 0.0f, screenSideLength)
513502

514503
glEnd();
515504

516-
517-
518-
519-
520-
521505
}
522506

507+
/**
508+
* Draw both dice.
509+
* @param dice the dice data structure for the board
510+
*/
523511
void DrawingGameVisitor::visit(GameDice& dice) {
524512

525513
static const GLuint diceTextures = loadImageAsTexture("resources/catan_dice_new.bmp");
526514
glBindTexture(GL_TEXTURE_2D, diceTextures);
527515

528516
glColor3d(1.0, 1.0, 1.0);
529-
static const std::map<int, std::pair<float, float>> topLeftOffset = {
530-
make_pair(1, make_pair(9.f, 3.f)),
531-
make_pair(2, make_pair(134.f, 3.f)),
532-
make_pair(3, make_pair(259.f, 3.f)),
533-
make_pair(4, make_pair(9.f, 142.f)),
534-
make_pair(5, make_pair(134.f, 142.f)),
535-
make_pair(6, make_pair(259.f, 142.f))
536-
};
537-
538-
drawTexturedRectangle(topLeftOffset.find(dice.getFirst())->second, 95.f,
539-
make_pair(.7f, .8f), 0.06);
517+
static std::map<int, std::pair<float, float>> topLeftOffset;
518+
//construct offset map
519+
for (int i = 1; i < 7; i++) {
540520

541-
542-
drawTexturedRectangle(topLeftOffset.find(dice.getSecond())->second, 95.f,
543-
make_pair(.78f, .8f), 0.06);
544-
521+
//topLeftOffset.emplace(i, make_pair(DiceXCoords[(i-1)%3], DiceYCoords[i/4]));
522+
topLeftOffset.insert(make_pair(i, make_pair(DiceXCoords[(i-1)%3], DiceYCoords[i/4])));
523+
}
545524

546525

547-
//render all dice
548-
//drawTexturedRectangle(make_pair(9.f, 3.f), 95.f, make_pair(.6f, .9f), 0.06);
549-
//drawTexturedRectangle(make_pair(8.f, 4.f), 96.f, make_pair(.67f, .95f), 0.06);
550-
//drawTexturedRectangle(make_pair(16.f, 8.f), 96.f, make_pair(.74f, .95f), 0.06);
551-
//drawTexturedRectangle(make_pair(2.f, 8.f), 96.f, make_pair(.6f, .95f), 0.06);
552-
//drawTexturedRectangle(make_pair(2.f, 8.f), 96.f, make_pair(.6f, .95f), 0.06);
553-
//drawTexturedRectangle(make_pair(2.f, 8.f), 96.f, make_pair(.6f, .95f), 0.06);
526+
drawTexturedRectangle(topLeftOffset.find(dice.getFirst())->second, DIE_SCREEN_SIDE_LENGTH,
527+
lDieScreenLoc, DIE_SIDE_LENGTH);
528+
554529

555-
glBindTexture(GL_TEXTURE_2D, 0);
556-
//hardcoded 2 die for testing
557-
//drawTexturedRectangle(make_pair(4.f, 8.f), 96.f, make_pair(.7f, .9f), 0.03);
530+
drawTexturedRectangle(topLeftOffset.find(dice.getSecond())->second, DIE_SCREEN_SIDE_LENGTH,
531+
rDieScreenLoc, DIE_SIDE_LENGTH);
558532

559533

534+
glBindTexture(GL_TEXTURE_2D, 0);
560535

561-
562-
563-
//std::cout << dice.getFirst() << "\n";
564-
565536
}
566537

567538
/**

0 commit comments

Comments
 (0)