Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
QHyodaIceT.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 <QHyodaIceT.h>
9
10/******************************************************************************
11 * QHyodaIceT class
12 *****************************************************************************/
13QHyodaIceT::QHyodaIceT(QWidget *prnt): QOpenGLWidget(prnt),
14 parent(prnt),
15 mouse(QVector2D()),
16 pov(QVector4D(13.25,26.75,0,0.73)),
17 image(NULL),
18 texture(0){
19 qDebug()<<"\33[31m[QHyodaIceT::QHyodaIceT] NEW\33[m";
20}
21
22
23
24/******************************************************************************
25 * ~QHyodaIceT
26 *****************************************************************************/
27QHyodaIceT::~QHyodaIceT(){
28 qDebug()<<"~QHyodaIceT";
29}
30
31
32// ****************************************************************************
33// * sxyz
34// * tcpMeshIceTImage utilise pour récupérer le pov
35// ****************************************************************************
36void QHyodaIceT::sxyz(double *v){
37 v[0]=pov.w();
38 v[1]=pov.x();
39 v[2]=pov.y();
40 v[3]=pov.z();
41}
42
43void QHyodaIceT::setPov(QVector4D v){
44 pov=v;
45}
46
47
48/******************************************************************************
49 * setImage
50 *****************************************************************************/
51void QHyodaIceT::setImage(QImage *qImg){
52 //qDebug()<<"\33[31m[QHyodaIceT::setImage]\33[m";
53 image=qImg;
54 update();
55}
56
57
58/******************************************************************************
59 * initializeGL
60 *****************************************************************************/
61void QHyodaIceT::initializeGL(){
62 qDebug()<<"\33[31m[QHyodaIceT::initializeGL]\33[m";
63 glViewport(0, 0, parent->width(), parent->height());
64 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
65 glEnable(GL_DEPTH_TEST);
66 glEnable(GL_NORMALIZE);
67 glPixelStorei(GL_UNPACK_ALIGNMENT,1);
68 glEnable(GL_TEXTURE_2D);
69 glGenTextures(1,&texture);
70 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
71 glBindTexture(GL_TEXTURE_2D, texture);
72 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
73 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
74 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
75 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
76 //glBindTexture(GL_TEXTURE_2D, 0);
77}
78
79
80/******************************************************************************
81 * resizeGL
82 *****************************************************************************/
83void QHyodaIceT::resizeGL(int w, int h){
84 //qDebug()<<"\33[31m[QHyodaIceT::resizeGL]\33[m";
85 glViewport(0.0, 0.0, w, h);
86 glMatrixMode(GL_PROJECTION);
87 glLoadIdentity();
88 glFrustum(-1.0f, 1.0f, -1.0f, 1.0f, +1, 8);
89 glTranslatef(0.0f, 0.0f, -2.0f);
90 update();
91}
92
93
94/******************************************************************************
95 * paintGL
96 *****************************************************************************/
97void QHyodaIceT::
98paintGL()
99{
100 if (!image)
101 return;
102 //qDebug()<<"\33[31m[QHyodaIceT::paintGL] "<<image->width()<<"x"<<image->height()<<"\33[m";
103 const double sqrtd=2.0;//sqrt(3.0);
104 saveGLState();
105
106 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
107 image->width(), image->height(), 0,
108 GL_RGBA, GL_UNSIGNED_BYTE, image->bits());
109 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
110 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
111 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
112 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
113
114 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
115 glBegin(GL_QUADS);
116 glTexCoord2d(0.0, 0.0); glVertex3d(-sqrtd, -sqrtd, 0.0);
117 glTexCoord2d(0.0, 1.0); glVertex3d(-sqrtd, +sqrtd, 0.0);
118 glTexCoord2d(1.0, 1.0); glVertex3d(+sqrtd, +sqrtd, 0.0);
119 glTexCoord2d(1.0, 0.0); glVertex3d(+sqrtd, -sqrtd, 0.0);
120 glEnd();
121
122 restoreGLState();
123}
124
125
126/******************************************************************************
127 * mousePressEvent
128 *****************************************************************************/
129void QHyodaIceT::mousePressEvent(QMouseEvent *e){
130 //qDebug()<<"\33[31m[QHyodaIceT::mousePressEvent]\33[m";
131 mouse = QVector2D(e->localPos());
132}
133
134/******************************************************************************
135 * mouseMoveEvent
136 *****************************************************************************/
137void QHyodaIceT::mouseMoveEvent(QMouseEvent *e){
138 //qDebug()<<"\33[31m[QHyodaIceT::mouseMoveEvent]\33[m";
139 QVector2D diff = QVector2D(e->localPos())-mouse;
140
141 if (e->buttons() & Qt::LeftButton) {
142 pov.setX(pov.x()+diff.y()/4.0f);
143 pov.setY(pov.y()+diff.x()/4.0f);
144 } else if (e->buttons() & Qt::RightButton) {
145 pov.setX(pov.x()+diff.y()/4.0f);
146 pov.setZ(pov.z()+diff.x()/4.0f);
147 }
148 mouse = QVector2D(e->localPos());
149 update();
150}
151
152/******************************************************************************
153 * wheelEvent
154 *****************************************************************************/
155void QHyodaIceT::wheelEvent(QWheelEvent *e){
156 //qDebug()<<"\33[31m[QHyodaIceT::wheelEvent]\33[m";
157 e->delta()>0?
158 pov.setW(pov.w()+pov.w()*0.1f):
159 pov.setW(pov.w()-pov.w()*0.1f);
160 update();
161}
162
163
164/******************************************************************************
165 * saveGLState
166 *****************************************************************************/
167void QHyodaIceT::saveGLState(){
168 glPushAttrib(GL_ALL_ATTRIB_BITS);
169 glMatrixMode(GL_PROJECTION);
170 glPushMatrix();
171 glMatrixMode(GL_MODELVIEW);
172 glPushMatrix();
173}
174
175
176/******************************************************************************
177 * restoreGLState
178 *****************************************************************************/
179void QHyodaIceT::restoreGLState(){
180 glMatrixMode(GL_PROJECTION);
181 glPopMatrix();
182 glMatrixMode(GL_MODELVIEW);
183 glPopMatrix();
184 glPopAttrib();
185}