Go to the documentation of this file.00001
00004
00005
00006
00007
00008 #include <qglv/opengl.hpp>
00009 #include <QGLViewer/qglviewer.h>
00010 #include "../../include/qglv/objects/teleport_arrow.hpp"
00011
00012
00013
00014
00015
00016 namespace qglv {
00017
00018
00019
00020
00021
00022
00023 TeleportArrow::~TeleportArrow() {}
00024
00025 void TeleportArrow::activate(bool mode) {
00026 teleport_mode_activated = mode;
00027 }
00028
00029 void TeleportArrow::checkIfGrabsMouse(int x, int y, const qglviewer::Camera* const camera) {
00030
00031
00032
00033 setGrabsMouse( teleport_mode_activated );
00034 }
00035
00036 void TeleportArrow::mousePressEvent( QMouseEvent* const event, qglviewer::Camera* const camera) {
00037 begin_point = _pointOnZPlane(event->pos(), camera);
00038 end_point = _pointOnZPlane(event->pos(), camera);
00039 moving = true;
00040 }
00041
00042 void TeleportArrow::mouseReleaseEvent(QMouseEvent* const event, qglviewer::Camera* const camera) {
00043 teleport_mode_activated = false;
00044 moving = false;
00045 emit deactivated();
00046 emit teleport(begin_point.x, begin_point.y, end_point.x, end_point.y);
00047 }
00048
00049 void TeleportArrow::mouseMoveEvent(QMouseEvent* const event, qglviewer::Camera* const camera)
00050 {
00051 if (moving) {
00052 end_point = _pointOnZPlane(event->pos(), camera);
00053 }
00054 }
00055
00056 qglviewer::Vec TeleportArrow::_pointOnZPlane(const QPoint& point, const qglviewer::Camera* camera) const {
00057 qglviewer::Vec origin, direction, point_under_pixel, point_on_z_plane;
00058 camera->convertClickToLine(point, origin, direction);
00059 bool found;
00060 point_under_pixel = camera->pointUnderPixel(point, found);
00061 float alpha = - origin.z / direction.z;
00062 point_on_z_plane.x = origin.x + alpha*direction.x;
00063 point_on_z_plane.y = origin.y + alpha*direction.y;
00064 point_on_z_plane.z = 0.0;
00065 return point_on_z_plane;
00066 }
00067 void TeleportArrow::mouseDoubleClickEvent(QMouseEvent* const event, qglviewer::Camera* const camera) {
00068 Q_UNUSED(event);
00069 Q_UNUSED(camera);
00070 std::cout << "Double click event"<< std::endl;
00071 }
00072 void TeleportArrow::wheelEvent(QWheelEvent* const event, qglviewer::Camera* const camera) {
00073 Q_UNUSED(event);
00074 Q_UNUSED(camera);
00075 std::cout << "Wheel event"<< std::endl;
00076 }
00077
00078 void TeleportArrow::draw()
00079 {
00080 if ( grabsMouse() ) {
00081 if (moving) {
00082 qreal radius = 0.02;
00083 qglv::colour(Green);
00084 QGLViewer::drawArrow(begin_point, end_point, radius, 30);
00085 }
00086 }
00087 }
00088
00089 }