57 #include "TrackballNode.hh" 58 #include <ACG/GL/GLPrimitives.hh> 81 glScalef(radius_, radius_, radius_);
84 glGetIntegerv(GL_POLYGON_MODE,previous);
85 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
87 sphere.draw_primitive();
88 glPolygonMode(GL_FRONT,previous[0]);
89 glPolygonMode(GL_BACK,previous[1]);
98 GLfloat backupColor[4], backupLineWidth;
99 glGetFloatv(GL_CURRENT_COLOR, backupColor);
100 glGetFloatv(GL_LINE_WIDTH, &backupLineWidth);
106 glColor3f(1.0, 0.0, 0.0);
112 glColor3f(0.0, 1.0, 0.0);
118 glColor3f(0.0, 0.0, 1.0);
125 glColor4fv(backupColor);
126 glLineWidth(backupLineWidth);
138 Vec2i newPoint2D(_event->pos().x(), _event->pos().y());
142 switch (_event->type())
144 case QEvent::MouseButtonPress:
150 case QEvent::MouseButtonDblClick:
155 if (_event->button() == Qt::LeftButton)
156 drawTrackball_ = !drawTrackball_;
159 if (_event->button() == Qt::MidButton)
160 drawAxes_ = !drawAxes_;
166 case QEvent::MouseMove:
168 bool hit0 =
mapToSphere(_state, newPoint2D, newPoint3D);
169 bool hit1 =
mapToSphere(_state, oldPoint2D_, oldPoint3D);
175 if ((_event->button() & Qt::LeftButton) &&
176 (_event->button() & Qt::MidButton))
178 double s = 1.0 + ((double) (newPoint2D[1] - oldPoint2D_[1]) /
185 else if (_event->button() & Qt::MidButton)
187 double value_x = (radius_ * ((newPoint2D[0] - oldPoint2D_[0]))
190 double value_y = (radius_ * ((newPoint2D[1] - oldPoint2D_[1]))
224 else if (_event->button() & Qt::LeftButton)
226 Vec3d axis = oldPoint3D % newPoint3D;
227 double cos_angle = ( oldPoint3D | newPoint3D );
230 if (fabs(cos_angle) < 1.0)
233 if (_event->modifiers() & Qt::AltModifier)
238 mat.
rotate(acos(cos_angle)*180.0/M_PI, axis);
249 else rotate(acos(cos_angle)*180.0/M_PI, axis);
264 oldPoint2D_ = newPoint2D;
277 unsigned int x = _v2[0];
282 Vec3d origin, direction;
293 double a = direction.
sqrnorm(),
294 b = 2.0 * (origin | direction),
299 if (d < 0.0)
return false;
300 else if (d == 0.0) t = -b / (2.0*a);
306 double t1 = (-b - d) * a;
307 double t2 = (-b + d) * a;
308 t = (t1 < t2) ? t1 : t2;
311 _v3 = origin + direction*t;
Namespace providing different geometric functions concerning angles.
Vec3d right() const
get right-vector w.r.t. camera coordinates
void translate(const Vec3d &_v)
Add a translation to the current Transformation.
decltype(std::declval< S >() *std::declval< S >()) sqrnorm() const
compute squared euclidean norm
int context_height() const
get gl context height
const GLMatrixd & scale() const
return scale matrix
int viewport_width() const
get viewport width
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM >>().norm())
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
VectorT< T, 3 > transform_point(const VectorT< T, 3 > &_v) const
transform point (x',y',z',1) = M * (x,y,z,1)
void rotate(double _angle, const Vec3d &_axis)
void transpose()
transpose matrix
void glVertex(const Vec2i &_v)
Wrapper: glVertex for Vec2i.
Vec3d up() const
get up-vector w.r.t. camera coordinates
bool mapToSphere(GLState &_state, const Vec2i &_v2, Vec3d &_v3)
Map 2D-screen-coords to trackball.
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode)
Draw the trackball + axes (if enabled)
const GLMatrixd & inverse_matrix() const
return inverse matrix
static void shadeModel(GLenum _mode)
replaces glShadeModel, supports locking
int viewport_height() const
get viewport height
void viewing_ray(int _x, int _y, Vec3d &_origin, Vec3d &_direction) const
void identity()
setup an identity matrix
virtual void mouseEvent(GLState &_state, QMouseEvent *_event)
get mouse events
void rotate(Scalar angle, Scalar x, Scalar y, Scalar z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
VectorT< T, 3 > transform_vector(const VectorT< T, 3 > &_v) const
transform vector (x',y',z',0) = A * (x,y,z,0)
const Vec3d & center() const
get center