System kolizji
This commit is contained in:
parent
8bd1c45046
commit
0346d04a0b
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -2,7 +2,7 @@
|
|||||||
<Project>
|
<Project>
|
||||||
<ProjectOutputs>
|
<ProjectOutputs>
|
||||||
<ProjectOutput>
|
<ProjectOutput>
|
||||||
<FullPath>C:\Users\Anna Niczyporuk\source\repos\GRK_Project\Debug\grk-cw9.exe</FullPath>
|
<FullPath>C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\Debug\grk-cw9.exe</FullPath>
|
||||||
</ProjectOutput>
|
</ProjectOutput>
|
||||||
</ProjectOutputs>
|
</ProjectOutputs>
|
||||||
<ContentFiles />
|
<ContentFiles />
|
||||||
|
@ -1,47 +1,55 @@
|
|||||||
main.cpp
|
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:\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\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\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\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\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(110,17): warning C4101: 'data': unreferenced local variable
|
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\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(135,38): warning C4305: '=': truncation from 'double' to 'float'
|
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\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\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\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\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\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\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
|
with
|
||||||
[
|
[
|
||||||
T=float
|
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
|
with
|
||||||
[
|
[
|
||||||
T=float
|
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\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\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(314,108): warning C4305: 'argument': truncation from 'double' to 'T'
|
||||||
with
|
with
|
||||||
[
|
[
|
||||||
T=float
|
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
|
with
|
||||||
[
|
[
|
||||||
T=float
|
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\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\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(325,59): warning C4305: 'argument': truncation from 'double' to 'T'
|
||||||
with
|
with
|
||||||
[
|
[
|
||||||
T=float
|
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\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\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\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\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(412,108): warning C4305: 'argument': truncation from 'double' to 'T'
|
||||||
with
|
with
|
||||||
[
|
[
|
||||||
T=float
|
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\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\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(493,21): warning C4305: '+=': truncation from 'double' to 'float'
|
||||||
Box.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification
|
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
|
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
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,2 +1,2 @@
|
|||||||
PlatformToolSet=v143:VCToolArchitecture=Native32Bit:VCToolsVersion=14.33.31629:TargetPlatformVersion=10.0.19041.0:
|
PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.29.30037:TargetPlatformVersion=10.0.19041.0:
|
||||||
Debug|Win32|C:\Users\Anna Niczyporuk\source\repos\GRK_Project\|
|
Debug|Win32|C:\Users\Artur\Desktop\studia\3\Grafika komputerowa\GRK_Project\|
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -13,6 +13,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="src\Box.cpp" />
|
<ClCompile Include="src\Box.cpp" />
|
||||||
<ClCompile Include="src\Camera.cpp" />
|
<ClCompile Include="src\Camera.cpp" />
|
||||||
|
<ClCompile Include="src\Collision_System.cpp" />
|
||||||
<ClCompile Include="src\main.cpp" />
|
<ClCompile Include="src\main.cpp" />
|
||||||
<ClCompile Include="src\Render_Utils.cpp" />
|
<ClCompile Include="src\Render_Utils.cpp" />
|
||||||
<ClCompile Include="src\Shader_Loader.cpp" />
|
<ClCompile Include="src\Shader_Loader.cpp" />
|
||||||
@ -64,7 +65,7 @@
|
|||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
<PlatformToolset>v143</PlatformToolset>
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
@ -54,6 +54,9 @@
|
|||||||
<ClCompile Include="src\TriangleSoup.cpp">
|
<ClCompile Include="src\TriangleSoup.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\Collision_System.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="src\objload.h">
|
<ClInclude Include="src\objload.h">
|
||||||
|
125
cw 9/src/Collision_System.cpp
Normal file
125
cw 9/src/Collision_System.cpp
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
#include "glew.h"
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#include "glm.hpp"
|
||||||
|
#include "ext.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
#include <cmath>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "freeglut.h"
|
||||||
|
#include <assimp/Importer.hpp>
|
||||||
|
#include <assimp/scene.h>
|
||||||
|
#include <assimp/postprocess.h>
|
||||||
|
|
||||||
|
#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<Bounding> 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);
|
||||||
|
}
|
||||||
|
};
|
@ -8,27 +8,56 @@
|
|||||||
#include <assimp/scene.h>
|
#include <assimp/scene.h>
|
||||||
#include <assimp/postprocess.h>
|
#include <assimp/postprocess.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Core::RenderContext::initFromAssimpMesh(aiMesh* mesh) {
|
void Core::RenderContext::initFromAssimpMesh(aiMesh* mesh) {
|
||||||
vertexArray = 0;
|
vertexArray = 0;
|
||||||
vertexBuffer = 0;
|
vertexBuffer = 0;
|
||||||
vertexIndexBuffer = 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<float> textureCoord;
|
std::vector<float> textureCoord;
|
||||||
std::vector<unsigned int> indices;
|
std::vector<unsigned int> indices;
|
||||||
//tex coord must be converted to 2d vecs
|
//tex coord must be converted to 2d vecs
|
||||||
for (unsigned int i = 0; i < mesh->mNumVertices; i++)
|
for (unsigned int i = 0; i < mesh->mNumVertices; i++)
|
||||||
{
|
{
|
||||||
|
float x, y;
|
||||||
if (mesh->mTextureCoords[0] != nullptr) {
|
if (mesh->mTextureCoords[0] != nullptr) {
|
||||||
textureCoord.push_back(mesh->mTextureCoords[0][i].x);
|
x = mesh->mTextureCoords[0][i].x;
|
||||||
textureCoord.push_back(mesh->mTextureCoords[0][i].y);
|
y = mesh->mTextureCoords[0][i].y;
|
||||||
}
|
} else {
|
||||||
else {
|
x = 0.0f;
|
||||||
textureCoord.push_back(0.0f);
|
y = 0.0f;
|
||||||
textureCoord.push_back(0.0f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
textureCoord.push_back(x);
|
||||||
|
textureCoord.push_back(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mesh->mTextureCoords[0] == nullptr) {
|
if (mesh->mTextureCoords[0] == nullptr) {
|
||||||
std::cout << "no uv coords\n";
|
std::cout << "no uv coords\n";
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "TriangleSoup.hpp"
|
#include "TriangleSoup.hpp"
|
||||||
|
|
||||||
#include "Box.cpp"
|
#include "Box.cpp"
|
||||||
|
#include "Collision_System.cpp"
|
||||||
#include <assimp/Importer.hpp>
|
#include <assimp/Importer.hpp>
|
||||||
#include <assimp/scene.h>
|
#include <assimp/scene.h>
|
||||||
#include <assimp/postprocess.h>
|
#include <assimp/postprocess.h>
|
||||||
@ -21,6 +22,8 @@ const unsigned int SHADOW_WIDTH = 1024, SHADOW_HEIGHT = 1024;
|
|||||||
|
|
||||||
int WIDTH = 500, HEIGHT = 500;
|
int WIDTH = 500, HEIGHT = 500;
|
||||||
|
|
||||||
|
CollisionSystem collisionSystem;
|
||||||
|
|
||||||
namespace models {
|
namespace models {
|
||||||
Core::RenderContext bedContext;
|
Core::RenderContext bedContext;
|
||||||
Core::RenderContext chairContext;
|
Core::RenderContext chairContext;
|
||||||
@ -382,7 +385,7 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
|||||||
WIDTH = width;
|
WIDTH = width;
|
||||||
HEIGHT = height;
|
HEIGHT = height;
|
||||||
}
|
}
|
||||||
void loadModelToContext(std::string path, Core::RenderContext& context)
|
void loadModelToContext(std::string path, Core::RenderContext& context, bool updateCollisionSystem)
|
||||||
{
|
{
|
||||||
Assimp::Importer import;
|
Assimp::Importer import;
|
||||||
const aiScene* scene = import.ReadFile(path, aiProcess_Triangulate | aiProcess_CalcTangentSpace);
|
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;
|
std::cout << "ERROR::ASSIMP::" << import.GetErrorString() << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cout << path << "\n";
|
||||||
context.initFromAssimpMesh(scene->mMeshes[0]);
|
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");
|
programWater = shaderLoader.CreateProgram("shaders/shader_water.vert", "shaders/shader_water.frag");
|
||||||
water.readOBJ("./models/plane2.obj");
|
water.readOBJ("./models/plane2.obj");
|
||||||
texture::water = Core::LoadTexture("textures/test.png");
|
texture::water = Core::LoadTexture("textures/test.png");
|
||||||
loadModelToContext("./models/sphere.obj", sphereContext);
|
loadModelToContext("./models/sphere.obj", sphereContext, false);
|
||||||
loadModelToContext("./models/spaceship.obj", shipContext);
|
loadModelToContext("./models/spaceship.obj", shipContext, false);
|
||||||
loadModelToContext("./models/bed.obj", models::bedContext);
|
loadModelToContext("./models/bed.obj", models::bedContext, true);
|
||||||
loadModelToContext("./models/chair.obj", models::chairContext);
|
loadModelToContext("./models/chair.obj", models::chairContext, true);
|
||||||
loadModelToContext("./models/desk.obj", models::deskContext);
|
loadModelToContext("./models/desk.obj", models::deskContext, true);
|
||||||
loadModelToContext("./models/door.obj", models::doorContext);
|
loadModelToContext("./models/door.obj", models::doorContext, false);
|
||||||
loadModelToContext("./models/drawer.obj", models::drawerContext);
|
loadModelToContext("./models/drawer.obj", models::drawerContext, false);
|
||||||
loadModelToContext("./models/marbleBust.obj", models::marbleBustContext);
|
loadModelToContext("./models/marbleBust.obj", models::marbleBustContext, false);
|
||||||
loadModelToContext("./models/materace.obj", models::materaceContext);
|
loadModelToContext("./models/materace.obj", models::materaceContext, false);
|
||||||
loadModelToContext("./models/pencils.obj", models::pencilsContext);
|
loadModelToContext("./models/pencils.obj", models::pencilsContext, false);
|
||||||
loadModelToContext("./models/plane.obj", models::planeContext);
|
loadModelToContext("./models/plane.obj", models::planeContext, false);
|
||||||
loadModelToContext("./models/room.obj", models::roomContext);
|
loadModelToContext("./models/room.obj", models::roomContext, false);
|
||||||
loadModelToContext("./models/spaceship.obj", models::spaceshipContext);
|
loadModelToContext("./models/spaceship.obj", models::spaceshipContext, false);
|
||||||
loadModelToContext("./models/sphere.obj", models::sphereContext);
|
loadModelToContext("./models/sphere.obj", models::sphereContext, false);
|
||||||
loadModelToContext("./models/window.obj", models::windowContext);
|
loadModelToContext("./models/window.obj", models::windowContext, true);
|
||||||
loadModelToContext("./models/test.obj", models::testContext);
|
loadModelToContext("./models/test.obj", models::testContext, false);
|
||||||
loadModelToContext("./models/cube.obj", models::cubeContext);
|
loadModelToContext("./models/cube.obj", models::cubeContext, false);
|
||||||
|
collisionSystem.calculateSceneBounding();
|
||||||
|
|
||||||
skyboxTexture = loadSkybox(faces);
|
skyboxTexture = loadSkybox(faces);
|
||||||
//drawSkybox(models::cubeContext, transformation, skyboxTexture);
|
//drawSkybox(models::cubeContext, transformation, skyboxTexture);
|
||||||
@ -449,31 +459,33 @@ void shutdown(GLFWwindow* window)
|
|||||||
void processInput(GLFWwindow* window)
|
void processInput(GLFWwindow* window)
|
||||||
{
|
{
|
||||||
glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f)));
|
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 angleSpeed = 0.05f * deltaTime * 60;
|
||||||
float moveSpeed = 0.05f * deltaTime * 60;
|
float moveSpeed = 0.05f * deltaTime * 60;
|
||||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
||||||
glfwSetWindowShouldClose(window, true);
|
glfwSetWindowShouldClose(window, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glm::vec3 newSpaceshipPos = spaceshipPos;
|
||||||
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||||
spaceshipPos += spaceshipDir * moveSpeed;
|
newSpaceshipPos += spaceshipDir * moveSpeed;
|
||||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||||
spaceshipPos -= spaceshipDir * moveSpeed;
|
newSpaceshipPos -= spaceshipDir * moveSpeed;
|
||||||
if (glfwGetKey(window, GLFW_KEY_X) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_X) == GLFW_PRESS)
|
||||||
spaceshipPos += spaceshipSide * moveSpeed;
|
newSpaceshipPos += spaceshipSide * moveSpeed;
|
||||||
if (glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS)
|
||||||
spaceshipPos -= spaceshipSide * moveSpeed;
|
newSpaceshipPos -= spaceshipSide * moveSpeed;
|
||||||
if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS)
|
|
||||||
spaceshipPos += spaceshipUp * moveSpeed;
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS)
|
|
||||||
spaceshipPos -= spaceshipUp * moveSpeed;
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
|
||||||
spaceshipDir = glm::vec3(glm::eulerAngleY(angleSpeed) * glm::vec4(spaceshipDir, 0));
|
spaceshipDir = glm::vec3(glm::eulerAngleY(angleSpeed) * glm::vec4(spaceshipDir, 0));
|
||||||
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
|
||||||
spaceshipDir = glm::vec3(glm::eulerAngleY(-angleSpeed) * glm::vec4(spaceshipDir, 0));
|
spaceshipDir = glm::vec3(glm::eulerAngleY(-angleSpeed) * glm::vec4(spaceshipDir, 0));
|
||||||
|
|
||||||
cameraPos = spaceshipPos - 0.5 * spaceshipDir + glm::vec3(0, 1, 0) * 0.2f;
|
|
||||||
cameraDir = spaceshipDir;
|
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)
|
if (glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS)
|
||||||
exposition -= 0.05;
|
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);
|
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
|
// funkcja jest glowna petla
|
||||||
|
58
grk-cw.sln
58
grk-cw.sln
@ -1,74 +1,20 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 17
|
# Visual Studio Version 16
|
||||||
VisualStudioVersion = 17.3.32929.385
|
VisualStudioVersion = 16.0.31321.278
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
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}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grk-cw9", "cw 9\grk-cw9.vcxproj", "{5BACD057-4B83-4CB6-A367-40A10BCE2149}"
|
||||||
EndProject
|
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
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|x86 = Debug|x86
|
Debug|x86 = Debug|x86
|
||||||
Release|x86 = Release|x86
|
Release|x86 = Release|x86
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
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.ActiveCfg = Debug|Win32
|
||||||
{5BACD057-4B83-4CB6-A367-40A10BCE2149}.Debug|x86.Build.0 = 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.ActiveCfg = Release|Win32
|
||||||
{5BACD057-4B83-4CB6-A367-40A10BCE2149}.Release|x86.Build.0 = 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
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
Loading…
Reference in New Issue
Block a user