81 lines
2.4 KiB
C++
81 lines
2.4 KiB
C++
#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");
|
|
} |