Make vertex a cpp.
This commit is contained in:
@@ -47,8 +47,7 @@ CPMAddPackage(
|
||||
|
||||
|
||||
|
||||
add_library(Re3D SHARED ${SOURCES}
|
||||
src/types/skybox.cpp)
|
||||
add_library(Re3D SHARED ${SOURCES})
|
||||
# Why god???
|
||||
set_target_properties(Re3D PROPERTIES LINKER_LANGUAGE CXX)
|
||||
|
||||
|
@@ -9,7 +9,7 @@ class Entity {
|
||||
protected:
|
||||
LinearAlgebra::Matrix4x4 coordinates;
|
||||
public:
|
||||
LinearAlgebra::Vector3 position; //X Y Z
|
||||
LinearAlgebra::Position position;//X Y Z
|
||||
uint32_t ticksAlive; //At 64tps it'd take 776 days to overflow.
|
||||
|
||||
LinearAlgebra::Vector3 GetPos() const;
|
||||
|
@@ -1,14 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
//#include <windows.h>
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <GL/gl.h>
|
||||
#include <types/vector.h>
|
||||
#include <engine/engine.h>
|
||||
|
||||
struct Vertex {
|
||||
GLfloat x, y, z;
|
||||
@@ -19,58 +15,10 @@ class VertexArray {
|
||||
public:
|
||||
std::vector<Vertex> vertices;
|
||||
std::vector<unsigned int> indices;
|
||||
|
||||
void scale(GLfloat multiplier) {
|
||||
for (auto & vertice : vertices) {
|
||||
vertice.x *= multiplier;
|
||||
vertice.y *= multiplier;
|
||||
vertice.z *= multiplier;
|
||||
}
|
||||
}
|
||||
|
||||
void load(const std::string& filename) {
|
||||
std::ifstream file(filename);
|
||||
if (!file.is_open()) {
|
||||
std::cout << "File not found: " << filename << std::endl;
|
||||
engine->quit();
|
||||
return;
|
||||
}
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
std::istringstream stream(line);
|
||||
std::string prefix;
|
||||
stream >> prefix;
|
||||
|
||||
if (prefix == "v") {
|
||||
float x, y, z;
|
||||
stream >> x >> y >> z;
|
||||
vertices.push_back({x, y, z});
|
||||
} else if (prefix == "vt") {
|
||||
float u, v;
|
||||
stream >> u >> v;
|
||||
vertices.back().u = u;
|
||||
vertices.back().v = v;
|
||||
} else if (prefix == "f") {
|
||||
unsigned int index, texCoordIndex;
|
||||
char slash;
|
||||
while (stream >> index >> slash >> texCoordIndex) {
|
||||
indices.push_back(index - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
void scale(GLfloat multiplier);
|
||||
void load(const std::string& filename);
|
||||
|
||||
|
||||
//Wrong
|
||||
void draw() {
|
||||
glBegin(GL_TRIANGLES);
|
||||
|
||||
for (size_t i = 0; i < indices.size(); i += 3) {
|
||||
glVertex3f(vertices[indices[i]].x, vertices[indices[i]].y, vertices[indices[i]].z);
|
||||
glVertex3f(vertices[indices[i + 1]].x, vertices[indices[i + 1]].y, vertices[indices[i + 1]].z);
|
||||
glVertex3f(vertices[indices[i + 2]].x, vertices[indices[i + 2]].y, vertices[indices[i + 2]].z);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
void draw();
|
||||
};
|
@@ -23,6 +23,7 @@ void Render::pre_render() {
|
||||
storeEntity(skybox);
|
||||
auto *player = new Player();
|
||||
player->angle = {0, 0, 0};
|
||||
player->draw = true;
|
||||
storeEntity(player);
|
||||
}
|
||||
//std::cout << engine->frameCount << std::endl;
|
||||
@@ -37,8 +38,10 @@ void Render::render() {
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
//TODO: *Always* render the camera first.
|
||||
for (auto& e : entityList)
|
||||
e->render();
|
||||
for (auto& e : entityList) {
|
||||
if (e->draw)
|
||||
e->render();
|
||||
}
|
||||
}
|
||||
|
||||
void Render::post_render() {
|
||||
|
54
src/types/vertex.cpp
Normal file
54
src/types/vertex.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include <engine/engine.h>
|
||||
#include <types/vertex.h>
|
||||
|
||||
void VertexArray::scale(GLfloat multiplier) {
|
||||
for (auto & vertex : vertices) {
|
||||
vertex.x *= multiplier;
|
||||
vertex.y *= multiplier;
|
||||
vertex.z *= multiplier;
|
||||
}
|
||||
}
|
||||
|
||||
void VertexArray::load (const std::string& filename) {
|
||||
std::ifstream file(filename);
|
||||
if (!file.is_open()) {
|
||||
std::cout << "File not found: " << filename << std::endl;
|
||||
engine->quit();
|
||||
return;
|
||||
}
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
std::istringstream stream(line);
|
||||
std::string prefix;
|
||||
stream >> prefix;
|
||||
|
||||
if (prefix == "v") {
|
||||
float x, y, z;
|
||||
stream >> x >> y >> z;
|
||||
vertices.push_back({x, y, z});
|
||||
} else if (prefix == "vt") {
|
||||
float u, v;
|
||||
stream >> u >> v;
|
||||
vertices.back().u = u;
|
||||
vertices.back().v = v;
|
||||
} else if (prefix == "f") {
|
||||
unsigned int index, texCoordIndex;
|
||||
char slash;
|
||||
while (stream >> index >> slash >> texCoordIndex) {
|
||||
indices.push_back(index - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
//TODO: Render queue
|
||||
void VertexArray::draw() {
|
||||
glBegin(GL_TRIANGLES);
|
||||
for (size_t i = 0; i < indices.size(); i += 3) {
|
||||
glVertex3f(vertices[indices[i]].x, vertices[indices[i]].y, vertices[indices[i]].z);
|
||||
glVertex3f(vertices[indices[i + 1]].x, vertices[indices[i + 1]].y, vertices[indices[i + 1]].z);
|
||||
glVertex3f(vertices[indices[i + 2]].x, vertices[indices[i + 2]].y, vertices[indices[i + 2]].z);
|
||||
}
|
||||
glEnd();
|
||||
}
|
Reference in New Issue
Block a user