1 #include "TrackballControl.hh"
3 #include <Base/Math/Vector3.hh>
4 #include <Gui/biasgl.h>
15 controlledObject_=NULL;
17 UseLeftDouble_ =
true;
26 MoveInViewingDirection(-Stepsize_);
31 MoveInViewingDirection(Stepsize_);
44 MoveInViewingDirection(stepsize);
53 controlledObject_->GetExtrinsics(C,R);
58 PointOfInterest_.
Sub(C, direction);
59 distance = direction.
NormL2();
60 if (
Equal(distance, 0.0)){
66 double nearClippingPlane = 0;
67 nearClippingPlane = controlledObject_->GetNearClippingPlane();
68 if(distance > (nearClippingPlane+stepsize) ) {
69 direction.
Multiply(stepsize, direction);
71 direction.
Multiply(nearClippingPlane-distance, direction);
82 controlledObject_->GetExtrinsics(C, up);
88 C.
Sub(PointOfInterest_, direction);
89 rotation.
MultVec(direction, direction);
91 direction.
Add(PointOfInterest_, C);
93 controlledObject_->SetExtrinsics(C, PointOfInterest_, up);
103 glGetIntegerv(GL_VIEWPORT, viewport);
109 double width = viewport[2];
110 double height = viewport[3];
114 controlledObject_->GetExtrinsics(C, up);
115 R = controlledObject_->GetMyselfAsProjectionParameterBase()->GetR();
119 double x = x1 / width * 2.0;
120 double y = y1 / height * 2.0;
125 double z = sqrt(2.0) - x * x - y * y;
139 x = x2 / width * 2.0;
140 y = y2 / height * 2.0;
145 z = sqrt(2.0) - x * x - y * y;
163 double angleRAD = acos(v1.ScalarProduct(v2));
165 RotateAroundPOI(axis, angleRAD);
172 if (! UseLeftDouble_) {
177 if(!controlledObject_->GetViewportCoordinates(x, y)) {
178 BIASERR(
"outside used viewport!");
184 if (homgPoint[3] != 0.0)
187 SetPointOfInterest(poi);
210 controlledObject_->GetExtrinsics(C, up);
214 PointOfInterest_.Sub(C, localPOI);
217 double poiDepth = localPOI.
Length();
221 HomgPoint2D projectedPOI = controlledObject_->Project(tmp);
224 projectedPOI[0] += (x1 - x2);
225 projectedPOI[1] += (y1 - y2);
226 projectedPOI[2] = 1.;
229 tmp = controlledObject_->UnProject(projectedPOI, poiDepth);
231 PointOfInterest_[0] = tmp[0]; PointOfInterest_[1] = tmp[1]; PointOfInterest_[2] = tmp[2];
233 PointOfInterest_.
Sub(localPOI, C);
235 controlledObject_->SetExtrinsics(C, PointOfInterest_, up);
297 controlledObject_->GetExtrinsics(C, up);
299 rotationAxis = PointOfInterest_ - C;
300 if(rotationAxis.
NormL2() == 0.0){
301 BIASERR(
"point of interest equals camera center\n");
303 R = controlledObject_->GetMyselfAsProjectionParameterBase()->GetR();
304 for(
unsigned int i=0; i<3; i++)
305 rotationAxis[i] = R[i][2];
313 controlledObject_->SetExtrinsics(C,
327 glGetIntegerv(GL_VIEWPORT, viewport);
328 int width = viewport[2];
329 int height = viewport[3];
332 controlledObject_->GetExtrinsics(C, up);
334 viewingDirection = PointOfInterest_ - C;
353 rotationAngle *= -1.0;
355 RotateAroundViewingDirection(rotationAngle);
363 PointOfInterest_ = poi;
365 if(controlledObject_==NULL)
return;
368 if (controlledObject_->PoseValid()){
369 controlledObject_->GetExtrinsics(C,up);
371 BIASERR(
"TrackballControl: PoseInvalid");
376 Stepsize_ = 0.05*dist.
NormL2();
378 controlledObject_->SetExtrinsics(C,poi,up);
387 if (controlledObject_){
390 controlledObject_->GetExtrinsics(oldC, oldR);
392 dist = (oldC-oldPOI).NormL2();
397 if (controlledObject_->PoseValid()){
398 controlledObject_->GetExtrinsics(C,R);
400 BIASERR(
"TrackballControl: PoseInvalid, using identity!");
401 C[0]=0;C[1]=0;C[2]=0;
405 A[0] = R[0][2]; A[1] = R[1][2]; A[2] = R[2][2];
407 SetPointOfInterest(C+A);
void Sub(const T &scalar, Vector4< T > &dest) const
Substraction with a scalar, storing results in destionation vector.
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
double Length() const
returns the Euclidean Length of the Vector
virtual bool LeftMouseDoubleClicked(int x, int y, int m)
Computes from the coordinates x,y a 3D point in the scene and tries to set it to the point of interes...
void Add(const T &scalar, Vector3< T > &dest) const
Addition with a scalar, storing results in destionation vector.
void SetGLProjectionParametersInterface(BIAS::GLProjectionParametersInterface *projInterface)
Set the ProjectionParametersInterface (camera)
void ScalarProduct(const Vector3< T > &argvec, T &result) const
scalar product (=inner product) of two vectors, storing the result in result
void Multiply(const T &scalar, Vector3< T > &dest) const
Multiplication with a scalar, storing results in destination vector.
void Homogenize()
homogenize class data member elements to W==1 by divison by W
bool LeftMouseMoved(int x1, int x2, int y1, int y2)
Rotates the camera around the point of interest.
bool MouseWheelUsed(double stepsize)
Handles Mouse Wheel events and zooms in or out.
bool MiddleMouseMoved(int x1, int x2, int y1, int y2)
Moves the camera left/right/up/down and sets new point of interest.
int MultVec(const Vector3< QUAT_TYPE > &vec, Vector3< QUAT_TYPE > &res) const
rotates the given Vector qith the quaternion ( q v q* ) the resulting vector is given in res ...
void RotateAroundViewingDirection(double rotationAngleRAD)
Rotate around viewing direction.
Abstract interface class to handle changes in rendering parameters by controllers and in rendering co...
void CrossProduct(const Vector3< T > &argvec, Vector3< T > &destvec) const
cross product of two vectors destvec = this x argvec
bool LeftAndRightMouseMoved(int x1, int x2, int y1, int y2)
react to mouse move if left and right button is pressed.
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
bool Equal(const T left, const T right, const T eps)
comparison function for floating point values See http://www.boost.org/libs/test/doc/components/test_...
void Sub(const T &scalar, Vector3< T > &dest) const
Substraction with a scalar, storing results in destination vector.
bool RightMouseMoved(int x1, int x2, int y1, int y2)
Moves the camera forward to point of interest if y2-y1 is positive else the camera is moved away from...
virtual void SetGLProjectionParametersInterface(BIAS::GLProjectionParametersInterface *interface_)
Set the camera projection parameters.
class for rotation with axis and angle
void RotateAroundPOI(BIAS::Vector3< double > axis, double angleRAD)
Rotate around the point of interest.
Vector3< T > & Normalize()
normalize this vector to length 1
void SetPointOfInterest(const BIAS::Vector3< double > &poi)
Set point of interest the controller will circle around.
double NormL2() const
the L2 norm sqrt(a^2 + b^2 + c^2)
class BIASGeometryBase_EXPORT HomgPoint3D
void SetValueAsAxisRad(const Vector3< QUAT_TYPE > &axis, QUAT_TYPE angle)
sets the quaternion with given rotation axis and angle (in rad)
void MoveInViewingDirection(double stepSize)
void SetIdentity()
set the elements of this matrix to the identity matrix (possibly overriding the inherited method) ...