drawWireframe

This commit is contained in:
2024-01-15 19:51:15 -05:00
parent 1855fd5739
commit 1f8047c34f
5 changed files with 22 additions and 4 deletions

View File

@@ -42,7 +42,7 @@ CPMAddPackage(
CPMAddPackage(
NAME J3ML
URL https://git.redacted.cc/josh/j3ml/archive/Prerelease-6.zip
URL https://git.redacted.cc/josh/j3ml/archive/Prerelease-7.zip
)
# BSD 2-clause license.

View File

@@ -19,5 +19,6 @@ public:
void scale(GLfloat multiplier);
void rotate(LinearAlgebra::Vector3 angle);
void load(const std::string& filename);
void drawWireframe();
void draw();
};

View File

@@ -21,6 +21,6 @@ int World::getEntityCount() {
VertexArray World::getPlayerBaseGeometry() {
if (playerBaseGeometry.vertices.empty())
playerBaseGeometry.load("assets/models/cube.obj");
playerBaseGeometry.load("assets/models/cone.obj");
return playerBaseGeometry;
}

View File

@@ -21,7 +21,7 @@ void Player::render() {
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);
geometry.draw();
geometry.drawWireframe();
glPopMatrix();
glPushMatrix();

View File

@@ -57,7 +57,8 @@ void VertexArray::draw() {
glEnd();
}
//Render wireframe if we have no faces.
//This only works for *really* simple shapes.
//Primarily for the bounding box.
if (indices.empty()) {
glBegin(GL_LINES);
for (int i = 0; i < 4; ++i) {
@@ -74,6 +75,22 @@ void VertexArray::draw() {
}
}
void VertexArray::drawWireframe() {
glBegin(GL_LINES);
for (size_t i = 0; i < indices.size(); i += 2) {
if (i + 1 < indices.size()) {
int index1 = static_cast<int>(indices[i]);
int index2 = static_cast<int>(indices[i + 1]);
if (index1 >= 0 && index1 < vertices.size() && index2 >= 0 && index2 < vertices.size()) {
glVertex3f(vertices[index1].x, vertices[index1].y, vertices[index1].z);
glVertex3f(vertices[index2].x, vertices[index2].y, vertices[index2].z);
}
}
}
glEnd();
}
//TODO: Fix gimbal lock when rotating in X or Z.
void VertexArray::rotate(LinearAlgebra::Vector3 angle) {
if (vertices.empty())