Compare commits
2 Commits
0725312d80
...
9a08770e6f
| Author | SHA1 | Date | |
|---|---|---|---|
| 9a08770e6f | |||
|
|
fa824192b7 |
400
main.cpp
400
main.cpp
@@ -75,46 +75,12 @@ void SetDCPixelFormat(HDC hDC);
|
|||||||
|
|
||||||
int polygonmode = 0;
|
int polygonmode = 0;
|
||||||
std::time_t lastTime = std::time(nullptr);
|
std::time_t lastTime = std::time(nullptr);
|
||||||
int monitormode = 0;
|
int monitormode = 1;
|
||||||
int monitormodecounter = 0;
|
int monitormodecounter = 0;
|
||||||
std::time_t monitormodehelper;
|
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 ##############################################^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
//Zmienne do ruchu ##############################################^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
FPSCounter fpsCounter;
|
FPSCounter fpsCounter;
|
||||||
static const int targetFPS = 144; // Celowany FPS
|
static const int targetFPS = 144; // Celowany FPS
|
||||||
@@ -148,11 +114,11 @@ float MoveSpeed = 1.0f; // Prędkość poruszania się
|
|||||||
float velocity = 0.0f; // Aktualna prędkość łazika
|
float velocity = 0.0f; // Aktualna prędkość łazika
|
||||||
const float friction = 0.1f; // Współczynnik tarcia (μ)
|
const float friction = 0.1f; // Współczynnik tarcia (μ)
|
||||||
const float maxSpeed = 3.0f; // Maksymalna prędkość łazika
|
const float maxSpeed = 3.0f; // Maksymalna prędkość łazika
|
||||||
const float acceleration = 0.1f;
|
const float acceleration = 0.2f;
|
||||||
float rotationVelocity = 0.0f; // Prędkość obrotu łazika
|
float rotationVelocity = 0.0f; // Prędkość obrotu łazika
|
||||||
const float rotationAcceleration = 0.1f; // Przyspieszenie obrotu
|
const float rotationAcceleration = 0.1f; // Przyspieszenie obrotu
|
||||||
const float rotationFriction = 0.05f; // Współczynnik tarcia obrotu
|
const float rotationFriction = 0.05f; // Współczynnik tarcia obrotu
|
||||||
const float maxRotationSpeed = 5.0f; // Maksymalna prędkość obrotu
|
const float maxRotationSpeed = 3.0f; // Maksymalna prędkość obrotu
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -825,19 +791,7 @@ void RenderScene(void) {
|
|||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
// Clear the screen
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
@@ -998,7 +952,7 @@ void CreateConsole() {
|
|||||||
freopen_s(&conerr, "conout$", "w", stderr);
|
freopen_s(&conerr, "conout$", "w", stderr);
|
||||||
}
|
}
|
||||||
else {
|
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) {
|
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
|
||||||
@@ -1075,20 +1029,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
float radRotation = Rotation * GL_PI / 180.0f;
|
float radRotation = Rotation * GL_PI / 180.0f;
|
||||||
switch (message) {
|
switch (message) {
|
||||||
// Window creation, setup for OpenGL
|
// Window creation, setup for OpenGL
|
||||||
case WM_CREATE:
|
case WM_CREATE:
|
||||||
// Store the device context
|
// Store the device context
|
||||||
hDC = GetDC(hWnd);
|
hDC = GetDC(hWnd);
|
||||||
|
|
||||||
// Select the pixel format
|
// Select the pixel format
|
||||||
SetDCPixelFormat(hDC);
|
SetDCPixelFormat(hDC);
|
||||||
|
|
||||||
// Create palette if needed
|
// Create palette if needed
|
||||||
hPalette = GetOpenGLPalette(hDC);
|
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
|
// Create the rendering context and make it current
|
||||||
hRC = wglCreateContext(hDC);
|
hRC = wglCreateContext(hDC);
|
||||||
@@ -1208,170 +1157,179 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
// Validate the newly painted client area
|
// Validate the newly painted client area
|
||||||
if (!monitormode) ValidateRect(hWnd, NULL);
|
if (!monitormode) ValidateRect(hWnd, NULL);
|
||||||
else InvalidateRect(hWnd, NULL, FALSE);
|
else InvalidateRect(hWnd, NULL, FALSE);
|
||||||
|
//break;
|
||||||
|
|
||||||
|
// Limit FPS
|
||||||
|
LimitFPS(targetFPS);
|
||||||
|
|
||||||
|
// Update FPS counter
|
||||||
|
if (monitormode) fpsCounter.update();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Limit FPS
|
case WM_QUERYNEWPALETTE:
|
||||||
LimitFPS(targetFPS);
|
// If the palette was created.
|
||||||
|
if (hPalette) {
|
||||||
|
int nRet;
|
||||||
|
|
||||||
// Update FPS counter
|
// Selects the palette into the current device context
|
||||||
fpsCounter.update();
|
SelectPalette(hDC, hPalette, FALSE);
|
||||||
break;
|
|
||||||
case WM_QUERYNEWPALETTE:
|
|
||||||
// If the palette was created.
|
|
||||||
if (hPalette) {
|
|
||||||
int nRet;
|
|
||||||
|
|
||||||
// Selects the palette into the current device context
|
// Map entries from the currently selected palette to
|
||||||
SelectPalette(hDC, hPalette, FALSE);
|
// the system palette. The return value is the number
|
||||||
|
// of palette entries modified.
|
||||||
|
nRet = RealizePalette(hDC);
|
||||||
|
|
||||||
// Map entries from the currently selected palette to
|
// Repaint, forces remap of palette in current window
|
||||||
// the system palette. The return value is the number
|
InvalidateRect(hWnd, NULL, FALSE);
|
||||||
// of palette entries modified.
|
|
||||||
nRet = RealizePalette(hDC);
|
|
||||||
|
|
||||||
// Repaint, forces remap of palette in current window
|
return nRet;
|
||||||
InvalidateRect(hWnd, NULL, FALSE);
|
}
|
||||||
|
break;
|
||||||
return nRet;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
// This window may set the palette, even though it is not the
|
// This window may set the palette, even though it is not the
|
||||||
// currently active window.
|
// currently active window.
|
||||||
case WM_PALETTECHANGED:
|
case WM_PALETTECHANGED:
|
||||||
// Don't do anything if the palette does not exist, or if
|
// Don't do anything if the palette does not exist, or if
|
||||||
// this is the window that changed the palette.
|
// this is the window that changed the palette.
|
||||||
if ((hPalette != NULL) && ((HWND)wParam != hWnd)) {
|
if ((hPalette != NULL) && ((HWND)wParam != hWnd)) {
|
||||||
// Select the palette into the device context
|
// Select the palette into the device context
|
||||||
SelectPalette(hDC, hPalette, FALSE);
|
SelectPalette(hDC, hPalette, FALSE);
|
||||||
|
|
||||||
// Map entries to system palette
|
// Map entries to system palette
|
||||||
RealizePalette(hDC);
|
RealizePalette(hDC);
|
||||||
|
|
||||||
// Remap the current colors to the newly realized palette
|
// Remap the current colors to the newly realized palette
|
||||||
UpdateColors(hDC);
|
UpdateColors(hDC);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
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;
|
break;
|
||||||
|
case WM_KEYUP:
|
||||||
|
|
||||||
|
switch (wParam) {
|
||||||
|
|
||||||
case WM_KEYDOWN:
|
case 'W':
|
||||||
|
keyWPressed = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'S':
|
||||||
|
keySPressed = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'A':
|
||||||
|
keyAPressed = false;
|
||||||
|
break;
|
||||||
|
|
||||||
switch (wParam) {
|
case 'D':
|
||||||
|
keyDPressed = false;
|
||||||
|
break;
|
||||||
|
|
||||||
case VK_UP:
|
// Obsługa innych klawiszy
|
||||||
xRot -= 5.0f;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VK_DOWN:
|
|
||||||
xRot += 5.0f;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VK_LEFT:
|
|
||||||
yRot -= 5.0f;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VK_RIGHT:
|
|
||||||
yRot += 5.0f;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'Q':
|
|
||||||
zRot += 5.0f;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'E':
|
|
||||||
zRot -= 5.0f;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'R':
|
|
||||||
xRot = 0;
|
|
||||||
yRot = 0;
|
|
||||||
zRot = 0;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ' ': // 32
|
|
||||||
polygonmode = !polygonmode;
|
|
||||||
if (polygonmode) timestampedCout("Uwaga! Tryb wireframe jest niewydajny i powinien sluzyc tylko do debugowania!");
|
|
||||||
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;
|
break;
|
||||||
|
|
||||||
default:
|
case WM_KEYDOWN:
|
||||||
timestampedCout("Nacisnieto nierozpoznany klawisz: " << (int)wParam);
|
|
||||||
}
|
|
||||||
|
|
||||||
xRot = (const int)xRot % 360;
|
switch (wParam) {
|
||||||
yRot = (const int)yRot % 360;
|
|
||||||
zRot = (const int)zRot % 360;
|
|
||||||
|
|
||||||
InvalidateRect(hWnd, NULL, FALSE);
|
case VK_UP:
|
||||||
break;
|
xRot -= 5.0f;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VK_DOWN:
|
||||||
|
xRot += 5.0f;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VK_LEFT:
|
||||||
|
yRot -= 5.0f;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VK_RIGHT:
|
||||||
|
yRot += 5.0f;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'Q':
|
||||||
|
zRot += 5.0f;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'E':
|
||||||
|
zRot -= 5.0f;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'R':
|
||||||
|
xRot = 0;
|
||||||
|
yRot = 0;
|
||||||
|
zRot = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ' ': // 32
|
||||||
|
polygonmode = !polygonmode;
|
||||||
|
if (polygonmode) timestampedCout("Uwaga! Tryb wireframe jest niewydajny i powinien sluzyc tylko do debugowania!");
|
||||||
|
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;
|
||||||
|
|
||||||
|
default:
|
||||||
|
timestampedCout("Nacisnieto nierozpoznany klawisz: " << (int)wParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
xRot = (const int)xRot % 360;
|
||||||
|
yRot = (const int)yRot % 360;
|
||||||
|
zRot = (const int)zRot % 360;
|
||||||
|
|
||||||
|
InvalidateRect(hWnd, NULL, FALSE);
|
||||||
|
break;
|
||||||
|
|
||||||
// A menu command
|
// A menu command
|
||||||
case WM_COMMAND:
|
case WM_COMMAND:
|
||||||
|
|
||||||
switch (LOWORD(wParam)) {
|
switch (LOWORD(wParam)) {
|
||||||
|
|
||||||
// Exit the program
|
// Exit the program
|
||||||
case ID_FILE_EXIT:
|
case ID_FILE_EXIT:
|
||||||
DestroyWindow(hWnd);
|
DestroyWindow(hWnd);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Display the about box
|
||||||
|
case ID_HELP_ABOUT:
|
||||||
|
DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_ABOUT), hWnd, (DLGPROC)AboutDlgProc);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Display the about box
|
case WM_TIMER:
|
||||||
case ID_HELP_ABOUT:
|
|
||||||
DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_ABOUT), hWnd, (DLGPROC)AboutDlgProc);
|
RenderScene();
|
||||||
|
SwapBuffers(hDC);
|
||||||
|
ValidateRect(hWnd, NULL);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
default: // Passes it on if unproccessed
|
||||||
break;
|
return (DefWindowProc(hWnd, message, wParam, lParam));
|
||||||
case WM_TIMER:
|
|
||||||
|
|
||||||
RenderScene();
|
|
||||||
SwapBuffers(hDC);
|
|
||||||
ValidateRect(hWnd, NULL);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: // Passes it on if unproccessed
|
|
||||||
return (DefWindowProc(hWnd, message, wParam, lParam));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (0L);
|
return (0L);
|
||||||
@@ -1382,46 +1340,46 @@ BOOL APIENTRY AboutDlgProc(HWND hDlg, UINT message, UINT wParam, LONG lParam) {
|
|||||||
|
|
||||||
switch (message) {
|
switch (message) {
|
||||||
// Initialize the dialog box
|
// Initialize the dialog box
|
||||||
case WM_INITDIALOG:
|
case WM_INITDIALOG:
|
||||||
int i;
|
int i;
|
||||||
GLenum glError;
|
GLenum glError;
|
||||||
|
|
||||||
// glGetString demo
|
// glGetString demo
|
||||||
SetDlgItemText(hDlg, IDC_OPENGL_VENDOR, reinterpret_cast<LPCSTR>(glGetString(GL_VENDOR)));
|
SetDlgItemText(hDlg, IDC_OPENGL_VENDOR, reinterpret_cast<LPCSTR>(glGetString(GL_VENDOR)));
|
||||||
SetDlgItemText(hDlg, IDC_OPENGL_RENDERER, (LPCSTR)glGetString(GL_RENDERER));
|
SetDlgItemText(hDlg, IDC_OPENGL_RENDERER, (LPCSTR)glGetString(GL_RENDERER));
|
||||||
SetDlgItemText(hDlg, IDC_OPENGL_VERSION, (LPCSTR)glGetString(GL_VERSION));
|
SetDlgItemText(hDlg, IDC_OPENGL_VERSION, (LPCSTR)glGetString(GL_VERSION));
|
||||||
SetDlgItemText(hDlg, IDC_OPENGL_EXTENSIONS, (LPCSTR)glGetString(GL_EXTENSIONS));
|
SetDlgItemText(hDlg, IDC_OPENGL_EXTENSIONS, (LPCSTR)glGetString(GL_EXTENSIONS));
|
||||||
|
|
||||||
// gluGetString demo
|
// gluGetString demo
|
||||||
SetDlgItemText(hDlg, IDC_GLU_VERSION, (LPCSTR)gluGetString(GLU_VERSION));
|
SetDlgItemText(hDlg, IDC_GLU_VERSION, (LPCSTR)gluGetString(GLU_VERSION));
|
||||||
SetDlgItemText(hDlg, IDC_GLU_EXTENSIONS, (LPCSTR)gluGetString(GLU_EXTENSIONS));
|
SetDlgItemText(hDlg, IDC_GLU_EXTENSIONS, (LPCSTR)gluGetString(GLU_EXTENSIONS));
|
||||||
|
|
||||||
|
|
||||||
// Display any recent error messages
|
// Display any recent error messages
|
||||||
i = 0;
|
i = 0;
|
||||||
do {
|
do {
|
||||||
glError = glGetError();
|
glError = glGetError();
|
||||||
SetDlgItemText(hDlg, IDC_ERROR1 + i, (LPCSTR)gluErrorString(glError));
|
SetDlgItemText(hDlg, IDC_ERROR1 + i, (LPCSTR)gluErrorString(glError));
|
||||||
i++;
|
i++;
|
||||||
} while (i < 6 && glError != GL_NO_ERROR);
|
} while (i < 6 && glError != GL_NO_ERROR);
|
||||||
|
|
||||||
|
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Process command messages
|
// Process command messages
|
||||||
case WM_COMMAND:
|
case WM_COMMAND:
|
||||||
|
|
||||||
// Validate and Make the changes
|
// Validate and Make the changes
|
||||||
if (LOWORD(wParam) == IDOK) EndDialog(hDlg, TRUE);
|
if (LOWORD(wParam) == IDOK) EndDialog(hDlg, TRUE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Closed from sysbox
|
// Closed from sysbox
|
||||||
case WM_CLOSE:
|
case WM_CLOSE:
|
||||||
|
|
||||||
EndDialog(hDlg, TRUE);
|
EndDialog(hDlg, TRUE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user