Implementation of WireframeAABB (Still validating?)
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 7m1s
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 7m1s
This commit is contained in:
1
main.cpp
1
main.cpp
@@ -167,6 +167,7 @@ public:
|
||||
J3D::DrawLine(Colors::Red, {-0.33,-0.125,1}, {-0.33,0.25,1});
|
||||
J3D::DrawString(Colors::Red, "JGL Sample Text", {-0.33, -0.1, 1.0f}, 1.f, 32, FreeSans, textAngle, true);
|
||||
J3D::WireframeSphere(Colors::Green, {0,0,0.5f}, 0.25f, 1.f, 10, 10);
|
||||
J3D::WireframeAABB(Colors::White, {0,0,0.25f}, {0.1f, 0.1f, 0.05f});
|
||||
//J3D::WireframeIcosahedron(Colors::Green, {0,0,0.5f}, 0.125f, 1.f);
|
||||
J3D::End();
|
||||
|
||||
|
68
src/JGL.cpp
68
src/JGL.cpp
@@ -1102,13 +1102,17 @@ namespace JGL {
|
||||
glColor4ubv(color.ptr());
|
||||
//glBindBuffer(GL_ARRAY_BUFFER, vertices.size());
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(Vector3), vertices.data());
|
||||
glDrawArrays(GL_LINES, 0, vertices.size());
|
||||
glDrawArrays(GL_LINE_LOOP, 0, vertices.size());
|
||||
glColor4fv(baseColor);
|
||||
}
|
||||
|
||||
|
||||
void J3D::WireframeIcosphere(const Color4 &color, const Vector3& position, float radius, float thickness,
|
||||
unsigned int subdivisions) {
|
||||
|
||||
// NOTE2SELF: Code i'm borrowing this from uses float-packed-arrays rather than discrete Vectors
|
||||
// working on translating that correctly...
|
||||
|
||||
// TODO: Revise this once J3ML::Geometry::Icosahedron is implemented.
|
||||
const float h_angle = J3ML::Math::Pi / 180.f * 72.f; // 72 degree = 360 / 5;
|
||||
const float v_angle = J3ML::Math::Atan(1.0f / 2.f); // elevation = 26.565;
|
||||
@@ -1168,6 +1172,8 @@ namespace JGL {
|
||||
for (i = 0; i < tmpIndices.size(); i++)
|
||||
{
|
||||
//v1 = tmpVertices[tmpIndices[i]];
|
||||
//v2 = tmpVertices[tmpIndices[i+1]];
|
||||
//v3 = tmpVertices[tmpIndices[i+2]];
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1214,5 +1220,65 @@ namespace JGL {
|
||||
glColor4fv(baseColor);
|
||||
}
|
||||
|
||||
void J3D::WireframeAABB(const Color4 &color, const Vector3 &pos, const Vector3 &radii, float thickness) {
|
||||
|
||||
// Top of cube
|
||||
Vector3 top_right_top = pos + Vector3(radii.x, radii.y, -radii.z);
|
||||
Vector3 top_left_top = pos + Vector3(-radii.x, radii.y, -radii.z);
|
||||
Vector3 bottom_left_top = pos - radii;
|
||||
Vector3 bottom_right_top = pos + Vector3(radii.x, radii.y, radii.z);
|
||||
|
||||
// Bottom of cube
|
||||
Vector3 top_right_bottom = pos + Vector3(radii.x, -radii.y, radii.z);
|
||||
Vector3 top_left_bottom = pos + Vector3(-radii.x, -radii.y, radii.z);
|
||||
Vector3 bottom_left_bottom = pos - radii;
|
||||
Vector3 bottom_right_bottom = pos + Vector3(radii.x, -radii.y, -radii.z);
|
||||
|
||||
// front of cube
|
||||
Vector3 top_right_front = pos + radii;
|
||||
Vector3 top_left_front = pos + Vector3(-radii.x, radii.y, radii.z);
|
||||
Vector3 bottom_left_front = pos + Vector3(-radii.x, -radii.y, radii.z);
|
||||
Vector3 bottom_right_front = pos + Vector3(radii.x, -radii.y, radii.z);
|
||||
|
||||
// back of cube
|
||||
Vector3 top_right_back = pos + Vector3(radii.x, -radii.y, -radii.z);
|
||||
Vector3 top_left_back = pos - radii;
|
||||
Vector3 bottom_left_back = pos + Vector3(-radii.x, radii.y, -radii.z);
|
||||
Vector3 bottom_right_back = pos + Vector3(radii.x, radii.y, -radii.z);
|
||||
|
||||
// left of cube
|
||||
Vector3 top_right_left = pos + Vector3(-radii.x, radii.y, radii.z);
|
||||
Vector3 top_left_left = pos + Vector3(-radii.x, radii.y, -radii.z);
|
||||
Vector3 bottom_left_left = pos - radii;
|
||||
Vector3 bottom_right_left = pos + Vector3(-radii.x, -radii.y, radii.z);
|
||||
|
||||
// right of cube
|
||||
Vector3 top_right_right = pos + Vector3(radii.x, radii.y, -radii.z);
|
||||
Vector3 top_left_right = pos + radii;
|
||||
Vector3 bottom_left_right = pos + Vector3(radii.x, -radii.y, radii.z);
|
||||
Vector3 bottom_right_right = pos + Vector3(radii.x, -radii.y, -radii.z);
|
||||
|
||||
std::vector<Vector3> vertices
|
||||
{
|
||||
top_right_top, top_left_top, bottom_left_top, bottom_right_top,
|
||||
top_right_bottom, top_left_bottom, bottom_left_bottom, bottom_right_bottom,
|
||||
top_right_front, top_left_front, bottom_left_front, bottom_right_front,
|
||||
top_right_back, top_left_back, bottom_left_back, bottom_right_back,
|
||||
top_right_left, top_left_left, bottom_left_left, bottom_right_left,
|
||||
top_right_right, top_left_right, bottom_left_right, bottom_right_right
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
glLineWidth(thickness);
|
||||
glColor4ubv(color.ptr());
|
||||
//glBindBuffer(GL_ARRAY_BUFFER, vertices.size());
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(Vector3), vertices.data());
|
||||
glDrawArrays(GL_LINE_LOOP, 0, vertices.size());
|
||||
glColor4fv(baseColor);
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
}
|
||||
|
Reference in New Issue
Block a user