FillSphere is completely fucked.
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m46s
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m46s
This commit is contained in:
@@ -328,6 +328,9 @@ namespace JGL {
|
||||
|
||||
void WireframeIcosahedron(const Color4 &color, const Vector3 &position, float radius, float thickness = 1.f);
|
||||
|
||||
/// Draws the 'Wireframe' outline of a sphere in 3D space.
|
||||
/// @param color
|
||||
|
||||
void WireframeSphere(const Color4& color, const Vector3& position, float radius, float thickness = 1.f, uint sectors = 10, uint stacks = 10);
|
||||
void WireframeSphere(const Color4& color, const Sphere& sphere, float thickness = 1.f, uint sectors = 10, uint stacks = 10);
|
||||
void WireframeIcosphere(const Color4& color, const Vector3& position, float radius, float thickness = 1.f, unsigned int subdivisions = 10);
|
||||
@@ -335,8 +338,8 @@ namespace JGL {
|
||||
void WireframeCubesphere(const Color4& color, const Vector3& position, float radius, float thickness = 1.f, unsigned int subdivisions = 10);
|
||||
void WireframeCubesphere(const Color4& color, const Sphere& sphere, float thickness = 1.f, unsigned int subdivisions = 10);
|
||||
|
||||
void FillSphere(const Color4& color, const Vector3& position, float radius, unsigned int subdivisions = 10);
|
||||
void FillSphere(const Color4& color, const Sphere& sphere, unsigned int subdivisions = 10);
|
||||
void FillSphere(const Color4& color, const Vector3& position, float radius, uint sectors = 10, uint stacks = 10);
|
||||
void FillSphere(const Color4& color, const Sphere& sphere, uint sectors = 10, uint stacks = 10);
|
||||
void FillIcosphere(const Color4& color, const Vector3& position, float radius, unsigned int subdivisions = 10);
|
||||
void FillIcosphere(const Color4& color, const Sphere& sphere, unsigned int subdivisions = 10);
|
||||
void FillCubesphere(const Color4& color, const Vector3& position, float radius, unsigned int subdivisions = 10);
|
||||
|
6
main.cpp
6
main.cpp
@@ -166,10 +166,10 @@ public:
|
||||
J3D::DrawLine(Colors::Red, {-0.33,-0.125,1}, {-1,-0.125,1});
|
||||
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::FillSphere(Colors::Green, {0,0,0.5f}, 0.25f, 10, 10);
|
||||
|
||||
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});
|
||||
//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});
|
||||
|
||||
//J3D::WireframeIcosahedron(Colors::Green, {0,0,0.5f}, 0.125f, 1.f);
|
||||
J3D::End();
|
||||
|
62
src/JGL.cpp
62
src/JGL.cpp
@@ -7,6 +7,7 @@
|
||||
#include <J3ML/Algorithm/Bezier.hpp>
|
||||
#include <JGL/logger/logger.h>
|
||||
#include <J3ML/Geometry/AABB.hpp>
|
||||
#include <J3ML/Geometry/Sphere.hpp>
|
||||
#include "JGL/types/VRamList.h"
|
||||
|
||||
JGL::RenderTarget* render_target = nullptr;
|
||||
@@ -1111,6 +1112,9 @@ namespace JGL {
|
||||
void J3D::WireframeIcosphere(const Color4 &color, const Vector3& position, float radius, float thickness,
|
||||
unsigned int subdivisions) {
|
||||
|
||||
if (!inJ3D)
|
||||
Logger::Error("Drawing J3D element before J3D begin.");
|
||||
|
||||
// NOTE2SELF: Code i'm borrowing this from uses float-packed-arrays rather than discrete Vectors
|
||||
// working on translating that correctly...
|
||||
|
||||
@@ -1180,6 +1184,10 @@ namespace JGL {
|
||||
}
|
||||
|
||||
void J3D::WireframeIcosahedron(const Color4 &color, const Vector3 &position, float radius, float thickness) {
|
||||
|
||||
if (!inJ3D)
|
||||
Logger::Error("Drawing J3D element before J3D begin.");
|
||||
|
||||
// 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;
|
||||
@@ -1223,6 +1231,10 @@ namespace JGL {
|
||||
|
||||
void J3D::WireframeAABB(const Color4 &color, const Vector3 &pos, const Vector3 &radii, float thickness) {
|
||||
|
||||
if (!inJ3D)
|
||||
Logger::Error("Drawing J3D element before J3D begin.");
|
||||
|
||||
|
||||
// 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);
|
||||
@@ -1282,6 +1294,9 @@ namespace JGL {
|
||||
}
|
||||
|
||||
void J3D::FillAABB(const Color4 &color, const Vector3 &pos, const Vector3 &radii) {
|
||||
if (!inJ3D)
|
||||
Logger::Error("Drawing J3D element before J3D begin.");
|
||||
|
||||
// Top of cube
|
||||
Vector3 top_right_top = pos + Vector3(radii.x, radii.y, -radii.z);
|
||||
Vector3 bottom_right_top = pos + Vector3(radii.x, radii.y, radii.z);
|
||||
@@ -1340,5 +1355,52 @@ namespace JGL {
|
||||
FillAABB(color, aabb.Centroid(), aabb.Size());
|
||||
}
|
||||
|
||||
void J3D::WireframeSphere(const Color4 &color, const Sphere &sphere, float thickness, uint sectors, uint stacks) {
|
||||
WireframeSphere(color, sphere.Centroid(), sphere.Radius, thickness, sectors, stacks);
|
||||
}
|
||||
|
||||
void J3D::FillSphere(const Color4 &color, const Vector3 &position, float radius, uint sectors, uint stacks) {
|
||||
if (!inJ3D)
|
||||
Logger::Error("Drawing J3D element before J3D begin.");
|
||||
|
||||
|
||||
glColor4ubv(color.ptr());
|
||||
|
||||
unsigned int lats = sectors;
|
||||
unsigned int longs = stacks;
|
||||
|
||||
float r = radius;
|
||||
std::vector<Vector3> vertices((lats + 1) * (longs + 1));
|
||||
|
||||
int index = 0;
|
||||
for (int i = 0; i <= lats; i++) {
|
||||
float lat = M_PI * (-0.5 + (float) i / lats);
|
||||
float z = J3ML::Math::Sin(lat);
|
||||
float zr = J3ML::Math::Cos(lat);
|
||||
|
||||
for (int j = 0; j <= longs; j++) {
|
||||
float lng = 2 * J3ML::Math::Pi * (float) (j - 1) / longs;
|
||||
float x = J3ML::Math::Cos(lng);
|
||||
float y = J3ML::Math::Sin(lng);
|
||||
|
||||
float pos_x = r * x * zr;
|
||||
float pos_y = r * y * zr;
|
||||
float pos_z = r * z;
|
||||
|
||||
pos_x += position.x;
|
||||
pos_y += position.y;
|
||||
pos_z += position.z;
|
||||
|
||||
vertices[index++] = Vector3(pos_x, pos_y, pos_z);
|
||||
}
|
||||
}
|
||||
|
||||
glColor4ubv(color.ptr());
|
||||
//glBindBuffer(GL_ARRAY_BUFFER, vertices.size());
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(Vector3), vertices.data());
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, vertices.size()); // TODO: Make it render correctingly!
|
||||
glColor4fv(baseColor);
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
}
|
||||
|
Reference in New Issue
Block a user