diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/gldisc.cpp | 70 | ||||
| -rw-r--r-- | src/gldisc.h | 6 |
2 files changed, 75 insertions, 1 deletions
diff --git a/src/gldisc.cpp b/src/gldisc.cpp index cf65450..5002fe8 100644 --- a/src/gldisc.cpp +++ b/src/gldisc.cpp @@ -3,15 +3,83 @@ GLDisc::GLDisc(double radius, double height, int sides) :GLBody(radius) { - + m_height = height; + m_sides = sides; } void GLDisc::makeSurface(QVector<GLPoint> *pointContainer, QVector<GLshort> *indexContainer) { + GLBody::makeSurface(pointContainer, indexContainer); + + QVector3D t0 = QVector3D(0.0, 0.0, 0.0); //dummy texture + + m_firstPoint = m_points->size(); + + m_points->append(GLPoint(v_Zero, -v_Z, t0, m_color)); + + for(int side = 0; side < m_sides; side++) + { + QVector2D tmp = calculatePoint(side * 2 * M_PI / m_sides); + + m_points->append(GLPoint(m_radius * tmp, -v_Z, t0, m_color)); + m_points->append(GLPoint(m_radius * tmp, tmp, t0, m_color)); + m_points->append(GLPoint(QVector3D(m_radius * tmp, m_height), tmp, t0, m_color)); + m_points->append(GLPoint(QVector3D(m_radius * tmp, m_height), v_Z, t0, m_color)); + } + + m_points->append(GLPoint(m_height * v_Z, v_Z, t0, m_color)); + + m_nextPoint = m_points->size(); + + m_firstIndex = m_indices->size(); + + for(int side = 0; side < m_sides - 1; side++) + { + m_indices->append(m_firstPoint); + m_indices->append(m_firstPoint + 1 + 4 * side); + m_indices->append(m_firstPoint + 5 + 4 * side); + + m_indices->append(m_firstPoint + 2 + 4 * side); + m_indices->append(m_firstPoint + 6 + 4 * side); + m_indices->append(m_firstPoint + 3 + 4 * side); + m_indices->append(m_firstPoint + 3 + 4 * side); + m_indices->append(m_firstPoint + 7 + 4 * side); + m_indices->append(m_firstPoint + 6 + 4 * side); + + m_indices->append(m_firstPoint + 4 + 4 * side); + m_indices->append(m_firstPoint + 8 + 4 * side); + m_indices->append(m_nextPoint - 1); + } + + m_indices->append(m_firstPoint); + m_indices->append(m_firstPoint + 1 + 4 * (m_sides - 1)); + m_indices->append(m_firstPoint + 1); + + m_indices->append(m_firstPoint + 2 + 4 * (m_sides - 1)); + m_indices->append(m_firstPoint + 2); + m_indices->append(m_firstPoint + 3 + 4 * (m_sides - 1)); + + m_indices->append(m_firstPoint + 3 + 4 * (m_sides - 1)); + m_indices->append(m_firstPoint + 3); + m_indices->append(m_firstPoint + 2); + + m_indices->append(m_firstPoint + 4 + 4 * (m_sides - 1)); + m_indices->append(m_firstPoint + 4); + m_indices->append(m_nextPoint - 1); + + m_nextIndex = m_indices->size(); } bool GLDisc::isHit(QVector3D p1, QVector3D p2) { } + +QVector2D GLDisc::calculatePoint(double sideAngle) +{ + double x = sin(sideAngle); + double y = cos(sideAngle); + + return QVector2D(x, y); +} diff --git a/src/gldisc.h b/src/gldisc.h index 21db6b8..18e935e 100644 --- a/src/gldisc.h +++ b/src/gldisc.h @@ -12,6 +12,12 @@ public: virtual void makeSurface(QVector<GLPoint> *pointContainer, QVector<GLshort> *indexContainer); virtual bool isHit(QVector3D p1, QVector3D p2); + +private: + QVector2D calculatePoint(double sideAngle); + + double m_height; + int m_sides; }; #endif // GLDISC_H |
