11 Commits

Author SHA1 Message Date
Pc
fa824192b7 To co w nazwie brancha + konsola w vsc 2025-01-07 23:16:46 +01:00
Pc
79c6a1e144 Klasa do fps + Limit Fps 2025-01-07 23:01:34 +01:00
Pc
01d7766b6a Sterowanie 5.0 + Klasa do fps 2025-01-07 22:20:22 +01:00
Pc
3171ebe504 Sterowanie 5.0 ? 2025-01-07 21:32:32 +01:00
Pc
039435ed73 Sterowanie na ocene chyba 5.0 ? 2025-01-07 21:25:14 +01:00
Pc
2afc119bb9 Sterowanie na ocene chyba 4.0 2025-01-07 20:49:20 +01:00
Pc
4956d74c1a Sterowanie na 3.0 2025-01-06 21:12:35 +01:00
495ec2e6ab nowa mapka (mapk2.obj) 2024-12-09 12:25:08 +01:00
633be80ec4 lekko poprawiona mapka, dodane nowe klasy do projektu w visual studio, oddzielny kolor dla mapki i łazika 2024-12-08 16:00:25 +01:00
2b51e31307 próba modularyzacji kodu, dodane klasy lazik oraz plane
- Makefile uwzględnia glfw
- projekt w visual studio także powinien linkować glfw
- dodano plik .gitignore
- klasa lazik stworzona z myślą o łaziku
- bliźniaczo podobna klasa plane stworzona z myślą o mapie
- dodano surowy projekt mapy (res/models/mapka.obj)
- usunięto zbędną klasę sześcian oraz plik wykonywalny .exe
- funkcja timestampedCout() przeniesiona do plików timeh.cpp/.hpp, co pozwala na używanie jej wszędzie
- w main.cpp:
	- zakomentowano masę (niepotrzebnego)/przeniesionego kodu
	- tryb monitorowania wydajności wyłącza ValidateRect(), co wymusza ciągłe renderowanie nowych klatek. pozwala to oszacować wpływ zmian na wydajność programu.
2024-12-07 03:47:17 +01:00
ef1a8b225b poprawiony model łazika (lazik4.obj, stoi tyłem), prymitywany licznik fps 2024-11-29 01:50:22 +01:00
20 changed files with 2283523 additions and 405 deletions

15
.gitignore vendored Normal file
View File

@@ -0,0 +1,15 @@
# Czarna lista plików przy commitowaniu
# (pliki do zignorowania przy udostępnianiu)
# folder z rzeczami z visual studio
.vs
# pliki wykonywalne, binarne
grafikaKBT
x64
output.exe
output2.exe
# obiekty testowe
res/models/lazik.obj
res/models/lazik2.obj
res/models/lazik4,5.obj

24
FPSCounter.cpp Normal file
View File

@@ -0,0 +1,24 @@
#include <iostream>
#include <chrono>
class FPSCounter {
public:
FPSCounter() : frameCount(0), lastTime(std::chrono::high_resolution_clock::now()) {}
void update() {
frameCount++;
auto currentTime = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> elapsed = currentTime - lastTime;
if (elapsed.count() >= 1.0) {
double fps = frameCount / elapsed.count();
std::cout << "FPS: " << fps << std::endl;
frameCount = 0;
lastTime = currentTime;
}
}
private:
int frameCount;
std::chrono::time_point<std::chrono::high_resolution_clock> lastTime;
};

View File

@@ -1,7 +1,7 @@
# mingw-w64-x86_64-gcc-14.1.0-3 to ostatnia wspierana wersja gcc, w której można stosować wildcard'y "*.cpp"
CC = "C:\\msys64\\mingw64\\bin\\g++.exe"
CFLAGS = -I.
DEPS = -lglew32 -lopengl32 -lglu32 -lgdi32
DEPS = -lglew32 -lglfw3 -lopengl32 -lglu32 -lgdi32
LINK = -L. -DGLEW_STATIC
OUTPUT = output.exe
CPPSTD = c++17

BIN
glfw3.dll Normal file

Binary file not shown.

View File

@@ -92,6 +92,7 @@
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<AdditionalDependencies>glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -116,18 +117,27 @@
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="FPSCounter.cpp" />
<ClCompile Include="glew.c" />
<ClCompile Include="lazik.cpp" />
<ClCompile Include="loadOBJ.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="szescian.cpp" />
<ClCompile Include="plane.cpp" />
<ClCompile Include="timeh.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="lazik.hpp" />
<ClInclude Include="loadOBJ.h" />
<ClInclude Include="plane.hpp" />
<ClInclude Include="RESOURCE.H" />
<ClInclude Include="szescian.h" />
<ClInclude Include="timeh.hpp" />
</ItemGroup>
<ItemGroup>
<None Include="glfw3.dll" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@@ -21,7 +21,19 @@
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="szescian.cpp">
<ClCompile Include="glew.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="lazik.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="timeh.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="plane.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="FPSCounter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
@@ -32,8 +44,19 @@
<ClInclude Include="RESOURCE.H">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="szescian.h">
<ClInclude Include="plane.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="lazik.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="timeh.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="glfw3.dll">
<Filter>Source Files</Filter>
</None>
</ItemGroup>
</Project>

81
lazik.cpp Normal file
View File

@@ -0,0 +1,81 @@
#include "lazik.hpp"
lazik::lazik(float x, float y, float z, const char* modelpath){
this->c_x = x;
this->c_y = y;
this->c_z = z;
this->modelpath = modelpath;
timestampedCout("lazik.cpp: Zaladowano dane w konstruktorze.")
}
void lazik::loadModel() {
timestampedCout("lazik.cpp:");
std::cout << " Ladowanie modelu ze sciezki " << this->modelpath << "...\n";
bool res = loadOBJ(this->modelpath, this->vertices, this->uvs, this->normals);
if (res) timestampedCout("Pomyslnie zaladowano model lazika.")
else timestampedCout("Nie udalo sie zaladowac modelu lazika.");
glGenBuffers(1, &vertexbuffer);
glBindBuffer(GL_ARRAY_BUFFER, this->vertexbuffer);
glBufferData(GL_ARRAY_BUFFER, this->vertices.size() * sizeof(glm::vec3), &vertices[0], GL_STATIC_DRAW);
glGenBuffers(1, &uvbuffer);
glBindBuffer(GL_ARRAY_BUFFER, this->uvbuffer);
glBufferData(GL_ARRAY_BUFFER, this->uvs.size() * sizeof(glm::vec2), &uvs[0], GL_STATIC_DRAW);
}
void lazik::draw() {
// 1st attribute buffer: vertices
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, this->vertexbuffer);
glVertexAttribPointer(
0, // attribute
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
// 2nd attribute buffer: UVs
glEnableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER, this->uvbuffer);
glVertexAttribPointer(
1, // attribute
2, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
// Draw vertices
glDrawArrays(GL_TRIANGLES, 0, this->vertices.size());
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
}
void lazik::moveX(float x){
// TODO: dodać timer do poniższych funkcji, aby czas przejścia z punktu A do B był uniezależniony od FPSów
timestampedCout("dummy moveX");
}
void lazik::moveY(float y){
timestampedCout("dummy moveY");
}
void lazik::moveZ(float z){
timestampedCout("dummy moveZ");
}
void lazik::moveXYZ(float x, float y, float z){
// TODO: modyfikować wektor z koordynatami oraz c_x, c_y, c_z
timestampedCout("dummy moveXYZ");
}

34
lazik.hpp Normal file
View File

@@ -0,0 +1,34 @@
#pragma once
#include <windows.h>
#include "GL/glew.h"
#include <gl/gl.h>
#include <gl/glu.h>
#include <vector>
#include <iostream>
#include "timeh.hpp"
#include "GL/glm/glm.hpp"
#include "loadOBJ.h"
class lazik {
private:
float c_x{0};
float c_y{0};
float c_z{0};
float rot_x{0};
float rot_y{0};
float rot_z{0};
std::vector <glm::vec3> vertices;
std::vector <glm::vec2> uvs;
std::vector <glm::vec3> normals; // Won't be used at the moment.
GLuint vertexbuffer;
GLuint uvbuffer;
const char* modelpath;
public:
lazik(float x, float y, float z, const char* modelpath);
void loadModel();
void draw();
void moveX(float x);
void moveY(float y);
void moveZ(float z);
void moveXYZ(float x, float y, float z);
};

834
main.cpp

File diff suppressed because it is too large Load Diff

Binary file not shown.

75
plane.cpp Normal file
View File

@@ -0,0 +1,75 @@
#include "plane.hpp"
plane::plane(float x, float y, float z, const char* modelpath){
this->c_x = x;
this->c_y = y;
this->c_z = z;
this->modelpath = modelpath;
timestampedCout("plane.cpp: Zaladowano dane w konstruktorze.")
}
void plane::loadModel() {
timestampedCout("plane.cpp:");
std::cout << " Ladowanie modelu ze sciezki " << this->modelpath << "...\n";
bool res = loadOBJ(this->modelpath, this->vertices, this->uvs, this->normals);
if (res) timestampedCout("Pomyslnie zaladowano model mapki.")
else timestampedCout("Nie udalo sie zaladowac modelu mapki.");
glGenBuffers(1, &vertexbuffer);
glBindBuffer(GL_ARRAY_BUFFER, this->vertexbuffer);
glBufferData(GL_ARRAY_BUFFER, this->vertices.size() * sizeof(glm::vec3), &vertices[0], GL_STATIC_DRAW);
glGenBuffers(1, &uvbuffer);
glBindBuffer(GL_ARRAY_BUFFER, this->uvbuffer);
glBufferData(GL_ARRAY_BUFFER, this->uvs.size() * sizeof(glm::vec2), &uvs[0], GL_STATIC_DRAW);
}
void plane::draw() {
// 1st attribute buffer: vertices
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, this->vertexbuffer);
glVertexAttribPointer(
0, // attribute
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
// 2nd attribute buffer: UVs
glEnableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER, this->uvbuffer);
glVertexAttribPointer(
1, // attribute
2, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
// Draw vertices
glDrawArrays(GL_TRIANGLES, 0, this->vertices.size());
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
}
void plane::moveX(float x){
timestampedCout("dummy moveX");
}
void plane::moveY(float y){
timestampedCout("dummy moveY");
}
void plane::moveZ(float z){
timestampedCout("dummy moveZ");
}

33
plane.hpp Normal file
View File

@@ -0,0 +1,33 @@
#pragma once
#include <windows.h>
#include "GL/glew.h"
#include <gl/gl.h>
#include <gl/glu.h>
#include <vector>
#include <iostream>
#include "timeh.hpp"
#include "GL/glm/glm.hpp"
#include "loadOBJ.h"
class plane {
private:
float c_x{0};
float c_y{0};
float c_z{0};
float rot_x{0};
float rot_y{0};
float rot_z{0};
std::vector <glm::vec3> vertices;
std::vector <glm::vec2> uvs;
std::vector <glm::vec3> normals; // Won't be used at the moment.
GLuint vertexbuffer;
GLuint uvbuffer;
const char* modelpath;
public:
plane(float x, float y, float z, const char* modelpath);
void loadModel();
void draw();
void moveX(float x);
void moveY(float y);
void moveZ(float z);
};

7421
res/models/lazik4.obj Normal file

File diff suppressed because it is too large Load Diff

89
res/models/mapka.obj Normal file
View File

@@ -0,0 +1,89 @@
# Blender 4.2.1 LTS
# www.blender.org
o Plane
v -25.000000 -0.200000 25.000000
v 275.000000 -0.200000 25.000000
v -25.000000 -0.200000 -275.000000
v 275.000000 -0.200000 -275.000000
vn -0.0000 1.0000 -0.0000
vt 1.000000 0.000000
vt 0.000000 1.000000
vt 0.000000 0.000000
vt 1.000000 1.000000
s 0
f 2/1/1 3/2/1 1/3/1
f 2/1/1 4/4/1 3/2/1
o Cube
v -15.000000 0.000000 15.000000
v -15.000000 40.000000 15.000000
v -15.000000 0.000000 -35.000004
v -15.000000 40.000000 -35.000004
v 15.000000 0.000000 15.000000
v 15.000000 40.000000 15.000000
v 15.000000 0.000000 -35.000004
v 15.000000 40.000000 -35.000004
v 0.000000 52.654823 15.000000
v 0.000000 52.654823 -35.000004
v -15.000000 20.000000 -35.000004
v 0.000000 40.000000 -35.000004
v 15.000000 20.000000 -35.000004
v 0.000000 20.000000 -35.000004
v -15.000000 10.000000 -35.000004
v -7.500000 20.000000 -35.000004
v 15.000000 10.000000 -35.000004
v 7.500000 20.000000 -35.000004
vn -1.0000 -0.0000 -0.0000
vn -0.0000 -0.0000 -1.0000
vn 1.0000 -0.0000 -0.0000
vn -0.0000 -0.0000 1.0000
vn -0.6448 0.7643 -0.0000
vn 0.6448 0.7643 -0.0000
vt 0.625000 0.000000
vt 0.500000 0.250000
vt 0.437500 0.250000
vt 0.625000 0.375000
vt 0.500000 0.500000
vt 0.500000 0.437500
vt 0.625000 0.750000
vt 0.375000 0.750000
vt 0.375000 1.000000
vt 0.750000 0.750000
vt 0.000000 0.000000
vt 0.437500 0.500000
vt 0.625000 0.250000
vt 0.500000 0.375000
vt 0.500000 0.312500
vt 0.375000 0.250000
vt 0.750000 0.500000
vt 0.625000 0.500000
vt 0.375000 0.000000
vt 0.375000 0.500000
vt 0.625000 1.000000
s 0
f 6/5/2 15/6/2 19/7/2
f 16/8/3 17/9/3 22/10/3
f 17/9/4 10/11/4 9/12/4
f 10/11/5 5/13/5 9/12/5
f 13/14/6 8/15/6 6/15/6
f 21/16/3 22/10/3 17/9/3
f 8/17/3 18/18/3 20/19/3
f 19/7/3 20/19/3 7/20/3
f 16/8/3 14/21/3 12/22/3
f 12/22/7 13/14/7 10/11/7
f 6/15/5 10/11/5 13/14/5
f 7/20/2 5/23/2 6/5/2
f 6/5/2 8/17/2 15/6/2
f 19/7/2 7/20/2 6/5/2
f 22/10/3 18/18/3 16/8/3
f 16/8/3 12/22/3 17/9/3
f 9/12/4 11/24/4 21/16/4
f 17/9/4 12/22/4 10/11/4
f 9/12/4 21/16/4 17/9/4
f 10/11/5 6/25/5 5/13/5
f 13/14/6 14/21/6 8/15/6
f 21/16/3 11/24/3 22/10/3
f 20/19/3 15/6/3 8/17/3
f 8/17/3 16/8/3 18/18/3
f 19/7/3 15/6/3 20/19/3
f 16/8/3 8/15/3 14/21/3
f 12/22/7 14/21/7 13/14/7

1101
res/models/mapka2.obj Normal file

File diff suppressed because it is too large Load Diff

2274083
res/models/mapka3.obj Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,71 +0,0 @@
#include "szescian.h"
void szescian::create(float x, float y, float z, float KRAWEDZ) {
this->c_x = x;
this->c_y = y;
this->c_z = z;
// Parametry wierzcholkow
GLfloat sa[3] = { x + 0.0f, y + 0.0f, z + 0.0f };
GLfloat sb[3] = { x + KRAWEDZ, y + 0.0f, z + 0.0f };
GLfloat sc[3] = { x + KRAWEDZ, y + KRAWEDZ, z + 0.0f };
GLfloat sd[3] = { x + 0.0f, y + KRAWEDZ, z + 0.0f };
GLfloat se[3] = { x + 0.0f, y + 0.0f, z - KRAWEDZ };
GLfloat sf[3] = { x + KRAWEDZ, y + 0.0f, z - KRAWEDZ };
GLfloat sg[3] = { x + KRAWEDZ, y + KRAWEDZ, z - KRAWEDZ };
GLfloat sh[3] = { x + 0.0f, y + KRAWEDZ, z - KRAWEDZ };
// Sciany skladowe
glColor3f(1.0f, 0.0f, 0.0f);
glBegin(GL_POLYGON);
glVertex3fv(sa);
glVertex3fv(sb);
glVertex3fv(sc);
glVertex3fv(sd);
glEnd();
glColor3f(0.0f, 1.0f, 0.0f);
glBegin(GL_POLYGON);
glVertex3fv(sb);
glVertex3fv(sf);
glVertex3fv(sg);
glVertex3fv(sc);
glEnd();
glColor3f(0.0f, 0.0f, 1.0f);
glBegin(GL_POLYGON);
glVertex3fv(sf);
glVertex3fv(se);
glVertex3fv(sh);
glVertex3fv(sg);
glEnd();
glColor3f(1.0f, 1.0f, 0.0f);
glBegin(GL_POLYGON);
glVertex3fv(se);
glVertex3fv(sa);
glVertex3fv(sd);
glVertex3fv(sh);
glEnd();
glColor3f(0.0f, 1.0f, 1.0f);
glBegin(GL_POLYGON);
glVertex3fv(sd);
glVertex3fv(sc);
glVertex3fv(sg);
glVertex3fv(sh);
glEnd();
glColor3f(1.0f, 0.0f, 1.0f);
glBegin(GL_POLYGON);
glVertex3fv(sa);
glVertex3fv(sb);
glVertex3fv(sf);
glVertex3fv(se);
glEnd();
}

View File

@@ -1,14 +0,0 @@
#pragma once
#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
class szescian
{
private:
float c_x{0};
float c_y{0};
float c_z{0};
public:
void create(float x, float y, float z, float KRAWEDZ);
};

5
timeh.cpp Normal file
View File

@@ -0,0 +1,5 @@
#include "timeh.hpp"
std::time_t getTime() {
return std::time(nullptr);
}

5
timeh.hpp Normal file
View File

@@ -0,0 +1,5 @@
#pragma once
#include <ctime>
#include <iostream>
std::time_t getTime();
#define timestampedCout(msg) {std::time_t currentTime = getTime(); std::cout << "( " << currentTime << ") " << msg << "\n";}