From acff4fc4f645494ed309176b626348938d026092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20A=2E=20Ortega=20Froysa?= Date: Mon, 17 Dec 2018 19:53:40 +0100 Subject: [PATCH] Game rendering almost complete. All that's missing is that for some reason one row/column won't render. --- src/System.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 9 deletions(-) diff --git a/src/System.cpp b/src/System.cpp index cada122..41afe0a 100644 --- a/src/System.cpp +++ b/src/System.cpp @@ -142,21 +142,65 @@ void System::run() { glm::vec3(0,0,0), // where the camera is looking 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("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("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 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) { case SDLK_UP: - tempy = (tempy + 1) % 3; + if(tempy > 0) + tempy--; break; case SDLK_DOWN: - tempy = (tempy - 1) % 3; + if(tempy < 2) + tempy++; break; case SDLK_RIGHT: - tempx = (tempx + 1) % 3; + if(tempx < 2) + tempx++; break; case SDLK_LEFT: - tempx = (tempx - 1) % 3; + if(tempx > 0) + tempx--; break; case SDLK_SPACE: if(board[tempx][tempy]!=0){