git-svn-id: svn://db.shs.com.ru/libs@629 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -263,6 +263,52 @@ Mesh * Primitive::arrow(int segments, float thick, float angle) {
|
||||
}
|
||||
|
||||
|
||||
Mesh * Primitive::torus(int segments_main, int segments_second, float radius_main, float radius_second) {
|
||||
Mesh * ret = new Mesh();
|
||||
QVector<QVector3D> & v(ret->vertices ());
|
||||
QVector<QVector3D> & n(ret->normals ());
|
||||
QVector<QVector2D> & t(ret->texcoords());
|
||||
QVector< Vector3i> & ind(ret->indicesTriangles());
|
||||
|
||||
QVector<QVector3D> cv, cn;
|
||||
QVector<QVector2D> ct;
|
||||
segments_second = qMax(segments_second + 1, 4);
|
||||
for (int i = 0; i < segments_second; i++) {
|
||||
double x = (double)i / (segments_second - 1);
|
||||
double a = x * M_2PI;
|
||||
cv << QVector3D(radius_second * cos(a), 0., radius_second * sin(a));
|
||||
cn << cv.back().normalized();
|
||||
ct << QVector2D(0., x);
|
||||
cv.back() += QVector3D(radius_main, 0., 0.);
|
||||
}
|
||||
|
||||
segments_main = qMax(segments_main + 1, 4);
|
||||
int ccnt = cv.size(), pcnt = 0;
|
||||
for (int i = 0; i < segments_main; i++) {
|
||||
double x = (double)i / (segments_main - 1);
|
||||
QMatrix4x4 rm;
|
||||
rm.rotate(x * 360., 0., 0., 1.);
|
||||
for (int j = 0; j < ccnt; j++) {
|
||||
ct[j].setX(x);
|
||||
v << rm.map(cv[j]);
|
||||
n << rm.map(cn[j]);
|
||||
}
|
||||
t.append(ct);
|
||||
if (i > 0) {
|
||||
for (int j = 0; j < ccnt - 1; j++) {
|
||||
ind << Vector3i(pcnt + j, pcnt + j + 1, pcnt + j - ccnt);
|
||||
ind << Vector3i(pcnt + j + 1, pcnt + j + 1 - ccnt, pcnt + j - ccnt);
|
||||
}
|
||||
}
|
||||
pcnt = v.size();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Mesh * Primitive::cubeFrame(float width, float length, float height) {
|
||||
Mesh * ret = new Mesh(GL_LINES);
|
||||
QVector3D scale(width, length, height);
|
||||
|
||||
Reference in New Issue
Block a user