15 #include "Base/Math/Constants.h"
16 #include "Base/Util/Assert.h"
29 ASSERT(0 <= cut && cut < 1);
35 float minPh, maxPh, phRge;
39 minPh = asinf(2 * cut - 1);
41 maxPh = asinf(1 - 2 * removedTop);
43 maxPh = float(M_PI_2) - float(M_PI) /
RINGS;
46 minPh = -float(M_PI_2) + float(M_PI) /
RINGS;
48 maxPh = asinf(1 - removedTop);
50 maxPh = float(M_PI_2) - float(M_PI) /
RINGS;
52 phRge = maxPh - minPh;
53 rings = qMax(2, qCeil(qreal(
RINGS * phRge) / M_PI));
55 ASSERT(qAbs(minPh) <
float(M_PI_2));
56 ASSERT(2 <= rings && 2 <= slices);
59 QVector<Vertices> vs_(rings);
60 QVector<Vertices> ns_(rings);
61 for (
auto& ring : vs_)
63 for (
auto& ring : ns_)
68 for (
int r = 0; r < rings; ++r) {
69 float ph = minPh + phRge * r / (rings - 1);
70 float cp = cosf(ph), sp = sinf(ph);
72 for (
int s = 0; s < slices; ++s) {
73 auto th = float(M_TWOPI * s / slices);
74 Vector3D v(R * cp * cosf(th), R * cp * sinf(th), R * sp);
83 int const nv = 6 * (rings)*slices;
89 for (
int r = 0; r < rings; ++r) {
90 auto &vr = vs_.at(r), &nr = ns_.at(r);
92 for (
int s = 0; s < slices; ++s) {
93 int s0 = s, s1 = (s + 1) % slices;
95 auto &v0 = vr.at(s0), &v1 = vr.at(s1);
96 auto &n0 = nr.at(s0), &n1 = nr.at(s1);
104 vp =
Vector3D(0, 0, -R + baseShift);
112 if (r + 1 == rings) {
114 if (removedTop > 0) {
118 vp =
Vector3D(0, 0, +R + baseShift);
125 auto &vr1 = vs_.at(r + 1), &nr1 = ns_.at(r + 1);
126 auto &n2 = nr1.at(s1), &n3 = nr1.at(s0);
127 vs.
addQuad(v0, v1, vr1.at(s1), vr1.at(s0));
static Mesh makeMesh(const Vertices &vs, Vertices const *ns=nullptr)
QVector< Vert_Normal > Mesh
static Mesh meshSphere(float cut, float baseShift=0.0f, float removedTop=0.0f)
void addTriangle(const Vector3D &, const Vector3D &, const Vector3D &)
void addQuad(const Vector3D &, const Vector3D &, const Vector3D &, const Vector3D &)
Vector3D normalized() const