VIDEO: extended shapebuilder
parent
8123421e55
commit
4c5caec28f
|
@ -52,6 +52,13 @@ void ShapeBuilder::aabbGridXZ(const math::AABB<float>& aabb, bool near, float st
|
|||
}
|
||||
}
|
||||
|
||||
void ShapeBuilder::line(const glm::vec3& start, const glm::vec3& end) {
|
||||
setPrimitive(Primitive::Lines);
|
||||
reserve(2);
|
||||
addIndex(addVertex(start));
|
||||
addIndex(addVertex(end));
|
||||
}
|
||||
|
||||
void ShapeBuilder::cube(const glm::vec3& mins, const glm::vec3& maxs) {
|
||||
setPrimitive(Primitive::Triangles);
|
||||
|
||||
|
@ -258,6 +265,33 @@ void ShapeBuilder::plane(const math::Plane& plane, bool normals) {
|
|||
addIndex(startIndex + 5);
|
||||
}
|
||||
|
||||
void ShapeBuilder::pyramid(const glm::vec3& size) {
|
||||
setPrimitive(Primitive::Triangles);
|
||||
|
||||
reserve(12);
|
||||
|
||||
const glm::vec3& tip = glm::vec3(_position.x, _position.y + size.y, _position.z);
|
||||
const glm::vec3& vlfl = glm::vec3(_position.x - size.x, _position.y, _position.z + size.z);
|
||||
const glm::vec3& vlfr = glm::vec3(_position.x + size.x, _position.y, _position.z + size.z);
|
||||
const glm::vec3& vlbl = glm::vec3(_position.x - size.x, _position.y, _position.z - size.z);
|
||||
const glm::vec3& vlbr = glm::vec3(_position.x + size.x, _position.y, _position.z - size.z);
|
||||
addIndex(addVertex(tip));
|
||||
addIndex(addVertex(vlfl));
|
||||
addIndex(addVertex(vlfr));
|
||||
|
||||
addIndex(addVertex(tip));
|
||||
addIndex(addVertex(vlbl));
|
||||
addIndex(addVertex(vlbr));
|
||||
|
||||
addIndex(addVertex(tip));
|
||||
addIndex(addVertex(vlbl));
|
||||
addIndex(addVertex(vlfl));
|
||||
|
||||
addIndex(addVertex(tip));
|
||||
addIndex(addVertex(vlbr));
|
||||
addIndex(addVertex(vlfr));
|
||||
}
|
||||
|
||||
void ShapeBuilder::frustum(const Camera& camera, int splitFrustum) {
|
||||
setPrimitive(Primitive::Lines);
|
||||
const uint32_t startIndex = _vertices.empty() ? 0u : (uint32_t)_vertices.size();
|
||||
|
@ -311,16 +345,16 @@ void ShapeBuilder::frustum(const Camera& camera, int splitFrustum) {
|
|||
}
|
||||
}
|
||||
|
||||
void ShapeBuilder::axis(float scale) {
|
||||
void ShapeBuilder::axis(const glm::vec3& scale) {
|
||||
setPrimitive(Primitive::Lines);
|
||||
const uint32_t startIndex = _vertices.empty() ? 0u : (uint32_t)_vertices.size();
|
||||
const glm::vec3 verticesAxis[] = {
|
||||
glm::vec3( 0.0f, 0.0f, 0.0f),
|
||||
glm::vec3(scale, 0.0f, 0.0f),
|
||||
glm::vec3( 0.0f, 0.0f, 0.0f),
|
||||
glm::vec3( 0.0f, scale, 0.0f),
|
||||
glm::vec3( 0.0f, 0.0f, 0.0f),
|
||||
glm::vec3( 0.0f, 0.0f, scale)};
|
||||
glm::vec3(_position.x, _position.y, _position.z),
|
||||
glm::vec3(_position.x + scale.x, _position.y, _position.z),
|
||||
glm::vec3(_position.x, _position.y, _position.z),
|
||||
glm::vec3(_position.x, _position.y + scale.y, _position.z),
|
||||
glm::vec3(_position.x, _position.y, _position.z),
|
||||
glm::vec3(_position.x, _position.y, _position.z + scale.z)};
|
||||
|
||||
reserve(SDL_arraysize(verticesAxis));
|
||||
|
||||
|
|
|
@ -89,6 +89,8 @@ public:
|
|||
|
||||
void cube(const glm::vec3& mins, const glm::vec3& maxs);
|
||||
|
||||
void line(const glm::vec3& start, const glm::vec3& end);
|
||||
|
||||
void aabb(const math::AABB<float>& aabb, bool renderGrid = false, float stepWidth = 1.0f);
|
||||
void aabb(const math::AABB<int>& aabb, bool renderGrid = false, float stepWidth = 1.0f);
|
||||
/**
|
||||
|
@ -98,6 +100,7 @@ public:
|
|||
void frustum(const Camera& camera, int splitFrustum = 0);
|
||||
void geom(const std::vector<glm::vec3>& vert, const std::vector<uint32_t>& indices, Primitive primitive = Primitive::Triangles);
|
||||
void plane(const math::Plane& plane, bool normal);
|
||||
void pyramid(const glm::vec3& size = glm::one<glm::vec3>());
|
||||
/**
|
||||
* Geometry layout for spheres is as follows (for 5 slices, 4 stacks):
|
||||
*
|
||||
|
@ -116,7 +119,8 @@ public:
|
|||
* + + + + + + south pole
|
||||
*/
|
||||
void sphere(int numSlices, int numStacks, float radius);
|
||||
void axis(float scale);
|
||||
void axis(float scale) { axis(glm::vec3(scale)); }
|
||||
void axis(const glm::vec3& scale);
|
||||
/**
|
||||
* @brief Frees the memory
|
||||
*/
|
||||
|
|
|
@ -61,64 +61,30 @@ void TestShapeBuilder::onRenderUI() {
|
|||
glm::vec3& scale = _scale[_meshCount];
|
||||
_shapeBuilder.setPosition(pos);
|
||||
|
||||
ImGui::SetNextWindowSize(ImVec2(540, 300));
|
||||
ImGui::Begin("Actions and Settings");
|
||||
|
||||
ImGui::Text("General settings");
|
||||
ImGui::Indent();
|
||||
ImGui::ColorEdit4("color", glm::value_ptr(_color), false);
|
||||
ImGui::PushItemWidth(width);
|
||||
ImGui::InputInt("x", &pos.x);
|
||||
ImGui::SameLine();
|
||||
ImGui::PushItemWidth(width);
|
||||
ImGui::InputInt("y", &pos.y);
|
||||
ImGui::SameLine();
|
||||
ImGui::PushItemWidth(width);
|
||||
ImGui::InputInt("z", &pos.z);
|
||||
ImGui::InputInt3("pos", glm::value_ptr(pos));
|
||||
ImGui::InputFloat3("scale", glm::value_ptr(scale));
|
||||
ImGui::Unindent();
|
||||
|
||||
ImGui::PushItemWidth(width);
|
||||
ImGui::InputFloat("sx", &scale.x);
|
||||
ImGui::SameLine();
|
||||
ImGui::PushItemWidth(width);
|
||||
ImGui::InputFloat("sy", &scale.y);
|
||||
ImGui::SameLine();
|
||||
ImGui::PushItemWidth(width);
|
||||
ImGui::InputFloat("sz", &scale.z);
|
||||
|
||||
int numSlices = 5;
|
||||
int numStacks = 4;
|
||||
float radius = 20.0f;
|
||||
ImGui::PushItemWidth(width);
|
||||
ImGui::InputInt("slices", &numSlices);
|
||||
ImGui::SameLine();
|
||||
ImGui::PushItemWidth(width);
|
||||
ImGui::InputInt("stacks", &numStacks);
|
||||
ImGui::SameLine();
|
||||
ImGui::PushItemWidth(width);
|
||||
ImGui::InputFloat("radius", &radius);
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("Sphere");
|
||||
ImGui::Indent();
|
||||
ImGui::InputInt("slices", &_sphere.numSlices);
|
||||
ImGui::InputInt("stacks", &_sphere.numStacks);
|
||||
ImGui::InputFloat("radius", &_sphere.radius);
|
||||
if (ImGui::Button("Sphere")) {
|
||||
_shapeBuilder.sphere(numSlices, numStacks, radius);
|
||||
_shapeBuilder.sphere(_sphere.numSlices, _sphere.numStacks, _sphere.radius);
|
||||
buildMesh = true;
|
||||
}
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::PushItemWidth(width);
|
||||
ImGui::InputFloat("mins.x", &_mins.x);
|
||||
ImGui::SameLine();
|
||||
ImGui::PushItemWidth(width);
|
||||
ImGui::InputFloat("mins.y", &_mins.y);
|
||||
ImGui::SameLine();
|
||||
ImGui::PushItemWidth(width);
|
||||
ImGui::InputFloat("mins.z", &_mins.z);
|
||||
|
||||
ImGui::PushItemWidth(width);
|
||||
ImGui::InputFloat("maxs.x", &_maxs.x);
|
||||
ImGui::SameLine();
|
||||
ImGui::PushItemWidth(width);
|
||||
ImGui::InputFloat("maxs.y", &_maxs.y);
|
||||
ImGui::SameLine();
|
||||
ImGui::PushItemWidth(width);
|
||||
ImGui::InputFloat("maxs.z", &_maxs.z);
|
||||
ImGui::Unindent();
|
||||
|
||||
ImGui::Text("Cube");
|
||||
ImGui::Indent();
|
||||
ImGui::InputFloat3("Mins", glm::value_ptr(_mins));
|
||||
ImGui::InputFloat3("Maxs", glm::value_ptr(_maxs));
|
||||
if (ImGui::Button("Cube")) {
|
||||
_shapeBuilder.cube(_mins, _maxs);
|
||||
buildMesh = true;
|
||||
|
@ -134,30 +100,48 @@ void TestShapeBuilder::onRenderUI() {
|
|||
_shapeBuilder.aabb(math::AABB<float>(_mins, _maxs));
|
||||
buildMesh = true;
|
||||
}
|
||||
ImGui::Unindent();
|
||||
|
||||
ImGui::Checkbox("Near plane", &_near);
|
||||
ImGui::SameLine();
|
||||
ImGui::InputFloat("Step width", &_stepWidth);
|
||||
if (ImGui::Button("AABB Grid XY")) {
|
||||
_shapeBuilder.aabbGridXY(math::AABB<float>(_mins, _maxs), _near, _stepWidth);
|
||||
if (ImGui::CollapsingHeader("AABB grid", ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_FramePadding)) {
|
||||
ImGui::Checkbox("Near plane", &_near);
|
||||
ImGui::InputFloat("Step width", &_stepWidth);
|
||||
if (ImGui::Button("AABB Grid XY")) {
|
||||
_shapeBuilder.aabbGridXY(math::AABB<float>(_mins, _maxs), _near, _stepWidth);
|
||||
buildMesh = true;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("AABB Grid XZ")) {
|
||||
_shapeBuilder.aabbGridXZ(math::AABB<float>(_mins, _maxs), _near, _stepWidth);
|
||||
buildMesh = true;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("AABB Grid YZ")) {
|
||||
_shapeBuilder.aabbGridYZ(math::AABB<float>(_mins, _maxs), _near, _stepWidth);
|
||||
buildMesh = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui::Button("Line")) {
|
||||
_shapeBuilder.line(_mins, _maxs);
|
||||
buildMesh = true;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("AABB Grid XZ")) {
|
||||
_shapeBuilder.aabbGridXZ(math::AABB<float>(_mins, _maxs), _near, _stepWidth);
|
||||
|
||||
if (ImGui::Button("Pyramid")) {
|
||||
_shapeBuilder.pyramid(scale);
|
||||
buildMesh = true;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("AABB Grid YZ")) {
|
||||
_shapeBuilder.aabbGridYZ(math::AABB<float>(_mins, _maxs), _near, _stepWidth);
|
||||
|
||||
if (ImGui::Button("Axis")) {
|
||||
_shapeBuilder.axis(scale);
|
||||
buildMesh = true;
|
||||
}
|
||||
ImGui::Separator();
|
||||
|
||||
if (buildMesh && _meshCount < lengthof(_meshes)) {
|
||||
_meshes[_meshCount] = _shapeRenderer.create(_shapeBuilder);
|
||||
if (_meshes[_meshCount] != -1) {
|
||||
++_meshCount;
|
||||
_position[_meshCount] = _position[_meshCount - 1];
|
||||
_scale[_meshCount] = _scale[_meshCount - 1];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,11 @@ private:
|
|||
glm::vec3 _maxs { 10.0f, 10.0f, 10.0f};
|
||||
int _meshes[render::ShapeRenderer::MAX_MESHES] {-1};
|
||||
int _meshUnitCube = -1;
|
||||
struct {
|
||||
int numSlices = 5;
|
||||
int numStacks = 4;
|
||||
float radius = 20.0f;
|
||||
} _sphere;
|
||||
|
||||
void doRender() override;
|
||||
void onRenderUI() override;
|
||||
|
|
Loading…
Reference in New Issue