Commit 2399d9ec authored by Stefan Pfeifer's avatar Stefan Pfeifer

Fix issue with geometry orientation

parent 5ae10114
......@@ -3,7 +3,12 @@
#include "bow/LimbProperties.hpp"
#include "numerics/ArcCurve.hpp"
#include "numerics/CubicSpline.hpp"
#include <qmath.h>
LimbMesh::LimbMesh(bool inverted)
: inverted(inverted)
{
}
void LimbMesh::setData(const InputData& data)
{
......@@ -76,8 +81,8 @@ void LimbMesh::setData(const InputData& data)
if(layer_indices.empty())
add_points(h_sum_prev, h_sum_next);
h_sum_prev += h_prev;
h_sum_next += h_next;
h_sum_prev -= h_prev;
h_sum_next -= h_next;
add_points(h_sum_prev, h_sum_next);
layer_indices.push_back(j);
......@@ -173,8 +178,17 @@ float LimbMesh::aabbDiagonal() const
return (aabb_max - aabb_min).length();
}
void LimbMesh::addQuad(const QVector3D& p0, const QVector3D& p1, const QVector3D& p2, const QVector3D& p3, const QColor& color)
void LimbMesh::addQuad(QVector3D p0, QVector3D p1, QVector3D p2, QVector3D p3, const QColor& color)
{
if(inverted)
{
p0.setX(-p0.x());
p1.setX(-p1.x());
p2.setX(-p2.x());
p3.setX(-p3.x());
std::swap(p1, p3);
}
QVector3D n0 = QVector3D::normal(p1 - p0, p3 - p0);
QVector3D n1 = QVector3D::normal(p2 - p1, p0 - p1);
QVector3D n2 = QVector3D::normal(p3 - p2, p1 - p2);
......
......@@ -8,7 +8,7 @@
class LimbMesh
{
public:
LimbMesh() = default;
LimbMesh(bool inverted);
void setData(const InputData& data);
const std::vector<GLfloat>& vertexData() const;
......@@ -18,10 +18,11 @@ public:
float aabbDiagonal() const;
private:
void addQuad(const QVector3D& p0, const QVector3D& p1, const QVector3D& p2, const QVector3D& p3, const QColor& color);
void addQuad(QVector3D p0, QVector3D p1, QVector3D p2, QVector3D p3, const QColor& color);
void addVertex(const QVector3D& position, const QVector3D& normal, const QColor& color);
std::vector<double> getEvalLengths(const InputData& data, unsigned n);
bool inverted;
std::vector<GLfloat> vertex_data;
QVector3D aabb_min;
QVector3D aabb_max;
......
......@@ -8,6 +8,8 @@
LimbView::LimbView()
: legend(new LayerLegend()),
limb_mesh_left(true),
limb_mesh_right(false),
shader_program(nullptr)
{
QSurfaceFormat format = QSurfaceFormat::defaultFormat();
......@@ -73,11 +75,14 @@ LimbView::~LimbView()
void LimbView::setData(const InputData& data)
{
legend->setData(data.layers);
limb_mesh.setData(data);
limb_mesh_left.setData(data);
limb_mesh_right.setData(data);
limb_mesh_vbo.create();
limb_mesh_vbo.bind();
limb_mesh_vbo.allocate(limb_mesh.vertexData().data(), limb_mesh.vertexData().size()*sizeof(GLfloat));
//limb_mesh_left_vbo.bind();
//limb_mesh_left_vbo.allocate(limb_mesh_left.vertexData().data(), limb_mesh_left.vertexData().size()*sizeof(GLfloat));
limb_mesh_right_vbo.bind();
limb_mesh_right_vbo.allocate(limb_mesh_right.vertexData().data(), limb_mesh_right.vertexData().size()*sizeof(GLfloat));
update();
}
......@@ -122,7 +127,8 @@ void LimbView::cleanup()
return;
makeCurrent();
limb_mesh_vbo.destroy();
//limb_mesh_left_vbo.destroy();
limb_mesh_right_vbo.destroy();
delete shader_program;
shader_program = nullptr;
doneCurrent();
......@@ -188,19 +194,34 @@ void LimbView::initializeGL()
loc_lightPosition = shader_program->uniformLocation("lightPosition");
// Setup vertex buffer object.
limb_mesh_vbo.create();
limb_mesh_vbo.bind();
limb_mesh_vbo.allocate(limb_mesh.vertexData().data(), limb_mesh.vertexData().size()*sizeof(GLfloat));
// limb_mesh_left_vbo.create();
// limb_mesh_left_vbo.bind();
// limb_mesh_left_vbo.allocate(limb_mesh_left.vertexData().data(), limb_mesh_left.vertexData().size()*sizeof(GLfloat));
// Store the vertex attribute bindings for the program.
// limb_mesh_left_vbo.bind();
// glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 9*sizeof(GLfloat), (void*)(0*sizeof(GLfloat)));
// glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 9*sizeof(GLfloat), (void*)(3*sizeof(GLfloat)));
// glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 9*sizeof(GLfloat), (void*)(6*sizeof(GLfloat)));
// glEnableVertexAttribArray(0);
// glEnableVertexAttribArray(1);
// glEnableVertexAttribArray(2);
// limb_mesh_left_vbo.release();
// Setup vertex buffer object.
limb_mesh_right_vbo.create();
limb_mesh_right_vbo.bind();
limb_mesh_right_vbo.allocate(limb_mesh_right.vertexData().data(), limb_mesh_right.vertexData().size()*sizeof(GLfloat));
// Store the vertex attribute bindings for the program.
limb_mesh_vbo.bind();
limb_mesh_right_vbo.bind();
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 9*sizeof(GLfloat), (void*)(0*sizeof(GLfloat)));
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 9*sizeof(GLfloat), (void*)(3*sizeof(GLfloat)));
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 9*sizeof(GLfloat), (void*)(6*sizeof(GLfloat)));
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
limb_mesh_vbo.release();
limb_mesh_right_vbo.release();
// Set fixed light position
shader_program->setUniformValue(loc_lightPosition, QVector3D(0.0f, 0.0f, 50.0f));
......@@ -217,8 +238,8 @@ void LimbView::paintGL()
m_world.setToIdentity();
m_world.rotate(rot_x, 1.0f, 0.0f, 0.0f);
m_world.rotate(rot_y, 0.0f, 1.0f, 0.0f);
m_world.scale(1.0f/limb_mesh.aabbDiagonal());
m_world.translate(-limb_mesh.aabbCenter());
m_world.scale(1.0f/limb_mesh_right.aabbDiagonal());
m_world.translate(-limb_mesh_right.aabbCenter());
m_camera.setToIdentity();
m_camera.translate(0.0f, 0.0f, -1.0f);
......@@ -236,7 +257,8 @@ void LimbView::paintGL()
shader_program->setUniformValue(loc_modelViewMatrix, m_camera*m_world);
shader_program->setUniformValue(loc_normalMatrix, m_world.normalMatrix());
glDrawArrays(GL_TRIANGLES, 0, limb_mesh.vertexCount());
// glDrawArrays(GL_TRIANGLES, 0, limb_mesh_left.vertexCount());
glDrawArrays(GL_TRIANGLES, 0, limb_mesh_right.vertexCount());
shader_program->release();
}
......@@ -252,8 +274,8 @@ void LimbView::mouseMoveEvent(QMouseEvent *event)
if(event->buttons() & Qt::LeftButton)
{
rot_x -= ROT_SPEED*delta_y;
rot_y -= ROT_SPEED*delta_x;
rot_x += ROT_SPEED*delta_y;
rot_y += ROT_SPEED*delta_x;
update();
}
else if(event->buttons() & Qt::MiddleButton)
......
......@@ -16,8 +16,8 @@ QT_FORWARD_DECLARE_CLASS(QOpenGLShaderProgram)
class LimbView: public QOpenGLWidget, protected QOpenGLFunctions
{
private:
const float DEFAULT_ROT_X = -20.0f; // Magic number
const float DEFAULT_ROT_Y = 30.0f; // Magic number
const float DEFAULT_ROT_X = 20.0f; // Magic number
const float DEFAULT_ROT_Y = -30.0f; // Magic number
const float DEFAULT_ZOOM = 1.1f; // Magic number
const float ZOOM_SPEED = 0.2f; // Magic number
const float ROT_SPEED = 0.15f; // Magic number
......@@ -44,9 +44,10 @@ private:
void wheelEvent(QWheelEvent* event) override;
LayerLegend* legend;
LimbMesh limb_mesh;
QOpenGLBuffer limb_mesh_vbo;
LimbMesh limb_mesh_left;
LimbMesh limb_mesh_right;
//QOpenGLBuffer limb_mesh_left_vbo;
QOpenGLBuffer limb_mesh_right_vbo;
QOpenGLShaderProgram* shader_program;
int loc_projectionMatrix;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment