added room colision

This commit is contained in:
minni0n 2023-02-02 20:03:52 +01:00
parent b5a86cd828
commit 31495f50b3
27 changed files with 84 additions and 39 deletions

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.

Binary file not shown.

View File

@ -2,7 +2,7 @@
<Project>
<ProjectOutputs>
<ProjectOutput>
<FullPath>C:\Users\arciom\Desktop\GRK_game_scene\Debug\grk-cw9.exe</FullPath>
<FullPath>C:\Users\Serhii\source\repos\grk_game_scene\Debug\grk-cw9.exe</FullPath>
</ProjectOutput>
</ProjectOutputs>
<ContentFiles />

View File

@ -1,48 +1,48 @@
 main.cpp
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\shared\minwindef.h(130,1): warning C4005: 'APIENTRY': macro redefinition
C:\Users\arciom\Desktop\GRK_game_scene\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123): message : see previous definition of 'APIENTRY'
C:\Users\arciom\Desktop\GRK_game_scene\cw 9\src\ex_9_1.hpp(124,30): warning C4305: 'initializing': truncation from 'double' to 'float'
C:\Users\arciom\Desktop\GRK_game_scene\cw 9\src\ex_9_1.hpp(166,38): warning C4305: '=': truncation from 'double' to 'float'
C:\Users\arciom\Desktop\GRK_game_scene\cw 9\src\ex_9_1.hpp(189,16): warning C4305: 'initializing': truncation from 'double' to 'float'
C:\Users\arciom\Desktop\GRK_game_scene\cw 9\src\ex_9_1.hpp(230,20): warning C4018: '<': signed/unsigned mismatch
C:\Users\arciom\Desktop\GRK_game_scene\cw 9\src\ex_9_1.hpp(266,13): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data
C:\Users\arciom\Desktop\GRK_game_scene\cw 9\src\ex_9_1.hpp(280,98): warning C4305: 'argument': truncation from 'double' to 'T'
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\shared\minwindef.h(130,1): warning C4005: 'APIENTRY': macro redefinition
C:\Users\Serhii\source\repos\grk_game_scene\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123): message : see previous definition of 'APIENTRY'
C:\Users\Serhii\source\repos\grk_game_scene\cw 9\src\ex_9_1.hpp(124,30): warning C4305: 'initializing': truncation from 'double' to 'float'
C:\Users\Serhii\source\repos\grk_game_scene\cw 9\src\ex_9_1.hpp(168,38): warning C4305: '=': truncation from 'double' to 'float'
C:\Users\Serhii\source\repos\grk_game_scene\cw 9\src\ex_9_1.hpp(191,16): warning C4305: 'initializing': truncation from 'double' to 'float'
C:\Users\Serhii\source\repos\grk_game_scene\cw 9\src\ex_9_1.hpp(232,20): warning C4018: '<': signed/unsigned mismatch
C:\Users\Serhii\source\repos\grk_game_scene\cw 9\src\ex_9_1.hpp(268,13): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data
C:\Users\Serhii\source\repos\grk_game_scene\cw 9\src\ex_9_1.hpp(282,98): warning C4305: 'argument': truncation from 'double' to 'T'
with
[
T=float
]
C:\Users\arciom\Desktop\GRK_game_scene\cw 9\src\ex_9_1.hpp(283,68): warning C4305: 'argument': truncation from 'double' to 'T'
C:\Users\Serhii\source\repos\grk_game_scene\cw 9\src\ex_9_1.hpp(285,68): warning C4305: 'argument': truncation from 'double' to 'T'
with
[
T=float
]
C:\Users\arciom\Desktop\GRK_game_scene\cw 9\src\ex_9_1.hpp(317,13): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data
C:\Users\arciom\Desktop\GRK_game_scene\cw 9\src\ex_9_1.hpp(372,13): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data
C:\Users\arciom\Desktop\GRK_game_scene\cw 9\src\ex_9_1.hpp(381,108): warning C4305: 'argument': truncation from 'double' to 'T'
C:\Users\Serhii\source\repos\grk_game_scene\cw 9\src\ex_9_1.hpp(319,13): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data
C:\Users\Serhii\source\repos\grk_game_scene\cw 9\src\ex_9_1.hpp(374,13): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data
C:\Users\Serhii\source\repos\grk_game_scene\cw 9\src\ex_9_1.hpp(383,108): warning C4305: 'argument': truncation from 'double' to 'T'
with
[
T=float
]
C:\Users\arciom\Desktop\GRK_game_scene\cw 9\src\ex_9_1.hpp(389,87): warning C4305: 'argument': truncation from 'double' to 'T'
C:\Users\Serhii\source\repos\grk_game_scene\cw 9\src\ex_9_1.hpp(391,87): warning C4305: 'argument': truncation from 'double' to 'T'
with
[
T=float
]
C:\Users\arciom\Desktop\GRK_game_scene\cw 9\src\ex_9_1.hpp(389,223): warning C4305: 'argument': truncation from 'double' to 'float'
C:\Users\arciom\Desktop\GRK_game_scene\cw 9\src\ex_9_1.hpp(392,59): warning C4305: 'argument': truncation from 'double' to 'T'
C:\Users\Serhii\source\repos\grk_game_scene\cw 9\src\ex_9_1.hpp(391,223): warning C4305: 'argument': truncation from 'double' to 'float'
C:\Users\Serhii\source\repos\grk_game_scene\cw 9\src\ex_9_1.hpp(394,59): warning C4305: 'argument': truncation from 'double' to 'T'
with
[
T=float
]
C:\Users\arciom\Desktop\GRK_game_scene\cw 9\src\ex_9_1.hpp(393,37): warning C4305: 'argument': truncation from 'double' to 'float'
C:\Users\arciom\Desktop\GRK_game_scene\cw 9\src\ex_9_1.hpp(428,2): warning C4305: 'argument': truncation from 'double' to 'float'
C:\Users\arciom\Desktop\GRK_game_scene\cw 9\src\ex_9_1.hpp(434,20): warning C4018: '<': signed/unsigned mismatch
C:\Users\arciom\Desktop\GRK_game_scene\cw 9\src\ex_9_1.hpp(439,50): warning C4305: 'argument': truncation from 'double' to 'float'
C:\Users\arciom\Desktop\GRK_game_scene\cw 9\src\ex_9_1.hpp(440,51): warning C4305: 'argument': truncation from 'double' to 'float'
C:\Users\arciom\Desktop\GRK_game_scene\cw 9\src\ex_9_1.hpp(512,21): warning C4018: '<': signed/unsigned mismatch
C:\Users\arciom\Desktop\GRK_game_scene\cw 9\src\ex_9_1.hpp(514,49): warning C4244: 'argument': conversion from 'double' to 'float', possible loss of data
C:\Users\arciom\Desktop\GRK_game_scene\cw 9\src\ex_9_1.hpp(669,21): warning C4305: '-=': truncation from 'double' to 'float'
C:\Users\arciom\Desktop\GRK_game_scene\cw 9\src\ex_9_1.hpp(671,21): warning C4305: '+=': truncation from 'double' to 'float'
C:\Users\Serhii\source\repos\grk_game_scene\cw 9\src\ex_9_1.hpp(395,37): warning C4305: 'argument': truncation from 'double' to 'float'
C:\Users\Serhii\source\repos\grk_game_scene\cw 9\src\ex_9_1.hpp(430,2): warning C4305: 'argument': truncation from 'double' to 'float'
C:\Users\Serhii\source\repos\grk_game_scene\cw 9\src\ex_9_1.hpp(436,20): warning C4018: '<': signed/unsigned mismatch
C:\Users\Serhii\source\repos\grk_game_scene\cw 9\src\ex_9_1.hpp(441,50): warning C4305: 'argument': truncation from 'double' to 'float'
C:\Users\Serhii\source\repos\grk_game_scene\cw 9\src\ex_9_1.hpp(442,51): warning C4305: 'argument': truncation from 'double' to 'float'
C:\Users\Serhii\source\repos\grk_game_scene\cw 9\src\ex_9_1.hpp(520,21): warning C4018: '<': signed/unsigned mismatch
C:\Users\Serhii\source\repos\grk_game_scene\cw 9\src\ex_9_1.hpp(522,49): warning C4244: 'argument': conversion from 'double' to 'float', possible loss of data
C:\Users\Serhii\source\repos\grk_game_scene\cw 9\src\ex_9_1.hpp(726,21): warning C4305: '-=': truncation from 'double' to 'float'
C:\Users\Serhii\source\repos\grk_game_scene\cw 9\src\ex_9_1.hpp(728,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\arciom\Desktop\GRK_game_scene\Debug\grk-cw9.exe
grk-cw9.vcxproj -> C:\Users\Serhii\source\repos\grk_game_scene\Debug\grk-cw9.exe

View File

@ -1,2 +1,2 @@
PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.29.30133:VCServicingVersionMFC=14.29.30136:VCServicingVersionCrtHeaders=14.29.30136:TargetPlatformVersion=10.0.22000.0:
Debug|Win32|C:\Users\arciom\Desktop\GRK_game_scene\|
PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.29.30133:TargetPlatformVersion=10.0.19041.0:
Debug|Win32|C:\Users\Serhii\source\repos\grk_game_scene\|

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -19,7 +19,7 @@ SpaceShip::SpaceShip(int numberOfLasers) {
gun.reserve(maxNumberOfLasers);
this->spaceShipDir = glm::vec3(-0.490263f, 0.000000f, 0.871578f);
this->spaceShipPos = glm::vec3(0.065808f, 1.250000f, -2.189549f);
this->spaceShipPos = glm::vec3(0.065808f, 1.250000f, -2.0);
for (int i = 0; i < maxNumberOfLasers; i++) {
gun.push_back(Laser(this->spaceShipDir, this->spaceShipPos, 0.01, false));

View File

@ -11,7 +11,7 @@
#include "Laser.h"
#include "SpaceShip.h"
#include <string>
#include "Box.cpp"
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
@ -156,6 +156,8 @@ std::vector<glm::vec3> lasersLightPos{ laserLightPos0, laserLightPos1, laserLigh
std::vector<Laser> lasers;
void updateDeltaTime(float time) {
if (lastTime < 0) {
lastTime = time;
@ -422,7 +424,7 @@ void renderScene(GLFWwindow* window)
// glm::vec3(0.3, 0.3, 0.5)
// );
drawObjectPBR(shipContext,
glm::translate(spaceShip.getSpaceShipPos()) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>()) * glm::scale(glm::vec3(0.03f)),
glm::translate(spaceShip.getSpaceShipPos()) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>()) * glm::scale(glm::vec3(0.015f)),
glm::vec3(0.3, 0.3, 0.5),
0.2, 1.0
);
@ -442,6 +444,12 @@ void renderScene(GLFWwindow* window)
}
/*std::cout << spaceShip.getSpaceShipPos().x << std::endl;
std::cout << spaceShip.getSpaceShipPos().y << std::endl;*/
//std::cout << spaceShip.getSpaceShipPos().z << std::endl;
//test depth buffer
/*glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(programTest);
@ -527,6 +535,8 @@ void mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
}
void init(GLFWwindow* window)
{
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
@ -592,7 +602,18 @@ void shutdown(GLFWwindow* window)
shaderLoader.DeleteProgram(program);
}
bool check_room_collision(int plus_or_minus) {
glm::vec3 spaceshipUp = glm::vec3(0.f, 1.f, 0.f);
float moveSpeed = 0.02f * deltaTime * 60;
glm::vec3 spaceShipPos = spaceShip.getSpaceShipPos() + (spaceShip.getSpaceShipDir() * moveSpeed) * plus_or_minus;
bool collision = spaceShipPos.z < -2.04 || spaceShipPos.z > 2.06 ||
spaceShipPos.x < -1.61 || spaceShipPos.x > 1.59 ||
spaceShipPos.y > 2.15 || spaceShipPos.y < 0.11;
return collision;
}
//obsluga wejscia
void processInput(GLFWwindow* window)
@ -603,38 +624,62 @@ void processInput(GLFWwindow* window)
glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceShip.getSpaceShipDir(), 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;
float moveSpeed = 0.02f * deltaTime * 60;
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
glfwSetWindowShouldClose(window, true);
}
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) {
//spaceshipPos += spaceshipDir * moveSpeed;
if (!check_room_collision(1)) {
spaceShip.setSpaceShipPos(spaceShip.getSpaceShipPos() + spaceShip.getSpaceShipDir() * moveSpeed);
}
//spaceshipPos += spaceshipDir * moveSpeed;
}
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) {
//spaceshipPos -= spaceshipDir * moveSpeed;
if (!check_room_collision(-1)) {
spaceShip.setSpaceShipPos(spaceShip.getSpaceShipPos() - spaceShip.getSpaceShipDir() * moveSpeed);
}
//spaceshipPos -= spaceshipDir * moveSpeed;
}
if (glfwGetKey(window, GLFW_KEY_X) == GLFW_PRESS) {
//spaceshipPos += spaceshipSide * moveSpeed;
if (!check_room_collision(1)) {
spaceShip.setSpaceShipPos(spaceShip.getSpaceShipPos() + spaceshipSide * moveSpeed);
}
}
if (glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS) {
if (!check_room_collision(-1)) {
spaceShip.setSpaceShipPos(spaceShip.getSpaceShipPos() - spaceshipSide * moveSpeed);
}
//spaceshipPos -= spaceshipSide * moveSpeed;
spaceShip.setSpaceShipPos(spaceShip.getSpaceShipPos() - spaceshipSide * moveSpeed);
}
if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) {
//spaceshipPos += spaceshipUp * moveSpeed;
if ((spaceShip.getSpaceShipPos() + spaceshipUp * moveSpeed).y > 2.25) {
std::cout << "Collision detected!" << std::endl;
}
else{
spaceShip.setSpaceShipPos(spaceShip.getSpaceShipPos() + spaceshipUp * moveSpeed);
}
if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS) {
//spaceshipPos -= spaceshipUp * moveSpeed;
}
if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS) {
if ((spaceShip.getSpaceShipPos() + spaceshipUp * moveSpeed).y < 0.05) {
std::cout << "Collision detected!" << std::endl;
}
else {
spaceShip.setSpaceShipPos(spaceShip.getSpaceShipPos() - spaceshipUp * moveSpeed);
}
}
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) {
//spaceshipDir = glm::vec3(glm::eulerAngleY(angleSpeed) * glm::vec4(spaceShip.getSpaceShipDir(), 0));