git-svn-id: svn://db.shs.com.ru/libs@636 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2019-11-27 21:49:24 +00:00
parent 988c4e1150
commit 09298fadcd
22 changed files with 291 additions and 173 deletions

View File

@@ -371,3 +371,37 @@ Mesh * Primitive::ellipsoidFrame(int segments_wl, int segments_h, float width, f
return ret;
}
Mesh * Primitive::coneFrame(int segments, float width, float length, float height) {
Mesh * ret = new Mesh(GL_LINES);
QVector<QVector3D> & v(ret->vertices ());
QVector<QVector3D> & n(ret->normals ());
QVector<QVector2D> & t(ret->texcoords());
QVector< Vector2i> & ind(ret->indicesLines());
int seg = qMax(segments + 1, 4);
double rx = width / 2., ry = length / 2.;
QVector3D cp;
for (int i = 0; i < seg; i++) {
double a = (double)i / (seg - 1) * M_2PI;
cp.setX(ry * cos(a));
cp.setY(rx * sin(a));
if (i > 0) {
v << QVector3D(0, 0, height);
t << QVector2D((double)(i - 1) / (seg - 1), 1.f);
double ta = ((double)i - 0.5) / (seg - 1) * M_2PI;
n << coneNormal(rx, ry, height, ta);
}
v << cp;
t << QVector2D((double)i / (seg - 1), 0.f);
n << coneNormal(rx, ry, height, a);
int si = v.size() - 1;
if (i > 0) {
ind << Vector2i(si - 1, si);
ind << Vector2i(si - 2, si);
}
}
return ret;
}