15 #include "Base/Math/Constants.h"
16 #include "Base/Util/Assert.h"
24 int const sides = qRound(numSides);
25 bool const smooth = (0 == sides);
26 int const slices = smooth ?
SLICES : sides;
31 float Rb = R, Rt = Rb * ratio_Rt_Rb, H = 2 * R;
34 Vertices vb(slices), vt(slices), nbt(slices);
35 float const nz = (1 - Rt / Rb) * H;
37 for (
int s = 0; s < slices; ++s) {
38 float th = float(M_TWOPI * s / slices), st = sinf(th), ct = cosf(th);
40 Vector3D vb_(Rb * ct, Rb * st, 0), vt_(Rt * ct, Rt * st, H);
48 int const nv = 6 * 2 * slices;
55 for (
int s = 0; s < slices; ++s) {
56 int s1 = s, s2 = (s + 1) % slices;
66 vs.
addQuad(vb.at(s1), vb.at(s2), vt.at(s2), vt.at(s1));
68 auto &n1 = nbt.at(s1), &n2 = nbt.at(s2);
73 ASSERT(vs.count() == nv);
74 ASSERT(!smooth || ns.count() == nv);
76 return makeMesh(vs, smooth ? &ns :
nullptr);
static Mesh makeMesh(const Vertices &vs, Vertices const *ns=nullptr)
QVector< Vert_Normal > Mesh
static Mesh meshColumn(float ratio_Rt_Rb, float numSides)
void addTriangle(const Vector3D &, const Vector3D &, const Vector3D &)
void addQuad(const Vector3D &, const Vector3D &, const Vector3D &, const Vector3D &)
void addVertex(const Vector3D &, int n=1)
Vector3D normalized() const