diff --git a/Debug/grk-cw9.exe b/Debug/grk-cw9.exe index 551897b..da138ec 100644 Binary files a/Debug/grk-cw9.exe and b/Debug/grk-cw9.exe differ diff --git a/Debug/grk-cw9.pdb b/Debug/grk-cw9.pdb index 5a084ed..0acb620 100644 Binary files a/Debug/grk-cw9.pdb and b/Debug/grk-cw9.pdb differ diff --git a/cw 9/Debug/Box.obj b/cw 9/Debug/Box.obj index 8ff28fd..f52bb1c 100644 Binary files a/cw 9/Debug/Box.obj and b/cw 9/Debug/Box.obj differ diff --git a/cw 9/Debug/Camera.obj b/cw 9/Debug/Camera.obj index 8cb2865..948c58c 100644 Binary files a/cw 9/Debug/Camera.obj and b/cw 9/Debug/Camera.obj differ diff --git a/cw 9/Debug/Render_Utils.obj b/cw 9/Debug/Render_Utils.obj index 7f8d810..883c23d 100644 Binary files a/cw 9/Debug/Render_Utils.obj and b/cw 9/Debug/Render_Utils.obj differ diff --git a/cw 9/Debug/SOIL.obj b/cw 9/Debug/SOIL.obj index 2c396be..af0dd2d 100644 Binary files a/cw 9/Debug/SOIL.obj and b/cw 9/Debug/SOIL.obj differ diff --git a/cw 9/Debug/Shader_Loader.obj b/cw 9/Debug/Shader_Loader.obj index 3e85e55..4c93a35 100644 Binary files a/cw 9/Debug/Shader_Loader.obj and b/cw 9/Debug/Shader_Loader.obj differ diff --git a/cw 9/Debug/Texture.obj b/cw 9/Debug/Texture.obj index aeadf34..7acfd06 100644 Binary files a/cw 9/Debug/Texture.obj and b/cw 9/Debug/Texture.obj differ diff --git a/cw 9/Debug/grk-cw9.exe.recipe b/cw 9/Debug/grk-cw9.exe.recipe index 0062e91..fa42ea7 100644 --- a/cw 9/Debug/grk-cw9.exe.recipe +++ b/cw 9/Debug/grk-cw9.exe.recipe @@ -2,7 +2,7 @@ - C:\Users\Anna Niczyporuk\source\repos\GRK_Project\Debug\grk-cw9.exe + C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\Debug\grk-cw9.exe diff --git a/cw 9/Debug/grk-cw9.log b/cw 9/Debug/grk-cw9.log index caefde1..d9acd36 100644 --- a/cw 9/Debug/grk-cw9.log +++ b/cw 9/Debug/grk-cw9.log @@ -1,47 +1,55 @@  main.cpp C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\shared\minwindef.h(130,1): warning C4005: 'APIENTRY': macro redefinition -C:\Users\Anna Niczyporuk\source\repos\GRK_Project\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123): message : see previous definition of 'APIENTRY' -C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(96,30): warning C4305: 'initializing': truncation from 'double' to 'float' -C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(110,17): warning C4101: 'data': unreferenced local variable -C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(135,38): warning C4305: '=': truncation from 'double' to 'float' -C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(164,16): warning C4305: 'initializing': truncation from 'double' to 'float' -C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(224,13): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data -C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(240,98): warning C4305: 'argument': truncation from 'double' to 'T' +C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123): message : see previous definition of 'APIENTRY' +C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\cw 9\src\Collision_System.cpp(95,16): warning C4244: 'initializing': conversion from 'float' to 'int', possible loss of data +C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\cw 9\src\Collision_System.cpp(96,14): warning C4244: 'initializing': conversion from 'float' to 'int', possible loss of data +C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\cw 9\src\Collision_System.cpp(98,17): warning C4244: 'initializing': conversion from 'float' to 'int', possible loss of data +C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\cw 9\src\Collision_System.cpp(99,15): warning C4244: 'initializing': conversion from 'float' to 'int', possible loss of data +C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\cw 9\src\Collision_System.cpp(108,9): warning C4244: 'initializing': conversion from 'float' to 'int', possible loss of data +C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\cw 9\src\Collision_System.cpp(109,9): warning C4244: 'initializing': conversion from 'float' to 'int', possible loss of data +C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\cw 9\src\Collision_System.cpp(119,29): warning C4244: 'return': conversion from 'int' to 'float', possible loss of data +C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\cw 9\src\Collision_System.cpp(123,29): warning C4244: 'return': conversion from 'int' to 'float', possible loss of data +C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\cw 9\src\ex_9_1.hpp(99,30): warning C4305: 'initializing': truncation from 'double' to 'float' +C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\cw 9\src\ex_9_1.hpp(113,17): warning C4101: 'data': unreferenced local variable +C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\cw 9\src\ex_9_1.hpp(138,38): warning C4305: '=': truncation from 'double' to 'float' +C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\cw 9\src\ex_9_1.hpp(167,16): warning C4305: 'initializing': truncation from 'double' to 'float' +C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\cw 9\src\ex_9_1.hpp(227,13): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data +C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\cw 9\src\ex_9_1.hpp(243,98): warning C4305: 'argument': truncation from 'double' to 'T' with [ T=float ] -C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(243,68): warning C4305: 'argument': truncation from 'double' to 'T' +C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\cw 9\src\ex_9_1.hpp(246,68): warning C4305: 'argument': truncation from 'double' to 'T' with [ T=float ] -C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(303,13): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data -C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(311,108): warning C4305: 'argument': truncation from 'double' to 'T' +C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\cw 9\src\ex_9_1.hpp(306,13): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data +C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\cw 9\src\ex_9_1.hpp(314,108): warning C4305: 'argument': truncation from 'double' to 'T' with [ T=float ] -C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(319,87): warning C4305: 'argument': truncation from 'double' to 'T' +C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\cw 9\src\ex_9_1.hpp(322,87): warning C4305: 'argument': truncation from 'double' to 'T' with [ T=float ] -C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(319,223): warning C4305: 'argument': truncation from 'double' to 'float' -C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(322,59): warning C4305: 'argument': truncation from 'double' to 'T' +C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\cw 9\src\ex_9_1.hpp(322,223): warning C4305: 'argument': truncation from 'double' to 'float' +C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\cw 9\src\ex_9_1.hpp(325,59): warning C4305: 'argument': truncation from 'double' to 'T' with [ T=float ] -C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(323,37): warning C4305: 'argument': truncation from 'double' to 'float' -C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(355,2): warning C4305: 'argument': truncation from 'double' to 'float' -C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(403,108): warning C4305: 'argument': truncation from 'double' to 'T' +C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\cw 9\src\ex_9_1.hpp(326,37): warning C4305: 'argument': truncation from 'double' to 'float' +C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\cw 9\src\ex_9_1.hpp(358,2): warning C4305: 'argument': truncation from 'double' to 'float' +C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\cw 9\src\ex_9_1.hpp(412,108): warning C4305: 'argument': truncation from 'double' to 'T' with [ T=float ] -C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(479,21): warning C4305: '-=': truncation from 'double' to 'float' -C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(481,21): warning C4305: '+=': truncation from 'double' to 'float' +C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\cw 9\src\ex_9_1.hpp(491,21): warning C4305: '-=': truncation from 'double' to 'float' +C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\cw 9\src\ex_9_1.hpp(493,21): warning C4305: '+=': truncation from 'double' to 'float' Box.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library - grk-cw9.vcxproj -> C:\Users\Anna Niczyporuk\source\repos\GRK_Project\Debug\grk-cw9.exe + grk-cw9.vcxproj -> C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\Debug\grk-cw9.exe diff --git a/cw 9/Debug/grk-cw9.tlog/CL.command.1.tlog b/cw 9/Debug/grk-cw9.tlog/CL.command.1.tlog index d6511ab..317d34b 100644 Binary files a/cw 9/Debug/grk-cw9.tlog/CL.command.1.tlog and b/cw 9/Debug/grk-cw9.tlog/CL.command.1.tlog differ diff --git a/cw 9/Debug/grk-cw9.tlog/CL.read.1.tlog b/cw 9/Debug/grk-cw9.tlog/CL.read.1.tlog index e5f1379..aa07227 100644 Binary files a/cw 9/Debug/grk-cw9.tlog/CL.read.1.tlog and b/cw 9/Debug/grk-cw9.tlog/CL.read.1.tlog differ diff --git a/cw 9/Debug/grk-cw9.tlog/CL.write.1.tlog b/cw 9/Debug/grk-cw9.tlog/CL.write.1.tlog index 1866195..3dd4be1 100644 Binary files a/cw 9/Debug/grk-cw9.tlog/CL.write.1.tlog and b/cw 9/Debug/grk-cw9.tlog/CL.write.1.tlog differ diff --git a/cw 9/Debug/grk-cw9.tlog/grk-cw9.lastbuildstate b/cw 9/Debug/grk-cw9.tlog/grk-cw9.lastbuildstate index 82bc4a6..d02932b 100644 --- a/cw 9/Debug/grk-cw9.tlog/grk-cw9.lastbuildstate +++ b/cw 9/Debug/grk-cw9.tlog/grk-cw9.lastbuildstate @@ -1,2 +1,2 @@ -PlatformToolSet=v143:VCToolArchitecture=Native32Bit:VCToolsVersion=14.33.31629:TargetPlatformVersion=10.0.19041.0: -Debug|Win32|C:\Users\Anna Niczyporuk\source\repos\GRK_Project\| +PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.29.30037:TargetPlatformVersion=10.0.19041.0: +Debug|Win32|C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\| diff --git a/cw 9/Debug/grk-cw9.tlog/link.command.1.tlog b/cw 9/Debug/grk-cw9.tlog/link.command.1.tlog index eb06ff6..661410c 100644 Binary files a/cw 9/Debug/grk-cw9.tlog/link.command.1.tlog and b/cw 9/Debug/grk-cw9.tlog/link.command.1.tlog differ diff --git a/cw 9/Debug/grk-cw9.tlog/link.read.1.tlog b/cw 9/Debug/grk-cw9.tlog/link.read.1.tlog index 4be7ab4..42286f1 100644 Binary files a/cw 9/Debug/grk-cw9.tlog/link.read.1.tlog and b/cw 9/Debug/grk-cw9.tlog/link.read.1.tlog differ diff --git a/cw 9/Debug/grk-cw9.tlog/link.write.1.tlog b/cw 9/Debug/grk-cw9.tlog/link.write.1.tlog index 2f92f68..ed6acac 100644 Binary files a/cw 9/Debug/grk-cw9.tlog/link.write.1.tlog and b/cw 9/Debug/grk-cw9.tlog/link.write.1.tlog differ diff --git a/cw 9/Debug/image_DXT.obj b/cw 9/Debug/image_DXT.obj index 4c39f4d..e030409 100644 Binary files a/cw 9/Debug/image_DXT.obj and b/cw 9/Debug/image_DXT.obj differ diff --git a/cw 9/Debug/image_helper.obj b/cw 9/Debug/image_helper.obj index 2139deb..d325d62 100644 Binary files a/cw 9/Debug/image_helper.obj and b/cw 9/Debug/image_helper.obj differ diff --git a/cw 9/Debug/main.obj b/cw 9/Debug/main.obj index 15a54e7..7241667 100644 Binary files a/cw 9/Debug/main.obj and b/cw 9/Debug/main.obj differ diff --git a/cw 9/Debug/stb_image_aug.obj b/cw 9/Debug/stb_image_aug.obj index ec33b6a..5720213 100644 Binary files a/cw 9/Debug/stb_image_aug.obj and b/cw 9/Debug/stb_image_aug.obj differ diff --git a/cw 9/Debug/vc142.idb b/cw 9/Debug/vc142.idb index 21b03b7..b1aafaa 100644 Binary files a/cw 9/Debug/vc142.idb and b/cw 9/Debug/vc142.idb differ diff --git a/cw 9/Debug/vc142.pdb b/cw 9/Debug/vc142.pdb index 7d5912d..b507485 100644 Binary files a/cw 9/Debug/vc142.pdb and b/cw 9/Debug/vc142.pdb differ diff --git a/cw 9/grk-cw9.vcxproj b/cw 9/grk-cw9.vcxproj index 4aab4ba..7ab3220 100644 --- a/cw 9/grk-cw9.vcxproj +++ b/cw 9/grk-cw9.vcxproj @@ -13,6 +13,7 @@ + @@ -64,7 +65,7 @@ Application true Unicode - v143 + v142 Application diff --git a/cw 9/grk-cw9.vcxproj.filters b/cw 9/grk-cw9.vcxproj.filters index ea3f186..48eb7e9 100644 --- a/cw 9/grk-cw9.vcxproj.filters +++ b/cw 9/grk-cw9.vcxproj.filters @@ -54,6 +54,9 @@ Source Files + + Source Files + diff --git a/cw 9/src/Collision_System.cpp b/cw 9/src/Collision_System.cpp new file mode 100644 index 0000000..c620340 --- /dev/null +++ b/cw 9/src/Collision_System.cpp @@ -0,0 +1,125 @@ +#include "glew.h" +#include +#include "glm.hpp" +#include "ext.hpp" +#include +#include +#include + +#include "freeglut.h" +#include +#include +#include + +#define matrixSize 1000 + +struct Bounding { + float minX, maxX, minZ, maxZ; +}; + +class CollisionSystem { +public: + bool matrix[matrixSize][matrixSize]; + float toAddX, toAddZ, toMultiplyX, toMultiplyZ; + + struct Bounding sceneBounding; + std::vector meshesBoundings; + + CollisionSystem() { + for (int i = 0; i < matrixSize; i++) { + for (int j = 0; j < matrixSize; j++) { + matrix[i][j] = false; + } + } + for (int i = 0; i < matrixSize; i++) { + matrix[i][0] = true; + matrix[i][matrixSize - 1] = true; + } + for (int i = 0; i < matrixSize; i++) { + matrix[0][i] = true; + matrix[matrixSize - 1][i] = true; + } + } + + void addMeshToMatrix(aiMesh* mesh) { + aiVector3D firstPosition = mesh->mVertices[0]; + + float meshMinX = firstPosition.x; + float meshMaxX = firstPosition.x; + float meshMinZ = firstPosition.z; + float meshMaxZ = firstPosition.z; + + for (unsigned int i = 1; i < mesh->mNumVertices; i++) + { + aiVector3D vertex = mesh->mVertices[i]; + + if (vertex.x < meshMinX) meshMinX = vertex.x; + if (vertex.z < meshMinZ) meshMinZ = vertex.z; + + if (vertex.x > meshMaxX) meshMaxX = vertex.x; + if (vertex.z > meshMaxZ) meshMaxZ = vertex.z; + } + + Bounding meshBounding = { + meshMinX, + meshMaxX, + meshMinZ, + meshMaxZ + }; + + meshesBoundings.push_back(meshBounding); + } + + void calculateSceneBounding() { + for (Bounding meshBounding : meshesBoundings) { + if (meshBounding.minX < sceneBounding.minX) { + sceneBounding.minX = meshBounding.minX; + } + if (meshBounding.maxX > sceneBounding.maxX) { + sceneBounding.maxX = meshBounding.maxX; + } + if (meshBounding.minZ < sceneBounding.minZ) { + sceneBounding.minZ = meshBounding.minZ; + } + if (meshBounding.maxZ > sceneBounding.maxZ) { + sceneBounding.maxZ = meshBounding.maxZ; + } + } + + toAddX = -sceneBounding.minX; + toAddZ = -sceneBounding.minZ; + toMultiplyX = (1 / (sceneBounding.maxX + toAddX)) * matrixSize; + toMultiplyZ = (1 / (sceneBounding.maxZ + toAddZ)) * matrixSize; + + for (Bounding meshBounding : meshesBoundings) { + int i_start = getRelativeZ(meshBounding.minZ); + int i_end = getRelativeZ(meshBounding.maxZ); + for (int i = i_start; i <= i_end; i++) { + int j_start = getRelativeX(meshBounding.minX); + int j_end = getRelativeX(meshBounding.maxX); + for (int j = j_start; j <= j_end; j++) { + matrix[i][j] = true; + } + } + } + } + + bool canMove(glm::vec3 pos) { + int z = getRelativeZ(pos.z); + int x = getRelativeX(pos.x); + + if (z < 0 || z >= matrixSize || x < 0 || x >= matrixSize) { + return true; + } + + return !(matrix[z][x]); + } + + float getRelativeX(float x) { + return (int)((x + toAddX) * toMultiplyX); + } + + float getRelativeZ(float z) { + return (int)((z + toAddZ) * toMultiplyZ); + } +}; \ No newline at end of file diff --git a/cw 9/src/Render_Utils.cpp b/cw 9/src/Render_Utils.cpp index 18f71f9..38248ce 100644 --- a/cw 9/src/Render_Utils.cpp +++ b/cw 9/src/Render_Utils.cpp @@ -8,27 +8,56 @@ #include #include - - void Core::RenderContext::initFromAssimpMesh(aiMesh* mesh) { vertexArray = 0; vertexBuffer = 0; vertexIndexBuffer = 0; + aiVector3D position = mesh->mVertices[0]; + + float minX = position.x, minY = position.y, minZ = position.z; + float maxX = position.x, maxY = position.y, maxZ = position.z; + + for (unsigned int i = 1; i < mesh->mNumVertices; i++) + { + aiVector3D vertex = mesh->mVertices[i]; + + if (vertex.x < minX) minX = vertex.x; + if (vertex.y < minY) minY = vertex.y; + if (vertex.z < minZ) minZ = vertex.z; + + if (vertex.x > maxX) maxX = vertex.x; + if (vertex.y > maxY) maxY = vertex.y; + if (vertex.z > maxZ) maxZ = vertex.z; + } + + float width = maxX - minX; + float height = maxZ - minZ; + + std::cout << "Mesh position: (" << position.x << ", " << position.y << ", " << position.z << ")" << std::endl; + std::cout << "X " << minX << " - " << maxX << "\n"; + std::cout << "Z " << minZ << " - " << maxZ << "\n"; + std::cout << "Mesh width (relative): " << width << std::endl; + std::cout << "Mesh height (relative): " << height << std::endl; + std::vector textureCoord; std::vector indices; //tex coord must be converted to 2d vecs for (unsigned int i = 0; i < mesh->mNumVertices; i++) { + float x, y; if (mesh->mTextureCoords[0] != nullptr) { - textureCoord.push_back(mesh->mTextureCoords[0][i].x); - textureCoord.push_back(mesh->mTextureCoords[0][i].y); - } - else { - textureCoord.push_back(0.0f); - textureCoord.push_back(0.0f); + x = mesh->mTextureCoords[0][i].x; + y = mesh->mTextureCoords[0][i].y; + } else { + x = 0.0f; + y = 0.0f; } + + textureCoord.push_back(x); + textureCoord.push_back(y); } + if (mesh->mTextureCoords[0] == nullptr) { std::cout << "no uv coords\n"; } diff --git a/cw 9/src/ex_9_1.hpp b/cw 9/src/ex_9_1.hpp index 71bc478..baca32d 100644 --- a/cw 9/src/ex_9_1.hpp +++ b/cw 9/src/ex_9_1.hpp @@ -10,6 +10,7 @@ #include "TriangleSoup.hpp" #include "Box.cpp" +#include "Collision_System.cpp" #include #include #include @@ -21,6 +22,8 @@ const unsigned int SHADOW_WIDTH = 1024, SHADOW_HEIGHT = 1024; int WIDTH = 500, HEIGHT = 500; +CollisionSystem collisionSystem; + namespace models { Core::RenderContext bedContext; Core::RenderContext chairContext; @@ -382,7 +385,7 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height) WIDTH = width; HEIGHT = height; } -void loadModelToContext(std::string path, Core::RenderContext& context) +void loadModelToContext(std::string path, Core::RenderContext& context, bool updateCollisionSystem) { Assimp::Importer import; const aiScene* scene = import.ReadFile(path, aiProcess_Triangulate | aiProcess_CalcTangentSpace); @@ -392,7 +395,13 @@ void loadModelToContext(std::string path, Core::RenderContext& context) std::cout << "ERROR::ASSIMP::" << import.GetErrorString() << std::endl; return; } + + std::cout << path << "\n"; context.initFromAssimpMesh(scene->mMeshes[0]); + + if (updateCollisionSystem) { + collisionSystem.addMeshToMatrix(scene->mMeshes[0]); + } } @@ -412,23 +421,24 @@ void init(GLFWwindow* window) programWater = shaderLoader.CreateProgram("shaders/shader_water.vert", "shaders/shader_water.frag"); water.readOBJ("./models/plane2.obj"); texture::water = Core::LoadTexture("textures/test.png"); - loadModelToContext("./models/sphere.obj", sphereContext); - loadModelToContext("./models/spaceship.obj", shipContext); - loadModelToContext("./models/bed.obj", models::bedContext); - loadModelToContext("./models/chair.obj", models::chairContext); - loadModelToContext("./models/desk.obj", models::deskContext); - loadModelToContext("./models/door.obj", models::doorContext); - loadModelToContext("./models/drawer.obj", models::drawerContext); - loadModelToContext("./models/marbleBust.obj", models::marbleBustContext); - loadModelToContext("./models/materace.obj", models::materaceContext); - loadModelToContext("./models/pencils.obj", models::pencilsContext); - loadModelToContext("./models/plane.obj", models::planeContext); - loadModelToContext("./models/room.obj", models::roomContext); - loadModelToContext("./models/spaceship.obj", models::spaceshipContext); - loadModelToContext("./models/sphere.obj", models::sphereContext); - loadModelToContext("./models/window.obj", models::windowContext); - loadModelToContext("./models/test.obj", models::testContext); - loadModelToContext("./models/cube.obj", models::cubeContext); + loadModelToContext("./models/sphere.obj", sphereContext, false); + loadModelToContext("./models/spaceship.obj", shipContext, false); + loadModelToContext("./models/bed.obj", models::bedContext, true); + loadModelToContext("./models/chair.obj", models::chairContext, true); + loadModelToContext("./models/desk.obj", models::deskContext, true); + loadModelToContext("./models/door.obj", models::doorContext, false); + loadModelToContext("./models/drawer.obj", models::drawerContext, false); + loadModelToContext("./models/marbleBust.obj", models::marbleBustContext, false); + loadModelToContext("./models/materace.obj", models::materaceContext, false); + loadModelToContext("./models/pencils.obj", models::pencilsContext, false); + loadModelToContext("./models/plane.obj", models::planeContext, false); + loadModelToContext("./models/room.obj", models::roomContext, false); + loadModelToContext("./models/spaceship.obj", models::spaceshipContext, false); + loadModelToContext("./models/sphere.obj", models::sphereContext, false); + loadModelToContext("./models/window.obj", models::windowContext, true); + loadModelToContext("./models/test.obj", models::testContext, false); + loadModelToContext("./models/cube.obj", models::cubeContext, false); + collisionSystem.calculateSceneBounding(); skyboxTexture = loadSkybox(faces); //drawSkybox(models::cubeContext, transformation, skyboxTexture); @@ -449,31 +459,33 @@ void shutdown(GLFWwindow* window) void processInput(GLFWwindow* window) { glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f))); - glm::vec3 spaceshipUp = glm::vec3(0.f, 1.f, 0.f); float angleSpeed = 0.05f * deltaTime * 60; float moveSpeed = 0.05f * deltaTime * 60; if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) { glfwSetWindowShouldClose(window, true); } + + glm::vec3 newSpaceshipPos = spaceshipPos; + if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) - spaceshipPos += spaceshipDir * moveSpeed; + newSpaceshipPos += spaceshipDir * moveSpeed; if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) - spaceshipPos -= spaceshipDir * moveSpeed; + newSpaceshipPos -= spaceshipDir * moveSpeed; if (glfwGetKey(window, GLFW_KEY_X) == GLFW_PRESS) - spaceshipPos += spaceshipSide * moveSpeed; + newSpaceshipPos += spaceshipSide * moveSpeed; if (glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS) - spaceshipPos -= spaceshipSide * moveSpeed; - if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) - spaceshipPos += spaceshipUp * moveSpeed; - if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS) - spaceshipPos -= spaceshipUp * moveSpeed; + newSpaceshipPos -= spaceshipSide * moveSpeed; if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) spaceshipDir = glm::vec3(glm::eulerAngleY(angleSpeed) * glm::vec4(spaceshipDir, 0)); if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) spaceshipDir = glm::vec3(glm::eulerAngleY(-angleSpeed) * glm::vec4(spaceshipDir, 0)); - cameraPos = spaceshipPos - 0.5 * spaceshipDir + glm::vec3(0, 1, 0) * 0.2f; cameraDir = spaceshipDir; + cameraPos = newSpaceshipPos - 0.5 * spaceshipDir + glm::vec3(0, 1, 0) * 0.2f; + + if ((newSpaceshipPos.x != spaceshipPos.x || newSpaceshipPos.y != spaceshipPos.y || newSpaceshipPos.z != spaceshipPos.z) && collisionSystem.canMove(newSpaceshipPos)) { + spaceshipPos = newSpaceshipPos; + } if (glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS) exposition -= 0.05; @@ -485,8 +497,14 @@ void processInput(GLFWwindow* window) printf("spaceshipDir = glm::vec3(%ff, %ff, %ff);\n", spaceshipDir.x, spaceshipDir.y, spaceshipDir.z); } - //cameraDir = glm::normalize(-cameraPos); + if (glfwGetKey(window, GLFW_KEY_4) == GLFW_PRESS) { + float x = collisionSystem.getRelativeX(spaceshipPos.x); + float z = collisionSystem.getRelativeZ(spaceshipPos.z); + printf("spaceshipPos = (%ff, %ff)\n", x, z); + } + + //cameraDir = glm::normalize(-cameraPos); } // funkcja jest glowna petla diff --git a/grk-cw.sln b/grk-cw.sln index 74faab8..5f4a8b5 100644 --- a/grk-cw.sln +++ b/grk-cw.sln @@ -1,74 +1,20 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.3.32929.385 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31321.278 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grk-cw2", "cw 2\grk-cw2.vcxproj", "{B4031E08-6274-4FFD-B41C-F8EA29E977FB}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grk-cw1", "cw 1\grk-cw1.vcxproj", "{1B448102-E76C-4347-BDC7-40D02A567DB6}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grk-cw3", "cw 3\grk-cw3.vcxproj", "{F201D210-49F1-4EFF-B8A0-56D56880D14B}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grk-cw4", "cw 4\grk-cw4.vcxproj", "{D7858112-9412-4E7E-AB73-A911604592EC}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grk-cw5", "cw 5\grk-cw5.vcxproj", "{7B84D06D-946D-4DCB-BD1A-B5635B0F83F0}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grk-cw6", "cw 6\grk-cw6.vcxproj", "{3952C396-B1C6-44CD-96DD-C1AC15D32978}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grk-cw8", "cw 8\grk-cw8.vcxproj", "{6D813233-7D21-4888-944E-8E3CCAC3EFD3}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grk-cw9", "cw 9\grk-cw9.vcxproj", "{5BACD057-4B83-4CB6-A367-40A10BCE2149}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grk-cw7", "cw 7\grk-cw7.vcxproj", "{F2FC2E8F-CBA6-49D7-8B73-4BFBCB64D310}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grk-cw10", "cw 11\grk-cw10.vcxproj", "{8DF85446-560F-459F-BB86-0477FCA30165}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x86 = Debug|x86 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {B4031E08-6274-4FFD-B41C-F8EA29E977FB}.Debug|x86.ActiveCfg = Debug|Win32 - {B4031E08-6274-4FFD-B41C-F8EA29E977FB}.Debug|x86.Build.0 = Debug|Win32 - {B4031E08-6274-4FFD-B41C-F8EA29E977FB}.Release|x86.ActiveCfg = Release|Win32 - {B4031E08-6274-4FFD-B41C-F8EA29E977FB}.Release|x86.Build.0 = Release|Win32 - {1B448102-E76C-4347-BDC7-40D02A567DB6}.Debug|x86.ActiveCfg = Debug|Win32 - {1B448102-E76C-4347-BDC7-40D02A567DB6}.Debug|x86.Build.0 = Debug|Win32 - {1B448102-E76C-4347-BDC7-40D02A567DB6}.Release|x86.ActiveCfg = Release|Win32 - {1B448102-E76C-4347-BDC7-40D02A567DB6}.Release|x86.Build.0 = Release|Win32 - {F201D210-49F1-4EFF-B8A0-56D56880D14B}.Debug|x86.ActiveCfg = Debug|Win32 - {F201D210-49F1-4EFF-B8A0-56D56880D14B}.Debug|x86.Build.0 = Debug|Win32 - {F201D210-49F1-4EFF-B8A0-56D56880D14B}.Release|x86.ActiveCfg = Release|Win32 - {F201D210-49F1-4EFF-B8A0-56D56880D14B}.Release|x86.Build.0 = Release|Win32 - {D7858112-9412-4E7E-AB73-A911604592EC}.Debug|x86.ActiveCfg = Debug|Win32 - {D7858112-9412-4E7E-AB73-A911604592EC}.Debug|x86.Build.0 = Debug|Win32 - {D7858112-9412-4E7E-AB73-A911604592EC}.Release|x86.ActiveCfg = Release|Win32 - {D7858112-9412-4E7E-AB73-A911604592EC}.Release|x86.Build.0 = Release|Win32 - {7B84D06D-946D-4DCB-BD1A-B5635B0F83F0}.Debug|x86.ActiveCfg = Debug|Win32 - {7B84D06D-946D-4DCB-BD1A-B5635B0F83F0}.Debug|x86.Build.0 = Debug|Win32 - {7B84D06D-946D-4DCB-BD1A-B5635B0F83F0}.Release|x86.ActiveCfg = Release|Win32 - {7B84D06D-946D-4DCB-BD1A-B5635B0F83F0}.Release|x86.Build.0 = Release|Win32 - {3952C396-B1C6-44CD-96DD-C1AC15D32978}.Debug|x86.ActiveCfg = Debug|Win32 - {3952C396-B1C6-44CD-96DD-C1AC15D32978}.Debug|x86.Build.0 = Debug|Win32 - {3952C396-B1C6-44CD-96DD-C1AC15D32978}.Release|x86.ActiveCfg = Release|Win32 - {3952C396-B1C6-44CD-96DD-C1AC15D32978}.Release|x86.Build.0 = Release|Win32 - {6D813233-7D21-4888-944E-8E3CCAC3EFD3}.Debug|x86.ActiveCfg = Debug|Win32 - {6D813233-7D21-4888-944E-8E3CCAC3EFD3}.Debug|x86.Build.0 = Debug|Win32 - {6D813233-7D21-4888-944E-8E3CCAC3EFD3}.Release|x86.ActiveCfg = Release|Win32 - {6D813233-7D21-4888-944E-8E3CCAC3EFD3}.Release|x86.Build.0 = Release|Win32 {5BACD057-4B83-4CB6-A367-40A10BCE2149}.Debug|x86.ActiveCfg = Debug|Win32 {5BACD057-4B83-4CB6-A367-40A10BCE2149}.Debug|x86.Build.0 = Debug|Win32 {5BACD057-4B83-4CB6-A367-40A10BCE2149}.Release|x86.ActiveCfg = Release|Win32 {5BACD057-4B83-4CB6-A367-40A10BCE2149}.Release|x86.Build.0 = Release|Win32 - {F2FC2E8F-CBA6-49D7-8B73-4BFBCB64D310}.Debug|x86.ActiveCfg = Debug|Win32 - {F2FC2E8F-CBA6-49D7-8B73-4BFBCB64D310}.Debug|x86.Build.0 = Debug|Win32 - {F2FC2E8F-CBA6-49D7-8B73-4BFBCB64D310}.Release|x86.ActiveCfg = Release|Win32 - {F2FC2E8F-CBA6-49D7-8B73-4BFBCB64D310}.Release|x86.Build.0 = Release|Win32 - {8DF85446-560F-459F-BB86-0477FCA30165}.Debug|x86.ActiveCfg = Debug|Win32 - {8DF85446-560F-459F-BB86-0477FCA30165}.Debug|x86.Build.0 = Debug|Win32 - {8DF85446-560F-459F-BB86-0477FCA30165}.Release|x86.ActiveCfg = Release|Win32 - {8DF85446-560F-459F-BB86-0477FCA30165}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE