63 #include "TrackballNode.hh" 86 glutWireSphere(radius_, 20, 20);
95 GLfloat backupColor[4], backupLineWidth;
96 glGetFloatv(GL_CURRENT_COLOR, backupColor);
97 glGetFloatv(GL_LINE_WIDTH, &backupLineWidth);
103 glColor3f(1.0, 0.0, 0.0);
109 glColor3f(0.0, 1.0, 0.0);
115 glColor3f(0.0, 0.0, 1.0);
122 glColor4fv(backupColor);
123 glLineWidth(backupLineWidth);
135 Vec2i newPoint2D(_event->pos().x(), _event->pos().y());
139 switch (_event->type())
141 case QEvent::MouseButtonPress:
147 case QEvent::MouseButtonDblClick:
152 if (_event->button() == Qt::LeftButton)
153 drawTrackball_ = !drawTrackball_;
156 if (_event->button() == Qt::MidButton)
157 drawAxes_ = !drawAxes_;
163 case QEvent::MouseMove:
165 bool hit0 =
mapToSphere(_state, newPoint2D, newPoint3D);
166 bool hit1 =
mapToSphere(_state, oldPoint2D_, oldPoint3D);
172 if ((_event->button() & Qt::LeftButton) &&
173 (_event->button() & Qt::MidButton))
175 double s = 1.0 + ((double) (newPoint2D[1] - oldPoint2D_[1]) /
182 else if (_event->button() & Qt::MidButton)
184 double value_x = (radius_ * ((newPoint2D[0] - oldPoint2D_[0]))
187 double value_y = (radius_ * ((newPoint2D[1] - oldPoint2D_[1]))
221 else if (_event->button() & Qt::LeftButton)
223 Vec3d axis = oldPoint3D % newPoint3D;
224 double cos_angle = ( oldPoint3D | newPoint3D );
227 if (fabs(cos_angle) < 1.0)
230 if (_event->modifiers() & Qt::AltModifier)
235 mat.
rotate(acos(cos_angle)*180.0/M_PI, axis);
246 else rotate(acos(cos_angle)*180.0/M_PI, axis);
261 oldPoint2D_ = newPoint2D;
274 unsigned int x = _v2[0];
279 Vec3d origin, direction;
290 double a = direction.
sqrnorm(),
291 b = 2.0 * (origin | direction),
296 if (d < 0.0)
return false;
297 else if (d == 0.0) t = -b / (2.0*a);
303 double t1 = (-b - d) * a;
304 double t2 = (-b + d) * a;
305 t = (t1 < t2) ? t1 : t2;
308 _v3 = origin + direction*t;
void transpose()
transpose matrix
VectorT< T, 3 > transform_point(const VectorT< T, 3 > &_v) const
transform point (x',y',z',1) = M * (x,y,z,1)
int context_height() const
get gl context height
void viewing_ray(int _x, int _y, Vec3d &_origin, Vec3d &_direction) const
bool mapToSphere(GLState &_state, const Vec2i &_v2, Vec3d &_v3)
Map 2D-screen-coords to trackball.
int viewport_width() const
get viewport width
void glVertex(const Vec2i &_v)
Wrapper: glVertex for Vec2i.
void rotate(Scalar angle, Scalar x, Scalar y, Scalar z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
Vec3d up() const
get up-vector w.r.t. camera coordinates
void identity()
setup an identity matrix
const Vec3d & center() const
get center
const GLMatrixd & scale() const
return scale matrix
static void disable(GLenum _cap)
replaces glDisable, but supports locking
Namespace providing different geometric functions concerning angles.
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM >>().norm())
decltype(std::declval< S >()*std::declval< S >()) sqrnorm() const
compute squared euclidean norm
void rotate(double _angle, const Vec3d &_axis)
void translate(const Vec3d &_v)
Add a translation to the current Transformation.
const GLMatrixd & inverse_matrix() const
return inverse matrix
int viewport_height() const
get viewport height
Vec3d right() const
get right-vector w.r.t. camera coordinates
virtual void mouseEvent(GLState &_state, QMouseEvent *_event)
get mouse events
VectorT< T, 3 > transform_vector(const VectorT< T, 3 > &_v) const
transform vector (x',y',z',0) = A * (x,y,z,0)
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode)
Draw the trackball + axes (if enabled)
static void shadeModel(GLenum _mode)
replaces glShadeModel, supports locking