28 #include "OpenGL/OpenGL.h"
32 #include "glc_lib/glc_context.h"
33 #include "glc_lib/glc_exception.h"
34 #include "glc_lib/glc_openglexception.h"
35 #include "glc_lib/viewport/glc_userinput.h"
40 const QString ModelViewGadgetWidget::fallbackAcFilename =
41 QString(
":/modelview/models/warning_sign.obj");
42 const QString ModelViewGadgetWidget::fallbackBgFilename = QString(
":/modelview/models/black.jpg");
45 : QGLWidget(new GLC_Context(QGLFormat(QGL::SampleBuffers)), parent)
50 , m_ModelBoundingBox()
52 , acFilename(fallbackAcFilename)
53 , bgFilename(fallbackBgFilename)
56 connect(&m_GlView, &GLC_Viewport::updateOpenGL,
this, &QGLWidget::updateGL);
57 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
59 m_Light.setPosition(4000.0, 40000.0, 80000.0);
61 m_Light.setAmbientColor(Qt::lightGray);
63 m_GlView.cameraHandle()->setDefaultUpVector(glc::Z_AXIS);
64 m_GlView.cameraHandle()->setRearView();
67 repColor.setRgbF(1.0, 0.11372, 0.11372, 0.0);
68 m_MoverController = GLC_Factory::instance()->createDefaultMoverController(repColor, &m_GlView);
74 attState = AttitudeActual::GetInstance(objManager);
76 connect(&m_MotionTimer, &QTimer::timeout,
this,
84 if (QFile::exists(acf)) {
87 acFilename = acf = fallbackAcFilename;
88 m_GlView.cameraHandle()->setFrontView();
94 if (QFile::exists(bgFilename)) {
97 qDebug() <<
"file " << bgf <<
" doesn't exists";
98 bgFilename = fallbackBgFilename;
105 m_World.collection()->setVboUsage(vboEnable);
115 void ModelViewGadgetWidget::initializeGL()
118 #if defined(Q_OS_MAC)
119 const GLint swapInterval = 1;
120 CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &swapInterval);
126 m_GlView.reframe(m_ModelBoundingBox);
128 glEnable(GL_NORMALIZE);
130 glEnable(GL_MULTISAMPLE);
132 m_MotionTimer.start(100);
133 setFocusPolicy(Qt::StrongFocus);
136 void ModelViewGadgetWidget::paintGL()
140 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
144 GLenum
error = glGetError();
145 if (error != GL_NO_ERROR) {
146 GLC_OpenGlException OpenGlException(
"ModelViewGadgetWidget::paintGL() ", error);
147 throw(OpenGlException);
152 GLC_Context::current()->glcLoadIdentity();
155 glEnable(GL_MULTISAMPLE);
158 m_GlView.setDistMinAndMax(m_World.boundingBox());
161 m_GlView.glExecuteCam();
165 m_World.render(0, glc::ShadingFlag);
166 m_World.render(0, glc::TransparentRenderFlag);
169 m_MoverController.drawActiveMoverRep();
170 }
catch (GLC_Exception &
e) {
171 qDebug() << e.what();
175 void ModelViewGadgetWidget::resizeGL(
int width,
int height)
177 m_GlView.setWinGLSize(width, height);
180 GLenum error = glGetError();
181 if (error != GL_NO_ERROR) {
182 GLC_OpenGlException OpenGlException(
"ModelViewGadgetWidget::resizeGL() ", error);
183 throw(OpenGlException);
189 void ModelViewGadgetWidget::CreateScene()
192 if (acFilename == fallbackAcFilename || !QFile::exists(bgFilename)) {
193 bgFilename = fallbackBgFilename;
197 m_GlView.loadBackGroundImage(bgFilename);
198 }
catch (GLC_Exception e) {
199 qDebug(
"ModelView: background image file loading failed.");
203 if (QFile::exists(acFilename)) {
204 QFile aircraft(acFilename);
205 m_World = GLC_Factory::instance()->createWorldFromFile(aircraft);
206 m_ModelBoundingBox = m_World.boundingBox();
207 m_GlView.reframe(m_ModelBoundingBox);
209 qDebug() <<
"ModelView: aircraft file not found:" << acFilename;
211 }
catch (GLC_Exception e) {
212 qDebug(
"ModelView: aircraft file loading failed.");
216 void ModelViewGadgetWidget::wheelEvent(QWheelEvent *e)
218 double delta = m_GlView.cameraHandle()->distEyeTarget() - (e->delta() / 4);
220 m_GlView.cameraHandle()->setDistEyeTarget(delta);
221 m_GlView.setDistMinAndMax(m_World.boundingBox());
224 void ModelViewGadgetWidget::mousePressEvent(QMouseEvent *e)
226 GLC_UserInput userInput(e->x(), e->y());
228 if (m_MoverController.hasActiveMover()) {
232 switch (e->button()) {
233 case (Qt::LeftButton):
234 m_MotionTimer.stop();
235 m_MoverController.setActiveMover(GLC_MoverController::TurnTable, userInput);
238 case (Qt::RightButton):
239 printf(
"VBO enabled: %s, VBO supported: %s, VBO used: %s\n", vboEnable ?
"yes" :
"no",
240 GLC_State::vboSupported() ?
"yes" :
"no", GLC_State::vboUsed() ?
"yes" :
"no");
241 printf(
"Renderer - %s \n", reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
242 printf(
"Extensions - %s\n", reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)));
249 void ModelViewGadgetWidget::mouseMoveEvent(QMouseEvent *e)
251 GLC_UserInput userInput(e->x(), e->y());
253 if (!m_MoverController.hasActiveMover()) {
256 m_MoverController.move(userInput);
257 m_GlView.setDistMinAndMax(m_World.boundingBox());
261 void ModelViewGadgetWidget::mouseReleaseEvent(QMouseEvent *)
263 if (!m_MoverController.hasActiveMover()) {
266 m_MoverController.setNoMover();
267 m_MotionTimer.start();
271 void ModelViewGadgetWidget::keyPressEvent(QKeyEvent *e)
273 if (e->key() == Qt::Key_1) {
274 m_GlView.cameraHandle()->setIsoView();
277 if (e->key() == Qt::Key_2) {
278 m_GlView.cameraHandle()->setFrontView();
281 if (e->key() == Qt::Key_3) {
282 m_GlView.cameraHandle()->setIsoView();
283 m_GlView.cameraHandle()->rotateAroundTarget(glc::Z_AXIS, glc::toRadian(90));
286 if (e->key() == Qt::Key_4) {
287 m_GlView.cameraHandle()->setLeftView();
290 if (e->key() == Qt::Key_5) {
291 m_GlView.cameraHandle()->setTopView();
292 m_GlView.cameraHandle()->rotateAroundTarget(glc::Z_AXIS, glc::toRadian(180));
295 if (e->key() == Qt::Key_6) {
296 m_GlView.cameraHandle()->setRightView();
300 if (e->key() == Qt::Key_7) {
301 m_GlView.cameraHandle()->setIsoView();
302 m_GlView.cameraHandle()->rotateAroundTarget(glc::Z_AXIS, glc::toRadian(-90));
305 if (e->key() == Qt::Key_8) {
306 m_GlView.cameraHandle()->setRearView();
310 if (e->key() == Qt::Key_9) {
311 m_GlView.cameraHandle()->setIsoView();
312 m_GlView.cameraHandle()->rotateAroundTarget(glc::Z_AXIS, glc::toRadian(180));
315 if (e->key() == Qt::Key_0) {
316 m_GlView.cameraHandle()->setBottomView();
317 m_GlView.cameraHandle()->rotateAroundTarget(glc::Z_AXIS, glc::toRadian(180));
327 AttitudeActual::DataFields
data = attState->getData();
328 GLC_StructOccurence *rootObject = m_World.rootOccurence();
339 m1.setRow(0, QVector4D(w, z, -y, x));
340 m1.setRow(1, QVector4D(-z, w, x, y));
341 m1.setRow(2, QVector4D(y, -x, w, z));
342 m1.setRow(3, QVector4D(-x, -y, -z, w));
344 m2.setRow(0, QVector4D(w, z, -y, -x));
345 m2.setRow(1, QVector4D(-z, w, x, -y));
346 m2.setRow(2, QVector4D(y, -x, w, -z));
347 m2.setRow(3, QVector4D(x, y, z, w));
348 QMatrix4x4 m0 = m1 * m2;
350 GLC_Matrix4x4 rootObjectRotation(m0.data());
351 rootObject->structInstance()->setMatrix(rootObjectRotation);
352 rootObject->updateChildrenAbsoluteMatrix();
Core plugin system that manages the plugins, their life cycle and their registered objects...
ModelViewGadgetWidget(QWidget *parent=nullptr)
void setAcFilename(QString acf)
void setBgFilename(QString bgf)
else error('Your technical computing program does not support file choosers.Please input the file name in the argument. ') end elseif nargin >0 logfile
void updateAttitude(int value)
void setVboEnable(bool eVbo)