Commit aaeac138 authored by schultezub's avatar schultezub
Browse files

Slightly adapted tgt::Navigation and tgt::Trackball for easier integration

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@216 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent 39064903
......@@ -46,26 +46,50 @@
namespace tgt {
/**
* Intermediate wrapper class for easier integration of tgt::Navigation into projects using
* separated cameras and canvases.
*/
class TGT_API IHasCamera {
public:
/**
* Pure virtual destructor
*/
virtual ~IHasCamera() = 0 {};
/**
* Returns the camera to modify by Navigation.
* Once a navigation is finished and the scene shall be rerendered, update() is called.
*/
virtual Camera* getCamera() = 0;
/**
* Notifies the camera holding object, that the navigation is finished.
*/
virtual void update() = 0;
};
class TGT_API Navigation : virtual public EventListener {
protected:
// navigation manipulates the camera of a certain canvas.
// we only need a pointer to this canvas, not to the camera (see getCamera).
GLCanvas* canvas_;
IHasCamera* hcam_;
public:
Navigation(GLCanvas* canv) {
canvas_ = canv;
Navigation(IHasCamera* hcam) {
hcam_ = hcam;
}
virtual ~Navigation() {}
void setCanvas(GLCanvas* canv) { canvas_ = canv; }
GLCanvas* getCanvas() const { return canvas_; }
// void setCanvas(GLCanvas* hcam) { hcam_ = hcam; }
// GLCanvas* getCanvas() const { return hcam_->; }
Camera* getCamera() const { return getCanvas()->getCamera(); }
Camera* getCamera() const { return hcam_->getCamera(); }
/// The following functions may be used to rotate the Camera about
/// an arbitrary axis.
......
......@@ -30,8 +30,9 @@
namespace tgt {
Trackball::Trackball(GLCanvas* canvas, bool defaultEventHandling, Timer* continuousSpinTimer)
: Navigation(canvas),
Trackball::Trackball(IHasCamera* hcam, const ivec2& viewportSize, bool defaultEventHandling, Timer* continuousSpinTimer)
: Navigation(hcam),
viewportSize_(viewportSize),
continuousSpin_(false),
continuousSpinTimer_(continuousSpinTimer),
continuousSpinStopwatch_(0),
......@@ -68,6 +69,7 @@ Trackball::~Trackball() {
void Trackball::reset() {
getCamera()->positionCamera(cameraPosition_, cameraFocus_, cameraUpVector_);
hcam_->update();
}
/*
......@@ -182,7 +184,7 @@ void Trackball::rotate(Quaternion<float> quat) {
continuousSpinStopwatch_->start();
}
getCanvas()->update();
hcam_->update();
}
void Trackball::rotate(vec3 axis, float phi) {
......@@ -244,7 +246,7 @@ void Trackball::move(float length, vec3 axis) {
moveCamera(-axis);
if (moveCenter_) { center_ -= axis; };
getCanvas()->update();
hcam_->update();
}
void Trackball::move(vec2 newMouse) {
......@@ -262,7 +264,7 @@ void Trackball::zoom(float factor) {
factor = 1.f / factor;
getCamera()->setPosition( (1.f-factor) * getCamera()->getFocus()
+ factor * getCamera()->getPosition());
getCanvas()->update();
hcam_->update();
}
void Trackball::zoom(vec2 newMouse) {
......@@ -271,7 +273,7 @@ void Trackball::zoom(vec2 newMouse) {
void Trackball::zoomAbsolute(float focallength) {
getCamera()->setPosition( getCamera()->getFocus() - focallength * getCamera()->getLook());
getCanvas()->update();
hcam_->update();
}
void Trackball::initializeContinuousSpin() {
......@@ -410,8 +412,8 @@ void Trackball::setKeyRoll(float acuteness, KeyEvent::KeyCode left, KeyEvent::Ke
}
vec2 Trackball::scaleMouse(const ivec2& mouse) const {
return vec2( static_cast<float>(mouse.x*2.f) / static_cast<float>(canvas_->getWidth()) - 1.f,
1.f - static_cast<float>(mouse.y*2.f) / static_cast<float>(canvas_->getHeight()) );
return vec2( static_cast<float>(mouse.x*2.f) / static_cast<float>(viewportSize_.x) - 1.f,
1.f - static_cast<float>(mouse.y*2.f) / static_cast<float>(viewportSize_.y) );
}
void Trackball::mousePressEvent(MouseEvent* e) {
......@@ -445,7 +447,7 @@ void Trackball::mouseMoveEvent(MouseEvent* e) {
if ( mouseRollButton_ & e->button() &&
(mouseRollMod_ == e->modifiers() || mouseRollMod_ & e->modifiers()) ) {
rollCameraHorz((newMouse.x-mouse_.x)/mouseRollAcuteness_);
getCanvas()->update();
hcam_->update();
}
mouse_ = newMouse;
......@@ -466,7 +468,7 @@ void Trackball::wheelEvent(MouseEvent* e) {
( mouseWheelUpRollLeft_ && (e->button()&MouseEvent::MOUSE_WHEEL_UP)) ||
(!mouseWheelUpRollLeft_ && (e->button()&MouseEvent::MOUSE_WHEEL_DOWN))
) );
getCanvas()->update();
hcam_->update();
}
e->ignore();
}
......@@ -508,10 +510,10 @@ void Trackball::keyEvent(KeyEvent* e) {
&& e->pressed() == keyRollPressed_) {
if (e->keyCode() == keyRollLeft_) {
rollCameraHorz(getRollAngle(keyRollAcuteness_, true));
getCanvas()->update();
hcam_->update();
} else if (e->keyCode() == keyRollRight_) {
rollCameraHorz(getRollAngle(keyRollAcuteness_, false));
getCanvas()->update();
hcam_->update();
}
}
e->ignore();
......@@ -544,7 +546,6 @@ float Trackball::getRollAngle(const float& acuteness, const bool& left) const {
void Trackball::timerEvent(TimeEvent* e) {
if (continuousSpin_ && continuousSpinTimer_ == e->getTimer() ) {
rotate(getLastOrientationChange());
canvas_->repaint();
}
}
......
......@@ -61,11 +61,14 @@ class Trackball : public Navigation {
/// tgt::Timer-object. As we need a toolkit-specific timer,
/// trackball cannot create it itself, the user has to provide
/// it to the constructor.
Trackball(GLCanvas* canvas, bool defaultEventHandling = true, Timer* continousSpinTimer = NULL);
Trackball(IHasCamera* hcam, const ivec2& viewportSize, bool defaultEventHandling = true, Timer* continousSpinTimer = NULL);
/// Destructor
virtual ~Trackball();
const ivec2& getViewportSize() const { return viewportSize_; };
void setViewprtSize(const ivec2& viewportSize) { viewportSize_ = viewportSize; };
/// Resets the trackball to the initial configuration of the canvas' camera.
void reset();
......@@ -126,8 +129,8 @@ class Trackball : public Navigation {
/// with respect to the camera's look vector.
float getCenterDistance();
GLCanvas* getCanvas() const { return canvas_; }
void setCanvas(GLCanvas* canvas) { canvas_ = canvas; }
// GLCanvas* getCanvas() const { return hcav_; }
// void setCanvas(GLCanvas* canvas) { hcav_ = canvas; }
Timer* getContinuousSpinTimer() const { return continuousSpinTimer_; }
......@@ -248,6 +251,9 @@ class Trackball : public Navigation {
///////////////////////////////////////////////////////////////////////////////////////////////
protected:
/// viewport size for mouse coordinates translation
ivec2 viewportSize_;
/// is this a continuously spinning Trackball?
bool continuousSpin_;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment