HUGE Performance Optimization.
This commit is contained in:
261893
assets/models/sphere_ridiculous.obj
Normal file
261893
assets/models/sphere_ridiculous.obj
Normal file
File diff suppressed because it is too large
Load Diff
@@ -26,6 +26,7 @@ public:
|
||||
bool fullscreen;
|
||||
bool debug = true;
|
||||
bool useVBO = true;
|
||||
bool drawCollision = true;
|
||||
uint64_t tickCount = 0;
|
||||
uint64_t frameCount = 0;
|
||||
float frameDelta = NULL;
|
||||
|
@@ -54,8 +54,6 @@ protected:
|
||||
public:
|
||||
std::string uuid;
|
||||
uint32_t ticksAlive; //At 64tps it'd take 776 days to overflow.
|
||||
|
||||
VertexArray boundingBox;
|
||||
[[nodiscard]] LinearAlgebra::Vector3 GetPos() const;
|
||||
void SetPos(const LinearAlgebra::Vector3& rhs);
|
||||
LinearAlgebra::Matrix4x4 GetMatrix() const;
|
||||
|
@@ -15,11 +15,13 @@ struct Vertex {
|
||||
};
|
||||
|
||||
class VertexArray {
|
||||
|
||||
private:
|
||||
std::vector<Vertex> boundingVolume;
|
||||
public:
|
||||
std::string name;
|
||||
std::vector<Vertex> vertices;
|
||||
std::vector<unsigned int> indices;
|
||||
VertexArray getBoundingVolume(LinearAlgebra::Vector3 angle);
|
||||
void rotate(const LinearAlgebra::Vector3& angle);
|
||||
void load(const std::string& filename);
|
||||
void drawWireframe();
|
||||
|
@@ -9,13 +9,13 @@ bool Occlusion::frustumCull(Camera* camera, Entity* entity) {
|
||||
//TODO: Transform the BoundingBox to world space.
|
||||
VertexArray AABB;
|
||||
|
||||
for (auto& vertex : entity->boundingBox.vertices) {
|
||||
Vertex out{};
|
||||
out.x = vertex.x;
|
||||
out.y = vertex.y;
|
||||
out.z = vertex.z;
|
||||
AABB.vertices.push_back(out);
|
||||
}
|
||||
//for (auto& vertex : entity->boundingBox.vertices) {
|
||||
//Vertex out{};
|
||||
//out.x = vertex.x;
|
||||
//out.y = vertex.y;
|
||||
//out.z = vertex.z;
|
||||
//AABB.vertices.push_back(out);
|
||||
//}
|
||||
|
||||
|
||||
//Returns "false" if the entity should not be occluded.
|
||||
|
@@ -1,7 +1,6 @@
|
||||
#include <types/player.h>
|
||||
#include <types/collision/collision.h>
|
||||
void Player::pre_render() {
|
||||
boundingBox = Collision::calculateBoundingBox(this, angle);
|
||||
hVelocity = 2;
|
||||
velAngle = angle;
|
||||
//hMove(LinearAlgebra::Vector3::Direction({0, velAngle.y, 0}), hVelocity);
|
||||
@@ -23,12 +22,16 @@ void Player::render() {
|
||||
glScalef(getScale(),getScale(),getScale());
|
||||
getGeometry()->draw();
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glPopMatrix();
|
||||
glPushMatrix();
|
||||
glColor3f(1,0,0);
|
||||
glTranslatef(position.x ,position.y,position.z);
|
||||
boundingBox.draw();
|
||||
glPopMatrix();
|
||||
|
||||
if (engine->drawCollision) {
|
||||
glPopMatrix();
|
||||
glPushMatrix();
|
||||
glColor3f(1, 0, 0);
|
||||
glTranslatef(position.x, position.y, position.z);
|
||||
getGeometry()->getBoundingVolume(angle).draw();
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
LinearAlgebra::Vector3 Player::cameraPoint(float distance) {
|
||||
@@ -76,7 +79,7 @@ VertexArray *Player::getGeometry() {
|
||||
void Player::loadGeometry() {
|
||||
VertexArray geometry;
|
||||
geometry.name = "player";
|
||||
std::string path = engine->workingDir + "/assets/models/cube.obj";
|
||||
std::string path = engine->workingDir + "/assets/models/sphere_ridiculous.obj";
|
||||
geometry.load(path);
|
||||
engine->world->geometryList.push_back(geometry);
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#include <engine/engine.h>
|
||||
#include <types/vertex.h>
|
||||
#include <types/collision/collision.h>
|
||||
#include <cmath>
|
||||
|
||||
void VertexArray::load (const std::string& filename) {
|
||||
@@ -47,22 +48,27 @@ void VertexArray::load (const std::string& filename) {
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
|
||||
//Copy verts to vram.
|
||||
if (engine->useVBO) {
|
||||
if (vbo == NULL) {
|
||||
GLfloat verts[vertices.size() * 3];
|
||||
size_t index = 0;
|
||||
for (const auto &vertex: vertices) {
|
||||
verts[index++] = vertex.x;
|
||||
verts[index++] = vertex.y;
|
||||
verts[index++] = vertex.z;
|
||||
}
|
||||
if (vbo == NULL) {
|
||||
GLfloat verts[vertices.size() * 3];
|
||||
size_t index = 0;
|
||||
for (const auto &vertex: vertices) {
|
||||
verts[index++] = vertex.x;
|
||||
verts[index++] = vertex.y;
|
||||
verts[index++] = vertex.z;
|
||||
}
|
||||
|
||||
glGenBuffers(1, &vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(verts), &verts, GL_STATIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(verts), &verts, GL_STATIC_DRAW); //GL_STATIC_DRAW means the VBO won't be changed atall.
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
}
|
||||
|
||||
boundingVolume = Collision::calculateBoundingBox(this, {0,0,0}).vertices;
|
||||
|
||||
}
|
||||
|
||||
//TODO: Render queue
|
||||
@@ -151,3 +157,11 @@ void VertexArray::rotate(const LinearAlgebra::Vector3& angle) {
|
||||
vertex.z = newZ;
|
||||
}
|
||||
}
|
||||
|
||||
VertexArray VertexArray::getBoundingVolume(LinearAlgebra::Vector3 angle) {
|
||||
VertexArray vArray;
|
||||
vArray.vertices = boundingVolume;
|
||||
vArray.rotate(angle);
|
||||
return vArray;
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user