Added support for osg::AutoTransform::setAutoRotateMode(AutoRotateMode) deprecating
the previous setAutoRotateToScreen(). Added support for ROTATE_TO_CAMERA mode. Cleaned up the autotransform demo to use a sensible number of labels
This commit is contained in:
parent
ed10594139
commit
3579506fa8
@ -71,7 +71,7 @@ osg::Node* createLabel3(const osg::Vec3& pos, float size, const std::string& lab
|
||||
return geode;
|
||||
}
|
||||
|
||||
osg::Node* createAxis(const osg::Vec3& s, const osg::Vec3& e, int numReps)
|
||||
osg::Node* createAxis(const osg::Vec3& s, const osg::Vec3& e, int numReps, osg::AutoTransform::AutoRotateMode autoRotateMode, const std::string& str)
|
||||
{
|
||||
osg::Group* group = new osg::Group;
|
||||
|
||||
@ -80,7 +80,7 @@ osg::Node* createAxis(const osg::Vec3& s, const osg::Vec3& e, int numReps)
|
||||
|
||||
osg::Vec3 pos = s;
|
||||
|
||||
bool useAuto = false;
|
||||
bool useAuto = true;
|
||||
if (useAuto)
|
||||
{
|
||||
osg::Vec3Array* vertices = new osg::Vec3Array;
|
||||
@ -89,9 +89,8 @@ osg::Node* createAxis(const osg::Vec3& s, const osg::Vec3& e, int numReps)
|
||||
{
|
||||
osg::AutoTransform* at = new osg::AutoTransform;
|
||||
at->setPosition(pos);
|
||||
at->setAutoRotateToScreen(true);
|
||||
at->setAutoScaleToScreen(true);
|
||||
at->addChild(createLabel(osg::Vec3(0.0f,0.0f,0.0f),40.0f,"Test 2"));
|
||||
at->setAutoRotateMode(autoRotateMode);
|
||||
at->addChild(createLabel(osg::Vec3(0.0f,0.0f,0.0f),dv.length()*0.2f,str));
|
||||
vertices->push_back(pos);
|
||||
pos += dv;
|
||||
|
||||
@ -118,7 +117,7 @@ osg::Node* createAxis(const osg::Vec3& s, const osg::Vec3& e, int numReps)
|
||||
|
||||
for(int i=0;i<numReps;++i)
|
||||
{
|
||||
group->addChild(createLabel3(osg::Vec3(pos),dv.length()*0.5f,"Test 2"));
|
||||
group->addChild(createLabel3(osg::Vec3(pos),dv.length()*0.5f,str));
|
||||
vertices->push_back(pos);
|
||||
pos += dv;
|
||||
|
||||
@ -146,11 +145,11 @@ osg::Node* createScene()
|
||||
{
|
||||
osg::Group* root = new osg::Group;
|
||||
|
||||
int numReps = 3333;
|
||||
// int numReps = 10;
|
||||
root->addChild(createAxis(osg::Vec3(0.0,0.0,0.0),osg::Vec3(1000.0,0.0,0.0),numReps));
|
||||
root->addChild(createAxis(osg::Vec3(0.0,0.0,0.0),osg::Vec3(0.0,1000.0,0.0),numReps));
|
||||
root->addChild(createAxis(osg::Vec3(0.0,0.0,0.0),osg::Vec3(0.0,0.0,1000.0),numReps));
|
||||
// int numReps = 3333;
|
||||
int numReps = 10;
|
||||
root->addChild(createAxis(osg::Vec3(0.0,0.0,0.0),osg::Vec3(1000.0,0.0,0.0),numReps,osg::AutoTransform::ROTATE_TO_CAMERA,"ROTATE_TO_CAMERA"));
|
||||
root->addChild(createAxis(osg::Vec3(0.0,0.0,0.0),osg::Vec3(0.0,1000.0,0.0),numReps,osg::AutoTransform::ROTATE_TO_SCREEN,"ROTATE_TO_SCREEN"));
|
||||
root->addChild(createAxis(osg::Vec3(0.0,0.0,0.0),osg::Vec3(0.0,0.0,1000.0),numReps,osg::AutoTransform::NO_ROTATION,"NO_ROTATION"));
|
||||
|
||||
return root;
|
||||
}
|
||||
|
@ -2,19 +2,18 @@
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSG_AUTOTRANSFORM
|
||||
#define OSG_AUTOTRANSFORM 1
|
||||
|
||||
#include <osg/AnimationPath>
|
||||
#include <osg/Group>
|
||||
#include <osg/Transform>
|
||||
#include <osg/Quat>
|
||||
@ -60,10 +59,40 @@ class SG_EXPORT AutoTransform : public Transform
|
||||
void setAutoUpdateEyeMovementTolerance(float tolerance) { _autoUpdateEyeMovementTolerance = tolerance; }
|
||||
float getAutoUpdateEyeMovementTolerance() const { return _autoUpdateEyeMovementTolerance; }
|
||||
|
||||
void setAutoRotateToScreen(bool autoRotateToScreen) { _autoRotateToScreen = autoRotateToScreen; _matrixDirty=true; }
|
||||
bool getAutoRotateToScreen() const { return _autoRotateToScreen; }
|
||||
|
||||
|
||||
|
||||
enum AutoRotateMode
|
||||
{
|
||||
NO_ROTATION,
|
||||
ROTATE_TO_SCREEN,
|
||||
ROTATE_TO_CAMERA
|
||||
};
|
||||
|
||||
void setAutoRotateMode(AutoRotateMode mode) { _autoRotateMode = mode; }
|
||||
|
||||
AutoRotateMode getAutoRotateMode() const { return _autoRotateMode; }
|
||||
|
||||
#ifdef USE_DEPRECATED_API
|
||||
void setAutoRotateToScreen(bool autoRotateToScreen)
|
||||
{
|
||||
setAutoRotateMode(autoRotateToScreen?ROTATE_TO_SCREEN:NO_ROTATION);
|
||||
}
|
||||
|
||||
bool getAutoRotateToCamera() const { return _autoRotateMode==ROTATE_TO_SCREEN; }
|
||||
|
||||
void setAutoRotateToCamera(bool autoRotateToCamera)
|
||||
{
|
||||
setAutoRotateMode(autoRotateToScreen?ROTATE_TO_CAMERA:NO_ROTATION);
|
||||
}
|
||||
|
||||
bool getAutoRotateToCamera() const { return _autoRotateMode==ROTATE_TO_SCREEN; }
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
void setAutoScaleToScreen(bool autoScaleToScreen) { _autoScaleToScreen = autoScaleToScreen; _matrixDirty=true; }
|
||||
|
||||
bool getAutoScaleToScreen() const { return _autoScaleToScreen; }
|
||||
|
||||
|
||||
@ -78,25 +107,27 @@ class SG_EXPORT AutoTransform : public Transform
|
||||
virtual ~AutoTransform() {}
|
||||
|
||||
|
||||
Vec3 _position;
|
||||
Vec3 _pivotPoint;
|
||||
float _autoUpdateEyeMovementTolerance;
|
||||
bool _autoRotateToScreen;
|
||||
bool _autoScaleToScreen;
|
||||
Vec3 _position;
|
||||
Vec3 _pivotPoint;
|
||||
float _autoUpdateEyeMovementTolerance;
|
||||
|
||||
mutable Quat _rotation;
|
||||
mutable Vec3 _scale;
|
||||
mutable bool _firstTimeToInitEyePoint;
|
||||
mutable osg::Vec3 _previousEyePoint;
|
||||
mutable int _previousWidth;
|
||||
mutable int _previousHeight;
|
||||
AutoRotateMode _autoRotateMode;
|
||||
|
||||
bool _autoScaleToScreen;
|
||||
|
||||
mutable Quat _rotation;
|
||||
mutable Vec3 _scale;
|
||||
mutable bool _firstTimeToInitEyePoint;
|
||||
mutable osg::Vec3 _previousEyePoint;
|
||||
mutable int _previousWidth;
|
||||
mutable int _previousHeight;
|
||||
mutable osg::Matrix _previousProjection;
|
||||
mutable osg::Vec3 _previousPosition;
|
||||
|
||||
|
||||
void computeMatrix() const;
|
||||
|
||||
mutable bool _matrixDirty;
|
||||
mutable bool _matrixDirty;
|
||||
mutable osg::Matrix _cachedMatrix;
|
||||
|
||||
|
||||
|
@ -2,12 +2,12 @@
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
#include <osg/AutoTransform>
|
||||
@ -17,28 +17,28 @@ using namespace osg;
|
||||
|
||||
AutoTransform::AutoTransform():
|
||||
_autoUpdateEyeMovementTolerance(0.0f),
|
||||
_autoRotateToScreen(false),
|
||||
_autoRotateMode(NO_ROTATION),
|
||||
_autoScaleToScreen(false),
|
||||
_scale(1.0f,1.0f,1.0f),
|
||||
_firstTimeToInitEyePoint(true),
|
||||
_matrixDirty(true)
|
||||
{
|
||||
// setNumChildrenRequiringUpdateTraversal(1);
|
||||
// setNumChildrenRequiringUpdateTraversal(1);
|
||||
}
|
||||
|
||||
AutoTransform::AutoTransform(const AutoTransform& pat,const CopyOp& copyop):
|
||||
Transform(pat,copyop),
|
||||
Transform(pat,copyop),
|
||||
_position(pat._position),
|
||||
_pivotPoint(pat._pivotPoint),
|
||||
_autoUpdateEyeMovementTolerance(pat._autoUpdateEyeMovementTolerance),
|
||||
_autoRotateToScreen(pat._autoRotateToScreen),
|
||||
_autoRotateMode(pat._autoRotateMode),
|
||||
_autoScaleToScreen(pat._autoScaleToScreen),
|
||||
_rotation(pat._rotation),
|
||||
_scale(pat._scale),
|
||||
_firstTimeToInitEyePoint(true),
|
||||
_matrixDirty(true)
|
||||
{
|
||||
// setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+1);
|
||||
// setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+1);
|
||||
}
|
||||
|
||||
bool AutoTransform::computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) const
|
||||
@ -113,7 +113,7 @@ void AutoTransform::accept(NodeVisitor& nv)
|
||||
}
|
||||
|
||||
osg::Vec3 eyePoint = cs->getEyeLocal();
|
||||
osg::Vec3 position = getPosition();
|
||||
osg::Vec3 position = getPosition();
|
||||
|
||||
const osg::Matrix& projection = cs->getProjectionMatrix();
|
||||
|
||||
@ -149,18 +149,27 @@ void AutoTransform::accept(NodeVisitor& nv)
|
||||
setScale(size);
|
||||
}
|
||||
|
||||
if (getAutoRotateToScreen())
|
||||
if (_autoRotateMode==ROTATE_TO_SCREEN)
|
||||
{
|
||||
osg::Quat rotation;
|
||||
cs->getModelViewMatrix().get(rotation);
|
||||
setRotation(rotation.inverse());
|
||||
}
|
||||
else if (_autoRotateMode==ROTATE_TO_CAMERA)
|
||||
{
|
||||
osg::Vec3 PosToEye = _position - eyePoint;
|
||||
osg::Matrix lookto = osg::Matrix::lookAt(
|
||||
osg::Vec3(0,0,0), PosToEye, cs->getUpLocal());
|
||||
Quat q;
|
||||
q.set(osg::Matrix::inverse(lookto));
|
||||
setRotation(q);
|
||||
}
|
||||
|
||||
_previousEyePoint = eyePoint;
|
||||
_previousWidth = width;
|
||||
_previousHeight = height;
|
||||
_previousProjection = projection;
|
||||
_previousPosition = position;
|
||||
_previousPosition = position;
|
||||
|
||||
_matrixDirty = true;
|
||||
}
|
||||
|
@ -93,7 +93,18 @@ bool AutoTransform_readLocalData(Object& obj, Input& fr)
|
||||
if (fr.matchSequence("autoRotateToScreen %w"))
|
||||
{
|
||||
std::string w(fr[1].getStr());
|
||||
transform.setAutoRotateToScreen(w == "TRUE");
|
||||
transform.setAutoRotateMode((w == "TRUE") ? osg::AutoTransform::ROTATE_TO_SCREEN : osg::AutoTransform::NO_ROTATION);
|
||||
fr += 2;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
if (fr.matchSequence("autoRotateMode %w"))
|
||||
{
|
||||
std::string w(fr[1].getStr());
|
||||
if (w=="ROTATE_TO_SCREEN") transform.setAutoRotateMode(osg::AutoTransform::ROTATE_TO_SCREEN);
|
||||
else if (w=="ROTATE_TO_CAMERA") transform.setAutoRotateMode(osg::AutoTransform::ROTATE_TO_CAMERA);
|
||||
else if (w=="NO_ROTATION") transform.setAutoRotateMode(osg::AutoTransform::NO_ROTATION);
|
||||
|
||||
fr += 2;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
@ -118,9 +129,18 @@ bool AutoTransform_writeLocalData(const Object& obj, Output& fw)
|
||||
fw.indent()<<"rotation "<<transform.getRotation()<<std::endl;
|
||||
fw.indent()<<"scale "<<transform.getScale()<<std::endl;
|
||||
fw.indent()<<"pivotPoint "<<transform.getPivotPoint()<<std::endl;
|
||||
fw.indent()<<"autoUpdateEyeMovementTolerance "<<transform.getAutoUpdateEyeMovementTolerance()<<std::endl;
|
||||
fw.indent()<<"autoRotateToScreen "<<(transform.getAutoRotateToScreen()?"TRUE":"FALSE")<<std::endl;
|
||||
fw.indent()<<"autoScaleToScreen "<<(transform.getAutoScaleToScreen()?"TRUE":"FALSE")<<std::endl;
|
||||
fw.indent()<<"autoUpdateEyeMovementTolerance "<<transform.getAutoUpdateEyeMovementTolerance()<<std::endl;
|
||||
fw.indent()<<"autoRotateMode ";
|
||||
switch(transform.getAutoRotateMode())
|
||||
{
|
||||
case(osg::AutoTransform::ROTATE_TO_SCREEN): fw<<"ROTATE_TO_SCREEN"<<std::endl; break;
|
||||
case(osg::AutoTransform::ROTATE_TO_CAMERA): fw<<"ROTATE_TO_CAMERA"<<std::endl; break;
|
||||
case(osg::AutoTransform::NO_ROTATION):
|
||||
default: fw<<"NO_ROTATION"<<std::endl; break;
|
||||
}
|
||||
|
||||
|
||||
fw.indent()<<"autoScaleToScreen "<<(transform.getAutoScaleToScreen()?"TRUE":"FALSE")<<std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user