Game rendering almost complete.

All that's missing is that for some reason one row/column won't render.
This commit is contained in:
Nicolás A. Ortega Froysa 2018-12-17 19:53:40 +01:00
parent adc8813e0d
commit acff4fc4f6

View File

@ -142,21 +142,65 @@ void System::run() {
glm::vec3(0,0,0), // where the camera is looking glm::vec3(0,0,0), // where the camera is looking
glm::vec3(0,1,0) // which way is vertically up glm::vec3(0,1,0) // which way is vertically up
); );
glm::mat4 mod = glm::mat4(1.0f); // identity matrix, object is at origin
shaders.at("default").setMat4("model", mod);
shaders.at("default").setMat4("proj", proj); shaders.at("default").setMat4("proj", proj);
shaders.at("default").setMat4("view", view); shaders.at("default").setMat4("view", view);
} }
asset_mngr.getModel("board")->setColor(1,0,0); {
// board model
glm::mat4 model = glm::mat4(1.0f);
shaders.at("default").setMat4("model", model);
}
asset_mngr.getModel("board")->setColor(0.87f,0.721f,0.529f);
asset_mngr.getModel("board")->draw(shaders.at("default")); asset_mngr.getModel("board")->draw(shaders.at("default"));
asset_mngr.getModel("cube")->setColor(0,1,0); {
asset_mngr.getModel("cube")->draw(shaders.at("default")); // temprary piece model
glm::mat4 model = glm::mat4(1.0f);
model *= glm::translate(model,
glm::vec3((tempx-1) * 3, 2.5f, (tempy-1) * 3));
shaders.at("default").setMat4("model", model);
}
if(xturn)
{
if(board[tempx][tempy] not_eq 0)
asset_mngr.getModel("cube")->setColor(1,0,0);
else
asset_mngr.getModel("cube")->setColor(0,1,0);
asset_mngr.getModel("cube")->draw(shaders.at("default"));
}
else
{
if(board[tempx][tempy] not_eq 0)
asset_mngr.getModel("sphere")->setColor(1,0,0);
else
asset_mngr.getModel("sphere")->setColor(0,1,0);
asset_mngr.getModel("sphere")->draw(shaders.at("default"));
}
for(unsigned int i = 0; i < 3; ++i) for(unsigned int i = 0; i < 3; ++i)
{ {
for(unsigned int j = 0; j < 3; ++j) for(unsigned int j = 0; j < 3; ++j)
{ {
if(board[i][j] not_eq 0)
{
glm::mat4 model = glm::mat4(1.0f);
model = glm::translate(model,
glm::vec3((i-1) * 3, 1, (j-1) * 3));
shaders.at("default").setMat4("model", model);
if(board[i][j] == 1)
{
asset_mngr.getModel("cube")->setColor(0,0,1);
asset_mngr.getModel("cube")->draw(shaders.at("default"));
}
else if(board[i][j] == 2)
{
asset_mngr.getModel("sphere")->setColor(0,0,1);
asset_mngr.getModel("sphere")->draw(shaders.at("default"));
}
}
} }
} }
@ -175,16 +219,20 @@ void System::handleKey(SDL_Keysym key){
switch(key.sym) switch(key.sym)
{ {
case SDLK_UP: case SDLK_UP:
tempy = (tempy + 1) % 3; if(tempy > 0)
tempy--;
break; break;
case SDLK_DOWN: case SDLK_DOWN:
tempy = (tempy - 1) % 3; if(tempy < 2)
tempy++;
break; break;
case SDLK_RIGHT: case SDLK_RIGHT:
tempx = (tempx + 1) % 3; if(tempx < 2)
tempx++;
break; break;
case SDLK_LEFT: case SDLK_LEFT:
tempx = (tempx - 1) % 3; if(tempx > 0)
tempx--;
break; break;
case SDLK_SPACE: case SDLK_SPACE:
if(board[tempx][tempy]!=0){ if(board[tempx][tempy]!=0){