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.
This commit is contained in:
77
plane.cpp
Normal file
77
plane.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
#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() {
|
||||
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
// 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");
|
||||
}
|
||||
Reference in New Issue
Block a user