24 #include "manipulatedCameraFrame.h"
25 #include "qglviewer.h"
27 #if QT_VERSION >= 0x040000
28 # include <QMouseEvent>
31 using namespace qglviewer;
40 : driveSpeed_(0.0), flyUpVector_(0.0, 1.0, 0.0)
45 connect(&flyTimer_, SIGNAL(timeout()), SLOT(flyUpdate()));
64 connect(&flyTimer_, SIGNAL(timeout()), SLOT(flyUpdate()));
81 void ManipulatedCameraFrame::flyUpdate()
83 static Vec flyDisp(0.0, 0.0, 0.0);
86 case QGLViewer::MOVE_FORWARD:
90 case QGLViewer::MOVE_BACKWARD:
94 case QGLViewer::DRIVE:
95 flyDisp.z =
flySpeed() * driveSpeed_;
110 void ManipulatedCameraFrame::updateFlyUpVector()
135 QDomElement mcp = document.createElement(
"ManipulatedCameraParameters");
136 mcp.setAttribute(
"flySpeed", QString::number(
flySpeed()));
153 QDomElement child=element.firstChild().toElement();
154 while (!child.isNull())
156 if (child.tagName() ==
"ManipulatedCameraParameters")
160 QDomElement schild=child.firstChild().toElement();
161 while (!schild.isNull())
163 if (schild.tagName() ==
"flyUpVector")
166 schild = schild.nextSibling().toElement();
169 child = child.nextSibling().toElement();
186 case QGLViewer::MOVE_FORWARD:
187 case QGLViewer::MOVE_BACKWARD:
188 case QGLViewer::DRIVE:
189 #if QT_VERSION >= 0x040000
190 flyTimer_.setSingleShot(
false);
209 case QGLViewer::TRANSLATE:
211 const QPoint delta = prevPos_ -
event->pos();
212 Vec trans(static_cast<float>(delta.x()), static_cast<float>(-delta.y()), 0.0);
214 switch (camera->
type())
216 case Camera::PERSPECTIVE :
220 case Camera::ORTHOGRAPHIC :
233 case QGLViewer::MOVE_FORWARD:
235 Quaternion rot = pitchYawQuaternion(event->x(),
event->y(), camera);
243 case QGLViewer::MOVE_BACKWARD:
245 Quaternion rot = pitchYawQuaternion(event->x(),
event->y(), camera);
252 case QGLViewer::DRIVE:
254 Quaternion rot = turnQuaternion(event->x(), camera);
257 driveSpeed_ = 0.01 * (
event->y() - pressPos_.y());
261 case QGLViewer::ZOOM:
265 Vec trans(0.0, 0.0, -coef * (event->y() - prevPos_.y()) / camera->
screenHeight());
270 case QGLViewer::LOOK_AROUND:
272 Quaternion rot = pitchYawQuaternion(event->x(),
event->y(), camera);
277 case QGLViewer::ROTATE:
288 case QGLViewer::SCREEN_ROTATE:
292 const float angle = atan2(event->y() - trans[1],
event->x() - trans[0]) - atan2(prevPos_.y()-trans[1], prevPos_.x()-trans[0]);
303 case QGLViewer::ROLL:
305 const float angle = M_PI * (
event->x() - prevPos_.x()) / camera->
screenWidth();
313 case QGLViewer::SCREEN_TRANSLATE:
318 trans.
setValue(static_cast<float>(prevPos_.x() -
event->x()), 0.0, 0.0);
320 trans.
setValue(0.0, static_cast<float>(event->y() - prevPos_.y()), 0.0);
322 switch (camera->
type())
324 case Camera::PERSPECTIVE :
328 case Camera::ORTHOGRAPHIC :
342 case QGLViewer::ZOOM_ON_REGION:
343 case QGLViewer::NO_MOUSE_ACTION:
347 if (action_ != QGLViewer::NO_MOUSE_ACTION)
349 prevPos_ =
event->pos();
350 if (action_ != QGLViewer::ZOOM_ON_REGION)
362 if ((action_ == QGLViewer::MOVE_FORWARD) || (action_ == QGLViewer::MOVE_BACKWARD) || (action_ == QGLViewer::DRIVE))
365 if (action_ == QGLViewer::ZOOM_ON_REGION)
382 case QGLViewer::ZOOM:
384 const float wheelSensitivityCoef = 8E-4f;
392 case QGLViewer::MOVE_FORWARD:
393 case QGLViewer::MOVE_BACKWARD:
403 if (previousConstraint_)
410 const int finalDrawAfterWheelEventDelay = 400;
413 #if QT_VERSION >= 0x040000
414 flyTimer_.setSingleShot(
true);
415 flyTimer_.start(finalDrawAfterWheelEventDelay);
417 flyTimer_.start(finalDrawAfterWheelEventDelay,
true);
423 action_ = QGLViewer::NO_MOUSE_ACTION;
429 Quaternion ManipulatedCameraFrame::turnQuaternion(
int x,
const Camera*
const camera)
436 Quaternion ManipulatedCameraFrame::pitchYawQuaternion(
int x,
int y,
const Camera*
const camera)