aboutsummaryrefslogtreecommitdiff
path: root/src/opengl_widget.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/opengl_widget.cc')
-rw-r--r--src/opengl_widget.cc18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/opengl_widget.cc b/src/opengl_widget.cc
index 2100af0..a4d9c8c 100644
--- a/src/opengl_widget.cc
+++ b/src/opengl_widget.cc
@@ -176,7 +176,7 @@ void OpenGLWidget::resizeGL(int w, int h) {
void OpenGLWidget::paintGL() {
- glEnable(GL_CULL_FACE); // i shouldn't have to do this every frame, should i?
+ glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
QMatrix4x4 trans;
@@ -258,3 +258,19 @@ QOpenGLShaderProgram *OpenGLWidget::getMainProgram() {
QOpenGLShaderProgram *OpenGLWidget::getLineProgram() {
return &line_program;
}
+
+
+bool OpenGLWidget::project(const QVector3D &p, QPoint &point) const {
+ QMatrix4x4 trans;
+ trans.translate(0, 0, -cam_dist);
+ QMatrix4x4 view = trans * rot;
+ QVector3D projected = proj * view * p;
+ if (projected.x() < -1 || projected.x() > 1
+ || projected.y() < -1 || projected.y() > 1
+ || projected.z() < -1 || projected.z() > 1) {
+ return false;
+ }
+ point.setX((projected.x() / 2 + .5) * (float) width());
+ point.setY(((projected.y() / 2 - .5) * -1) * (float) height());
+ return true;
+}