Merge branch 'tanderson-review-spaceballRework'

This commit is contained in:
Juergen Riegel 2012-03-19 18:54:46 +01:00
commit 72cdbb8191
7 changed files with 61 additions and 69 deletions

View File

@ -79,10 +79,10 @@ const char* BlenderNavigationStyle::mouseButtons(ViewerMode mode)
SbBool BlenderNavigationStyle::processSoEvent(const SoEvent * const ev)
{
// Events when in "ready-to-seek" mode are ignored, except those
// which influence the seek mode itself -- these are handled further
// up the inheritance hierarchy.
if (this->isSeekMode()) { return inherited::processSoEvent(ev); }
// Events when in "ready-to-seek" mode are ignored, except those
// which influence the seek mode itself -- these are handled further
// up the inheritance hierarchy.
if (this->isSeekMode()) { return inherited::processSoEvent(ev); }
const SoType type(ev->getTypeId());
@ -291,20 +291,9 @@ SbBool BlenderNavigationStyle::processSoEvent(const SoEvent * const ev)
// Spaceball & Joystick handling
if (type.isDerivedFrom(SoMotion3Event::getClassTypeId())) {
SoMotion3Event * const event = (SoMotion3Event *) ev;
SoCamera * const camera = viewer->getCamera();
SbVec3f dir = event->getTranslation();
if (camera->getTypeId().isDerivedFrom(SoOrthographicCamera::getClassTypeId())){
static float zoomConstant(-.03f);
dir[2] = 0.0;//don't move the cam for z translation.
SoOrthographicCamera *oCam = static_cast<SoOrthographicCamera *>(camera);
oCam->scaleHeight(1.0-event->getTranslation()[2] * zoomConstant);
}
camera->orientation.getValue().multVec(dir,dir);
camera->position = camera->position.getValue() + dir;
camera->orientation = event->getRotation() * camera->orientation.getValue();
const SoMotion3Event * const event = static_cast<const SoMotion3Event * const>(ev);
if (event)
this->processMotionEvent(event);
processed = TRUE;
}

View File

@ -320,20 +320,9 @@ SbBool CADNavigationStyle::processSoEvent(const SoEvent * const ev)
// Spaceball & Joystick handling
if (type.isDerivedFrom(SoMotion3Event::getClassTypeId())) {
SoMotion3Event * const event = (SoMotion3Event *) ev;
SoCamera * const camera = viewer->getCamera();
SbVec3f dir = event->getTranslation();
if (camera->getTypeId().isDerivedFrom(SoOrthographicCamera::getClassTypeId())){
static float zoomConstant(-.03f);
dir[2] = 0.0;//don't move the cam for z translation.
SoOrthographicCamera *oCam = static_cast<SoOrthographicCamera *>(camera);
oCam->scaleHeight(1.0-event->getTranslation()[2] * zoomConstant);
}
camera->orientation.getValue().multVec(dir,dir);
camera->position = camera->position.getValue() + dir;
camera->orientation = event->getRotation() * camera->orientation.getValue();
const SoMotion3Event * const event = static_cast<const SoMotion3Event * const>(ev);
if (event)
this->processMotionEvent(event);
processed = TRUE;
}

View File

@ -285,16 +285,10 @@ SbBool InventorNavigationStyle::processSoEvent(const SoEvent * const ev)
// Spaceball & Joystick handling
if (type.isDerivedFrom(SoMotion3Event::getClassTypeId())) {
SoMotion3Event * const event = (SoMotion3Event *) ev;
SoCamera * const camera = viewer->getCamera();
if (camera) {
SbVec3f dir = event->getTranslation();
camera->orientation.getValue().multVec(dir,dir);
camera->position = camera->position.getValue() + dir;
camera->orientation =
event->getRotation() * camera->orientation.getValue();
processed = TRUE;
}
const SoMotion3Event * const event = static_cast<const SoMotion3Event * const>(ev);
if (event)
this->processMotionEvent(event);
processed = TRUE;
}
enum {

View File

@ -1140,6 +1140,37 @@ SbBool NavigationStyle::processSoEvent(const SoEvent * const ev)
return viewer->processSoEventBase(ev);
}
SbBool NavigationStyle::processMotionEvent(const SoMotion3Event * const ev)
{
SoCamera * const camera = viewer->getCamera();
if (!camera)
return FALSE;
SbViewVolume volume(camera->getViewVolume());
SbVec3f center(volume.getSightPoint(camera->focalDistance.getValue()));
float scale(volume.getWorldToScreenScale(center, 1.0));
float translationFactor = scale * .0001;
SbVec3f dir = ev->getTranslation();
if (camera->getTypeId().isDerivedFrom(SoOrthographicCamera::getClassTypeId())){
SoOrthographicCamera *oCam = static_cast<SoOrthographicCamera *>(camera);
oCam->scaleHeight(1.0 + (dir[2] * 0.0001));
dir[2] = 0.0;//don't move the cam for z translation.
}
SbRotation newRotation(ev->getRotation() * camera->orientation.getValue());
SbVec3f newPosition, newDirection;
newRotation.multVec(SbVec3f(0.0, 0.0, -1.0), newDirection);
newPosition = center - (newDirection * camera->focalDistance.getValue());
camera->orientation.setValue(newRotation);
camera->orientation.getValue().multVec(dir,dir);
camera->position = newPosition + (dir * translationFactor);
return TRUE;
}
void NavigationStyle::setPopupMenuEnabled(const SbBool on)
{
this->menuenabled = on;

View File

@ -38,6 +38,7 @@
// forward declarations
class SoEvent;
class SoMotion3Event;
class SoQtViewer;
class SoCamera;
class SoSensor;
@ -90,10 +91,10 @@ public:
Clip = 3, /**< Clip objects using a lasso. */
};
enum OrbitStyle {
Turntable,
Trackball
};
enum OrbitStyle {
Turntable,
Trackball
};
public:
NavigationStyle();
@ -126,6 +127,7 @@ public:
void setViewingMode(const ViewerMode newmode);
int getViewingMode() const;
virtual SbBool processEvent(const SoEvent * const ev);
virtual SbBool processMotionEvent(const SoMotion3Event * const ev);
void setPopupMenuEnabled(const SbBool on);
SbBool isPopupMenuEnabled(void) const;

View File

@ -79,10 +79,10 @@ const char* TouchpadNavigationStyle::mouseButtons(ViewerMode mode)
SbBool TouchpadNavigationStyle::processSoEvent(const SoEvent * const ev)
{
// Events when in "ready-to-seek" mode are ignored, except those
// which influence the seek mode itself -- these are handled further
// up the inheritance hierarchy.
if (this->isSeekMode()) { return inherited::processSoEvent(ev); }
// Events when in "ready-to-seek" mode are ignored, except those
// which influence the seek mode itself -- these are handled further
// up the inheritance hierarchy.
if (this->isSeekMode()) { return inherited::processSoEvent(ev); }
const SoType type(ev->getTypeId());
@ -265,20 +265,9 @@ SbBool TouchpadNavigationStyle::processSoEvent(const SoEvent * const ev)
// Spaceball & Joystick handling
if (type.isDerivedFrom(SoMotion3Event::getClassTypeId())) {
SoMotion3Event * const event = (SoMotion3Event *) ev;
SoCamera * const camera = viewer->getCamera();
SbVec3f dir = event->getTranslation();
if (camera->getTypeId().isDerivedFrom(SoOrthographicCamera::getClassTypeId())){
static float zoomConstant(-.03f);
dir[2] = 0.0;//don't move the cam for z translation.
SoOrthographicCamera *oCam = static_cast<SoOrthographicCamera *>(camera);
oCam->scaleHeight(1.0-event->getTranslation()[2] * zoomConstant);
}
camera->orientation.getValue().multVec(dir,dir);
camera->position = camera->position.getValue() + dir;
camera->orientation = event->getRotation() * camera->orientation.getValue();
const SoMotion3Event * const event = static_cast<const SoMotion3Event * const>(ev);
if (event)
this->processMotionEvent(event);
processed = TRUE;
}

View File

@ -1070,18 +1070,16 @@ void View3DInventorViewer::processEvent(QEvent * event)
motionEvent->setHandled(true);
static float translationConstant(-.001f);
float xTrans, yTrans, zTrans;
xTrans = static_cast<float>(motionEvent->translationX());
yTrans = static_cast<float>(motionEvent->translationY());
zTrans = static_cast<float>(motionEvent->translationZ());
SbVec3f translationVector(xTrans, yTrans, zTrans * -1.0);
translationVector *= translationConstant;
SbVec3f translationVector(xTrans, yTrans, zTrans);
static float rotationConstant(.0001f);
SbRotation xRot, yRot, zRot;
xRot.setValue(SbVec3f(-1.0, 0.0, 0.0), static_cast<float>(motionEvent->rotationX()) * rotationConstant);
yRot.setValue(SbVec3f(0.0, -1.0, 0.0), static_cast<float>(motionEvent->rotationY()) * rotationConstant);
xRot.setValue(SbVec3f(1.0, 0.0, 0.0), static_cast<float>(motionEvent->rotationX()) * rotationConstant);
yRot.setValue(SbVec3f(0.0, 1.0, 0.0), static_cast<float>(motionEvent->rotationY()) * rotationConstant);
zRot.setValue(SbVec3f(0.0, 0.0, 1.0), static_cast<float>(motionEvent->rotationZ()) * rotationConstant);
SoMotion3Event motion3Event;