mirror of https://github.com/CGAL/cgal
fix warning in camera and fix fps display in cgal_qt5 so we don't have to overwrite it in the viewer
Begin the implementation of the graphcal hints
This commit is contained in:
parent
6584abd90b
commit
3995c80524
|
|
@ -27,7 +27,11 @@
|
|||
|
||||
#include <QClipboard>
|
||||
#include <QOpenGLFunctions_2_1>
|
||||
#include <QOpenGLShaderProgram>
|
||||
#include <QOpenGLVertexArrayObject>
|
||||
#include <QOpenGLBuffer>
|
||||
#include <QMap>
|
||||
#include <QVector>
|
||||
#include <QTime>
|
||||
#include <QGLContext>
|
||||
|
||||
|
|
@ -69,7 +73,7 @@ implementation.
|
|||
class QGLVIEWER_EXPORT QGLViewer : public QOpenGLWidget, public QOpenGLFunctions_2_1 {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
public:
|
||||
explicit QGLViewer(QGLContext* context, QWidget *parent = 0,
|
||||
Qt::WindowFlags flags = 0);
|
||||
explicit QGLViewer(QWidget *parent = 0,
|
||||
|
|
@ -118,6 +122,8 @@ public Q_SLOTS:
|
|||
/*! Sets the state of axisIsDrawn(). Emits the axisIsDrawnChanged() signal.
|
||||
* See also toggleAxisIsDrawn(). */
|
||||
void setAxisIsDrawn(bool draw = true) {
|
||||
if(!draw)
|
||||
axis_size = 0;
|
||||
axisIsDrawn_ = draw;
|
||||
Q_EMIT axisIsDrawnChanged(draw);
|
||||
update();
|
||||
|
|
@ -125,6 +131,11 @@ public Q_SLOTS:
|
|||
/*! Sets the state of gridIsDrawn(). Emits the gridIsDrawnChanged() signal.
|
||||
* See also toggleGridIsDrawn(). */
|
||||
void setGridIsDrawn(bool draw = true) {
|
||||
if(!draw)
|
||||
{
|
||||
grid_size=0;
|
||||
g_axis_size=0;
|
||||
}
|
||||
gridIsDrawn_ = draw;
|
||||
Q_EMIT gridIsDrawnChanged(draw);
|
||||
update();
|
||||
|
|
@ -357,6 +368,10 @@ public:
|
|||
\c QTimer, when animationIsStarted() or when the camera is manipulated with
|
||||
the mouse. */
|
||||
qreal currentFPS() { return f_p_s_; }
|
||||
/*!
|
||||
* Returns the string used to display the current fps.
|
||||
*/
|
||||
QString fpsString() { return fpsString_; }
|
||||
/*! Returns \c true if the viewer is in fullScreen mode.
|
||||
|
||||
Default value is \c false. Set by setFullScreen() or toggleFullScreen().
|
||||
|
|
@ -404,12 +419,10 @@ private:
|
|||
/*! @name Display methods */
|
||||
//@{
|
||||
public:
|
||||
static void drawArrow(qreal = 1.0, qreal = -1.0,
|
||||
int = 12);
|
||||
static void drawArrow(const qglviewer::Vec &, const qglviewer::Vec &,
|
||||
qreal = -1.0, int = 12);
|
||||
static void drawAxis(qreal = 1.0);
|
||||
static void drawGrid(qreal = 1.0, int = 10);
|
||||
void drawArrow(double r, double R, int prec,
|
||||
qglviewer::Vec from, qglviewer::Vec to, qglviewer::Vec color, std::vector<float> &data);
|
||||
void drawAxis(qreal l = 1.0);
|
||||
void drawGrid(qreal size= 1.0, int nbSubdivisions = 10);
|
||||
|
||||
virtual void startScreenCoordinatesSystem(bool upward = false) const;
|
||||
virtual void stopScreenCoordinatesSystem() const;
|
||||
|
|
@ -1456,6 +1469,30 @@ private:
|
|||
|
||||
// H e l p w i n d o w
|
||||
QTabWidget *helpWidget_;
|
||||
|
||||
//internal drawing buffers
|
||||
enum VBO
|
||||
{
|
||||
Grid = 0,
|
||||
Grid_axis,
|
||||
Axis,
|
||||
VBO_size
|
||||
};
|
||||
enum VAO
|
||||
{
|
||||
GRID = 0,
|
||||
GRID_AXIS,
|
||||
AXIS,
|
||||
VAO_size
|
||||
};
|
||||
QOpenGLShaderProgram rendering_program;
|
||||
QOpenGLShaderProgram rendering_program_light;
|
||||
QOpenGLVertexArrayObject vaos[VAO_size];
|
||||
QVector<QOpenGLBuffer> vbos;
|
||||
std::size_t grid_size;
|
||||
std::size_t g_axis_size;
|
||||
std::size_t axis_size;
|
||||
|
||||
};
|
||||
|
||||
#endif // QGLVIEWER_QGLVIEWER_H
|
||||
|
|
|
|||
|
|
@ -1664,11 +1664,11 @@ void MultiplyMatrices4by4OpenGL_GLdouble(GLdouble *result, GLdouble *matrix1, GL
|
|||
r3[2] = MAT(m, 3, 2), r3[3] = MAT(m, 3, 3),
|
||||
r3[7] = 1.0, r3[4] = r3[5] = r3[6] = 0.0;
|
||||
/* choose pivot - or die */
|
||||
if (fabsf(r3[0]) > fabsf(r2[0]))
|
||||
if (fabs(r3[0]) > fabs(r2[0]))
|
||||
SWAP_ROWS_GLdouble(r3, r2);
|
||||
if (fabsf(r2[0]) > fabsf(r1[0]))
|
||||
if (fabs(r2[0]) > fabs(r1[0]))
|
||||
SWAP_ROWS_GLdouble(r2, r1);
|
||||
if (fabsf(r1[0]) > fabsf(r0[0]))
|
||||
if (fabs(r1[0]) > fabs(r0[0]))
|
||||
SWAP_ROWS_GLdouble(r1, r0);
|
||||
if (0.0 == r0[0])
|
||||
return 0;
|
||||
|
|
@ -1713,9 +1713,9 @@ void MultiplyMatrices4by4OpenGL_GLdouble(GLdouble *result, GLdouble *matrix1, GL
|
|||
r3[7] -= m3 * s;
|
||||
}
|
||||
/* choose pivot - or die */
|
||||
if (fabsf(r3[1]) > fabsf(r2[1]))
|
||||
if (fabs(r3[1]) > fabs(r2[1]))
|
||||
SWAP_ROWS_GLdouble(r3, r2);
|
||||
if (fabsf(r2[1]) > fabsf(r1[1]))
|
||||
if (fabs(r2[1]) > fabs(r1[1]))
|
||||
SWAP_ROWS_GLdouble(r2, r1);
|
||||
if (0.0 == r1[1])
|
||||
return 0;
|
||||
|
|
@ -1747,7 +1747,7 @@ void MultiplyMatrices4by4OpenGL_GLdouble(GLdouble *result, GLdouble *matrix1, GL
|
|||
r3[7] -= m3 * s;
|
||||
}
|
||||
/* choose pivot - or die */
|
||||
if (fabsf(r3[2]) > fabsf(r2[2]))
|
||||
if (fabs(r3[2]) > fabs(r2[2]))
|
||||
SWAP_ROWS_GLdouble(r3, r2);
|
||||
if (0.0 == r2[2])
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -409,8 +409,8 @@ void KeyFrameInterpolator::drawPath(int mask, int nbFrames, qreal scale) {
|
|||
glMultMatrixd(fr.matrix());
|
||||
if (mask & 2)
|
||||
drawCamera(scale);
|
||||
if (mask & 4)
|
||||
QGLViewer::drawAxis(scale / 10.0);
|
||||
//if (mask & 4)
|
||||
// QGLViewer::drawAxis(scale / 10.0);
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,11 +70,6 @@ are provided.
|
|||
See the project main page for details on the project and installation steps. */
|
||||
|
||||
void QGLViewer::defaultConstructor() {
|
||||
// Test OpenGL context
|
||||
// if (glGetString(GL_VERSION) == 0)
|
||||
// qWarning("Unable to get OpenGL version, context may not be available -
|
||||
// Check your configuration");
|
||||
|
||||
int poolIndex = QGLViewer::QGLViewerPool_.indexOf(NULL);
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
|
||||
|
|
@ -149,6 +144,7 @@ void QGLViewer::defaultConstructor() {
|
|||
currentlyPressedKey_ = Qt::Key(0);
|
||||
|
||||
setAttribute(Qt::WA_NoSystemBackground);
|
||||
axisIsDrawn_ = true;
|
||||
|
||||
tileRegion_ = NULL;
|
||||
}
|
||||
|
|
@ -256,6 +252,153 @@ void QGLViewer::initializeGL() {
|
|||
} else
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
//OpenGL buffers and programs initialization
|
||||
for(int i=0; i<VAO_size; ++i)
|
||||
{
|
||||
vaos[i].create();
|
||||
}
|
||||
vbos.resize(VBO_size);
|
||||
for(int i=0; i<VBO_size; ++i)
|
||||
{
|
||||
vbos[i].create();
|
||||
}
|
||||
//program without light
|
||||
{
|
||||
//Vertex source code
|
||||
const char v_s[] =
|
||||
{
|
||||
"#version 120 \n"
|
||||
"attribute highp vec4 vertex;\n"
|
||||
"uniform highp mat4 mvp_matrix;\n"
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
" gl_Position = mvp_matrix * vertex; \n"
|
||||
"} \n"
|
||||
"\n"
|
||||
};
|
||||
//Fragment source code
|
||||
const char f_s[] =
|
||||
{
|
||||
"#version 120 \n"
|
||||
"uniform highp vec4 color; \n"
|
||||
"void main(void) { \n"
|
||||
"gl_FragColor = color; \n"
|
||||
"} \n"
|
||||
"\n"
|
||||
};
|
||||
|
||||
//It is said in the doc that a QOpenGLShader is
|
||||
// only destroyed with the QOpenGLShaderProgram
|
||||
//it has been linked with.
|
||||
QOpenGLShader vertex_shader(QOpenGLShader::Vertex);
|
||||
if(!vertex_shader.compileSourceCode(v_s))
|
||||
{
|
||||
std::cerr<<"Compiling vertex source FAILED"<<std::endl;
|
||||
}
|
||||
|
||||
QOpenGLShader fragment_shader(QOpenGLShader::Fragment);
|
||||
if(!fragment_shader.compileSourceCode(f_s))
|
||||
{
|
||||
std::cerr<<"Compiling fragmentsource FAILED"<<std::endl;
|
||||
}
|
||||
|
||||
if(!rendering_program.addShader(&vertex_shader))
|
||||
{
|
||||
std::cerr<<"adding vertex shader FAILED"<<std::endl;
|
||||
}
|
||||
if(!rendering_program.addShader(&fragment_shader))
|
||||
{
|
||||
std::cerr<<"adding fragment shader FAILED"<<std::endl;
|
||||
}
|
||||
if(!rendering_program.link())
|
||||
{
|
||||
qDebug() << rendering_program.log();
|
||||
}
|
||||
}
|
||||
//program with light
|
||||
{
|
||||
//Vertex source code
|
||||
const char vertex_source[] =
|
||||
{
|
||||
"#version 120 \n"
|
||||
"attribute highp vec4 vertex;\n"
|
||||
"attribute highp vec3 normal;\n"
|
||||
"attribute highp vec4 colors;\n"
|
||||
"uniform highp mat4 mvp_matrix;\n"
|
||||
"uniform highp mat4 mv_matrix; \n"
|
||||
"varying highp vec4 fP; \n"
|
||||
"varying highp vec3 fN; \n"
|
||||
"varying highp vec4 color; \n"
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
" color = vec4(colors.xyz, 1.0f); \n"
|
||||
" fP = mv_matrix * vertex; \n"
|
||||
" fN = mat3(mv_matrix)* normal; \n"
|
||||
" gl_Position = vec4(mvp_matrix * vertex); \n"
|
||||
"} \n"
|
||||
"\n"
|
||||
};
|
||||
//Fragment source code
|
||||
const char fragment_source[] =
|
||||
{
|
||||
"#version 120 \n"
|
||||
"varying highp vec4 color; \n"
|
||||
"varying highp vec4 fP; \n"
|
||||
"varying highp vec3 fN; \n"
|
||||
"void main(void) { \n"
|
||||
" highp vec4 light_pos = vec4(0.0f, 0.0f, 1.0f, 1.0f); \n"
|
||||
" highp vec4 light_diff = vec4(1.0f, 1.0f, 1.0f, 1.0f); \n"
|
||||
" highp vec4 light_spec = vec4(0.0f, 0.0f, 0.0f, 1.0f); \n"
|
||||
" highp vec4 light_amb = vec4(0.4f, 0.4f, 0.4f, 0.4f); \n"
|
||||
" highp float spec_power = 51.8f ; \n"
|
||||
" vec3 L = light_pos.xyz - fP.xyz; \n"
|
||||
" vec3 V = -fP.xyz; \n"
|
||||
" vec3 N; \n"
|
||||
" if(fN == vec3(0.0,0.0,0.0)) \n"
|
||||
" N = vec3(0.0,0.0,0.0); \n"
|
||||
" else \n"
|
||||
" N = normalize(fN); \n"
|
||||
" L = normalize(L); \n"
|
||||
" V = normalize(V); \n"
|
||||
" vec3 R = reflect(-L, N); \n"
|
||||
" vec4 diffuse = max(abs(dot(N,L)),0.0) * light_diff*color; \n"
|
||||
" vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; \n"
|
||||
|
||||
"gl_FragColor = color*light_amb + diffuse + specular; \n"
|
||||
"gl_FragColor = vec4(gl_FragColor.xyz, 1.0f); \n"
|
||||
"} \n"
|
||||
"\n"
|
||||
};
|
||||
|
||||
//It is said in the doc that a QOpenGLShader is
|
||||
// only destroyed with the QOpenGLShaderProgram
|
||||
//it has been linked with.
|
||||
QOpenGLShader vertex_shader(QOpenGLShader::Vertex);
|
||||
if(!vertex_shader.compileSourceCode(vertex_source))
|
||||
{
|
||||
std::cerr<<"Compiling vertex source FAILED"<<std::endl;
|
||||
}
|
||||
|
||||
QOpenGLShader fragment_shader(QOpenGLShader::Fragment);
|
||||
if(!fragment_shader.compileSourceCode(fragment_source))
|
||||
{
|
||||
std::cerr<<"Compiling fragmentsource FAILED"<<std::endl;
|
||||
}
|
||||
|
||||
if(!rendering_program_light.addShader(&vertex_shader))
|
||||
{
|
||||
std::cerr<<"adding vertex shader FAILED"<<std::endl;
|
||||
}
|
||||
if(!rendering_program_light.addShader(&fragment_shader))
|
||||
{
|
||||
std::cerr<<"adding fragment shader FAILED"<<std::endl;
|
||||
}
|
||||
if(!rendering_program_light.link())
|
||||
{
|
||||
qDebug() << rendering_program_light.log();
|
||||
}
|
||||
}
|
||||
|
||||
// Calls user defined method. Default emits a signal.
|
||||
init();
|
||||
|
||||
|
|
@ -334,40 +477,7 @@ that in draw(), the user can rely on the OpenGL context he defined. Respect this
|
|||
convention (by pushing/popping the different attributes) if you overload this
|
||||
method. */
|
||||
void QGLViewer::postDraw() {
|
||||
// Reset model view matrix to world coordinates origin
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
camera()->loadModelViewMatrix();
|
||||
// TODO restore model loadProjectionMatrixStereo
|
||||
|
||||
// Save OpenGL state
|
||||
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
||||
|
||||
// Set neutral GL state
|
||||
glDisable(GL_TEXTURE_1D);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
#ifdef GL_TEXTURE_3D // OpenGL 1.2 Only...
|
||||
glDisable(GL_TEXTURE_3D);
|
||||
#endif
|
||||
|
||||
glDisable(GL_TEXTURE_GEN_Q);
|
||||
glDisable(GL_TEXTURE_GEN_R);
|
||||
glDisable(GL_TEXTURE_GEN_S);
|
||||
glDisable(GL_TEXTURE_GEN_T);
|
||||
|
||||
#ifdef GL_RESCALE_NORMAL // OpenGL 1.2 Only...
|
||||
glEnable(GL_RESCALE_NORMAL);
|
||||
#endif
|
||||
|
||||
glDisable(GL_COLOR_MATERIAL);
|
||||
glColor4f(foregroundColor().redF(), foregroundColor().greenF(),
|
||||
foregroundColor().blueF(), foregroundColor().alphaF());
|
||||
|
||||
if (cameraIsEdited())
|
||||
camera()->drawAllPaths();
|
||||
|
||||
// Pivot point, line when camera rolls, zoom region
|
||||
drawVisualHints();
|
||||
|
||||
if (gridIsDrawn()) {
|
||||
glLineWidth(1.0);
|
||||
|
|
@ -375,9 +485,10 @@ void QGLViewer::postDraw() {
|
|||
}
|
||||
if (axisIsDrawn()) {
|
||||
glLineWidth(2.0);
|
||||
drawAxis(camera()->sceneRadius());
|
||||
drawAxis(1.0);
|
||||
}
|
||||
|
||||
drawVisualHints();
|
||||
// FPS computation
|
||||
const unsigned int maxCounter = 20;
|
||||
if (++fpsCounter_ == maxCounter) {
|
||||
|
|
@ -696,11 +807,8 @@ void QGLViewer::drawLight(GLenum light, qreal scale) const {
|
|||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
|
||||
void QGLViewer::renderText(int x, int y, const QString &str,
|
||||
const QFont &font) {
|
||||
// Retrieve last OpenGL color to use as a font color
|
||||
GLdouble glColor[4];
|
||||
glGetDoublev(GL_CURRENT_COLOR, glColor);
|
||||
QColor fontColor = QColor(255 * glColor[0], 255 * glColor[1],
|
||||
255 * glColor[2], 255 * glColor[3]);
|
||||
QColor fontColor = QColor(0, 0,
|
||||
0, 255);
|
||||
|
||||
// Render text
|
||||
QPainter painter(this);
|
||||
|
|
@ -3298,7 +3406,65 @@ Limitation : One needs to have access to visualHint_ to overload this method.
|
|||
|
||||
Removed from the documentation for this reason. */
|
||||
void QGLViewer::drawVisualHints() {
|
||||
rendering_program.bind();
|
||||
vaos[GRID].bind();
|
||||
QMatrix4x4 mvpMatrix;
|
||||
double mat[16];
|
||||
camera()->getModelViewProjectionMatrix(mat);
|
||||
for(int i=0; i < 16; i++)
|
||||
{
|
||||
mvpMatrix.data()[i] = (float)mat[i];
|
||||
}
|
||||
QMatrix4x4 mvMatrix;
|
||||
for(int i=0; i < 16; i++)
|
||||
{
|
||||
mvMatrix.data()[i] = camera()->orientation().inverse().matrix()[i];
|
||||
}
|
||||
rendering_program.setUniformValue("mvp_matrix", mvpMatrix);
|
||||
rendering_program.setUniformValue("color", QColor(Qt::lightGray));
|
||||
glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(grid_size));
|
||||
vaos[GRID].release();
|
||||
rendering_program.release();
|
||||
|
||||
rendering_program_light.bind();
|
||||
vaos[GRID_AXIS].bind();
|
||||
|
||||
rendering_program_light.setUniformValue("mvp_matrix", mvpMatrix);
|
||||
rendering_program_light.setUniformValue("mv_matrix", mvMatrix);
|
||||
glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(g_axis_size/9));
|
||||
vaos[GRID_AXIS].release();
|
||||
|
||||
qglviewer::Camera::Type camera_type = camera()->type();
|
||||
camera()->setType(qglviewer::Camera::ORTHOGRAPHIC);
|
||||
for(int i=0; i < 16; i++)
|
||||
{
|
||||
mvMatrix.data()[i] = camera()->orientation().inverse().matrix()[i];
|
||||
}
|
||||
mvpMatrix.setToIdentity();
|
||||
mvpMatrix.ortho(-1,1,-1,1,-1,1);
|
||||
mvpMatrix = mvpMatrix*mvMatrix;
|
||||
rendering_program_light.setUniformValue("mvp_matrix", mvpMatrix);
|
||||
rendering_program_light.setUniformValue("mv_matrix", mvMatrix);
|
||||
camera()->setType(camera_type);
|
||||
vaos[AXIS].bind();
|
||||
int viewport[4];
|
||||
int scissor[4];
|
||||
|
||||
// The viewport and the scissor are changed to fit the upper right
|
||||
// corner. Original values are saved.
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
glGetIntegerv(GL_SCISSOR_BOX, scissor);
|
||||
|
||||
// Axis viewport size, in pixels
|
||||
const int size = 100;
|
||||
glViewport(width()*devicePixelRatio()-size, height()*devicePixelRatio()-size, size, size);
|
||||
glScissor (width()*devicePixelRatio()-size, height()*devicePixelRatio()-size, size, size);
|
||||
glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(axis_size / 9));
|
||||
// The viewport and the scissor are restored.
|
||||
glScissor(scissor[0],scissor[1],scissor[2],scissor[3]);
|
||||
glViewport(viewport[0],viewport[1],viewport[2],viewport[3]);
|
||||
vaos[AXIS].release();
|
||||
rendering_program_light.release();
|
||||
}
|
||||
|
||||
/*! Defines the mask that will be used to drawVisualHints(). The only available
|
||||
|
|
@ -3319,56 +3485,286 @@ void QGLViewer::resetVisualHints() { visualHint_ = 0; }
|
|||
// A x i s a n d G r i d d i s p l a y l i s t s //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*! Draws a 3D arrow along the positive Z axis.
|
||||
/*! Draws a 3D arrow between the 3D point \p from and the 3D point \p to.
|
||||
\p data is filled with the three components of a point, then its normal, and then its color, which makes it filled like this:
|
||||
[P1.x-P1.y-P1.z-N1.x-N1.y-N1.z-C1.r-C1.g-C1.b|P2.x-P2.y-P2.z-N2.x-N2.y-N2.z-C2.r-C2.g-C2.b|...]
|
||||
*/
|
||||
void QGLViewer::drawArrow(double r,double R, int prec, qglviewer::Vec from,
|
||||
qglviewer::Vec to, qglviewer::Vec color,
|
||||
std::vector<float> &data) {
|
||||
qglviewer::Vec temp = to-from;
|
||||
QVector3D dir = QVector3D(temp.x, temp.y, temp.z);
|
||||
QMatrix4x4 mat;
|
||||
mat.setToIdentity();
|
||||
mat.translate(from.x, from.y, from.z);
|
||||
mat.scale(dir.length());
|
||||
dir.normalize();
|
||||
float angle = 0.0;
|
||||
if(std::sqrt((dir.x()*dir.x()+dir.y()*dir.y())) > 1)
|
||||
angle = 90.0f;
|
||||
else
|
||||
angle =acos(dir.y()/std::sqrt(dir.x()*dir.x()+dir.y()*dir.y()+dir.z()*dir.z()))*180.0/M_PI;
|
||||
|
||||
\p length, \p radius and \p nbSubdivisions define its geometry. If \p radius is
|
||||
negative (default), it is set to 0.05 * \p length.
|
||||
QVector3D axis;
|
||||
axis = QVector3D(dir.z(), 0, -dir.x());
|
||||
mat.rotate(angle, axis);
|
||||
|
||||
Use drawArrow(const Vec& from, const Vec& to, qreal radius, int nbSubdivisions)
|
||||
or change the \c ModelView matrix to place the arrow in 3D.
|
||||
//Head
|
||||
const float Rf = static_cast<float>(R);
|
||||
for(int d = 0; d<360; d+= 360/prec)
|
||||
{
|
||||
float D = (float) (d * M_PI / 180.);
|
||||
float a = (float) std::atan(Rf / 0.33);
|
||||
QVector4D p(0., 1., 0, 1.);
|
||||
QVector4D n(Rf*sin(D), sin(a), Rf*cos(D), 1.);
|
||||
QVector4D pR = mat*p;
|
||||
QVector4D nR = mat*n;
|
||||
|
||||
Uses current color and does not modify the OpenGL state. */
|
||||
void QGLViewer::drawArrow(qreal , qreal , int ) {
|
||||
}
|
||||
//point A1
|
||||
data.push_back(pR.x());
|
||||
data.push_back(pR.y());
|
||||
data.push_back(pR.z());
|
||||
data.push_back(nR.x());
|
||||
data.push_back(nR.y());
|
||||
data.push_back(nR.z());
|
||||
data.push_back((float)color.x);
|
||||
data.push_back((float)color.y);
|
||||
data.push_back((float)color.z);
|
||||
|
||||
/*! Draws a 3D arrow between the 3D point \p from and the 3D point \p to, both
|
||||
defined in the current ModelView coordinates system.
|
||||
//point B1
|
||||
p = QVector4D(Rf*sin(D), 0.66f, Rf* cos(D), 1.f);
|
||||
n = QVector4D(sin(D), sin(a), cos(D), 1.);
|
||||
pR = mat*p;
|
||||
nR = mat*n;
|
||||
data.push_back(pR.x());
|
||||
data.push_back(pR.y());
|
||||
data.push_back(pR.z());
|
||||
data.push_back(nR.x());
|
||||
data.push_back(nR.y());
|
||||
data.push_back(nR.z());
|
||||
data.push_back((float)color.x);
|
||||
data.push_back((float)color.y);
|
||||
data.push_back((float)color.z);
|
||||
//point C1
|
||||
D = (d+360/prec)*M_PI/180.0;
|
||||
p = QVector4D(Rf* sin(D), 0.66f, Rf* cos(D), 1.f);
|
||||
n = QVector4D(sin(D), sin(a), cos(D), 1.0);
|
||||
pR = mat*p;
|
||||
nR = mat*n;
|
||||
|
||||
See drawArrow(qreal length, qreal radius, int nbSubdivisions) for details. */
|
||||
void QGLViewer::drawArrow(const Vec &, const Vec &, qreal ,
|
||||
int ) {
|
||||
data.push_back(pR.x());
|
||||
data.push_back(pR.y());
|
||||
data.push_back(pR.z());
|
||||
data.push_back(nR.x());
|
||||
data.push_back(nR.y());
|
||||
data.push_back(nR.z());
|
||||
data.push_back((float)color.x);
|
||||
data.push_back((float)color.y);
|
||||
data.push_back((float)color.z);
|
||||
|
||||
}
|
||||
|
||||
//cylinder
|
||||
//body of the cylinder
|
||||
const float rf = static_cast<float>(r);
|
||||
for(int d = 0; d<360; d+= 360/prec)
|
||||
{
|
||||
//point A1
|
||||
double D = d*M_PI/180.0;
|
||||
QVector4D p(rf*sin(D), 0.66f, rf*cos(D), 1.f);
|
||||
QVector4D n(sin(D), 0.f, cos(D), 1.f);
|
||||
QVector4D pR = mat*p;
|
||||
QVector4D nR = mat*n;
|
||||
|
||||
data.push_back(pR.x());
|
||||
data.push_back(pR.y());
|
||||
data.push_back(pR.z());
|
||||
data.push_back(nR.x());
|
||||
data.push_back(nR.y());
|
||||
data.push_back(nR.z());
|
||||
data.push_back(color.x);
|
||||
data.push_back(color.y);
|
||||
data.push_back(color.z);
|
||||
//point B1
|
||||
p = QVector4D(rf * sin(D),0,rf*cos(D), 1.0);
|
||||
n = QVector4D(sin(D), 0, cos(D), 1.0);
|
||||
pR = mat*p;
|
||||
nR = mat*n;
|
||||
|
||||
|
||||
data.push_back(pR.x());
|
||||
data.push_back(pR.y());
|
||||
data.push_back(pR.z());
|
||||
data.push_back(nR.x());
|
||||
data.push_back(nR.y());
|
||||
data.push_back(nR.z());
|
||||
data.push_back(color.x);
|
||||
data.push_back(color.y);
|
||||
data.push_back(color.z);
|
||||
//point C1
|
||||
D = (d+360/prec)*M_PI/180.0;
|
||||
p = QVector4D(rf * sin(D),0,rf*cos(D), 1.0);
|
||||
n = QVector4D(sin(D), 0, cos(D), 1.0);
|
||||
pR = mat*p;
|
||||
nR = mat*n;
|
||||
data.push_back(pR.x());
|
||||
data.push_back(pR.y());
|
||||
data.push_back(pR.z());
|
||||
data.push_back(nR.x());
|
||||
data.push_back(nR.y());
|
||||
data.push_back(nR.z());
|
||||
data.push_back(color.x);
|
||||
data.push_back(color.y);
|
||||
data.push_back(color.z);
|
||||
//point A2
|
||||
D = (d+360/prec)*M_PI/180.0;
|
||||
|
||||
p = QVector4D(rf * sin(D),0,rf*cos(D), 1.0);
|
||||
n = QVector4D(sin(D), 0, cos(D), 1.0);
|
||||
pR = mat*p;
|
||||
nR = mat*n;
|
||||
data.push_back(pR.x());
|
||||
data.push_back(pR.y());
|
||||
data.push_back(pR.z());
|
||||
data.push_back(nR.x());
|
||||
data.push_back(nR.y());
|
||||
data.push_back(nR.z());
|
||||
data.push_back((float)color.x);
|
||||
data.push_back((float)color.y);
|
||||
data.push_back((float)color.z);
|
||||
//point B2
|
||||
p = QVector4D(rf * sin(D), 0.66f, rf*cos(D), 1.f);
|
||||
n = QVector4D(sin(D), 0, cos(D), 1.0);
|
||||
pR = mat*p;
|
||||
nR = mat*n;
|
||||
data.push_back(pR.x());
|
||||
data.push_back(pR.y());
|
||||
data.push_back(pR.z());
|
||||
data.push_back(nR.x());
|
||||
data.push_back(nR.y());
|
||||
data.push_back(nR.z());
|
||||
data.push_back((float)color.x);
|
||||
data.push_back((float)color.y);
|
||||
data.push_back((float)color.z);
|
||||
//point C2
|
||||
D = d*M_PI/180.0;
|
||||
p = QVector4D(rf * sin(D), 0.66f, rf*cos(D), 1.f);
|
||||
n = QVector4D(sin(D), 0.f, cos(D), 1.f);
|
||||
pR = mat*p;
|
||||
nR = mat*n;
|
||||
data.push_back(pR.x());
|
||||
data.push_back(pR.y());
|
||||
data.push_back(pR.z());
|
||||
data.push_back(nR.x());
|
||||
data.push_back(nR.y());
|
||||
data.push_back(nR.z());
|
||||
data.push_back(color.x);
|
||||
data.push_back(color.y);
|
||||
data.push_back(color.z);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*! Draws an XYZ axis, with a given size (default is 1.0).
|
||||
|
||||
The axis position and orientation matches the current modelView matrix state:
|
||||
The axis orientation matches the current modelView matrix state:
|
||||
three arrows (red, green and blue) of length \p length are drawn along the
|
||||
positive X, Y and Z directions.
|
||||
|
||||
Use the following code to display the current position and orientation of a
|
||||
qglviewer::Frame: \code glPushMatrix(); glMultMatrixd(frame.matrix());
|
||||
QGLViewer::drawAxis(sceneRadius() / 5.0); // Or any scale
|
||||
glPopMatrix();
|
||||
\endcode
|
||||
|
||||
The current color and line width are used to draw the X, Y and Z characters at
|
||||
the extremities of the three arrows. The OpenGL state is not modified by this
|
||||
method.
|
||||
|
||||
axisIsDrawn() uses this method to draw a representation of the world coordinate
|
||||
system. See also QGLViewer::drawArrow() and QGLViewer::drawGrid(). */
|
||||
void QGLViewer::drawAxis(qreal) {
|
||||
positive X, Y and Z directions in the top right corner of the screen.
|
||||
X arrow is red, Y arrow is green and Z arrow is blue.*/
|
||||
void QGLViewer::drawAxis(qreal length) {
|
||||
std::vector<float> data;
|
||||
data.resize(0);
|
||||
drawArrow(0.06,0.12,10, qglviewer::Vec(0,0,0),qglviewer::Vec(length,0,0),qglviewer::Vec(1,0,0), data);
|
||||
drawArrow(0.06,0.12,10, qglviewer::Vec(0,0,0),qglviewer::Vec(0,length,0),qglviewer::Vec(0,1,0), data);
|
||||
drawArrow(0.06,0.12,10, qglviewer::Vec(0,0,0),qglviewer::Vec(0,0,length),qglviewer::Vec(0,0,1), data);
|
||||
rendering_program_light.bind();
|
||||
vaos[AXIS].bind();
|
||||
vbos[Axis].bind();
|
||||
vbos[Axis].allocate(data.data(), static_cast<int>(data.size()) * sizeof(float));
|
||||
rendering_program_light.enableAttributeArray("vertex");
|
||||
rendering_program_light.setAttributeBuffer("vertex",GL_FLOAT,0,3,
|
||||
static_cast<int>(9*sizeof(float)));
|
||||
|
||||
rendering_program_light.enableAttributeArray("normal");
|
||||
rendering_program_light.setAttributeBuffer("normal",GL_FLOAT,3*sizeof(float),3,
|
||||
static_cast<int>(9*sizeof(float)));
|
||||
|
||||
rendering_program_light.enableAttributeArray("colors");
|
||||
rendering_program_light.setAttributeBuffer("colors",GL_FLOAT,6*sizeof(float),3,
|
||||
static_cast<int>(9*sizeof(float)));
|
||||
vbos[Axis].release();
|
||||
vaos[AXIS].release();
|
||||
axis_size = data.size();
|
||||
rendering_program_light.release();
|
||||
}
|
||||
|
||||
/*! Draws a grid in the XY plane, centered on (0,0,0) (defined in the current
|
||||
coordinate system).
|
||||
|
||||
\p size (OpenGL units) and \p nbSubdivisions define its geometry. Set the \c
|
||||
GL_MODELVIEW matrix to place and orientate the grid in 3D space (see the
|
||||
drawAxis() documentation).
|
||||
\p size (OpenGL units) and \p nbSubdivisions define its geometry.*/
|
||||
void QGLViewer::drawGrid(qreal size, int nbSubdivisions) {
|
||||
|
||||
//The Grid
|
||||
std::vector<float> v_Grid;
|
||||
for (int i=0; i<=nbSubdivisions; ++i)
|
||||
{
|
||||
const float pos = size*(2.0*i/nbSubdivisions-1.0);
|
||||
v_Grid.push_back(pos);
|
||||
v_Grid.push_back(-size);
|
||||
v_Grid.push_back(0.0);
|
||||
|
||||
The OpenGL state is not modified by this method. */
|
||||
void QGLViewer::drawGrid(qreal , int ) {
|
||||
v_Grid.push_back(pos);
|
||||
v_Grid.push_back(+size);
|
||||
v_Grid.push_back(0.0);
|
||||
|
||||
v_Grid.push_back(-size);
|
||||
v_Grid.push_back(pos);
|
||||
v_Grid.push_back(0.0);
|
||||
|
||||
v_Grid.push_back( size);
|
||||
v_Grid.push_back( pos);
|
||||
v_Grid.push_back( 0.0);
|
||||
}
|
||||
rendering_program.bind();
|
||||
vaos[GRID].bind();
|
||||
vbos[Grid].bind();
|
||||
vbos[Grid].allocate(v_Grid.data(),static_cast<int>(v_Grid.size()*sizeof(float)));
|
||||
rendering_program.enableAttributeArray("vertex");
|
||||
rendering_program.setAttributeBuffer("vertex",GL_FLOAT,0,3);
|
||||
vbos[Grid].release();
|
||||
vaos[GRID].release();
|
||||
rendering_program.release();
|
||||
grid_size = v_Grid.size();
|
||||
|
||||
//The Axis
|
||||
std::vector<float> d_axis;
|
||||
d_axis.resize(0);
|
||||
//d_axis is filled by drawArrow always this way : V.x V.y V.z N.x N.y N.z C.r C.g C.b, so it is possible
|
||||
//to use a single buffer with offset and stride
|
||||
drawArrow(0.005*size,0.02*size,10, qglviewer::Vec(0,0,0),qglviewer::Vec(size,0,0),qglviewer::Vec(1,0,0), d_axis);
|
||||
drawArrow(0.005*size,0.02*size,10, qglviewer::Vec(0,0,0),qglviewer::Vec(0,size,0),qglviewer::Vec(0,1,0), d_axis);
|
||||
|
||||
rendering_program_light.bind();
|
||||
vaos[GRID_AXIS].bind();
|
||||
vbos[Grid_axis].bind();
|
||||
vbos[Grid_axis].allocate(d_axis.data(), static_cast<int>(d_axis.size()) * sizeof(float));
|
||||
rendering_program_light.enableAttributeArray("vertex");
|
||||
rendering_program_light.setAttributeBuffer("vertex",GL_FLOAT,0,3,
|
||||
static_cast<int>(9*sizeof(float)));
|
||||
|
||||
rendering_program_light.enableAttributeArray("normal");
|
||||
rendering_program_light.setAttributeBuffer("normal",GL_FLOAT,3*sizeof(float),3,
|
||||
static_cast<int>(9*sizeof(float)));
|
||||
|
||||
rendering_program_light.enableAttributeArray("colors");
|
||||
rendering_program_light.setAttributeBuffer("colors",GL_FLOAT,6*sizeof(float),3,
|
||||
static_cast<int>(9*sizeof(float)));
|
||||
vbos[Grid_axis].release();
|
||||
|
||||
vaos[GRID_AXIS].release();
|
||||
rendering_program_light.release();
|
||||
|
||||
g_axis_size = d_axis.size();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -32,11 +32,6 @@ public:
|
|||
bool clipping;
|
||||
QVector4D clipbox[6];
|
||||
QPainter *painter;
|
||||
// F P S d i s p l a y
|
||||
QTime fpsTime;
|
||||
unsigned int fpsCounter;
|
||||
QString fpsString;
|
||||
float f_p_s;
|
||||
// M e s s a g e s
|
||||
QString message;
|
||||
bool _displayMessage;
|
||||
|
|
@ -45,14 +40,6 @@ public:
|
|||
bool is_ogl_4_3;
|
||||
bool is_2d_selection_mode;
|
||||
|
||||
//! Holds useful data to draw the axis system
|
||||
struct AxisData
|
||||
{
|
||||
std::vector<float> *vertices;
|
||||
std::vector<float> *normals;
|
||||
std::vector<float> *colors;
|
||||
};
|
||||
|
||||
//! The buffers used to draw the axis system
|
||||
QOpenGLBuffer buffers[8];
|
||||
//! The VAO used to draw the axis system
|
||||
|
|
@ -62,17 +49,6 @@ public:
|
|||
//! The rendering program used to draw the distance
|
||||
QOpenGLShaderProgram rendering_program_dist;
|
||||
QList<TextItem*> distance_text;
|
||||
//! Holds the vertices data for the axis system
|
||||
std::vector<float> v_Axis;
|
||||
//! Holds the normals data for the axis system
|
||||
std::vector<float> n_Axis;
|
||||
//! Holds the color data for the axis system
|
||||
std::vector<float> c_Axis;
|
||||
//! Decides if the axis system must be drawn or not
|
||||
bool axis_are_displayed;
|
||||
bool grid_is_displayed;
|
||||
std::size_t grid_size;
|
||||
std::size_t v_gaxis_size;
|
||||
//! Decides if the text is displayed in the drawVisualHints function.
|
||||
bool has_text;
|
||||
//! Decides if the distance between APoint and BPoint must be drawn;
|
||||
|
|
@ -90,18 +66,6 @@ public:
|
|||
bool extension_is_found;
|
||||
|
||||
TextRenderer *textRenderer;
|
||||
/*!
|
||||
* \brief makeArrow creates an arrow and stores it in a struct of vectors.
|
||||
* \param R the radius of the arrow.
|
||||
* \param prec the precision of the quadric. The lower this value is, the higher precision you get.
|
||||
* It can be any int between 1 and 360.
|
||||
* \param from the starting point of the arrow.
|
||||
* \param to the destination point of the arrow (the pointed extremity).
|
||||
* \param color the RGB color of the arrow.
|
||||
* \param data the struct of std::vector that will contain the results.
|
||||
*/
|
||||
void makeArrow(double R, int prec, qglviewer::Vec from, qglviewer::Vec to, qglviewer::Vec color, AxisData &data);
|
||||
void drawGrid(qreal size, int nbSubdivisions=10);
|
||||
//!Clears the distance display
|
||||
void clearDistancedisplay();
|
||||
void draw_aux(bool with_names, Viewer*);
|
||||
|
|
@ -133,14 +97,11 @@ Viewer::Viewer(QWidget* parent, bool antialiasing)
|
|||
this, SLOT(printMessage(QString,int)) );
|
||||
connect(&d->messageTimer, SIGNAL(timeout()), SLOT(hideMessage()));
|
||||
setShortcut(EXIT_VIEWER, 0);
|
||||
setShortcut(DRAW_AXIS, 0);
|
||||
setKeyDescription(Qt::Key_T,
|
||||
tr("Turn the camera by 180 degrees"));
|
||||
setKeyDescription(Qt::Key_M,
|
||||
tr("Toggle macro mode: useful to view details very near from the camera, "
|
||||
"but decrease the z-buffer precision"));
|
||||
setKeyDescription(Qt::Key_A,
|
||||
tr("Toggle the axis system visibility."));
|
||||
setKeyDescription(Qt::Key_I + Qt::CTRL,
|
||||
tr("Toggle the primitive IDs visibility of the selected Item."));
|
||||
setKeyDescription(Qt::Key_D,
|
||||
|
|
@ -176,19 +137,13 @@ Viewer::Viewer(QWidget* parent, bool antialiasing)
|
|||
|
||||
#endif // QGLVIEWER_VERSION >= 2.5.0
|
||||
prev_radius = sceneRadius();
|
||||
d->axis_are_displayed = true;
|
||||
d->grid_is_displayed = false;
|
||||
d->grid_size = 0;
|
||||
d->has_text = false;
|
||||
d->i_is_pressed = false;
|
||||
d->z_is_pressed = false;
|
||||
d->fpsTime.start();
|
||||
d->fpsCounter=0;
|
||||
d->f_p_s=0.0;
|
||||
d->fpsString=tr("%1Hz", "Frames per seconds, in Hertz").arg("?");
|
||||
d->distance_is_displayed = false;
|
||||
d->is_d_pressed = false;
|
||||
d->viewer = this;
|
||||
setTextIsEnabled(true);
|
||||
}
|
||||
|
||||
Viewer::~Viewer()
|
||||
|
|
@ -246,8 +201,6 @@ void Viewer::fastDraw()
|
|||
|
||||
void Viewer::initializeGL()
|
||||
{
|
||||
#if QGLVIEWER_VERSION >= 0x020700
|
||||
|
||||
QSurfaceFormat format;
|
||||
format.setDepthBufferSize(24);
|
||||
format.setStencilBufferSize(8);
|
||||
|
|
@ -271,30 +224,6 @@ void Viewer::initializeGL()
|
|||
CGAL_warning_msg(created && context()->isValid(), "The openGL context initialization failed "
|
||||
"and the default context (2.0) will be used" );
|
||||
makeCurrent();
|
||||
#else
|
||||
QGLFormat format;
|
||||
format.setVersion(4,3);
|
||||
format.setProfile(QGLFormat::CompatibilityProfile);
|
||||
QGLContext *new_context = new QGLContext(format, this);
|
||||
new_context->setFormat(format);
|
||||
bool created = new_context->create();
|
||||
if(!created || new_context->format().profile() != QGLFormat::CompatibilityProfile) {
|
||||
// impossible to get a 4.3 compatibility profile, retry with 2.0
|
||||
format.setVersion(2,1);
|
||||
new_context->setFormat(format);
|
||||
created = new_context->create();
|
||||
d->is_ogl_4_3 = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
d->is_ogl_4_3 = true;
|
||||
d->_recentFunctions = new QOpenGLFunctions_4_3_Compatibility();
|
||||
}
|
||||
CGAL_warning_msg(created && new_context->isValid(), "The openGL context initialization failed "
|
||||
"and the default context (2.0) will be used" );
|
||||
this->setContext(new_context);
|
||||
context()->makeCurrent();
|
||||
#endif
|
||||
QGLViewer::initializeGL();
|
||||
initializeOpenGLFunctions();
|
||||
if(isOpenGL_4_3())
|
||||
|
|
@ -461,42 +390,6 @@ void Viewer::initializeGL()
|
|||
qDebug() << d->rendering_program_dist.log();
|
||||
}
|
||||
}
|
||||
|
||||
Viewer_impl::AxisData data;
|
||||
d->v_Axis.resize(0);
|
||||
d->n_Axis.resize(0);
|
||||
d->c_Axis.resize(0);
|
||||
data.vertices = &d->v_Axis;
|
||||
data.normals = &d->n_Axis;
|
||||
data.colors = &d->c_Axis;
|
||||
GLdouble l = 1.0;
|
||||
d->makeArrow(0.06,10, qglviewer::Vec(0,0,0),qglviewer::Vec(l,0,0),qglviewer::Vec(1,0,0), data);
|
||||
d->makeArrow(0.06,10, qglviewer::Vec(0,0,0),qglviewer::Vec(0,l,0),qglviewer::Vec(0,1,0), data);
|
||||
d->makeArrow(0.06,10, qglviewer::Vec(0,0,0),qglviewer::Vec(0,0,l),qglviewer::Vec(0,0,1), data);
|
||||
|
||||
d->rendering_program.bind();
|
||||
d->vao[0].bind();
|
||||
d->buffers[0].bind();
|
||||
d->buffers[0].allocate(d->v_Axis.data(), static_cast<int>(d->v_Axis.size()) * sizeof(float));
|
||||
d->rendering_program.enableAttributeArray("vertex");
|
||||
d->rendering_program.setAttributeBuffer("vertex",GL_FLOAT,0,3);
|
||||
d->buffers[0].release();
|
||||
|
||||
d->buffers[1].bind();
|
||||
d->buffers[1].allocate(d->n_Axis.data(), static_cast<int>(d->n_Axis.size() * sizeof(float)));
|
||||
d->rendering_program.enableAttributeArray("normal");
|
||||
d->rendering_program.setAttributeBuffer("normal",GL_FLOAT,0,3);
|
||||
d->buffers[1].release();
|
||||
|
||||
d->buffers[2].bind();
|
||||
d->buffers[2].allocate(d->c_Axis.data(), static_cast<int>(d->c_Axis.size() * sizeof(float)));
|
||||
d->rendering_program.enableAttributeArray("colors");
|
||||
d->rendering_program.setAttributeBuffer("colors",GL_FLOAT,0,3);
|
||||
d->buffers[2].release();
|
||||
d->vao[0].release();
|
||||
|
||||
d->rendering_program.release();
|
||||
|
||||
d->painter = new QPainter();
|
||||
d->initialized = true;
|
||||
}
|
||||
|
|
@ -577,14 +470,6 @@ void Viewer::keyPressEvent(QKeyEvent* e)
|
|||
|
||||
return;
|
||||
}
|
||||
else if(e->key() == Qt::Key_A) {
|
||||
d->axis_are_displayed = !d->axis_are_displayed;
|
||||
update();
|
||||
}
|
||||
else if(e->key() == Qt::Key_G) {
|
||||
d->grid_is_displayed = !d->grid_is_displayed;
|
||||
update();
|
||||
}
|
||||
else if(e->key() == Qt::Key_I) {
|
||||
d->i_is_pressed = true;
|
||||
}
|
||||
|
|
@ -896,250 +781,10 @@ void Viewer::endSelection(const QPoint&)
|
|||
d->draw_aux(false, this);
|
||||
}
|
||||
|
||||
void Viewer_impl::makeArrow(double R, int prec, qglviewer::Vec from, qglviewer::Vec to, qglviewer::Vec color, Viewer_impl::AxisData &data)
|
||||
{
|
||||
qglviewer::Vec temp = to-from;
|
||||
QVector3D dir = QVector3D(temp.x, temp.y, temp.z);
|
||||
QMatrix4x4 mat;
|
||||
mat.setToIdentity();
|
||||
mat.translate(from.x, from.y, from.z);
|
||||
mat.scale(dir.length());
|
||||
dir.normalize();
|
||||
float angle = 0.0;
|
||||
if(std::sqrt((dir.x()*dir.x()+dir.y()*dir.y())) > 1)
|
||||
angle = 90.0f;
|
||||
else
|
||||
angle =acos(dir.y()/std::sqrt(dir.x()*dir.x()+dir.y()*dir.y()+dir.z()*dir.z()))*180.0/M_PI;
|
||||
|
||||
QVector3D axis;
|
||||
axis = QVector3D(dir.z(), 0, -dir.x());
|
||||
mat.rotate(angle, axis);
|
||||
|
||||
//Head
|
||||
const float Rf = static_cast<float>(R);
|
||||
for(int d = 0; d<360; d+= 360/prec)
|
||||
{
|
||||
float D = (float) (d * M_PI / 180.);
|
||||
float a = (float) std::atan(Rf / 0.33);
|
||||
QVector4D p(0., 1., 0, 1.);
|
||||
QVector4D n(Rf*2.*sin(D), sin(a), Rf*2.*cos(D), 1.);
|
||||
QVector4D pR = mat*p;
|
||||
QVector4D nR = mat*n;
|
||||
|
||||
//point A1
|
||||
data.vertices->push_back(pR.x());
|
||||
data.vertices->push_back(pR.y());
|
||||
data.vertices->push_back(pR.z());
|
||||
data.normals->push_back(nR.x());
|
||||
data.normals->push_back(nR.y());
|
||||
data.normals->push_back(nR.z());
|
||||
data.colors->push_back((float)color.x);
|
||||
data.colors->push_back((float)color.y);
|
||||
data.colors->push_back((float)color.z);
|
||||
|
||||
//point B1
|
||||
p = QVector4D(Rf*2.*sin(D), 0.66f, Rf*2.* cos(D), 1.f);
|
||||
n = QVector4D(sin(D), sin(a), cos(D), 1.);
|
||||
pR = mat*p;
|
||||
nR = mat*n;
|
||||
data.vertices->push_back(pR.x());
|
||||
data.vertices->push_back(pR.y());
|
||||
data.vertices->push_back(pR.z());
|
||||
data.normals->push_back(nR.x());
|
||||
data.normals->push_back(nR.y());
|
||||
data.normals->push_back(nR.z());
|
||||
data.colors->push_back((float)color.x);
|
||||
data.colors->push_back((float)color.y);
|
||||
data.colors->push_back((float)color.z);
|
||||
//point C1
|
||||
D = (d+360/prec)*M_PI/180.0;
|
||||
p = QVector4D(Rf*2.* sin(D), 0.66f, Rf *2.* cos(D), 1.f);
|
||||
n = QVector4D(sin(D), sin(a), cos(D), 1.0);
|
||||
pR = mat*p;
|
||||
nR = mat*n;
|
||||
|
||||
data.vertices->push_back(pR.x());
|
||||
data.vertices->push_back(pR.y());
|
||||
data.vertices->push_back(pR.z());
|
||||
data.normals->push_back(nR.x());
|
||||
data.normals->push_back(nR.y());
|
||||
data.normals->push_back(nR.z());
|
||||
data.colors->push_back((float)color.x);
|
||||
data.colors->push_back((float)color.y);
|
||||
data.colors->push_back((float)color.z);
|
||||
|
||||
}
|
||||
|
||||
//cylinder
|
||||
//body of the cylinder
|
||||
for(int d = 0; d<360; d+= 360/prec)
|
||||
{
|
||||
//point A1
|
||||
double D = d*M_PI/180.0;
|
||||
QVector4D p(Rf*sin(D), 0.66f, Rf*cos(D), 1.f);
|
||||
QVector4D n(sin(D), 0.f, cos(D), 1.f);
|
||||
QVector4D pR = mat*p;
|
||||
QVector4D nR = mat*n;
|
||||
|
||||
data.vertices->push_back(pR.x());
|
||||
data.vertices->push_back(pR.y());
|
||||
data.vertices->push_back(pR.z());
|
||||
data.normals->push_back(nR.x());
|
||||
data.normals->push_back(nR.y());
|
||||
data.normals->push_back(nR.z());
|
||||
data.colors->push_back(color.x);
|
||||
data.colors->push_back(color.y);
|
||||
data.colors->push_back(color.z);
|
||||
//point B1
|
||||
p = QVector4D(Rf * sin(D),0,Rf*cos(D), 1.0);
|
||||
n = QVector4D(sin(D), 0, cos(D), 1.0);
|
||||
pR = mat*p;
|
||||
nR = mat*n;
|
||||
|
||||
|
||||
data.vertices->push_back(pR.x());
|
||||
data.vertices->push_back(pR.y());
|
||||
data.vertices->push_back(pR.z());
|
||||
data.normals->push_back(nR.x());
|
||||
data.normals->push_back(nR.y());
|
||||
data.normals->push_back(nR.z());
|
||||
data.colors->push_back(color.x);
|
||||
data.colors->push_back(color.y);
|
||||
data.colors->push_back(color.z);
|
||||
//point C1
|
||||
D = (d+360/prec)*M_PI/180.0;
|
||||
p = QVector4D(Rf * sin(D),0,Rf*cos(D), 1.0);
|
||||
n = QVector4D(sin(D), 0, cos(D), 1.0);
|
||||
pR = mat*p;
|
||||
nR = mat*n;
|
||||
data.vertices->push_back(pR.x());
|
||||
data.vertices->push_back(pR.y());
|
||||
data.vertices->push_back(pR.z());
|
||||
data.normals->push_back(nR.x());
|
||||
data.normals->push_back(nR.y());
|
||||
data.normals->push_back(nR.z());
|
||||
data.colors->push_back(color.x);
|
||||
data.colors->push_back(color.y);
|
||||
data.colors->push_back(color.z);
|
||||
//point A2
|
||||
D = (d+360/prec)*M_PI/180.0;
|
||||
|
||||
p = QVector4D(Rf * sin(D),0,Rf*cos(D), 1.0);
|
||||
n = QVector4D(sin(D), 0, cos(D), 1.0);
|
||||
pR = mat*p;
|
||||
nR = mat*n;
|
||||
data.vertices->push_back(pR.x());
|
||||
data.vertices->push_back(pR.y());
|
||||
data.vertices->push_back(pR.z());
|
||||
data.normals->push_back(nR.x());
|
||||
data.normals->push_back(nR.y());
|
||||
data.normals->push_back(nR.z());
|
||||
data.colors->push_back((float)color.x);
|
||||
data.colors->push_back((float)color.y);
|
||||
data.colors->push_back((float)color.z);
|
||||
//point B2
|
||||
p = QVector4D(Rf * sin(D), 0.66f, Rf*cos(D), 1.f);
|
||||
n = QVector4D(sin(D), 0, cos(D), 1.0);
|
||||
pR = mat*p;
|
||||
nR = mat*n;
|
||||
data.vertices->push_back(pR.x());
|
||||
data.vertices->push_back(pR.y());
|
||||
data.vertices->push_back(pR.z());
|
||||
data.normals->push_back(nR.x());
|
||||
data.normals->push_back(nR.y());
|
||||
data.normals->push_back(nR.z());
|
||||
data.colors->push_back((float)color.x);
|
||||
data.colors->push_back((float)color.y);
|
||||
data.colors->push_back((float)color.z);
|
||||
//point C2
|
||||
D = d*M_PI/180.0;
|
||||
p = QVector4D(Rf * sin(D), 0.66f, Rf*cos(D), 1.f);
|
||||
n = QVector4D(sin(D), 0.f, cos(D), 1.f);
|
||||
pR = mat*p;
|
||||
nR = mat*n;
|
||||
data.vertices->push_back(pR.x());
|
||||
data.vertices->push_back(pR.y());
|
||||
data.vertices->push_back(pR.z());
|
||||
data.normals->push_back(nR.x());
|
||||
data.normals->push_back(nR.y());
|
||||
data.normals->push_back(nR.z());
|
||||
data.colors->push_back(color.x);
|
||||
data.colors->push_back(color.y);
|
||||
data.colors->push_back(color.z);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Viewer::drawVisualHints()
|
||||
{
|
||||
|
||||
QGLViewer::drawVisualHints();
|
||||
if(d->axis_are_displayed)
|
||||
{
|
||||
d->rendering_program.bind();
|
||||
qglviewer::Camera::Type camera_type = camera()->type();
|
||||
camera()->setType(qglviewer::Camera::ORTHOGRAPHIC);
|
||||
QMatrix4x4 mvpMatrix;
|
||||
QMatrix4x4 mvMatrix;
|
||||
for(int i=0; i < 16; i++)
|
||||
{
|
||||
mvMatrix.data()[i] = camera()->orientation().inverse().matrix()[i];
|
||||
}
|
||||
mvpMatrix.ortho(-1,1,-1,1,-1,1);
|
||||
mvpMatrix = mvpMatrix*mvMatrix;
|
||||
camera()->setType(camera_type);
|
||||
QVector4D position(0.0f,0.0f,1.0f,1.0f );
|
||||
// define material
|
||||
QVector4D ambient;
|
||||
QVector4D diffuse;
|
||||
QVector4D specular;
|
||||
GLfloat shininess ;
|
||||
// Ambient
|
||||
ambient[0] = 0.29225f;
|
||||
ambient[1] = 0.29225f;
|
||||
ambient[2] = 0.29225f;
|
||||
ambient[3] = 1.0f;
|
||||
// Diffuse
|
||||
diffuse[0] = 0.50754f;
|
||||
diffuse[1] = 0.50754f;
|
||||
diffuse[2] = 0.50754f;
|
||||
diffuse[3] = 1.0f;
|
||||
// Specular
|
||||
specular[0] = 0.0f;
|
||||
specular[1] = 0.0f;
|
||||
specular[2] = 0.0f;
|
||||
specular[3] = 0.0f;
|
||||
// Shininess
|
||||
shininess = 51.2f;
|
||||
|
||||
d->rendering_program.setUniformValue("light_pos", position);
|
||||
d->rendering_program.setUniformValue("mvp_matrix", mvpMatrix);
|
||||
d->rendering_program.setUniformValue("mv_matrix", mvMatrix);
|
||||
d->rendering_program.setUniformValue("light_diff", diffuse);
|
||||
d->rendering_program.setUniformValue("light_spec", specular);
|
||||
d->rendering_program.setUniformValue("light_amb", ambient);
|
||||
d->rendering_program.setUniformValue("spec_power", shininess);
|
||||
|
||||
d->vao[0].bind();
|
||||
int viewport[4];
|
||||
int scissor[4];
|
||||
|
||||
// The viewport and the scissor are changed to fit the upper right
|
||||
// corner. Original values are saved.
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
glGetIntegerv(GL_SCISSOR_BOX, scissor);
|
||||
|
||||
// Axis viewport size, in pixels
|
||||
const int size = 100;
|
||||
glViewport(width()*devicePixelRatio()-size, height()*devicePixelRatio()-size, size, size);
|
||||
glScissor (width()*devicePixelRatio()-size, height()*devicePixelRatio()-size, size, size);
|
||||
glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(d->v_Axis.size() / 3));
|
||||
// The viewport and the scissor are restored.
|
||||
glScissor(scissor[0],scissor[1],scissor[2],scissor[3]);
|
||||
glViewport(viewport[0],viewport[1],viewport[2],viewport[3]);
|
||||
d->vao[0].release();
|
||||
d->rendering_program.release();
|
||||
}
|
||||
|
||||
if(d->distance_is_displayed)
|
||||
{
|
||||
|
|
@ -1169,82 +814,12 @@ void Viewer::drawVisualHints()
|
|||
glLineWidth(1.0f);
|
||||
|
||||
}
|
||||
if(d->grid_is_displayed)
|
||||
{
|
||||
//draws the distance
|
||||
QMatrix4x4 mvpMatrix;
|
||||
double mat[16];
|
||||
camera()->getModelViewProjectionMatrix(mat);
|
||||
//nullifies the translation
|
||||
for(int i=0; i < 16; i++)
|
||||
{
|
||||
mvpMatrix.data()[i] = (float)mat[i];
|
||||
}
|
||||
d->rendering_program_dist.bind();
|
||||
d->rendering_program_dist.setUniformValue("mvp_matrix", mvpMatrix);
|
||||
d->vao[2].bind();
|
||||
glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(d->grid_size));
|
||||
d->vao[2].release();
|
||||
d->rendering_program_dist.release();
|
||||
|
||||
d->rendering_program.bind();
|
||||
QMatrix4x4 mvMatrix;
|
||||
for(int i=0; i < 16; i++)
|
||||
{
|
||||
mvMatrix.data()[i] = camera()->orientation().inverse().matrix()[i];
|
||||
}
|
||||
QVector4D position(0.0f,0.0f,1.0f,1.0f );
|
||||
// define material
|
||||
QVector4D ambient;
|
||||
QVector4D diffuse;
|
||||
QVector4D specular;
|
||||
GLfloat shininess ;
|
||||
// Ambient
|
||||
ambient[0] = 0.29225f;
|
||||
ambient[1] = 0.29225f;
|
||||
ambient[2] = 0.29225f;
|
||||
ambient[3] = 1.0f;
|
||||
// Diffuse
|
||||
diffuse[0] = 0.50754f;
|
||||
diffuse[1] = 0.50754f;
|
||||
diffuse[2] = 0.50754f;
|
||||
diffuse[3] = 1.0f;
|
||||
// Specular
|
||||
specular[0] = 0.0f;
|
||||
specular[1] = 0.0f;
|
||||
specular[2] = 0.0f;
|
||||
specular[3] = 0.0f;
|
||||
// Shininess
|
||||
shininess = 51.2f;
|
||||
|
||||
d->rendering_program.setUniformValue("light_pos", position);
|
||||
d->rendering_program.setUniformValue("mvp_matrix", mvpMatrix);
|
||||
d->rendering_program.setUniformValue("mv_matrix", mvMatrix);
|
||||
d->rendering_program.setUniformValue("light_diff", diffuse);
|
||||
d->rendering_program.setUniformValue("light_spec", specular);
|
||||
d->rendering_program.setUniformValue("light_amb", ambient);
|
||||
d->rendering_program.setUniformValue("spec_power", shininess);
|
||||
|
||||
d->vao[3].bind();
|
||||
// Axis viewport size, in pixels
|
||||
glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(d->v_gaxis_size / 3));
|
||||
// The viewport and the scissor are restored.
|
||||
d->vao[3].release();
|
||||
d->rendering_program.release();
|
||||
}
|
||||
|
||||
if (!d->painter->isActive())
|
||||
d->painter->begin(this);
|
||||
//So that the text is drawn in front of everything
|
||||
d->painter->beginNativePainting();
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
d->painter->endNativePainting();
|
||||
//prints FPS
|
||||
TextItem *fps_text = new TextItem(20, int(1.5*((QApplication::font().pixelSize()>0)?QApplication::font().pixelSize():QApplication::font().pointSize())),0,d->fpsString,false, QFont(), Qt::gray);
|
||||
if(FPSIsDisplayed())
|
||||
{
|
||||
d->textRenderer->addText(fps_text);
|
||||
}
|
||||
//Prints the displayMessage
|
||||
QFont font = QFont();
|
||||
QFontMetrics fm(font);
|
||||
|
|
@ -1254,8 +829,7 @@ void Viewer::drawVisualHints()
|
|||
d->textRenderer->addText(message_text);
|
||||
}
|
||||
d->textRenderer->draw(this);
|
||||
if(FPSIsDisplayed())
|
||||
d->textRenderer->removeText(fps_text);
|
||||
|
||||
if (d->_displayMessage)
|
||||
d->textRenderer->removeText(message_text);
|
||||
}
|
||||
|
|
@ -1414,29 +988,6 @@ void Viewer::paintGL()
|
|||
doneCurrent();
|
||||
}
|
||||
|
||||
void Viewer::postDraw()
|
||||
{
|
||||
|
||||
#ifdef GL_RESCALE_NORMAL // OpenGL 1.2 Only...
|
||||
glEnable(GL_RESCALE_NORMAL);
|
||||
#endif
|
||||
|
||||
if (cameraIsEdited())
|
||||
camera()->drawAllPaths();
|
||||
|
||||
// Pivot point, line when camera rolls, zoom region
|
||||
drawVisualHints();
|
||||
|
||||
// FPS computation
|
||||
const unsigned int maxCounter = 20;
|
||||
if (++d->fpsCounter == maxCounter)
|
||||
{
|
||||
d->f_p_s = 1000.0 * maxCounter / d->fpsTime.restart();
|
||||
d->fpsString = tr("%1Hz", "Frames per seconds, in Hertz").arg(d->f_p_s, 0, 'f', ((d->f_p_s < 10.0)?1:0));
|
||||
d->fpsCounter = 0;
|
||||
}
|
||||
|
||||
}
|
||||
void Viewer::displayMessage(const QString &_message, int delay)
|
||||
{
|
||||
d->message = _message;
|
||||
|
|
@ -1759,7 +1310,6 @@ qglviewer::Vec Viewer::offset()const { return d->offset; }
|
|||
void Viewer::setSceneBoundingBox(const qglviewer::Vec &min, const qglviewer::Vec &max)
|
||||
{
|
||||
QGLViewer::setSceneBoundingBox(min+d->offset, max+d->offset);
|
||||
d->drawGrid(camera()->sceneRadius());
|
||||
}
|
||||
|
||||
void Viewer::updateIds(CGAL::Three::Scene_item * item)
|
||||
|
|
@ -1797,79 +1347,7 @@ void Viewer::enableClippingBox(QVector4D box[6])
|
|||
|
||||
|
||||
bool Viewer::isOpenGL_4_3() const { return d->is_ogl_4_3; }
|
||||
void Viewer_impl::drawGrid(qreal size, int nbSubdivisions)
|
||||
{
|
||||
std::vector<float> v_Grid;
|
||||
std::vector<float> v_gAxis;
|
||||
std::vector<float> n_gAxis;
|
||||
std::vector<float> c_gAxis;
|
||||
for (int i=0; i<=nbSubdivisions; ++i)
|
||||
{
|
||||
const float pos = size*(2.0*i/nbSubdivisions-1.0);
|
||||
v_Grid.push_back(pos);
|
||||
v_Grid.push_back(-size);
|
||||
v_Grid.push_back(0.0);
|
||||
|
||||
v_Grid.push_back(pos);
|
||||
v_Grid.push_back(+size);
|
||||
v_Grid.push_back(0.0);
|
||||
|
||||
v_Grid.push_back(-size);
|
||||
v_Grid.push_back(pos);
|
||||
v_Grid.push_back(0.0);
|
||||
|
||||
v_Grid.push_back( size);
|
||||
v_Grid.push_back( pos);
|
||||
v_Grid.push_back( 0.0);
|
||||
}
|
||||
rendering_program_dist.bind();
|
||||
vao[2].bind();
|
||||
buffers[4].bind();
|
||||
buffers[4].allocate(v_Grid.data(),static_cast<int>(v_Grid.size()*sizeof(float)));
|
||||
rendering_program_dist.enableAttributeArray("vertex");
|
||||
rendering_program_dist.setAttributeBuffer("vertex",GL_FLOAT,0,3);
|
||||
buffers[4].release();
|
||||
vao[2].release();
|
||||
rendering_program_dist.release();
|
||||
grid_size = v_Grid.size();
|
||||
|
||||
Viewer_impl::AxisData data;
|
||||
v_gAxis.resize(0);
|
||||
n_gAxis.resize(0);
|
||||
c_gAxis.resize(0);
|
||||
data.vertices = &v_gAxis;
|
||||
data.normals = &n_gAxis;
|
||||
data.colors = &c_gAxis;
|
||||
makeArrow(0.02*size,10, qglviewer::Vec(0,0,0),qglviewer::Vec(size,0,0),qglviewer::Vec(1,0,0), data);
|
||||
makeArrow(0.02*size,10, qglviewer::Vec(0,0,0),qglviewer::Vec(0,size,0),qglviewer::Vec(0,1,0), data);
|
||||
makeArrow(0.02*size,10, qglviewer::Vec(0,0,0),qglviewer::Vec(0,0,size),qglviewer::Vec(0,0,1), data);
|
||||
|
||||
rendering_program.bind();
|
||||
vao[3].bind();
|
||||
buffers[5].bind();
|
||||
buffers[5].allocate(v_gAxis.data(), static_cast<int>(v_gAxis.size()) * sizeof(float));
|
||||
rendering_program.enableAttributeArray("vertex");
|
||||
rendering_program.setAttributeBuffer("vertex",GL_FLOAT,0,3);
|
||||
buffers[5].release();
|
||||
|
||||
buffers[6].bind();
|
||||
buffers[6].allocate(n_gAxis.data(), static_cast<int>(n_gAxis.size() * sizeof(float)));
|
||||
rendering_program.enableAttributeArray("normal");
|
||||
rendering_program.setAttributeBuffer("normal",GL_FLOAT,0,3);
|
||||
buffers[6].release();
|
||||
|
||||
buffers[7].bind();
|
||||
buffers[7].allocate(c_gAxis.data(), static_cast<int>(c_gAxis.size() * sizeof(float)));
|
||||
rendering_program.enableAttributeArray("colors");
|
||||
rendering_program.setAttributeBuffer("colors",GL_FLOAT,0,3);
|
||||
buffers[7].release();
|
||||
vao[3].release();
|
||||
|
||||
rendering_program.release();
|
||||
|
||||
v_gaxis_size = v_gAxis.size();
|
||||
|
||||
}
|
||||
QOpenGLFunctions_4_3_Compatibility* Viewer::openGL_4_3_functions() { return d->_recentFunctions; }
|
||||
|
||||
void Viewer::set2DSelectionMode(bool b) { d->is_2d_selection_mode = b; }
|
||||
|
|
|
|||
|
|
@ -131,7 +131,6 @@ public Q_SLOTS:
|
|||
}
|
||||
|
||||
protected:
|
||||
void postDraw()Q_DECL_OVERRIDE;
|
||||
void paintEvent(QPaintEvent *)Q_DECL_OVERRIDE;
|
||||
void paintGL()Q_DECL_OVERRIDE;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue