summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormario <mario@notk.org>2011-11-28 23:26:15 +0100
committermario <mario@notk.org>2011-11-28 23:26:15 +0100
commit8b28ca5cb5108055eb2ea93b0182ce50f3a1eb01 (patch)
treee5976534e024aa02ce8e088a08ee4a697ef22297
parentff3e1de3ea683911fde48da09c43391360e90d5c (diff)
Began to fix display
-rw-r--r--MainWindow.cpp120
-rw-r--r--MainWindow.h2
-rw-r--r--Player.cpp1
3 files changed, 78 insertions, 45 deletions
diff --git a/MainWindow.cpp b/MainWindow.cpp
index af713e8..f238979 100644
--- a/MainWindow.cpp
+++ b/MainWindow.cpp
@@ -29,13 +29,16 @@ void f_onTimer(int v) {
MainWindow::getInstance().onTimer();
}
-float hex2fColor(uint color, char num)
+void hex2fColor(uint color, float &out_red, float &out_green, float &out_blue)
{
- float colors[3];
- colors[0] = (float) ((color & 0x0000FF) >> 0) / 256.;
- colors[1] = (float) ((color & 0x00FF00) >> 8) / 256.;
- colors[2] = (float) ((color & 0xFF0000) >> 16) / 256.;
- return colors[num];
+ float colors[3];
+ colors[0] = (float) ((color & 0x0000FF) >> 0) / 256.f;
+ colors[1] = (float) ((color & 0x00FF00) >> 8) / 256.f;
+ colors[2] = (float) ((color & 0xFF0000) >> 16) / 256.f;
+ out_blue = colors[0];
+ out_green = colors[1];
+ out_red = colors[2];
+
}
void f_doNothing() {}
@@ -50,7 +53,7 @@ void MainWindow::onChangeSize(int w, int h)
{
if (h == 0)
h = 1;
- float ratio = w * 1.0 / h;
+ float ratio = w * 1.0f / h;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, w, h);
@@ -68,51 +71,81 @@ void MainWindow::onRenderScene() {
if(m_pField)
{
Coordinates maxC = m_pField->getMaxCoordinates();
- float GridStepX = (2 * 1./maxC.x) -1;
- float GridStepY = (2 * 1./maxC.y) -1;
- //glColor3f(hex2fColor(, 0), hex2fColor(, 1), hex2fColor(, 2));
- //GL_LINES
+ float GridStepX = (2 * 1.f/maxC.x) -1;
+ float GridStepY = (2 * 1.f/maxC.y) -1;
+
PlayerColor color;
+ float red, green, blue;
+ color = emptyColors[0];
+ hex2fColor(color, red, green, blue);
+ glColor3f(red, green, blue);
+ glBegin(GL_POLYGON);
+ glVertex2f(-1, -1);
+ glVertex2f( 1, -1);
+ glVertex2f( 1, 1);
+ glVertex2f(-1, 1);
+ glEnd();
+
+
+ uint lineX = 0;
+ uint lineY = 0;
+ color = emptyColors[1];
+
+ hex2fColor(color, red, green, blue);
+ glColor3f(red, green, blue);
+ glBegin(GL_LINES);
+ for (lineX = 0; lineX < maxC.x; lineX += 10)
+ {
+ glVertex2f(2 * ((float) lineX / maxC.x) - 1, -1);
+ glVertex2f(2 * ((float) lineX / maxC.x) - 1, 1);
+ }
+ for (lineY = 0; lineY < maxC.y; lineY += 10)
+ {
+ glVertex2f(-1, 2 * ((float) lineY / maxC.x) - 1);
+ glVertex2f( 1, 2 * ((float) lineY / maxC.x) - 1);
+ }
+ glEnd();
for(uint coordX = 0; coordX < maxC.x; ++coordX)
{
for(uint coordY = 0; coordY < maxC.y; ++coordY)
{
Cell c = m_pField->getCell(Coordinates(coordX, coordY));
-
- switch(c.getState())
+ if (c.getState() != EMPTY_CELL)
{
- case EMPTY_CELL:
- color = emptyColors[( ! ((coordX % 10 == 0) || (coordY % 10 == 0)) ? 0 : 1)];
- glColor3f(hex2fColor(color, 0), hex2fColor(color, 1), hex2fColor(color, 2));
- break;
- case BOOM:
- color = 0xFFFFFF;
- glColor3f(hex2fColor(color, 0), hex2fColor(color, 1), hex2fColor(color, 2));
- break;
- case PLAYER_WALL:
- color = playerColors[c.getPlayer()->getNumber() % 4];
- glColor3f(hex2fColor(color, 0)/2, hex2fColor(color, 1)/2, hex2fColor(color, 2)/2);
- break;
- case PLAYER:
- color = playerColors[c.getPlayer()->getNumber() % 4];
- glColor3f(hex2fColor(color, 0), hex2fColor(color, 1), hex2fColor(color, 2));
- break;
- }
+ switch(c.getState())
+ {
+ case BOOM:
+ color = 0xFFFFFF;
+ hex2fColor(color, red, green, blue);
+ glColor3f(red, green, blue);
+ break;
+ case PLAYER_WALL:
+ color = playerColors[c.getPlayer()->getNumber() % 4];
+ hex2fColor(color, red, green, blue);
+ glColor3f(red, green, blue);
+ break;
+ case PLAYER:
+ color = playerColors[c.getPlayer()->getNumber() % 4];
+ hex2fColor(color, red, green, blue);
+ glColor3f(red, green, blue);
+ break;
+ }
- //glBegin(GL_POLYGON);
- // float floatCoordX = 2 * ((float) coordX / maxC.x) - 1;
- // float floatCoordY = 2 * ((float) coordY / maxC.y) - 1;
- // glVertex2f(floatCoordX , floatCoordY );
- // glVertex2f(floatCoordX + GridStepX, floatCoordY );
- // glVertex2f(floatCoordX , floatCoordY + GridStepY);
- // glVertex2f(floatCoordX + GridStepX, floatCoordY + GridStepY);
- //glEnd();
- glBegin(GL_POINTS);
- float floatCoordX = 2 * ((float) coordX / maxC.x) - 1;
- float floatCoordY = 2 * ((float) coordY / maxC.y) - 1;
- glVertex2f(floatCoordX , floatCoordY );
- glEnd();
+ glBegin(GL_POLYGON);
+ float floatCoordX = 2 * ((float) coordX / maxC.x) - 1;
+ float floatCoordY = 2 * ((float) coordY / maxC.y) - 1;
+ glVertex2f(floatCoordX , floatCoordY );
+ glVertex2f(floatCoordX + GridStepX, floatCoordY );
+ glVertex2f(floatCoordX , floatCoordY + GridStepY);
+ glVertex2f(floatCoordX + GridStepX, floatCoordY + GridStepY);
+ glEnd();
+ //glBegin(GL_POINTS);
+ // float floatCoordX = 2 * ((float) coordX / maxC.x) - 1;
+ // float floatCoordY = 2 * ((float) coordY / maxC.y) - 1;
+ // glVertex2f(floatCoordX , floatCoordY );
+ //glEnd();
+ }
}
}
}
@@ -128,7 +161,6 @@ void MainWindow::onTimer()
int time = glutGet(GLUT_ELAPSED_TIME);
m_pGame->updateGame(time);
onRenderScene();
- std::cout << "update" << std::endl;
}
glutTimerFunc(WINDOW_TIMER, f_onTimer, 0);
}
diff --git a/MainWindow.h b/MainWindow.h
index e9cf6a4..9c38c21 100644
--- a/MainWindow.h
+++ b/MainWindow.h
@@ -14,7 +14,7 @@ void f_onChangeSize(int w, int h);
void f_onTimer(int v=0);
void f_onDisplay();
-float hex2fColor(uint color, char num);
+void hex2fColor(uint color, float &out_red, float &out_green, float &out_blue);
class MainWindow
{
diff --git a/Player.cpp b/Player.cpp
index 7da641f..2f880ed 100644
--- a/Player.cpp
+++ b/Player.cpp
@@ -1,4 +1,5 @@
#include "Player.h"
+#include <iostream>
Player::Player(PlayerNumber PlayerID, Coordinates InitialPoint, VelocityVector initialVel) : m_playerID(PlayerID), m_currentCoordinates(InitialPoint), m_velocityVector(initialVel)
{