Make the bounding box actually work correctly.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include <types/vertex.h>
|
||||
#include <types/entity.h>
|
||||
|
||||
namespace BoundingBox {
|
||||
VertexArray calculateAABB(VertexArray* vArray);
|
||||
|
@@ -35,11 +35,11 @@ public:
|
||||
// William continues to load assets on the first frame.
|
||||
if (engine->frameCount == 1) {
|
||||
geometry.load("assets/models/cube.obj");
|
||||
geometry.scale(0.5f);
|
||||
//geometry.scale(0.5f);
|
||||
position = {0,-2,0};
|
||||
}
|
||||
//Rotate
|
||||
std::cout << "Occluded: " << occluded << std::endl;
|
||||
//std::cout << "Occluded: " << occluded << std::endl;
|
||||
this->angle.y = 255*engine->frameDelta;
|
||||
//this->angle.x = 1;
|
||||
geometry.rotate(angle);
|
||||
@@ -48,12 +48,10 @@ public:
|
||||
void render() override {
|
||||
glColor3f(0.75,0.75,0.75);
|
||||
glPushMatrix();
|
||||
//glRotatef(angle.x,1.0f, 0.0f, 0.0f);
|
||||
//glRotatef(angle.y,0.0f, 1.0f, 0.0f);
|
||||
//glRotatef(angle.z,0.0f, 0.0f, 1.0f);
|
||||
glTranslatef(position.x ,position.y,position.z);
|
||||
geometry.draw();
|
||||
boundingBox.draw();
|
||||
glColor3f(1,0,0);
|
||||
boundingBox.drawWireframe();
|
||||
glPopMatrix();
|
||||
}
|
||||
};
|
||||
|
@@ -23,4 +23,5 @@ public:
|
||||
|
||||
//Wrong
|
||||
void draw();
|
||||
void drawWireframe();
|
||||
};
|
@@ -16,9 +16,9 @@ void Occlusion::frustumCull(Camera* camera) {
|
||||
// Transform the bounding box vertices to world space
|
||||
for (auto& vertex : e->boundingBox.vertices) {
|
||||
Vertex out{};
|
||||
out.x = vertex.x + e->position.x;
|
||||
out.y = vertex.y + e->position.y;
|
||||
out.z = vertex.z + e->position.z;
|
||||
out.x = vertex.x;
|
||||
out.y = vertex.y;
|
||||
out.z = vertex.z;
|
||||
AABB.vertices.push_back(out);
|
||||
}
|
||||
|
||||
|
@@ -36,6 +36,9 @@ VertexArray BoundingBox::calculateAABB(VertexArray* vArray) {
|
||||
output.vertices.push_back(Vertex(maxX, minY, maxZ));
|
||||
output.vertices.push_back(Vertex(minX, maxY, maxZ));
|
||||
output.vertices.push_back(Vertex(maxX, maxY, maxZ));
|
||||
//std::cout << "Bounding Box: " << std::endl;
|
||||
//for (auto vertex : output.vertices)
|
||||
//std::cout << "X: " << vertex.x << "Y: " << vertex.y << "Z: " << vertex.z << std::endl;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
@@ -56,6 +56,21 @@ void VertexArray::draw() {
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void VertexArray::drawWireframe() {
|
||||
glBegin(GL_LINES);
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
glVertex3f(vertices[i].x, vertices[i].y, vertices[i].z);
|
||||
glVertex3f(vertices[(i + 1) % 4].x, vertices[(i + 1) % 4].y, vertices[(i + 1) % 4].z);
|
||||
|
||||
glVertex3f(vertices[i + 4].x, vertices[i + 4].y, vertices[i + 4].z);
|
||||
glVertex3f(vertices[((i + 1) % 4) + 4].x, vertices[((i + 1) % 4) + 4].y, vertices[((i + 1) % 4) + 4].z);
|
||||
|
||||
glVertex3f(vertices[i].x, vertices[i].y, vertices[i].z);
|
||||
glVertex3f(vertices[i + 4].x, vertices[i + 4].y, vertices[i + 4].z);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void VertexArray::rotate(LinearAlgebra::Vector3 angle) {
|
||||
LinearAlgebra::Vector3 angleRad = LinearAlgebra::Vector3(Math::Radians(angle.x), Math::Radians(angle.y), Math::Radians(angle.z));
|
||||
|
||||
|
Reference in New Issue
Block a user