Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
QHyodaGL.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7#include <QtWidgets>
8#include <QHyodaGL.h>
9
10#ifndef GL_MULTISAMPLE
11#define GL_MULTISAMPLE 0x809D
12#endif
13
14QHyodaGL::QHyodaGL(QWidget *parent):QOpenGLWidget(parent){
15 qDebug()<<"\33[31m[QHyodaGL::QHyodaGL] NEW\33[m";
16 pov.setX(30.0);
17 pov.setY(-45.0);
18 pov.setZ(0.0);
19 pov.setW(100.0);
20}
21
22void QHyodaGL::initializeGL(void){
23 qDebug()<<"\33[31m[QHyodaGL::initializeGL]\33[m";
24 glPointSize(8.0);
25 glLineWidth(1.0);
26 glShadeModel(GL_SMOOTH);
27 glEnable(GL_MULTISAMPLE);
28 glEnable(GL_POINT_SMOOTH);
29 glClearDepth(1.0f);
30 glEnable(GL_DEPTH_TEST);
31 glDepthFunc(GL_LEQUAL);
32 //glEnable(GL_CULL_FACE);
33 glLineStipple(1, 0x0101); // Mode pointillé
34 glEnable(GL_LINE_STIPPLE);
35}
36
37void QHyodaGL::paintGL(){
38 //qDebug()<<"\33[31m[QHyodaGL::paintGL]\33[m";
39 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
40 glPushMatrix();
41 glLoadIdentity();
42 glTranslatef(0.0f, 0.0f, -16.0f);
43 glRotatef(pov.x(), 1.0f, 0.0f, 0.0f);
44 glRotatef(pov.y(), 0.0f, 1.0f, 0.0f);
45 glRotatef(pov.z(), 0.0f, 0.0f, 1.0f);
46 glScalef(pov.w(), pov.w(), pov.w());
47 draw();
48 glPopMatrix();
49}
50
51void QHyodaGL::resizeGL(int w, int h){
52 //qDebug()<<"\33[31m[QHyodaGL::resizeGL]\33[m";
53 const int side = qMin(w, h);
54 glViewport((w-side)/2,(h-side)/2,side,side);
55 glMatrixMode(GL_PROJECTION);
56 glLoadIdentity();
57 glOrtho(-2.0f,+2.0f,-2.0f,+2.0f,1.0f,32.0f);
58 glMatrixMode(GL_MODELVIEW);
59}
60
61void QHyodaGL::mousePressEvent(QMouseEvent *event){
62 //qDebug()<<"\33[31m[QHyodaGL::mousePressEvent]\33[m";
63 mouse = QVector2D(event->localPos());
64}
65
66void QHyodaGL::mouseMoveEvent(QMouseEvent *event){
67 //qDebug()<<"\33[31m[QHyodaGL::mouseMoveEvent]\33[m";
68 QVector2D diff = QVector2D(event->localPos())-mouse;
69 if (event->buttons() & Qt::LeftButton) {
70 pov.setX(pov.x()+diff.y()/4.0f);
71 pov.setY(pov.y()+diff.x()/4.0f);
72 } else if (event->buttons() & Qt::RightButton) {
73 pov.setX(pov.x()+diff.y()/4.0f);
74 pov.setZ(pov.z()+diff.x()/4.0f);
75 }
76 mouse = QVector2D(event->localPos());
77}
78
79void QHyodaGL::wheelEvent(QWheelEvent *e){
80 //qDebug()<<"\33[31m[QHyodaGL::mouseWheelEvent]\33[m";
81 e->delta()>0?
82 pov.setW(pov.w()+pov.w()*0.1f):
83 pov.setW(pov.w()-pov.w()*0.1f);
84 //update();
85}