BatchWireframeAABB
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 5m54s
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 5m54s
This commit is contained in:
@@ -512,8 +512,16 @@ namespace JGL {
|
||||
/// Draws an outline of an axis-aligned bounding box in 3D space.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param aabb The AABB object to render.
|
||||
/// @param thickness The line-width to draw the Icosphere outline with.
|
||||
void WireframeAABB(const Color4& color, const AABB& aabb, float thickness = 1.f);
|
||||
|
||||
/// Draws outlines of multiple axis-aligned bounding-boxes in 3D space.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param boxes The boxes to be drawn.
|
||||
/// @param box_count The number of boxes to be drawn.
|
||||
/// @param thickness The line-width to draw the Icosahedron outline with.
|
||||
void BatchWireframeAABB(const Color4& color, const AABB* boxes, const size_t& box_count, float thickness = 1.f);
|
||||
|
||||
/// Draws a solid axis-aligned bounding box in 3D space.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param pos The point in 3D space that is the center of the AABB.
|
||||
|
7
main.cpp
7
main.cpp
@@ -4,6 +4,7 @@
|
||||
#include <chrono>
|
||||
#include <J3ML/LinearAlgebra/Vector2.hpp>
|
||||
#include <JGL/logger/logger.h>
|
||||
#include <J3ML/Geometry/AABB.hpp>
|
||||
|
||||
using J3ML::LinearAlgebra::Vector2;
|
||||
using namespace JGL;
|
||||
@@ -164,11 +165,13 @@ 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 * 100, true);
|
||||
//J3D::WireframeSphere(Colors::Green, {0,0,0.5f}, 0.25f, 1, 128, 128);
|
||||
Sphere sphere[5] = {{{0,0, 0.5f}, 0.2125}, {{0,0, 0.5f}, 0.025},{{0,0, 0.5f}, 0.05},{{0,0, 0.5f}, 0.075},{{0,0, 0.5f}, 0.1}};
|
||||
J3D::BatchWireframeRevoSphere(Colors::Green, sphere, 1, 1, 16, 16, true);
|
||||
Sphere sphere = {{0,0, 0.5f}, 0.2125};
|
||||
J3D::BatchWireframeRevoSphere(Colors::Green, &sphere, 1, 1, 16, 16, true);
|
||||
//J3D::FillAABB(Colors::Whites::AliceBlue, {0,0,0.5f}, {0.1f, 0.05f, 0.1f});
|
||||
//J3D::WireframeAABB(Colors::Gray, {0,0,0.5f}, {0.11f, 0.06f, 0.11f});
|
||||
|
||||
AABB boxes[1] = {{Vector3(-0.2125, -0.2125,0.28750), Vector3(0.2125,0.2125,0.7125)}};
|
||||
J3D::BatchWireframeAABB(Colors::Yellow, boxes, 1, 1);
|
||||
J3D::WireframeOBB(Colors::Red, {0, 0, 1.5f}, {0.40f, 0.10f, 0.10f}, {0,textAngle.y, 0});
|
||||
|
||||
//J3D::DrawCubicBezierCurve(Colors::Blue, {0,0,0.3}, {0,0,0.5}, {0.2,0,0.3}, {0.2, 0.3, 0.1}, 30);
|
||||
|
93
src/JGL.cpp
93
src/JGL.cpp
@@ -1296,70 +1296,43 @@ namespace JGL {
|
||||
glColor4fv(baseColor);
|
||||
}
|
||||
|
||||
void J3D::WireframeAABB(const Color4& color, const Vector3& pos, const Vector3& radii, float thickness) {
|
||||
void J3D::BatchWireframeAABB(const Color4& color, const AABB* boxes, const size_t &box_count, float thickness) {
|
||||
|
||||
if (!inJ3D)
|
||||
Logger::Error("Drawing J3D element before J3D begin.");
|
||||
std::array<Vector3, 24> vertices {
|
||||
Vector3(-1, 1, -1), Vector3(1, 1, -1),
|
||||
Vector3(1, 1, -1), Vector3(1, 1, 1),
|
||||
Vector3(1, 1, 1), Vector3(-1, 1, 1),
|
||||
Vector3(-1, 1, 1), Vector3(-1, 1, -1),
|
||||
Vector3(-1, -1, -1), Vector3(1, -1, -1),
|
||||
Vector3(1, -1, -1), Vector3(1, -1, 1),
|
||||
Vector3(1, -1, 1), Vector3(-1, -1, 1),
|
||||
Vector3(-1, -1, 1), Vector3(-1, -1, -1),
|
||||
Vector3(-1, -1, -1), Vector3(-1, 1, -1),
|
||||
Vector3(1, -1, -1), Vector3(1, 1, -1),
|
||||
Vector3(1, -1, 1), Vector3(1, 1, 1),
|
||||
Vector3(-1, -1, 1), Vector3(-1, 1, 1)
|
||||
};
|
||||
|
||||
|
||||
// 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());
|
||||
glLineWidth(thickness);
|
||||
for (size_t i = 0; i < box_count; i++) {
|
||||
Vector3 delta = (boxes[i].maxPoint - boxes[i].minPoint) / 2;
|
||||
Vector3 center = boxes[i].Centroid();
|
||||
glPushMatrix();
|
||||
glTranslatef(center.x, center.y, center.z);
|
||||
glScalef(delta.x, delta.y, delta.z);
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(Vector3), vertices.data());
|
||||
glDrawArrays(GL_LINES, 0, vertices.size());
|
||||
glPopMatrix();
|
||||
}
|
||||
glColor4fv(baseColor);
|
||||
}
|
||||
|
||||
void J3D::WireframeAABB(const Color4& color, const Vector3& pos, const Vector3& radii, float thickness) {
|
||||
AABB aabb = {Vector3(pos.x - radii.x, pos.y - radii.y, pos.z - radii.z), Vector3(pos.x + radii.x, pos.y + radii.y, pos.z + radii.z)};
|
||||
BatchWireframeAABB(color, &aabb, 1, thickness);
|
||||
}
|
||||
|
||||
void J3D::FillAABB(const Color4 &color, const Vector3 &pos, const Vector3 &radii) {
|
||||
if (!inJ3D)
|
||||
Logger::Error("Drawing J3D element before J3D begin.");
|
||||
@@ -1464,8 +1437,8 @@ namespace JGL {
|
||||
glColor4fv(baseColor);
|
||||
}
|
||||
|
||||
void J3D::WireframeAABB(const Color4 &color, const AABB &aabb, float thickness) {
|
||||
WireframeAABB(color, aabb.Centroid(), aabb.Size(), thickness);
|
||||
void J3D::WireframeAABB(const Color4& color, const AABB& aabb, float thickness) {
|
||||
BatchWireframeAABB(color, &aabb, 1, thickness);
|
||||
}
|
||||
|
||||
// Why is this here?
|
||||
|
Reference in New Issue
Block a user