summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorStefan Suhren <suhren.stefan@fh-swf.de>2016-01-12 10:58:42 +0100
committerStefan Suhren <suhren.stefan@fh-swf.de>2016-01-12 10:58:42 +0100
commite8df759ad34ed3ea6a678be6e1e419fbc70a075c (patch)
tree2f0812a88b6db20a601360de62fbaf86b84c78e9 /src
parent3c65cf89b31e4d75a4c19573facd65d620b0c191 (diff)
downloadMultimedia-e8df759ad34ed3ea6a678be6e1e419fbc70a075c.tar.gz
Multimedia-e8df759ad34ed3ea6a678be6e1e419fbc70a075c.zip
Add a cone shape
Diffstat (limited to 'src')
-rw-r--r--src/glcone.cpp101
-rw-r--r--src/glcone.h18
2 files changed, 119 insertions, 0 deletions
diff --git a/src/glcone.cpp b/src/glcone.cpp
new file mode 100644
index 0000000..7730454
--- /dev/null
+++ b/src/glcone.cpp
@@ -0,0 +1,101 @@
+#include "glcone.h"
+
+GLCone::GLCone(QVector3D lowerMiddlePoint, double lowerRadius, double upperRadius, double height,
+ int sides, GLColorRgba color, QString textureFile)
+ : GLDisc(lowerRadius, height, lowerMiddlePoint, sides, color, textureFile)
+{
+ m_height = height;
+ m_sides = sides;
+
+ m_center = v_Z * 0.5 * m_height;
+
+ m_circleRadius = lowerRadius;
+
+ m_upperCircleRadius = upperRadius;
+
+ m_lowerMiddlePoint = lowerMiddlePoint;
+}
+
+void GLCone::makeSurface(QVector<GLPoint> *pointContainer,
+ QVector<GLshort> *indexContainer)
+{
+ GLBody::makeSurface(pointContainer, indexContainer);
+
+ m_firstPoint = m_points->size();
+
+ m_points->append(GLPoint(v_Zero, -v_Z, QVector3D(0.5, 0.5, 0.0), m_color));
+
+ for (int side = 0; side < m_sides; side++)
+ {
+ QVector3D tmp = calculatePoint(side * 2 * M_PI / m_sides);
+
+ QVector3D tmpTextCoo = (0.5 * tmp) + QVector3D(0.5, 0.5, 0.0);
+ QVector3D topBarrel = QVector3D(m_upperCircleRadius * tmp .x(), m_upperCircleRadius * tmp .y(), m_height);
+ QVector3D bottomBarrel = m_circleRadius * tmp;
+ QVector3D tangent = QVector3D::crossProduct(bottomBarrel, v_Z);
+ QVector3D barrelVector = topBarrel - bottomBarrel;
+ QVector3D barrelNormal = QVector3D::crossProduct(barrelVector, tangent);
+
+ m_points->append(GLPoint(bottomBarrel, -v_Z, tmpTextCoo, m_color));
+ m_points->append(GLPoint(bottomBarrel, barrelNormal, tmpTextCoo, m_color));
+ m_points->append(GLPoint(topBarrel, barrelNormal,
+ tmpTextCoo, m_color));
+ m_points->append(GLPoint(topBarrel, v_Z,
+ tmpTextCoo, m_color));
+ }
+
+ m_points->append(GLPoint(m_height * v_Z, v_Z, QVector3D(0.5, 0.5, 0.0),
+ 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();
+}
+
+void GLCone::draw(GLESRenderer *renderer)
+{
+ renderer->pushMvMatrix();
+
+ renderer->translate(m_lowerMiddlePoint);
+
+ GLBody::draw(renderer);
+
+ renderer->popMvMatrix();
+}
diff --git a/src/glcone.h b/src/glcone.h
new file mode 100644
index 0000000..c078ca5
--- /dev/null
+++ b/src/glcone.h
@@ -0,0 +1,18 @@
+#ifndef GLCONE_H
+#define GLCONE_H
+
+#include "gldisc.h"
+
+class GLCone : public GLDisc
+{
+public:
+ GLCone(QVector3D lowerMiddlePoint = QVector3D(0.0, 0.0, 0.0), double lowerRadius = 1.0, double upperRadius = 0.5, double height = 2.0, int sides = 10, GLColorRgba color = GLColorRgba::clBlue, QString textureFile = "");
+
+ virtual void makeSurface(QVector<GLPoint> *pointContainer, QVector<GLshort> *indexContainer);
+ virtual void draw(GLESRenderer *renderer);
+
+protected:
+ double m_upperCircleRadius;
+};
+
+#endif // GLCONE_H