Compare commits
2 Commits
49fee6ded8
...
b01fa46b8a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b01fa46b8a | ||
|
|
4759a5419e |
45
main.cpp
45
main.cpp
@@ -241,11 +241,11 @@ static void UpdateRover(const std::vector<Plot>& fences) {
|
|||||||
float roverZMax = newFoward + roverHalfLengthZ;
|
float roverZMax = newFoward + roverHalfLengthZ;
|
||||||
|
|
||||||
// Sprawdzanie kolizji przed aktualizacją pozycji
|
// Sprawdzanie kolizji przed aktualizacją pozycji
|
||||||
if (Kolizja == true) {
|
if (!Kolizja == true) {
|
||||||
if (CheckAllFencesCollision(roverZMin, roverZMax, roverXMin, roverXMax, fences)) {
|
if (CheckAllFencesCollision(roverZMin, roverZMax, roverXMin, roverXMax, fences)) {
|
||||||
// Jeśli jest kolizja, zatrzymujemy łazik
|
// Jeśli jest kolizja, zatrzymujemy łazik
|
||||||
velocity = 0.0f;
|
velocity = 0.0f;
|
||||||
cout << "Kolizja podczas ruchu\n";
|
//cout << "Kolizja podczas ruchu\n";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Jeśli brak kolizji, aktualizujemy pozycję
|
// Jeśli brak kolizji, aktualizujemy pozycję
|
||||||
@@ -261,11 +261,11 @@ static void UpdateRover(const std::vector<Plot>& fences) {
|
|||||||
|
|
||||||
// Obracamy narożniki łazika
|
// Obracamy narożniki łazika
|
||||||
std::vector<std::pair<float, float>> corners(4);
|
std::vector<std::pair<float, float>> corners(4);
|
||||||
corners[0] = { Sides - roverHalfWidthX, Foward - roverHalfLengthZ }; // Lewy dolny
|
corners[0] = {Sides - roverHalfWidthX, Foward - roverHalfLengthZ}; // Lewy dolny
|
||||||
corners[1] = { Sides + roverHalfWidthX, Foward - roverHalfLengthZ }; // Prawy dolny
|
corners[1] = {Sides + roverHalfWidthX, Foward - roverHalfLengthZ}; // Prawy dolny
|
||||||
corners[2] = { Sides - roverHalfWidthX, Foward + roverHalfLengthZ }; // Lewy górny
|
corners[2] = {Sides - roverHalfWidthX, Foward + roverHalfLengthZ}; // Lewy górny
|
||||||
corners[3] = { Sides + roverHalfWidthX, Foward + roverHalfLengthZ }; // Prawy górny
|
corners[3] = {Sides + roverHalfWidthX, Foward + roverHalfLengthZ}; // Prawy górny
|
||||||
|
bool collisionDetected = false;
|
||||||
// Obracamy wszystkie narożniki
|
// Obracamy wszystkie narożniki
|
||||||
for (auto& corner : corners) {
|
for (auto& corner : corners) {
|
||||||
float x = corner.first;
|
float x = corner.first;
|
||||||
@@ -273,22 +273,25 @@ static void UpdateRover(const std::vector<Plot>& fences) {
|
|||||||
|
|
||||||
corner.first = Sides + (x - Sides) * cos(radNewRotation) - (z - Foward) * sin(radNewRotation);
|
corner.first = Sides + (x - Sides) * cos(radNewRotation) - (z - Foward) * sin(radNewRotation);
|
||||||
corner.second = Foward + (x - Sides) * sin(radNewRotation) + (z - Foward) * cos(radNewRotation);
|
corner.second = Foward + (x - Sides) * sin(radNewRotation) + (z - Foward) * cos(radNewRotation);
|
||||||
}
|
|
||||||
|
|
||||||
// Sprawdzamy kolizję na podstawie obróconych narożników
|
// Sprawdzamy kolizję na podstawie obróconych narożników
|
||||||
bool collisionDetected = false;
|
|
||||||
for (const auto& corner : corners) {
|
|
||||||
if (CheckAllFencesCollision(corner.first, corner.first, corner.second, corner.second, fences)) {
|
if (CheckAllFencesCollision(corner.first, corner.first, corner.second, corner.second, fences)) {
|
||||||
collisionDetected = true;
|
collisionDetected = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (CheckAllFencesCollision( corner.second, corner.second, corner.first, corner.first, fences)) {
|
||||||
|
collisionDetected = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (collisionDetected) {
|
if (collisionDetected) {
|
||||||
rotationVelocity = 0.0f; // Zatrzymujemy obrót
|
rotationVelocity = 0.0f; // Zatrzymujemy obrót
|
||||||
cout << "Kolizja podczas obrotu\n";
|
//cout << "Kolizja podczas obrotu\n";
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Aktualizujemy rotację, jeśli nie ma kolizji
|
// Aktualizujemy rotację, jeśli nie ma kolizji
|
||||||
Rotation = newRotation;
|
Rotation = newRotation;
|
||||||
if (Rotation >= 360.0f) Rotation -= 360.0f;
|
if (Rotation >= 360.0f) Rotation -= 360.0f;
|
||||||
@@ -1147,8 +1150,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, texture[0]); // aktywuje obiekt tekstury
|
glBindTexture(GL_TEXTURE_2D, texture[0]); // aktywuje obiekt tekstury
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
|
||||||
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||||
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||||
@@ -1165,8 +1168,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
bitmapData = LoadBitmapFile((char*)"res/img/grass02.bmp", &bitmapInfoHeader);
|
bitmapData = LoadBitmapFile((char*)"res/img/grass02.bmp", &bitmapInfoHeader);
|
||||||
glBindTexture(GL_TEXTURE_2D, texture[1]); // aktywuje obiekt tekstury
|
glBindTexture(GL_TEXTURE_2D, texture[1]); // aktywuje obiekt tekstury
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
|
||||||
@@ -1181,8 +1184,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
bitmapData = LoadBitmapFile((char*)"res/img/barnroof.bmp", &bitmapInfoHeader);
|
bitmapData = LoadBitmapFile((char*)"res/img/barnroof.bmp", &bitmapInfoHeader);
|
||||||
glBindTexture(GL_TEXTURE_2D, texture[2]); // aktywuje obiekt tekstury
|
glBindTexture(GL_TEXTURE_2D, texture[2]); // aktywuje obiekt tekstury
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||||
@@ -1197,8 +1200,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
bitmapData = LoadBitmapFile((char*)"res/img/brickwall.bmp", &bitmapInfoHeader);
|
bitmapData = LoadBitmapFile((char*)"res/img/brickwall.bmp", &bitmapInfoHeader);
|
||||||
glBindTexture(GL_TEXTURE_2D, texture[3]); // aktywuje obiekt tekstury
|
glBindTexture(GL_TEXTURE_2D, texture[3]); // aktywuje obiekt tekstury
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||||
|
|||||||
Reference in New Issue
Block a user