|
|
|
|
@@ -75,63 +75,35 @@ void SetDCPixelFormat(HDC hDC);
|
|
|
|
|
|
|
|
|
|
int polygonmode = 0;
|
|
|
|
|
std::time_t lastTime = std::time(nullptr);
|
|
|
|
|
int monitormode = 0;
|
|
|
|
|
int monitormode = 1;
|
|
|
|
|
int monitormodecounter = 0;
|
|
|
|
|
std::time_t monitormodehelper;
|
|
|
|
|
|
|
|
|
|
//Zmienne do ruchu ##############################################
|
|
|
|
|
/*
|
|
|
|
|
float Foward = 0.0f; // Pozycja łazika w przód/tył
|
|
|
|
|
float Sides = 0.0f; // Pozycja łazika w lewo/prawo
|
|
|
|
|
float Rotation = 0.0f; // Rotacja łazika (w stopniach)
|
|
|
|
|
|
|
|
|
|
// Zmienne do sterowania kamerą
|
|
|
|
|
float CameraHeight = 50.0f; // Wysokość kamery
|
|
|
|
|
|
|
|
|
|
void MoveRover(bool forward) {
|
|
|
|
|
// Zamieniamy kąt na radiany
|
|
|
|
|
float radRotation = Rotation * GL_PI / 180.0f;
|
|
|
|
|
|
|
|
|
|
// Wektor ruchu w kierunku przód/tył (kierunek łazika)
|
|
|
|
|
float moveX = cos(radRotation);
|
|
|
|
|
float moveZ = sin(radRotation);
|
|
|
|
|
|
|
|
|
|
// Ruch w przód
|
|
|
|
|
if (forward) {
|
|
|
|
|
Sides -= 1.1f * moveX;
|
|
|
|
|
Foward -= 1.1f * moveZ;
|
|
|
|
|
}
|
|
|
|
|
// Ruch w tył
|
|
|
|
|
else {
|
|
|
|
|
Sides += 1.1f * moveX;
|
|
|
|
|
Foward += 1.1f * moveZ;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Funkcja do obrotu kamery i łazika (A/D)
|
|
|
|
|
void RotateRoverAndCamera(float angle) {
|
|
|
|
|
Rotation += angle;
|
|
|
|
|
if (Rotation >= 360.0f) Rotation -= 360.0f;
|
|
|
|
|
if (Rotation < 0.0f) Rotation += 360.0f;
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
//Zmienne do ruchu ##############################################^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
FPSCounter fpsCounter;
|
|
|
|
|
|
|
|
|
|
static const int targetFPS = 144; // Celowany FPS
|
|
|
|
|
//Fps counter
|
|
|
|
|
void LimitFPS(int targetFPS) {
|
|
|
|
|
static void LimitFPS(int targetFPS) {
|
|
|
|
|
static auto lastTime = std::chrono::high_resolution_clock::now();
|
|
|
|
|
auto currentTime = std::chrono::high_resolution_clock::now();
|
|
|
|
|
std::chrono::duration<double> elapsed = currentTime - lastTime;
|
|
|
|
|
|
|
|
|
|
// Jeśli upłynęło za mało czasu, aby osiągnąć target FPS, czekamy
|
|
|
|
|
// Obliczamy czas na jedną klatkę
|
|
|
|
|
double frameTime = 1.0 / targetFPS; // Czas na jedną klatkę w sekundach
|
|
|
|
|
if (elapsed.count() < frameTime) {
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::duration<double>(frameTime - elapsed.count()));
|
|
|
|
|
double timeToWait = frameTime - elapsed.count(); // Obliczamy czas do czekania
|
|
|
|
|
|
|
|
|
|
if (timeToWait > 0.0) {
|
|
|
|
|
// Jeśli czas do czekania jest większy niż 0, to śpimy przez tę wartość
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::duration<double>(timeToWait));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lastTime = std::chrono::high_resolution_clock::now();
|
|
|
|
|
lastTime = currentTime; // Zaktualizuj czas dla następnej iteracji
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Kolizja = false;
|
|
|
|
|
bool keyWPressed = false;
|
|
|
|
|
bool keySPressed = false;
|
|
|
|
|
bool keyAPressed = false;
|
|
|
|
|
@@ -146,46 +118,69 @@ float MoveSpeed = 1.0f; // Prędkość poruszania się
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float velocity = 0.0f; // Aktualna prędkość łazika
|
|
|
|
|
const float friction = 0.1f; // Współczynnik tarcia (μ)
|
|
|
|
|
const float maxSpeed = 3.0f; // Maksymalna prędkość łazika
|
|
|
|
|
const float acceleration = 0.1f;
|
|
|
|
|
float rotationVelocity = 0.0f; // Prędkość obrotu łazika
|
|
|
|
|
const float rotationAcceleration = 0.1f; // Przyspieszenie obrotu
|
|
|
|
|
const float rotationFriction = 0.05f; // Współczynnik tarcia obrotu
|
|
|
|
|
const float maxRotationSpeed = 5.0f; // Maksymalna prędkość obrotu
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const float friction = 0.1f; // Współczynnik tarcia (μ)
|
|
|
|
|
const float maxSpeed = 5.0f; // Maksymalna prędkość łazika
|
|
|
|
|
const float acceleration = 0.2f;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Funkcja do poruszania łazikiem
|
|
|
|
|
void MoveRover(bool forward) {
|
|
|
|
|
// Zamieniamy kąt na radiany
|
|
|
|
|
float radRotation = Rotation * GL_PI / 180.0f;
|
|
|
|
|
const float rotationAcceleration = 0.075f; // Przyspieszenie obrotu
|
|
|
|
|
const float rotationFriction = 0.1f; // Współczynnik tarcia obrotu
|
|
|
|
|
const float maxRotationSpeed = 0.7f; // Maksymalna prędkość obrotu
|
|
|
|
|
|
|
|
|
|
// Wektor ruchu w kierunku przód/tył (kierunek łazika)
|
|
|
|
|
float moveX = cos(radRotation);
|
|
|
|
|
float moveZ = sin(radRotation);
|
|
|
|
|
// Struktura do reprezentacji płotu
|
|
|
|
|
struct Plot {
|
|
|
|
|
GLfloat xc; // Środek płotu w osi X
|
|
|
|
|
GLfloat yc; // Środek płotu w osi Y (nieużywane w kolizji, ale może być pomocne)
|
|
|
|
|
GLfloat zc; // Środek płotu w osi Z
|
|
|
|
|
GLfloat length; // Długość płotu
|
|
|
|
|
GLfloat gruboscY; // Grubość płotu
|
|
|
|
|
bool mod_x; // 0 - płot pionowy, 1 - płot poziomy
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Ruch w przód
|
|
|
|
|
if (forward) {
|
|
|
|
|
Sides -= MoveSpeed * moveX;
|
|
|
|
|
Foward -= MoveSpeed * moveZ;
|
|
|
|
|
}
|
|
|
|
|
// Ruch w tył
|
|
|
|
|
else {
|
|
|
|
|
Sides += MoveSpeed * moveX;
|
|
|
|
|
Foward += MoveSpeed * moveZ;
|
|
|
|
|
// Funkcja sprawdzająca kolizję z płotem
|
|
|
|
|
// Funkcja sprawdzająca kolizję z płotem, uwzględniając wymiary łazika
|
|
|
|
|
static bool CheckFenceCollision(float roverXMin, float roverXMax, float roverZMin, float roverZMax, const Plot& plot) {
|
|
|
|
|
if (plot.mod_x == 0) { // Płot pionowy (równoległy do osi Z)
|
|
|
|
|
float xMin = plot.xc - plot.gruboscY / 2.0f;
|
|
|
|
|
float xMax = plot.xc + plot.gruboscY / 2.0f;
|
|
|
|
|
float zMin = plot.zc - plot.length / 2.0f;
|
|
|
|
|
float zMax = plot.zc + plot.length / 2.0f;
|
|
|
|
|
|
|
|
|
|
// Sprawdzenie, czy którykolwiek fragment łazika wchodzi w obszar płotu
|
|
|
|
|
if (roverXMax >= xMin && roverXMin <= xMax && // Kolizja w osi X
|
|
|
|
|
roverZMax >= zMin && roverZMin <= zMax) { // Kolizja w osi Z
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else { // Płot poziomy (równoległy do osi X)
|
|
|
|
|
float xMin = plot.xc - plot.length / 2.0f;
|
|
|
|
|
float xMax = plot.xc + plot.length / 2.0f;
|
|
|
|
|
float zMin = plot.zc - plot.gruboscY / 2.0f;
|
|
|
|
|
float zMax = plot.zc + plot.gruboscY / 2.0f;
|
|
|
|
|
|
|
|
|
|
// Funkcja do obracania łazika wokół osi Y
|
|
|
|
|
void RotateRoverAndCamera(float angle) {
|
|
|
|
|
Rotation += angle;
|
|
|
|
|
if (Rotation >= 360.0f) Rotation -= 360.0f;
|
|
|
|
|
if (Rotation < 0.0f) Rotation += 360.0f;
|
|
|
|
|
// Sprawdzenie, czy którykolwiek fragment łazika wchodzi w obszar płotu
|
|
|
|
|
if (roverXMax >= xMin && roverXMin <= xMax && // Kolizja w osi X
|
|
|
|
|
roverZMax >= zMin && roverZMin <= zMax) { // Kolizja w osi Z
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UpdateRover() {
|
|
|
|
|
// Funkcja ogólna do sprawdzania kolizji ze wszystkimi płotami
|
|
|
|
|
static bool CheckAllFencesCollision(float roverXMin, float roverXMax, float roverZMin, float roverZMax, const std::vector<Plot>& fences) {
|
|
|
|
|
for (const auto& fence : fences) {
|
|
|
|
|
if (CheckFenceCollision(roverXMin, roverXMax, roverZMin, roverZMax, fence)) {
|
|
|
|
|
return true; // Kolizja wykryta z którymś płotem
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false; // Brak kolizji
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void UpdateRover(const std::vector<Plot>& fences) {
|
|
|
|
|
// Przyspieszanie w przód
|
|
|
|
|
if (keyWPressed) {
|
|
|
|
|
velocity += acceleration;
|
|
|
|
|
@@ -208,7 +203,7 @@ void UpdateRover() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Obracanie
|
|
|
|
|
// Obracanie (rotacja z driftowaniem)
|
|
|
|
|
if (keyAPressed) {
|
|
|
|
|
rotationVelocity += rotationAcceleration;
|
|
|
|
|
if (rotationVelocity > maxRotationSpeed) rotationVelocity = maxRotationSpeed;
|
|
|
|
|
@@ -218,30 +213,116 @@ void UpdateRover() {
|
|
|
|
|
if (rotationVelocity < -maxRotationSpeed) rotationVelocity = -maxRotationSpeed;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// Hamowanie obrotu (wytracanie prędkości z powodu tarcia)
|
|
|
|
|
// Jeśli żadna z klawiszy A/D nie jest wciśnięta, to stopniowo spowalniamy rotację (drift)
|
|
|
|
|
float driftFactor = 0.1f; // Mniejsza wartość = dłuższy drift
|
|
|
|
|
if (rotationVelocity > 0) {
|
|
|
|
|
rotationVelocity -= rotationFriction;
|
|
|
|
|
rotationVelocity -= rotationFriction * driftFactor;
|
|
|
|
|
if (rotationVelocity < 0) rotationVelocity = 0;
|
|
|
|
|
}
|
|
|
|
|
else if (rotationVelocity < 0) {
|
|
|
|
|
rotationVelocity += rotationFriction;
|
|
|
|
|
rotationVelocity += rotationFriction * driftFactor;
|
|
|
|
|
if (rotationVelocity > 0) rotationVelocity = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Aktualizacja pozycji na podstawie prędkości
|
|
|
|
|
float radRotation = Rotation * GL_PI / 180.0f;
|
|
|
|
|
Sides -= velocity * cos(radRotation);
|
|
|
|
|
Foward -= velocity * sin(radRotation);
|
|
|
|
|
// Wyliczenie nowej pozycji na podstawie prędkości
|
|
|
|
|
float radRotation = Rotation * GL_PI / 180.0f; // Przeliczamy rotację na radiany
|
|
|
|
|
float newSides = Sides - velocity * cos(radRotation); // Nowa pozycja w osi X
|
|
|
|
|
float newFoward = Foward - velocity * sin(radRotation); // Nowa pozycja w osi Z
|
|
|
|
|
|
|
|
|
|
// Aktualizacja kąta obrotu
|
|
|
|
|
// Wymiary łazika (połówki w osi X i Z)
|
|
|
|
|
const float roverHalfWidthX = 19.0f; // 38/2
|
|
|
|
|
const float roverHalfLengthZ = 12.0f; // 24/2
|
|
|
|
|
|
|
|
|
|
// Wyliczenie obszaru zajmowanego przez łazik
|
|
|
|
|
float roverXMin = newSides - roverHalfWidthX;
|
|
|
|
|
float roverXMax = newSides + roverHalfWidthX;
|
|
|
|
|
float roverZMin = newFoward - roverHalfLengthZ;
|
|
|
|
|
float roverZMax = newFoward + roverHalfLengthZ;
|
|
|
|
|
|
|
|
|
|
// Sprawdzanie kolizji przed aktualizacją pozycji
|
|
|
|
|
if (!Kolizja == true) {
|
|
|
|
|
if (CheckAllFencesCollision(roverZMin, roverZMax, roverXMin, roverXMax, fences)) {
|
|
|
|
|
// Jeśli jest kolizja, zatrzymujemy łazik
|
|
|
|
|
velocity = 0.0f;
|
|
|
|
|
//cout << "Kolizja podczas ruchu\n";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// Jeśli brak kolizji, aktualizujemy pozycję
|
|
|
|
|
Sides = newSides;
|
|
|
|
|
Foward = newFoward;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sprawdzanie kolizji podczas obrotu
|
|
|
|
|
if (rotationVelocity != 0.0f) {
|
|
|
|
|
// Wyliczamy nową rotację
|
|
|
|
|
float newRotation = Rotation + rotationVelocity;
|
|
|
|
|
float radNewRotation = newRotation * GL_PI / 180.0f;
|
|
|
|
|
|
|
|
|
|
// Obracamy narożniki łazika
|
|
|
|
|
std::vector<std::pair<float, float>> corners(4);
|
|
|
|
|
corners[0] = {Sides - roverHalfWidthX, Foward - roverHalfLengthZ}; // Lewy dolny
|
|
|
|
|
corners[1] = {Sides + roverHalfWidthX, Foward - roverHalfLengthZ}; // Prawy dolny
|
|
|
|
|
corners[2] = {Sides - roverHalfWidthX, Foward + roverHalfLengthZ}; // Lewy górny
|
|
|
|
|
corners[3] = {Sides + roverHalfWidthX, Foward + roverHalfLengthZ}; // Prawy górny
|
|
|
|
|
bool collisionDetected = false;
|
|
|
|
|
// Obracamy wszystkie narożniki
|
|
|
|
|
for (auto& corner : corners) {
|
|
|
|
|
float x = corner.first;
|
|
|
|
|
float z = corner.second;
|
|
|
|
|
|
|
|
|
|
corner.first = Sides + (x - Sides) * cos(radNewRotation) - (z - Foward) * sin(radNewRotation);
|
|
|
|
|
corner.second = Foward + (x - Sides) * sin(radNewRotation) + (z - Foward) * cos(radNewRotation);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Sprawdzamy kolizję na podstawie obróconych narożników
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (CheckAllFencesCollision(corner.first, corner.first, corner.second, corner.second, fences)) {
|
|
|
|
|
collisionDetected = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (CheckAllFencesCollision( corner.second, corner.second, corner.first, corner.first, fences)) {
|
|
|
|
|
collisionDetected = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (collisionDetected) {
|
|
|
|
|
rotationVelocity = 0.0f; // Zatrzymujemy obrót
|
|
|
|
|
//cout << "Kolizja podczas obrotu\n";
|
|
|
|
|
} else {
|
|
|
|
|
// Aktualizujemy rotację, jeśli nie ma kolizji
|
|
|
|
|
Rotation = newRotation;
|
|
|
|
|
if (Rotation >= 360.0f) Rotation -= 360.0f;
|
|
|
|
|
if (Rotation < 0.0f) Rotation += 360.0f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// Jeśli kolizje są wyłączone, aktualizujemy wszystko bez sprawdzania
|
|
|
|
|
Sides = newSides;
|
|
|
|
|
Foward = newFoward;
|
|
|
|
|
Rotation += rotationVelocity;
|
|
|
|
|
if (Rotation >= 360.0f) Rotation -= 360.0f;
|
|
|
|
|
if (Rotation < 0.0f) Rotation += 360.0f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<Plot> fences = {
|
|
|
|
|
{-550.0f, 3.0f, 50.0f, 1310.0f, 4.0f, 0}, // 0 - pionowo
|
|
|
|
|
{ 50.0f, 3.0f, -600.0f, 1200.0f, 4.0f, 1}, // 1 - poziomo
|
|
|
|
|
{ 650.0f, 3.0f, 50.0f, 1310.0f, 4.0f, 0}, // 0 - pionowo
|
|
|
|
|
{ 50.0f, 3.0f, 695.0f, 1200.0f, 4.0f, 1} // 1 - poziomo
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Change viewing volume and viewport. Called when window is resized
|
|
|
|
|
void ChangeSize(GLsizei w, GLsizei h) {
|
|
|
|
|
void static ChangeSize(GLsizei w, GLsizei h) {
|
|
|
|
|
GLfloat nRange = 100.0f;
|
|
|
|
|
//GLfloat fAspect;
|
|
|
|
|
// Prevent a divide by zero
|
|
|
|
|
@@ -279,7 +360,7 @@ void ChangeSize(GLsizei w, GLsizei h) {
|
|
|
|
|
// opis: ładuje mapę bitową z pliku i zwraca jej adres.
|
|
|
|
|
// Wypełnia strukturę nagłówka.
|
|
|
|
|
// Nie obsługuje map 8-bitowych.
|
|
|
|
|
unsigned char* LoadBitmapFile(char* filename, BITMAPINFOHEADER* bitmapInfoHeader) {
|
|
|
|
|
static unsigned char* LoadBitmapFile(char* filename, BITMAPINFOHEADER* bitmapInfoHeader) {
|
|
|
|
|
FILE* filePtr; // wskaźnik pozycji pliku
|
|
|
|
|
BITMAPFILEHEADER bitmapFileHeader; // nagłówek pliku
|
|
|
|
|
unsigned char* bitmapImage; // dane obrazu
|
|
|
|
|
@@ -364,7 +445,7 @@ void SetDCPixelFormat(HDC hDC) {
|
|
|
|
|
SetPixelFormat(hDC, nPixelFormat, &pfd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void skrzynka(GLfloat k) {
|
|
|
|
|
static void skrzynka(GLfloat k) {
|
|
|
|
|
glColor3d(0.8, 0.7, 0.3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -417,24 +498,29 @@ void skrzynka(GLfloat k) {
|
|
|
|
|
glEnd();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void platforma(GLfloat xc, GLfloat yc, GLfloat zc, GLfloat xlen, GLfloat zlen) {
|
|
|
|
|
static void platforma(GLfloat xc, GLfloat yc, GLfloat zc, GLfloat xlen, GLfloat zlen) {
|
|
|
|
|
glColor3d(0.729, 0.91, 0.51); // jasnozielony, dla grass02.bmp
|
|
|
|
|
|
|
|
|
|
glColor3d(0.729, 0.91, 0.51); // jasnozielony, dla grass02.bmp (https://rgbcolorpicker.com/0-1)
|
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture[1]); // Wybieramy teksturę
|
|
|
|
|
|
|
|
|
|
// Ustawienie powtarzania tekstury
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // Powtarzanie w kierunku S
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // Powtarzanie w kierunku T
|
|
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture[1]);
|
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
|
glTexCoord2d(1.0, 1.0); glVertex3d(xc - xlen, yc, zc - zlen);
|
|
|
|
|
glTexCoord2d(1.0, 0.0); glVertex3d(xc + xlen, yc, zc - zlen);
|
|
|
|
|
glTexCoord2d(0.0, 0.0); glVertex3d(xc + xlen, yc, zc + zlen);
|
|
|
|
|
glTexCoord2d(0.0, 1.0); glVertex3d(xc - xlen, yc, zc + zlen);
|
|
|
|
|
// Powtarzające się współrzędne tekstury (np. *5, aby powtórzyła się 5 razy)
|
|
|
|
|
glTexCoord2d(5.0, 5.0); glVertex3d(xc - xlen, yc, zc - zlen); // Lewy dolny
|
|
|
|
|
glTexCoord2d(5.0, 0.0); glVertex3d(xc + xlen, yc, zc - zlen); // Prawy dolny
|
|
|
|
|
glTexCoord2d(0.0, 0.0); glVertex3d(xc + xlen, yc, zc + zlen); // Prawy górny
|
|
|
|
|
glTexCoord2d(0.0, 5.0); glVertex3d(xc - xlen, yc, zc + zlen); // Lewy górny
|
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void stodola(GLfloat xc, GLfloat yc, GLfloat zc, GLfloat krawedz) {
|
|
|
|
|
|
|
|
|
|
static void stodola(GLfloat xc, GLfloat yc, GLfloat zc, GLfloat krawedz) {
|
|
|
|
|
|
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
|
|
@@ -497,7 +583,8 @@ void stodola(GLfloat xc, GLfloat yc, GLfloat zc, GLfloat krawedz) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void plot(GLfloat xc, GLfloat yc, GLfloat zc, GLfloat length, GLfloat gruboscY, bool mod_x) {
|
|
|
|
|
static void plot(GLfloat xc, GLfloat yc, GLfloat zc, GLfloat length, GLfloat gruboscY, bool mod_x)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
GLfloat grubosc = 1.0f;
|
|
|
|
|
|
|
|
|
|
@@ -719,18 +806,21 @@ void plot(GLfloat xc, GLfloat yc, GLfloat zc, GLfloat length, GLfloat gruboscY,
|
|
|
|
|
lazik user(10.0f, 0.0f, 0.0f, "res/models/lazik4.obj"); // obiekty eksportujemy z Forward Axis Z, Up Axis Y.
|
|
|
|
|
plane mapa( 0.0f, 0.0f, 0.0f, "res/models/mapka3_nofence_noplatform.obj");
|
|
|
|
|
|
|
|
|
|
void SetupRC() {
|
|
|
|
|
static void SetupRC() {
|
|
|
|
|
// Light values and coordinates
|
|
|
|
|
GLfloat ambientLight[] = { 0.3f, 0.3f, 0.3f, 1.0f };
|
|
|
|
|
GLfloat diffuseLight[] = { 0.7f, 0.7f, 0.7f, 1.0f };
|
|
|
|
|
GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
|
|
|
|
GLfloat lightPos[] = {50.0f, -100.0f, 50.0f, 1.0f};
|
|
|
|
|
GLfloat specref[] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
|
|
|
|
|
|
|
|
|
// Multiple light positions (for light coming from all sides)
|
|
|
|
|
GLfloat lightPos1[] = { 50.0f, -100.0f, 50.0f, 1.0f }; // Light 0 position
|
|
|
|
|
GLfloat lightPos2[] = { -50.0f, -100.0f, 50.0f, 1.0f }; // Light 1 position
|
|
|
|
|
GLfloat lightPos3[] = { 50.0f, -100.0f, -50.0f, 1.0f }; // Light 2 position
|
|
|
|
|
GLfloat lightPos4[] = { -50.0f, -100.0f, -50.0f, 1.0f }; // Light 3 position
|
|
|
|
|
|
|
|
|
|
glEnable(GL_DEPTH_TEST); // Hidden surface removal
|
|
|
|
|
glFrontFace(GL_CCW); // Counter clock-wise polygons face out
|
|
|
|
|
//glEnable(GL_CULL_FACE); // Do not calculate inside of jet // !!! znacząco poprawia wydajność
|
|
|
|
|
glFrontFace(GL_CCW); // Counter clockwise polygons face out
|
|
|
|
|
glDepthFunc(GL_LESS);
|
|
|
|
|
|
|
|
|
|
// Enable lighting
|
|
|
|
|
@@ -740,9 +830,30 @@ void SetupRC() {
|
|
|
|
|
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
|
|
|
|
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
|
|
|
|
|
glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
|
|
|
|
|
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
|
|
|
|
|
glLightfv(GL_LIGHT0, GL_POSITION, lightPos1);
|
|
|
|
|
glEnable(GL_LIGHT0);
|
|
|
|
|
|
|
|
|
|
// Setup and enable light 1
|
|
|
|
|
glLightfv(GL_LIGHT1, GL_AMBIENT, ambientLight);
|
|
|
|
|
glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuseLight);
|
|
|
|
|
glLightfv(GL_LIGHT1, GL_SPECULAR, specular);
|
|
|
|
|
glLightfv(GL_LIGHT1, GL_POSITION, lightPos2);
|
|
|
|
|
glEnable(GL_LIGHT1);
|
|
|
|
|
|
|
|
|
|
// Setup and enable light 2
|
|
|
|
|
glLightfv(GL_LIGHT2, GL_AMBIENT, ambientLight);
|
|
|
|
|
glLightfv(GL_LIGHT2, GL_DIFFUSE, diffuseLight);
|
|
|
|
|
glLightfv(GL_LIGHT2, GL_SPECULAR, specular);
|
|
|
|
|
glLightfv(GL_LIGHT2, GL_POSITION, lightPos3);
|
|
|
|
|
glEnable(GL_LIGHT2);
|
|
|
|
|
|
|
|
|
|
// Setup and enable light 3
|
|
|
|
|
glLightfv(GL_LIGHT3, GL_AMBIENT, ambientLight);
|
|
|
|
|
glLightfv(GL_LIGHT3, GL_DIFFUSE, diffuseLight);
|
|
|
|
|
glLightfv(GL_LIGHT3, GL_SPECULAR, specular);
|
|
|
|
|
glLightfv(GL_LIGHT3, GL_POSITION, lightPos4);
|
|
|
|
|
glEnable(GL_LIGHT3);
|
|
|
|
|
|
|
|
|
|
// Enable color tracking
|
|
|
|
|
glEnable(GL_COLOR_MATERIAL);
|
|
|
|
|
|
|
|
|
|
@@ -751,14 +862,12 @@ void SetupRC() {
|
|
|
|
|
|
|
|
|
|
// All materials hereafter have full specular reflectivity
|
|
|
|
|
// with a high shine
|
|
|
|
|
glMaterialfv(GL_FRONT, GL_SPECULAR, specref);
|
|
|
|
|
GLfloat specref2[] = {0.2f, 0.2f, 0.2f, 0.2f};
|
|
|
|
|
glMaterialfv(GL_FRONT, GL_SPECULAR, specref2);
|
|
|
|
|
glMateriali(GL_FRONT, GL_SHININESS, 128);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// White background
|
|
|
|
|
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
|
|
|
|
|
// Black brush
|
|
|
|
|
//glColor3f(0.0, 0.0, 0.0);
|
|
|
|
|
|
|
|
|
|
// Initialize GLEW
|
|
|
|
|
timestampedCout("Inicjalizowanie GLEW...");
|
|
|
|
|
@@ -770,153 +879,96 @@ void SetupRC() {
|
|
|
|
|
|
|
|
|
|
timestampedCout("Zainicjalizowano GLEW.");
|
|
|
|
|
|
|
|
|
|
// glfw3 jest w teorii niepotrzebny, ale może się przydać
|
|
|
|
|
// do przepisania kodu na podobny do tego stąd:
|
|
|
|
|
// https://github.com/opengl-tutorials/ogl/blob/master/tutorial07_model_loading/tutorial07.cpp
|
|
|
|
|
// Initialize GLFW3
|
|
|
|
|
timestampedCout("Inicjalizowanie GLFW3...");
|
|
|
|
|
if (!glfwInit()) {
|
|
|
|
|
timestampedCout("Failed to initialize GLFW");
|
|
|
|
|
}
|
|
|
|
|
timestampedCout("Zainicjalizowano GLFW3.");
|
|
|
|
|
|
|
|
|
|
// glGenVertexArrays(1, &VertexArrayID);
|
|
|
|
|
// glBindVertexArray(VertexArrayID);
|
|
|
|
|
|
|
|
|
|
// Załaduj shadery
|
|
|
|
|
|
|
|
|
|
// programID = LoadShaders("res/shaders/TransformVertexShader.vertexshader", "res/shaders/TextureFragmentShader.fragmentshader");
|
|
|
|
|
// MatrixID = glGetUniformLocation(programID, "MVP");
|
|
|
|
|
// user.passProgramID(programID);
|
|
|
|
|
|
|
|
|
|
// Załaduj model z pliku .obj
|
|
|
|
|
|
|
|
|
|
// Load models
|
|
|
|
|
timestampedCout("Ladowanie modelu lazika...");
|
|
|
|
|
user.loadModel();
|
|
|
|
|
timestampedCout("Ladowanie modelu mapki...");
|
|
|
|
|
mapa.loadModel();
|
|
|
|
|
|
|
|
|
|
glfwSwapInterval(1);
|
|
|
|
|
|
|
|
|
|
//glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RenderScene(void) {
|
|
|
|
|
|
|
|
|
|
//float normal[3]; // Storage for calculated surface normal
|
|
|
|
|
void static RenderScene(void) {
|
|
|
|
|
// Ustawienie liczby próbek dla antyaliasingu
|
|
|
|
|
glfwWindowHint(GLFW_SAMPLES, 16); // 4x MSAA (Wielokrotne próbkowanie)
|
|
|
|
|
|
|
|
|
|
// Save the matrix state and do the rotations
|
|
|
|
|
// Włączenie antyaliasingu (MSAA)
|
|
|
|
|
glEnable(GL_MULTISAMPLE);
|
|
|
|
|
|
|
|
|
|
// Przywrócenie macierzy modelu i ustawienie obrotów
|
|
|
|
|
glPushMatrix();
|
|
|
|
|
glRotatef(xRot, 1.0f, 0.0f, 0.0f);
|
|
|
|
|
glRotatef(yRot, 0.0f, 1.0f, 0.0f);
|
|
|
|
|
glRotatef(zRot, 0.0f, 0.0f, 1.0f);
|
|
|
|
|
|
|
|
|
|
// gluLookAt(
|
|
|
|
|
// 0, 0, 0, // the position of your camera, in world space
|
|
|
|
|
// 0, 0, 0, // where you want to look at, in world space
|
|
|
|
|
// 0, 1, 0 // probably glm::vec3(0,1,0), but (0,-1,0) would make you looking upside-down, which can be great too
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
// Ustawienie trybu rysowania wielokątów
|
|
|
|
|
switch (polygonmode) {
|
|
|
|
|
case 1:
|
|
|
|
|
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
|
|
|
|
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // Rysowanie linii
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
|
|
|
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // Wypełnianie poligonów
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// prymitywny licznik FPS
|
|
|
|
|
if (monitormode) {
|
|
|
|
|
std::time_t now_t = std::time(nullptr);
|
|
|
|
|
//yRot -= 1; // showcase demo
|
|
|
|
|
if (now_t > monitormodehelper) {
|
|
|
|
|
std::cout << (int)(monitormodecounter / (now_t - monitormodehelper)) << " fps\n";
|
|
|
|
|
monitormodehelper = now_t;
|
|
|
|
|
monitormodecounter = 0;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
monitormodecounter++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Clear the screen
|
|
|
|
|
// Czyszczenie ekranu przed rysowaniem
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
|
|
|
// Use our shader
|
|
|
|
|
//timestampedCout("programID wynosi " << programID);
|
|
|
|
|
//glUseProgram(programID);
|
|
|
|
|
|
|
|
|
|
// // Bind our texture in Texture Unit 0
|
|
|
|
|
// glActiveTexture(GL_TEXTURE0);
|
|
|
|
|
// glBindTexture(GL_TEXTURE_2D, Texture);
|
|
|
|
|
// // Set our "myTextureSampler" sampler to use Texture Unit 0
|
|
|
|
|
// glUniform1i(TextureID, 0);
|
|
|
|
|
//glLoadIdentity(); // Zresetowanie macierzy widoku
|
|
|
|
|
//
|
|
|
|
|
//############################################################################################
|
|
|
|
|
//Sterowanie
|
|
|
|
|
//############################################################################################
|
|
|
|
|
// Przywrócenie macierzy widoku
|
|
|
|
|
gluLookAt(
|
|
|
|
|
Foward - 100.0f * sin((Rotation + 180.0f) * GL_PI / 180.0f), // Pozycja kamery wokół łazika (w poziomie)
|
|
|
|
|
CameraHeight, // Wysokość kamery
|
|
|
|
|
Sides - 100.0f * cos((Rotation + 180.0f) * GL_PI / 180.0f), // Kamera wzdłuż osi X i Z
|
|
|
|
|
Foward, 0.0f, Sides, // Punkt, na który patrzy kamera (łazik)
|
|
|
|
|
Foward - 50.0f * sin((Rotation + 180.0f) * GL_PI / 180.0f), // Pozycja kamery
|
|
|
|
|
CameraHeight/4, // Wysokość kamery
|
|
|
|
|
Sides - 50.0f * cos((Rotation + 180.0f) * GL_PI / 180.0f), // Kamera wzdłuż osi X i Z
|
|
|
|
|
Foward, 0.0f, Sides, // Punkt patrzenia (łazik)
|
|
|
|
|
0.0f, 1.0f, 0.0f // Wektor "góry"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Rysowanie mapy (nie porusza się)
|
|
|
|
|
// Rysowanie mapy
|
|
|
|
|
glPushMatrix();
|
|
|
|
|
glColor3f(0.0, 1.0, 0.0); // Zielony kolor dla mapy
|
|
|
|
|
platforma(50.0f, 0.0f, 45.0f, 60.0f, 65.0f);
|
|
|
|
|
//mapa.draw();
|
|
|
|
|
glColor3f(0.0, 1.0, 0.0); // Zielony kolor
|
|
|
|
|
mapa.draw();
|
|
|
|
|
platforma(50.0f, 0.0f, 45.0f, 600.0f, 650.0f);
|
|
|
|
|
glPopMatrix();
|
|
|
|
|
|
|
|
|
|
// Rysowanie łazika (porusza się i obraca)
|
|
|
|
|
// Rysowanie łazika
|
|
|
|
|
glPushMatrix();
|
|
|
|
|
|
|
|
|
|
glTranslatef(Foward, 0.0f, Sides); // Translacja łazika na jego pozycję
|
|
|
|
|
glRotatef(Rotation, 0.0f, 1.0f, 0.0f); // Obrót łazika wokół własnej osi
|
|
|
|
|
glTranslatef(Foward, 0.0f, Sides); // Translacja łazika
|
|
|
|
|
glRotatef(Rotation, 0.0f, 1.0f, 0.0f); // Obrót łazika
|
|
|
|
|
glColor3f(1.0, 0.0, 0.0); // Czerwony kolor dla łazika
|
|
|
|
|
|
|
|
|
|
user.draw();
|
|
|
|
|
UpdateRover();
|
|
|
|
|
UpdateRover(fences);
|
|
|
|
|
fpsCounter.update();
|
|
|
|
|
glPopMatrix();
|
|
|
|
|
|
|
|
|
|
//skrzynka(50);
|
|
|
|
|
plot(-10.0f, 3.0f, 45.0f, 130.0f, 4.0f, 0); // 0 - pionowo
|
|
|
|
|
plot( 50.0f, 3.0f, -20.0f, 120.0f, 4.0f, 1); // 1 - poziomo
|
|
|
|
|
plot(110.0f, 3.0f, 45.0f, 130.0f, 4.0f, 0);
|
|
|
|
|
plot( 50.0f, 3.0f, 110.0f, 120.0f, 4.0f, 1);
|
|
|
|
|
|
|
|
|
|
// stodola(2.0f, 0.0f, -7.5f, 20.0f);
|
|
|
|
|
// Rysowanie innych obiektów
|
|
|
|
|
plot(-550.0f, 3.0f, 50.0f, 1310.0f, 4.0f, 0); // 0 - pionowo
|
|
|
|
|
plot( 50.0f, 3.0f, -600.0f, 1200.0f, 4.0f, 1); // 1 - poziomo
|
|
|
|
|
plot( 650.0f, 3.0f, 50.0f, 1310.0f, 4.0f, 0);
|
|
|
|
|
plot( 50.0f, 3.0f, 695.0f, 1200.0f, 4.0f, 1);
|
|
|
|
|
stodola(10.0f, 0.0f, 2.0f, 40.0f);
|
|
|
|
|
|
|
|
|
|
// Zamiana buforów (double buffering)
|
|
|
|
|
//glColor3f(1.0, 0.0, 0.0);
|
|
|
|
|
//user.draw();
|
|
|
|
|
//glColor3f(0.0, 1.0, 0.0);
|
|
|
|
|
//mapa.draw();
|
|
|
|
|
//glColor3f(0.0, 0.0, 0.0);
|
|
|
|
|
fpsCounter.update();
|
|
|
|
|
// glfwSwapBuffers(window); // Przełączenie buforów
|
|
|
|
|
// glfwPollEvents(); // Obsługa zdarzeń
|
|
|
|
|
|
|
|
|
|
// Zamiana buforów (double buffering)
|
|
|
|
|
glPopMatrix(); // Przywrócenie poprzedniej macierzy
|
|
|
|
|
glMatrixMode(GL_MODELVIEW); // Ustawienie trybu modelu-widoku
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Swap buffers
|
|
|
|
|
//glfwSwapBuffers(window);
|
|
|
|
|
//glfwPollEvents();
|
|
|
|
|
|
|
|
|
|
//Wyrysowanie prostokata:
|
|
|
|
|
//glRectd(-10.0,-10.0,20.0,20.0);
|
|
|
|
|
|
|
|
|
|
glPopMatrix(); // wymagane
|
|
|
|
|
glMatrixMode(GL_MODELVIEW); // zmniejsza zużycie GPU
|
|
|
|
|
|
|
|
|
|
// Flush drawing commands
|
|
|
|
|
//glFlush();
|
|
|
|
|
// Wymuszenie wykonania wszystkich rysunków
|
|
|
|
|
glFlush();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If necessary, creates a 3-3-2 palette for the device context listed.
|
|
|
|
|
HPALETTE GetOpenGLPalette(HDC hDC) {
|
|
|
|
|
HPALETTE static GetOpenGLPalette(HDC hDC) {
|
|
|
|
|
HPALETTE hRetPal = NULL; // Handle to palette to be created
|
|
|
|
|
PIXELFORMATDESCRIPTOR pfd; // Pixel Format Descriptor
|
|
|
|
|
LOGPALETTE* pPal; // Pointer to memory for logical palette
|
|
|
|
|
@@ -986,7 +1038,7 @@ HPALETTE GetOpenGLPalette(HDC hDC) {
|
|
|
|
|
// Return the handle to the new palette
|
|
|
|
|
return hRetPal;
|
|
|
|
|
}
|
|
|
|
|
void CreateConsole() {
|
|
|
|
|
void static CreateConsole() {
|
|
|
|
|
// Tworzenie nowej konsoli
|
|
|
|
|
if (AllocConsole()) {
|
|
|
|
|
// Przekierowanie standardowych strumieni do konsoli
|
|
|
|
|
@@ -998,13 +1050,13 @@ void CreateConsole() {
|
|
|
|
|
freopen_s(&conerr, "conout$", "w", stderr);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
MessageBox(NULL, "Nie udało się utworzyć konsoli.", "Błąd", MB_OK | MB_ICONERROR);
|
|
|
|
|
MessageBox(NULL, "Nie udalo sie utworzyc konsoli.", "Blad", MB_OK | MB_ICONERROR);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
|
|
|
|
|
CreateConsole();
|
|
|
|
|
MSG msg; // Windows message structure
|
|
|
|
|
WNDCLASS wc; // Windows class structure
|
|
|
|
|
WNDCLASS wc{}; // Windows class structure
|
|
|
|
|
HWND hWnd; // Storeage for window handle
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1085,11 +1137,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
|
// Create palette if needed
|
|
|
|
|
hPalette = GetOpenGLPalette(hDC);
|
|
|
|
|
|
|
|
|
|
// Create the rendering context and make it current
|
|
|
|
|
hRC = wglCreateContext(hDC);
|
|
|
|
|
wglMakeCurrent(hDC, hRC);
|
|
|
|
|
SetupRC();
|
|
|
|
|
|
|
|
|
|
// Create the rendering context and make it current
|
|
|
|
|
hRC = wglCreateContext(hDC);
|
|
|
|
|
wglMakeCurrent(hDC, hRC);
|
|
|
|
|
@@ -1103,8 +1150,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
|
|
|
|
|
|
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_MIN_FILTER, GL_NEAREST);
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
|
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_T, GL_CLAMP);
|
|
|
|
|
@@ -1121,8 +1168,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
|
bitmapData = LoadBitmapFile((char*)"res/img/grass02.bmp", &bitmapInfoHeader);
|
|
|
|
|
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_MIN_FILTER, GL_NEAREST);
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
|
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_T, GL_MIRRORED_REPEAT);
|
|
|
|
|
@@ -1137,8 +1184,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
|
bitmapData = LoadBitmapFile((char*)"res/img/barnroof.bmp", &bitmapInfoHeader);
|
|
|
|
|
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_MIN_FILTER, GL_NEAREST);
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
|
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_T, GL_CLAMP);
|
|
|
|
|
@@ -1153,8 +1200,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
|
bitmapData = LoadBitmapFile((char*)"res/img/brickwall.bmp", &bitmapInfoHeader);
|
|
|
|
|
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_MIN_FILTER, GL_NEAREST);
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
|
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_T, GL_CLAMP);
|
|
|
|
|
@@ -1200,6 +1247,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
|
// The painting function. This message sent by Windows
|
|
|
|
|
// whenever the screen needs updating.
|
|
|
|
|
case WM_PAINT:
|
|
|
|
|
LimitFPS(targetFPS);
|
|
|
|
|
// Call OpenGL drawing code
|
|
|
|
|
RenderScene();
|
|
|
|
|
|
|
|
|
|
@@ -1208,14 +1256,14 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
|
// Validate the newly painted client area
|
|
|
|
|
if (!monitormode) ValidateRect(hWnd, NULL);
|
|
|
|
|
else InvalidateRect(hWnd, NULL, FALSE);
|
|
|
|
|
break;
|
|
|
|
|
//break;
|
|
|
|
|
|
|
|
|
|
// Limit FPS
|
|
|
|
|
LimitFPS(targetFPS);
|
|
|
|
|
// Uaktualniaj FPS
|
|
|
|
|
// Ogranicz FPS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update FPS counter
|
|
|
|
|
fpsCounter.update();
|
|
|
|
|
break;
|
|
|
|
|
case WM_QUERYNEWPALETTE:
|
|
|
|
|
// If the palette was created.
|
|
|
|
|
if (hPalette) {
|
|
|
|
|
@@ -1254,28 +1302,32 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case WM_KEYUP:
|
|
|
|
|
|
|
|
|
|
switch (wParam) {
|
|
|
|
|
|
|
|
|
|
case 'W':
|
|
|
|
|
keyWPressed = false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'S':
|
|
|
|
|
keySPressed = false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'A':
|
|
|
|
|
keyAPressed = false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'D':
|
|
|
|
|
keyDPressed = false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
// Obsługa innych klawiszy
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (wParam) {
|
|
|
|
|
|
|
|
|
|
case VK_UP:
|
|
|
|
|
@@ -1312,28 +1364,34 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
|
polygonmode = !polygonmode;
|
|
|
|
|
if (polygonmode) timestampedCout("Uwaga! Tryb wireframe jest niewydajny i powinien sluzyc tylko do debugowania!");
|
|
|
|
|
break;
|
|
|
|
|
case 'K':
|
|
|
|
|
Kolizja = !Kolizja;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'W':
|
|
|
|
|
keyWPressed = true;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'S':
|
|
|
|
|
keySPressed = true;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'A':
|
|
|
|
|
keyAPressed = true;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'D':
|
|
|
|
|
keyDPressed = true;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 114: // F3
|
|
|
|
|
monitormode = !monitormode;
|
|
|
|
|
if (monitormode) {
|
|
|
|
|
monitormodehelper = std::time(nullptr) - 1;
|
|
|
|
|
timestampedCout("Wlaczono tryb monitorowania wydajnosci.");
|
|
|
|
|
}
|
|
|
|
|
if (!monitormode) timestampedCout("Wylaczono tryb monitorowania wydajnosci.");
|
|
|
|
|
break;
|
|
|
|
|
// case 114: // F3
|
|
|
|
|
// monitormode = !monitormode;
|
|
|
|
|
// if (monitormode) {
|
|
|
|
|
// monitormodehelper = std::time(nullptr) - 1;
|
|
|
|
|
// timestampedCout("Wlaczono tryb monitorowania wydajnosci.");
|
|
|
|
|
// }
|
|
|
|
|
// if (!monitormode) timestampedCout("Wylaczono tryb monitorowania wydajnosci.");
|
|
|
|
|
// break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
timestampedCout("Nacisnieto nierozpoznany klawisz: " << (int)wParam);
|
|
|
|
|
@@ -1363,6 +1421,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case WM_TIMER:
|
|
|
|
|
|
|
|
|
|
RenderScene();
|
|
|
|
|
|