24 #include <qmatrix4x4.h>
25 #include <qopenglbuffer.h>
26 #include <qopenglcontext.h>
27 #include <qopenglfunctions_4_3_core.h>
28 #include <qopenglshaderprogram.h>
29 #include <qopenglvertexarrayobject.h>
30 #include <qtransform.h>
31 #include <qvector3d.h>
43 #include <QOpenGLFunctions_4_3_Core>
46 void drawBoundingBox(
const QVector3D& boxDimensions, QOpenGLShaderProgram* shaderProgram,
47 const QMatrix4x4& model,
const QMatrix4x4& view,
const QMatrix4x4& projection)
49 QOpenGLFunctions_4_3_Core gl;
50 gl.initializeOpenGLFunctions();
54 QOpenGLBuffer vbo(QOpenGLBuffer::VertexBuffer);
57 vbo.allocate(bboxMesh.
vertices().data(), bboxMesh.
vertices().size() *
sizeof(QVector3D));
59 QOpenGLVertexArrayObject vao;
63 int vertexLocation = shaderProgram->attributeLocation(
"pos");
64 shaderProgram->enableAttributeArray(vertexLocation);
65 shaderProgram->setAttributeBuffer(vertexLocation, GL_FLOAT, 0, 3, 0);
67 int modelLocation = shaderProgram->uniformLocation(
"model");
68 shaderProgram->setUniformValue(modelLocation, model);
69 int viewLocation = shaderProgram->uniformLocation(
"view");
70 shaderProgram->setUniformValue(viewLocation, view);
71 int projectionLocation = shaderProgram->uniformLocation(
"projection");
72 shaderProgram->setUniformValue(projectionLocation, projection);
74 int colorLocation = shaderProgram->uniformLocation(
"color");
76 QVector3D vectorColor = QVector3D(color.redF(), color.greenF(), color.blueF());
77 shaderProgram->setUniformValue(colorLocation, vectorColor);
79 QOpenGLBuffer indexBuffer(QOpenGLBuffer::IndexBuffer);
82 indexBuffer.allocate(bboxMesh.
indices().data(), bboxMesh.
indices().size() *
sizeof(
unsigned int));
84 gl.glDrawElements(GL_LINES, 24, GL_UNSIGNED_INT, 0);
85 gl.glDrawArrays(GL_POINTS, 0, 8);
86 indexBuffer.release(QOpenGLBuffer::IndexBuffer);
87 indexBuffer.destroy();
88 vbo.release(QOpenGLBuffer::VertexBuffer);
130 glColor3f(1.0, 0.0, 0.0);
134 glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
138 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
142 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
146 glShadeModel(GL_FLAT);
150 glShadeModel(GL_SMOOTH);
154 glEnable(GL_LIGHTING);
155 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
157 static GLfloat ambient[] = {0.1f, 0.1f, 0.1f, 1.0f};
158 static GLfloat ambientBIS[] = {0.8f, 0.8f, 0.8f, 0.8f};
159 static GLfloat diffuse[] = {0.8f, 0.8f, 0.8f, 1.0f};
160 static GLfloat specular[] = {0.8f, 0.8f, 0.8f, 1.0f};
161 static GLfloat shininess = 50.;
162 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientBIS);
163 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
164 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
165 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
166 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
168 glMatrixMode(GL_PROJECTION);
189 if (pElement->
isA(
"TYGeometryNode"))
232 GLint polygon_mode[2];
233 glGetIntegerv(GL_POLYGON_MODE, polygon_mode);
239 glMatrixMode(GL_PROJECTION);
241 glMatrixMode(GL_MODELVIEW);
242 glLoadMatrixf(currentCamera->
viewMatrix().constData());
246 glMatrixMode(GL_MODELVIEW);
256 for (
int il = 0; il <
_tabLights.size(); il++)
262 float colorSpec[] = {0.0, 0.0, 0.0, 1.0};
263 float colorShine[] = {127.0};
264 glMaterialfv(GL_FRONT, GL_SPECULAR, colorSpec);
265 glMaterialfv(GL_FRONT, GL_SHININESS, colorShine);
266 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
267 glEnable(GL_COLOR_MATERIAL);
270 glEnable(GL_LINE_SMOOTH);
272 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
273 glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
275 glEnable(GL_NORMALIZE);
276 glEnable(GL_DEPTH_TEST);
279 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
286 glGetFloatv(GL_PROJECTION_MATRIX, proj);
288 glGetIntegerv(GL_VIEWPORT, viewport);
290 glMatrixMode(GL_PROJECTION);
296 glMatrixMode(GL_MODELVIEW);
300 glMatrixMode(GL_PROJECTION);
310 std::vector<TYElement*>::iterator iterElements;
320 if (*iterElements !=
nullptr)
323 if (pTYElementGraphic !=
nullptr)
325 pTYElementGraphic->
display(overlayRenderContext);
334 glMatrixMode(GL_MODELVIEW);
345 glDisable(GL_LIGHTING);
346 std::vector<OGLElement*>::iterator iter;
354 glPolygonMode(GL_FRONT_AND_BACK, polygon_mode[0]);
367 if (pParent && pParent->
isA(
"TYProjet"))
369 pGraphObj = pParent->getGraphicObject();
373 glRotatef(-90.0, 1.0, 0.0, 0.0);
376 pGraphObj->
display(renderContext);
383 bool _bFinded =
false;
384 std::vector<OGLElement*>::iterator iter;
415 std::vector<OGLElement*>::iterator iter;
416 bool _bFinded =
false;
430 bool _bFinded =
false;
431 std::vector<TYElement*>::iterator iter;
447 std::vector<TYElement*>::iterator iter;
448 bool _bFinded =
false;
465 void gluPickMatrix(GLdouble x, GLdouble y, GLdouble deltax, GLdouble deltay, GLint viewport[4])
467 if (deltax <= 0 || deltay <= 0)
473 glTranslated((viewport[2] - 2 * (x - viewport[0])) / deltax,
474 (viewport[3] - 2 * (y - viewport[1])) / deltay, 0);
475 glScaled(viewport[2] / deltax, viewport[3] / deltay, 1.0);
489 viewMatrix.rotate(90, -1, 0, 0);
491 QMatrix4x4 projectionMatrix = camera->projectionMatrix();
494 TYElementGraphic* modelerElementGraphic = modelerElement->getGraphicObject();
496 modelerElementGraphic->
getChilds(allModelerElementGraphics,
true);
499 QMatrix4x4 invertedGlobalModelerMatrix{};
500 if (modelerGeoNode !=
nullptr)
501 invertedGlobalModelerMatrix =
505 allModelerElementGraphics.push_back(modelerElementGraphic);
509 shaderProgram->bind();
510 for (
auto element : allModelerElementGraphics)
512 if (element->isBoundingBoxVisible() &&
dynamic_cast<const TYGeometryNodeGraphic*
>(element) ==
nullptr)
514 const OBox boundingBox = element->boundingBox();
519 const TYElement* parent = element->getTYElement();
521 while (geoNode ==
nullptr && parent->
getParent())
527 QMatrix4x4 globalMatrix{};
528 if (geoNode !=
nullptr)
535 QMatrix4x4 bboxTranslation;
536 bboxTranslation.translate(QVector3D((boundingBox.
_min.
_x + boundingBox.
_max.
_x),
541 QVector3D bboxDimensions(boundingBox.
_max.
_x - boundingBox.
_min.
_x,
544 QMatrix4x4 modelMatrix = invertedGlobalModelerMatrix * globalMatrix * bboxTranslation;
549 shaderProgram->release();
Representation graphique d'un element de base (fichier header)
list< const TYElementGraphic * > TYListPtrConstTYElementGraphic
List de pointeur de TYElement.
Representation graphique d'un GeometryNode (fichier header)
void gluPickMatrix(GLdouble x, GLdouble y, GLdouble deltax, GLdouble deltay, GLint viewport[4])
void drawBoundingBox(const QVector3D &boxDimensions, QOpenGLShaderProgram *shaderProgram, const QMatrix4x4 &model, const QMatrix4x4 &view, const QMatrix4x4 &projection)
Realise le rendu VTK et le rendu OpenGL (fichier header)
Contexte de rendu utilisé par les fonctions d'affichage.
@ Display
The current render is intended to be displayed on screen.
@ Picking
The current render is only done for picking purpose.
@ Overlay
The current render pass is for overlay elements.
OPoint3D _min
Minimal coordinates of the OBox.
OPoint3D _max
Maximal coordinates of the OBox.
double _y
y coordinate of OCoord3D
double _z
z coordinate of OCoord3D
double _x
x coordinate of OCoord3D
void getPosition(double &x, double &y, double &z) const
const QMatrix4x4 & projectionMatrix() const
const QMatrix4x4 & viewMatrix() const
const std::vector< unsigned int > & indices() const
const std::vector< QVector3D > & vertices() const
void setMaterial(const OGLSimpleMaterial &material)
OGLSimpleMaterial material()
static OGLShaderManager * instance(QOpenGLContext *context)
QOpenGLShaderProgram * getShaderProgram(ShaderId shaderId)
static OGLSimpleMaterial BOUNDING_BOX
bool isA(const char *className) const
classe graphique pour un element de base
virtual void getChilds(TYListPtrTYElementGraphic &childs, bool recursif=true)
virtual void display(TYRenderContext &renderContext)
TYElement * getParent() const
classe graphique pour un GeometryNode
void displayPushingParentMatrix(TYRenderContext &renderContext, TYGeometryNode *pDansCeRepere)
TYGeometryNode * GetGeoNodeParent() const
static TYGeometryNode * GetGeoNode(TYElement *pElement)
std::vector< TYElement * > _tabSelectedElements
Elements selectionnes.
void _renderScene(TYRenderContext &renderContext) const
0 --> render all, 1 --> render 2D, 2 --> render 3D
void removeSelectedElement(TYElement *pElement)
void addLight(OGLLightElement *pOGLElementLight)
void addOGLElement(OGLElement *pOGLElement)
void invalidateScene(void)
void clearTabSelectedElement()
void removeOGLElement(OGLElement *pOGLElement)
std::vector< OGLLightElement * > _tabLights
Liste des lumieres dans la scene 3D.
QMatrix4x4 _boundingBoxScaleMatrix
GLuint _displayList
Display liste globale.
void renderBoundingBoxes(TYRenderContext &renderContext) const
RenderMode _renderMode
Mode de rendu.
OGLCamera * _pActiveCamera
void updateDisplayListOverlay(TYRenderContext &renderContext, TYGeometryNode *pElement, TYGeometryNode *pDansCeRepere)
std::vector< OGLElement * > _tabOGLElement
void setRenderMode(RenderMode mode)
double * _pBackgroundColor
std::vector< OGLLightElement * > getLights()
GLuint _displayListOverlay
Display liste pour les deplacements.
void drawElement(TYRenderContext &renderContext) const
RenderMode getRenderMode()
bool _sceneRenderCacheIsDirty
void OpenGLRender(TYRenderContext &renderContext, int x=0, int y=0)
void addSelectedElement(TYElement *pElement)
const TYRenderViewport viewport
TYElement *const modelerElement
const OGLCamera * camera() const