21
#include "PreCompiled.h"
23
#include <Base/Console.h>
24
#include <Inventor/SbLine.h>
25
#include <Inventor/SbPlane.h>
26
#include <Inventor/SoEventManager.h>
27
#include <Inventor/SoPickedPoint.h>
28
#include <Inventor/actions/SoHandleEventAction.h>
29
#include <Inventor/actions/SoRayPickAction.h>
30
#include <Inventor/actions/SoSearchAction.h>
31
#include <Inventor/events/SoEvents.h>
32
#include <Inventor/nodes/SoLocateHighlight.h>
33
#include <Inventor/nodes/SoOrthographicCamera.h>
34
#include <Inventor/nodes/SoPerspectiveCamera.h>
35
#include <Inventor/nodes/SoSeparator.h>
37
#if !defined(FC_OS_MACOSX)
43
#include "SoQTQuarterAdaptor.h"
47
static unsigned char fps2dfont[][12] = {
48
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
49
{ 0, 0, 12, 12, 0, 8, 12, 12, 12, 12, 12, 0 },
50
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 20, 20 },
51
{ 0, 0, 18, 18, 18, 63, 18, 18, 63, 18, 18, 0 },
52
{ 0, 8, 28, 42, 10, 10, 12, 24, 40, 42, 28, 8 },
53
{ 0, 0, 6, 73, 41, 22, 8, 52, 74, 73, 48, 0 },
54
{ 0, 12, 18, 18, 12, 25, 37, 34, 34, 29, 0, 0 },
55
{ 12, 12, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
56
{ 0, 6, 8, 8, 16, 16, 16, 16, 16, 8, 8, 6 },
57
{ 0, 48, 8, 8, 4, 4, 4, 4, 4, 8, 8, 48 },
58
{ 0, 0, 0, 0, 0, 0, 8, 42, 20, 42, 8, 0 },
59
{ 0, 0, 0, 8, 8, 8,127, 8, 8, 8, 0, 0 },
60
{ 0, 24, 12, 12, 0, 0, 0, 0, 0, 0, 0, 0 },
61
{ 0, 0, 0, 0, 0, 0,127, 0, 0, 0, 0, 0 },
62
{ 0, 0, 24, 24, 0, 0, 0, 0, 0, 0, 0, 0 },
63
{ 0, 32, 32, 16, 16, 8, 8, 8, 4, 4, 2, 2 },
64
{ 0, 0, 28, 34, 34, 34, 34, 34, 34, 34, 28, 0 },
65
{ 0, 0, 8, 8, 8, 8, 8, 8, 40, 24, 8, 0 },
66
{ 0, 0, 62, 32, 16, 8, 4, 2, 2, 34, 28, 0 },
67
{ 0, 0, 28, 34, 2, 2, 12, 2, 2, 34, 28, 0 },
68
{ 0, 0, 4, 4, 4,126, 68, 36, 20, 12, 4, 0 },
69
{ 0, 0, 28, 34, 2, 2, 2, 60, 32, 32, 62, 0 },
70
{ 0, 0, 28, 34, 34, 34, 60, 32, 32, 34, 28, 0 },
71
{ 0, 0, 16, 16, 16, 8, 8, 4, 2, 2, 62, 0 },
72
{ 0, 0, 28, 34, 34, 34, 28, 34, 34, 34, 28, 0 },
73
{ 0, 0, 28, 34, 2, 2, 30, 34, 34, 34, 28, 0 },
74
{ 0, 0, 24, 24, 0, 0, 0, 24, 24, 0, 0, 0 },
75
{ 0, 48, 24, 24, 0, 0, 0, 24, 24, 0, 0, 0 },
76
{ 0, 0, 0, 2, 4, 8, 16, 8, 4, 2, 0, 0 },
77
{ 0, 0, 0, 0, 0,127, 0,127, 0, 0, 0, 0 },
78
{ 0, 0, 0, 16, 8, 4, 2, 4, 8, 16, 0, 0 },
79
{ 0, 0, 16, 16, 0, 16, 28, 2, 2, 2, 60, 0 },
80
{ 0, 0, 28, 32, 73, 86, 82, 82, 78, 34, 28, 0 },
81
{ 0, 0, 33, 33, 33, 63, 18, 18, 18, 12, 12, 0 },
82
{ 0, 0, 60, 34, 34, 34, 60, 34, 34, 34, 60, 0 },
83
{ 0, 0, 14, 16, 32, 32, 32, 32, 32, 18, 14, 0 },
84
{ 0, 0, 56, 36, 34, 34, 34, 34, 34, 36, 56, 0 },
85
{ 0, 0, 62, 32, 32, 32, 60, 32, 32, 32, 62, 0 },
86
{ 0, 0, 16, 16, 16, 16, 30, 16, 16, 16, 30, 0 },
87
{ 0, 0, 14, 18, 34, 34, 32, 32, 32, 18, 14, 0 },
88
{ 0, 0, 34, 34, 34, 34, 62, 34, 34, 34, 34, 0 },
89
{ 0, 0, 62, 8, 8, 8, 8, 8, 8, 8, 62, 0 },
90
{ 0, 0,112, 8, 8, 8, 8, 8, 8, 8, 62, 0 },
91
{ 0, 0, 33, 33, 34, 36, 56, 40, 36, 34, 33, 0 },
92
{ 0, 0, 30, 16, 16, 16, 16, 16, 16, 16, 16, 0 },
93
{ 0, 0, 33, 33, 33, 45, 45, 45, 51, 51, 33, 0 },
94
{ 0, 0, 34, 34, 38, 38, 42, 42, 50, 50, 34, 0 },
95
{ 0, 0, 12, 18, 33, 33, 33, 33, 33, 18, 12, 0 },
96
{ 0, 0, 32, 32, 32, 60, 34, 34, 34, 34, 60, 0 },
97
{ 3, 6, 12, 18, 33, 33, 33, 33, 33, 18, 12, 0 },
98
{ 0, 0, 34, 34, 34, 36, 60, 34, 34, 34, 60, 0 },
99
{ 0, 0, 60, 2, 2, 6, 28, 48, 32, 32, 30, 0 },
100
{ 0, 0, 8, 8, 8, 8, 8, 8, 8, 8,127, 0 },
101
{ 0, 0, 28, 34, 34, 34, 34, 34, 34, 34, 34, 0 },
102
{ 0, 0, 12, 12, 18, 18, 18, 33, 33, 33, 33, 0 },
103
{ 0, 0, 34, 34, 34, 54, 85, 73, 73, 73, 65, 0 },
104
{ 0, 0, 34, 34, 20, 20, 8, 20, 20, 34, 34, 0 },
105
{ 0, 0, 8, 8, 8, 8, 20, 20, 34, 34, 34, 0 },
106
{ 0, 0, 62, 32, 16, 16, 8, 4, 4, 2, 62, 0 },
107
{ 0, 14, 8, 8, 8, 8, 8, 8, 8, 8, 8, 14 },
108
{ 0, 2, 2, 4, 4, 8, 8, 8, 16, 16, 32, 32 },
109
{ 0, 56, 8, 8, 8, 8, 8, 8, 8, 8, 8, 56 },
110
{ 0, 0, 0, 0, 0, 34, 34, 20, 20, 8, 8, 0 },
111
{ 0,127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
112
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 24, 12 },
113
{ 0, 0, 29, 34, 34, 30, 2, 34, 28, 0, 0, 0 },
114
{ 0, 0, 60, 34, 34, 34, 34, 50, 44, 32, 32, 32 },
115
{ 0, 0, 14, 16, 32, 32, 32, 16, 14, 0, 0, 0 },
116
{ 0, 0, 26, 38, 34, 34, 34, 34, 30, 2, 2, 2 },
117
{ 0, 0, 28, 34, 32, 62, 34, 34, 28, 0, 0, 0 },
118
{ 0, 0, 16, 16, 16, 16, 16, 16, 62, 16, 16, 14 },
119
{ 28, 2, 2, 26, 38, 34, 34, 34, 30, 0, 0, 0 },
120
{ 0, 0, 34, 34, 34, 34, 34, 50, 44, 32, 32, 32 },
121
{ 0, 0, 8, 8, 8, 8, 8, 8, 56, 0, 8, 8 },
122
{ 56, 4, 4, 4, 4, 4, 4, 4, 60, 0, 4, 4 },
123
{ 0, 0, 33, 34, 36, 56, 40, 36, 34, 32, 32, 32 },
124
{ 0, 0, 8, 8, 8, 8, 8, 8, 8, 8, 8, 56 },
125
{ 0, 0, 73, 73, 73, 73, 73,109, 82, 0, 0, 0 },
126
{ 0, 0, 34, 34, 34, 34, 34, 50, 44, 0, 0, 0 },
127
{ 0, 0, 28, 34, 34, 34, 34, 34, 28, 0, 0, 0 },
128
{ 32, 32, 60, 34, 34, 34, 34, 50, 44, 0, 0, 0 },
129
{ 2, 2, 26, 38, 34, 34, 34, 34, 30, 0, 0, 0 },
130
{ 0, 0, 16, 16, 16, 16, 16, 24, 22, 0, 0, 0 },
131
{ 0, 0, 60, 2, 2, 28, 32, 32, 30, 0, 0, 0 },
132
{ 0, 0, 14, 16, 16, 16, 16, 16, 62, 16, 16, 0 },
133
{ 0, 0, 26, 38, 34, 34, 34, 34, 34, 0, 0, 0 },
134
{ 0, 0, 8, 8, 20, 20, 34, 34, 34, 0, 0, 0 },
135
{ 0, 0, 34, 34, 34, 85, 73, 73, 65, 0, 0, 0 },
136
{ 0, 0, 34, 34, 20, 8, 20, 34, 34, 0, 0, 0 },
137
{ 48, 16, 8, 8, 20, 20, 34, 34, 34, 0, 0, 0 },
138
{ 0, 0, 62, 32, 16, 8, 4, 2, 62, 0, 0, 0 },
139
{ 0, 6, 8, 8, 8, 4, 24, 4, 8, 8, 8, 6 },
140
{ 0, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 },
141
{ 0, 48, 8, 8, 8, 16, 12, 16, 8, 8, 8, 48 },
142
{ 0, 0, 0, 0, 0, 0, 78, 57, 0, 0, 0, 0 }
147
constexpr const int defaultSize = 100;
150
SIM::Coin3D::Quarter::SoQTQuarterAdaptor::SoQTQuarterAdaptor(QWidget* parent,
151
const QtGLWidget* sharewidget,
152
Qt::WindowFlags flags)
153
: QuarterWidget(parent, sharewidget, flags)
154
, matrixaction(SbViewportRegion(defaultSize, defaultSize))
159
SIM::Coin3D::Quarter::SoQTQuarterAdaptor::SoQTQuarterAdaptor(const QtGLFormat& format,
161
const QtGLWidget* shareWidget,
162
Qt::WindowFlags flags)
163
: QuarterWidget(format, parent, shareWidget, flags)
164
, matrixaction(SbViewportRegion(defaultSize, defaultSize))
169
SIM::Coin3D::Quarter::SoQTQuarterAdaptor::SoQTQuarterAdaptor(QtGLContext* context,
171
const QtGLWidget* sharewidget,
172
Qt::WindowFlags flags)
173
: QuarterWidget(context, parent, sharewidget, flags)
174
, matrixaction(SbViewportRegion(defaultSize, defaultSize))
179
SIM::Coin3D::Quarter::SoQTQuarterAdaptor::~SoQTQuarterAdaptor()
184
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::init()
187
m_interactionnesting = 0;
188
m_seekdistance = 50.0F;
189
m_seekdistanceabs = false;
191
m_inseekmode = false;
192
m_storedcamera = nullptr;
193
m_viewingflag = false;
196
m_seeksensor = new SoTimerSensor(SoQTQuarterAdaptor::seeksensorCB, (void*)this);
197
getSoEventManager()->setNavigationState(SoEventManager::NO_NAVIGATION);
204
QWidget* SIM::Coin3D::Quarter::SoQTQuarterAdaptor::getWidget()
211
QWidget* SIM::Coin3D::Quarter::SoQTQuarterAdaptor::getGLWidget()
216
QWidget* SIM::Coin3D::Quarter::SoQTQuarterAdaptor::getWidget() const
220
return const_cast<SoQTQuarterAdaptor*>(this);
223
QWidget* SIM::Coin3D::Quarter::SoQTQuarterAdaptor::getGLWidget() const
228
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::setCameraType(SoType type)
230
SoCamera* cam = getSoRenderManager()->getCamera();
231
if (cam && !cam->isOfType(SoPerspectiveCamera::getClassTypeId()) &&
232
!cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
233
Base::Console().Warning("Quarter::setCameraType",
234
"Only SoPerspectiveCamera and SoOrthographicCamera is supported.");
239
SoType perspectivetype = SoPerspectiveCamera::getClassTypeId();
240
SbBool oldisperspective = cam ? cam->getTypeId().isDerivedFrom(perspectivetype) : false;
241
SbBool newisperspective = type.isDerivedFrom(perspectivetype);
244
if (oldisperspective == newisperspective) {
248
SoCamera* currentcam = getSoRenderManager()->getCamera();
249
SoCamera* newcamera = static_cast<SoCamera*>(type.createInstance());
252
if(newisperspective) {
253
convertOrtho2Perspective(dynamic_cast<SoOrthographicCamera*>(currentcam),
254
dynamic_cast<SoPerspectiveCamera*>(newcamera));
257
convertPerspective2Ortho(dynamic_cast<SoPerspectiveCamera*>(currentcam),
258
dynamic_cast<SoOrthographicCamera*>(newcamera));
261
getSoRenderManager()->setCamera(newcamera);
262
getSoEventManager()->setCamera(newcamera);
265
auto superscene = dynamic_cast<SoSeparator*>(getSoRenderManager()->getSceneGraph());
267
sa.setInterest(SoSearchAction::FIRST);
268
sa.setType(SoCamera::getClassTypeId());
269
sa.apply(superscene);
272
SoNode* node = sa.getPath()->getTail();
273
SoGroup* parent = static_cast<SoGroup*>(sa.getPath()->getNodeFromTail(1));
275
if (node && node->isOfType(SoCamera::getClassTypeId())) {
276
parent->replaceChild(node, newcamera);
281
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::convertOrtho2Perspective(const SoOrthographicCamera* in,
282
SoPerspectiveCamera* out)
285
Base::Console().Log("Quarter::convertOrtho2Perspective",
286
"Cannot convert camera settings due to wrong input.");
289
out->aspectRatio.setValue(in->aspectRatio.getValue());
290
out->focalDistance.setValue(in->focalDistance.getValue());
291
out->orientation.setValue(in->orientation.getValue());
292
out->position.setValue(in->position.getValue());
293
out->viewportMapping.setValue(in->viewportMapping.getValue());
295
SbRotation camrot = in->orientation.getValue();
297
float focaldist = float(in->height.getValue() / (2.0*tan(M_PI / 8.0)));
299
SbVec3f offset(0,0,focaldist-in->focalDistance.getValue());
301
camrot.multVec(offset,offset);
302
out->position.setValue(offset+in->position.getValue());
304
out->focalDistance.setValue(focaldist);
307
out->heightAngle = (float)(M_PI / 4.0);
310
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::convertPerspective2Ortho(const SoPerspectiveCamera* in,
311
SoOrthographicCamera* out)
313
out->aspectRatio.setValue(in->aspectRatio.getValue());
314
out->focalDistance.setValue(in->focalDistance.getValue());
315
out->orientation.setValue(in->orientation.getValue());
316
out->position.setValue(in->position.getValue());
317
out->viewportMapping.setValue(in->viewportMapping.getValue());
319
float focaldist = in->focalDistance.getValue();
321
out->height = 2.0F * focaldist * (float)tan(in->heightAngle.getValue() / 2.0);
324
SoCamera* SIM::Coin3D::Quarter::SoQTQuarterAdaptor::getCamera() const
326
return getSoRenderManager()->getCamera();
329
const SbViewportRegion & SIM::Coin3D::Quarter::SoQTQuarterAdaptor::getViewportRegion() const
331
return getSoRenderManager()->getViewportRegion();
334
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::setViewing(bool enable)
336
m_viewingflag = enable;
341
SoGLRenderAction* action = getSoRenderManager()->getGLRenderAction();
344
SoLocateHighlight::turnOffCurrentHighlight(action);
349
bool SIM::Coin3D::Quarter::SoQTQuarterAdaptor::isViewing() const
351
return m_viewingflag;
354
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::interactiveCountInc()
357
assert(m_interactionnesting < 100);
359
if (++m_interactionnesting == 1) {
360
m_interactionStartCallback.invokeCallbacks(this);
364
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::interactiveCountDec()
366
if (--m_interactionnesting <= 0) {
367
m_interactionEndCallback.invokeCallbacks(this);
368
m_interactionnesting = 0;
372
int SIM::Coin3D::Quarter::SoQTQuarterAdaptor::getInteractiveCount() const
374
return m_interactionnesting;
378
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::addStartCallback(SIM::Coin3D::Quarter::SoQTQuarterAdaptorCB* func, void* data)
380
m_interactionStartCallback.addCallback((SoCallbackListCB*)func, data);
383
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::removeStartCallback(SIM::Coin3D::Quarter::SoQTQuarterAdaptorCB* func, void* data)
385
m_interactionStartCallback.removeCallback((SoCallbackListCB*)func, data);
388
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::addFinishCallback(SIM::Coin3D::Quarter::SoQTQuarterAdaptorCB* func, void* data)
390
m_interactionEndCallback.addCallback((SoCallbackListCB*)func, data);
393
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::removeFinishCallback(SIM::Coin3D::Quarter::SoQTQuarterAdaptorCB* func, void* data)
395
m_interactionEndCallback.removeCallback((SoCallbackListCB*)func, data);
399
float SIM::Coin3D::Quarter::SoQTQuarterAdaptor::getSeekDistance() const
401
return m_seekdistance;
404
float SIM::Coin3D::Quarter::SoQTQuarterAdaptor::getSeekTime() const
409
bool SIM::Coin3D::Quarter::SoQTQuarterAdaptor::isSeekMode() const
414
bool SIM::Coin3D::Quarter::SoQTQuarterAdaptor::isSeekValuePercentage() const
416
return !m_seekdistanceabs;
419
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::setPickRadius(float pickRadius)
421
this->pickRadius = pickRadius;
422
SoEventManager* evm = this->getSoEventManager();
424
SoHandleEventAction* hea = evm->getHandleEventAction();
426
hea->setPickRadius(pickRadius);
431
bool SIM::Coin3D::Quarter::SoQTQuarterAdaptor::seekToPoint(const SbVec2s& screenpos)
434
SoRayPickAction rpaction(getSoRenderManager()->getViewportRegion());
435
rpaction.setPoint(screenpos);
436
rpaction.setRadius(pickRadius);
437
rpaction.apply(getSoRenderManager()->getSceneGraph());
439
SoPickedPoint* picked = rpaction.getPickedPoint();
442
this->interactiveCountInc();
443
this->setSeekMode(false);
448
hitpoint = picked->getPoint();
450
this->seekToPoint(hitpoint);
454
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::seekToPoint(const SbVec3f& scenepos)
456
SbVec3f hitpoint(scenepos);
458
m_camerastartposition = getSoRenderManager()->getCamera()->position.getValue();
459
m_camerastartorient = getSoRenderManager()->getCamera()->orientation.getValue();
463
SbMatrix cameramatrix;
464
SbMatrix camerainverse;
465
getCameraCoordinateSystem(getSoRenderManager()->getCamera(),
469
camerainverse.multVecMatrix(hitpoint, hitpoint);
471
float fd = m_seekdistance;
473
if(!m_seekdistanceabs) {
474
fd *= (hitpoint - getSoRenderManager()->getCamera()->position.getValue()).length()/100.0F;
477
getSoRenderManager()->getCamera()->focalDistance = fd;
479
SbVec3f dir = hitpoint - m_camerastartposition;
485
getSoRenderManager()->getCamera()->orientation.getValue().multVec(SbVec3f(0, 0, -1), olddir);
486
SbRotation diffrot(olddir, dir);
487
m_cameraendposition = hitpoint - fd * dir;
488
m_cameraendorient = getSoRenderManager()->getCamera()->orientation.getValue() * diffrot;
490
if(m_seeksensor->isScheduled()) {
491
m_seeksensor->unschedule();
492
interactiveCountDec();
495
m_seeksensor->setBaseTime(SbTime::getTimeOfDay());
496
m_seeksensor->schedule();
497
interactiveCountInc();
500
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::setSeekDistance(const float distance)
502
m_seekdistance = distance;
505
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::setSeekMode(bool enable)
507
if(!enable && m_seeksensor->isScheduled()) {
508
m_seeksensor->unschedule();
509
interactiveCountDec();
512
m_inseekmode = enable;
515
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::setSeekTime(const float seconds)
517
m_seekperiod = seconds;
520
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::setSeekValueAsPercentage(bool on)
522
m_seekdistanceabs = !on;
525
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::getCameraCoordinateSystem(SoCamera* camera,
530
searchaction.reset();
531
searchaction.setSearchingAll(true);
532
searchaction.setInterest(SoSearchAction::FIRST);
533
searchaction.setNode(camera);
534
searchaction.apply(root);
536
matrix = inverse = SbMatrix::identity();
538
if(searchaction.getPath()) {
539
matrixaction.apply(searchaction.getPath());
540
matrix = matrixaction.getMatrix();
541
inverse = matrixaction.getInverse();
544
searchaction.reset();
547
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::seeksensorCB(void* data, SoSensor* sensor)
549
SoQTQuarterAdaptor* thisp = static_cast<SoQTQuarterAdaptor*>(data);
550
SbTime currenttime = SbTime::getTimeOfDay();
552
SoTimerSensor* timer = static_cast<SoTimerSensor*>(sensor);
554
float par = float((currenttime - timer->getBaseTime()).getValue()) / thisp->m_seekperiod;
556
if ((par > 1.0F) || (par + timer->getInterval().getValue() > 1.0F)) {
560
bool end = (par == 1.0F);
562
par = (float)((1.0 - cos(M_PI * par)) * 0.5);
564
thisp->getSoRenderManager()->getCamera()->position = thisp->m_camerastartposition +
565
(thisp->m_cameraendposition - thisp->m_camerastartposition) * par;
566
thisp->getSoRenderManager()->getCamera()->orientation =
567
SbRotation::slerp(thisp->m_camerastartorient,
568
thisp->m_cameraendorient,
572
thisp->setSeekMode(false);
576
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::saveHomePosition()
578
SoCamera* cam = getSoRenderManager()->getCamera();
583
SoType type = cam->getTypeId();
584
assert(type.isDerivedFrom(SoNode::getClassTypeId()));
585
assert(type.canCreateInstance());
588
m_storedcamera->unref();
591
m_storedcamera = static_cast<SoNode*>(type.createInstance());
592
m_storedcamera->ref();
594
m_storedcamera->copyFieldValues(getSoRenderManager()->getCamera());
597
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::resetToHomePosition()
599
SoCamera* cam = getSoRenderManager()->getCamera();
604
if(!m_storedcamera) {
608
SoType ttype = getSoRenderManager()->getCamera()->getTypeId();
609
SoType stype = m_storedcamera->getTypeId();
612
if (ttype == stype) {
616
getSoRenderManager()->getCamera()->copyFieldValues(m_storedcamera);
619
else if(ttype == SoOrthographicCamera::getClassTypeId() &&
620
stype == SoPerspectiveCamera::getClassTypeId()) {
621
convertPerspective2Ortho(dynamic_cast<SoPerspectiveCamera*>(m_storedcamera),
622
dynamic_cast<SoOrthographicCamera*>(getSoRenderManager()->getCamera()));
625
else if(ttype == SoPerspectiveCamera::getClassTypeId() &&
626
stype == SoOrthographicCamera::getClassTypeId()) {
627
convertOrtho2Perspective(dynamic_cast<SoOrthographicCamera*>(m_storedcamera),
628
dynamic_cast<SoPerspectiveCamera*>(getSoRenderManager()->getCamera()));
638
SIM::Coin3D::Quarter::SoQTQuarterAdaptor::draw2DString(const char* str,
643
glPushAttrib(GL_ENABLE_BIT|GL_CURRENT_BIT);
645
glDisable(GL_LIGHTING);
646
glDisable(GL_DEPTH_TEST);
647
glDisable(GL_TEXTURE_2D);
650
glMatrixMode(GL_MODELVIEW);
654
glMatrixMode(GL_PROJECTION);
657
glOrtho(0.0, glsize[0], 0.0, glsize[1], -1, 1);
659
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
671
glColor3f(1.0, 1.0, 0.0);
672
glRasterPos2f(position[0], position[1]);
675
glMatrixMode(GL_PROJECTION);
677
glMatrixMode(GL_MODELVIEW);
680
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
685
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::printString(const char* str)
688
std::size_t len = strlen(str);
690
for(std::size_t i = 0; i < len; i++) {
691
glBitmap(8, 12, 0.0, 2.0, 10.0, 0.0, fps2dfont[str[i] - 32]);
696
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::moveCameraScreen(const SbVec2f& screenpos)
698
SoCamera* cam = getSoRenderManager()->getCamera();
702
SbViewVolume vv = cam->getViewVolume(getGLWidget()->width() / getGLWidget()->height());
703
SbPlane panplane = vv.getPlane(cam->focalDistance.getValue());
705
constexpr const float mid = 0.5F;
707
vv.projectPointToLine(screenpos + SbVec2f(mid, mid), line);
708
SbVec3f current_planept;
709
panplane.intersect(line, current_planept);
710
vv.projectPointToLine(SbVec2f(mid, mid), line);
712
panplane.intersect(line, old_planept);
716
cam->position = cam->position.getValue() - (current_planept - old_planept);
719
bool SIM::Coin3D::Quarter::SoQTQuarterAdaptor::processSoEvent(const SoEvent* event)
721
const SoType type(event->getTypeId());
723
constexpr const float delta = 0.1F;
724
if(type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
725
const SoKeyboardEvent* keyevent = static_cast<const SoKeyboardEvent*>(event);
727
if(keyevent->getState() == SoButtonEvent::DOWN) {
728
switch(keyevent->getKey()) {
730
case SoKeyboardEvent::LEFT_ARROW:
731
moveCameraScreen(SbVec2f(-delta, 0.0F));
734
case SoKeyboardEvent::UP_ARROW:
735
moveCameraScreen(SbVec2f(0.0F, delta));
738
case SoKeyboardEvent::RIGHT_ARROW:
739
moveCameraScreen(SbVec2f(delta, 0.0F));
742
case SoKeyboardEvent::DOWN_ARROW:
743
moveCameraScreen(SbVec2f(0.0F, -delta));
752
return SIM::Coin3D::Quarter::QuarterWidget::processSoEvent(event);
758
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::paintEvent(QPaintEvent* event)
760
double start = SbTime::getTimeOfDay().getValue();
761
QuarterWidget::paintEvent(event);
762
this->framesPerSecond = addFrametime(start);
765
void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::resetFrameCounter()
767
this->framecount = 0;
768
this->frametime = 0.0F;
769
this->drawtime = 0.0F;
770
this->starttime = SbTime::getTimeOfDay().getValue();
771
this->framesPerSecond = SbVec2f(0, 0);
774
SbVec2f SIM::Coin3D::Quarter::SoQTQuarterAdaptor::addFrametime(double starttime)
776
constexpr const double FPS_FACTOR = 0.7;
777
constexpr const double FIVE_SECS = 5000.0;
778
constexpr const float ONE_SEC = 1000.0F;
782
double timeofday = SbTime::getTimeOfDay().getValue();
785
double drawtime = timeofday - starttime;
786
this->drawtime = (drawtime*FPS_FACTOR) + this->drawtime*(1.0 - FPS_FACTOR);
791
double frametime = std::min(timeofday-this->starttime, std::max(drawtime, FIVE_SECS));
792
this->frametime = (frametime*FPS_FACTOR) + this->frametime*(1.0 - FPS_FACTOR);
794
this->starttime = timeofday;
795
return {ONE_SEC * float(this->drawtime), 1.0F / float(this->frametime)};
799
#include "moc_SoQTQuarterAdaptor.cpp"