Implemented NodeVisitor's getLocalToWorldMatrix and getWorldToLocalMatrix

to allow users to querry the current accumulated matrix state within the
scene graph.
This commit is contained in:
Robert Osfield
2002-02-10 22:35:22 +00:00
parent e6638d9974
commit 7d03f8a548
4 changed files with 152 additions and 10 deletions

View File

@@ -53,9 +53,6 @@ Randall Hopper <aa8vb@yahoo.com>
- port to FreeBSD.
- warning fixes to IRIX compilation.
Phil Akin <Phil Atkin <philatkin@philatkin.com>
- port to OSX.
Ulrich Hertlein <u.hertlein@bit-side.com>
- support for IBM Mirror Repeat extension in osg::Texture
- support for texture subloading in osg::Texture

75
INSTALL
View File

@@ -243,6 +243,81 @@ Compiling under MacOS X (instructions written by Phil Atkin)
gone in 10.1 or it may be a weirdy in the Mac GLUT implementation, but
forewarned is forearmed.
--
Compiling under MacOS X
------------------------------------------------------------
OpenSceneGraph requires libdl which is the dynamic library loader. For
some strange reason it's not part of the OSX or the Apple Developer
Tools. It is available from the Apple Darwin site but, even stranger, I
haven't met anyone who could get it to compile. So the best thing to do
is get Fink. This isn't a major hassle because if you're serious about
osx development you should have it anyway and it's a pretty painless
install. Go to...
fink.sourceforge.net
download the binary .dmg and follow the instructions.
Once it's installed you can then get the libdl package which is actually
called dlcompat
% fink install dlcompat
fink will download, patch, compile and install the libdl stuff. It
should take about 30 seconds.
That's not all though because fink installs stuff in it's own
directories rather than the standard /usr/local so you have to make a
few minor changes to the make files.
Edit...
${OSGHOME}/Make/makedefs.macosx
and change the following lines. Note the '/sw' bits.
10: LCINCS += -I/usr/local/include -I/sw/include
20: FRAMEWORKS = -L/sw/lib -framework GLUT -framework Carbon -framework
OpenGL
"Why didn't you put '-L/sw/lib' in 'LDFLAGS'?" you ask. Well I tried
that and it didn't work.
While your editing Makefiles check out the OSG docs for the
dependencies. Some parts of OSG rely on other libraries (eg. libpng) so
if you don't have these you might want to comment some stuff out in the
build lists, or get the libs. OSG has a quicktime module so you don't
need most of the image plugins anyway.
OSG needs a bunch of environment variables to compile and run so you
might as well set these up now. Here's my .cshrc file.
source /sw/bin/init.csh
setenv OSGHOME /Users/henry/dev/osg-0.8.43
setenv OSGDATA /Users/henry/dev/OpenSceneGraph-Data
setenv OSG_LD_LIBRARY_PATH ${OSGHOME}/lib
setenv OSGFILEPATH ./:${OSGDATA}:${OSGDATA}/Images
You will recognise the first line from the fink installation
instructions. Remember to source in this file after you've made the
changes...
% source ~/.cshrc
and then you're ready to compile. In the terminal type...
% cd ${OSGHOME}
% make clean
% make macosx
Then go and have a cup of coffee because it takes bloody ages:)
OSGFILEPATH environmental variable
----------------------------------

View File

@@ -156,11 +156,11 @@ class SG_EXPORT NodeVisitor : public Referenced
* to the current Node being visited.*/
const NodePath& getNodePath() const { return _nodePath; }
/** Get the Local To World Matrix from the NodePath for specified Transform::Mode.*/
const bool getLocalToWorldMatrix(Matrix& matrix, MatrixMode mode);
/** Get the Local To World Matrix from the NodePath for specified Transform::Mode, and u.*/
const bool getLocalToWorldMatrix(Matrix& matrix, MatrixMode mode,Node* node);
/** Get the World To Local Matrix from the NodePath for specified Transform::Mode.*/
const bool getWorldToLocalMatrix(Matrix& matrix, MatrixMode mode);
const bool getWorldToLocalMatrix(Matrix& matrix, MatrixMode mode,Node* node);
virtual void apply(Node& node) { traverse(node);}

View File

@@ -1,4 +1,5 @@
#include <osg/NodeVisitor>
#include <osg/Transform>
#include <stdlib.h>
using namespace osg;
@@ -44,12 +45,81 @@ void NodeVisitor::setTraversalVisitor(NodeVisitor* nv)
else _traversalMode = TRAVERSE_NONE;
}
const bool NodeVisitor::getLocalToWorldMatrix(Matrix& /*matrix*/, MatrixMode /*mode*/)
class TransformVisitor : public NodeVisitor
{
return false;
public:
enum CoordMode
{
WORLD_TO_LOCAL,
LOCAL_TO_WORLD
};
MatrixMode _matrixMode;
CoordMode _coordMode;
Matrix& _matrix;
NodeVisitor* _nodeVisitor;
TransformVisitor(Matrix& matrix,MatrixMode matrixMode,CoordMode coordMode,NodeVisitor* nv):
NodeVisitor(),
_matrixMode(matrixMode),
_coordMode(coordMode),
_matrix(matrix),
_nodeVisitor(nv)
{}
virtual void apply(Transform& transform)
{
bool applyTransform =
(_matrixMode==transform.getMatrixMode()) ||
(_matrixMode==MODELVIEW && (transform.getMatrixMode()==MODEL || transform.getMatrixMode()==VIEW));
if (applyTransform)
{
if (_coordMode==LOCAL_TO_WORLD)
{
osg::Matrix localToWorldMat;
transform.getLocalToWorldMatrix(localToWorldMat,_nodeVisitor);
_matrix.preMult(localToWorldMat);
}
else // worldToLocal
{
osg::Matrix worldToLocalMat;
transform.getWorldToLocalMatrix(worldToLocalMat,_nodeVisitor);
_matrix.postMult(worldToLocalMat);
}
}
}
};
const bool NodeVisitor::getLocalToWorldMatrix(Matrix& matrix, MatrixMode mode, Node* node)
{
matrix.makeIdentity();
TransformVisitor tv(matrix,mode,TransformVisitor::LOCAL_TO_WORLD,this);
for(NodePath::iterator itr=_nodePath.begin();
itr!=_nodePath.end();
++itr)
{
if (*itr==node) return true; // don't account for matrix attached to specofied node
(*itr)->accept(tv);
}
return true;
}
const bool NodeVisitor::getWorldToLocalMatrix(Matrix& /*matrix*/, MatrixMode /*mode*/)
const bool NodeVisitor::getWorldToLocalMatrix(Matrix& matrix, MatrixMode mode, Node* node)
{
return false;
matrix.makeIdentity();
TransformVisitor tv(matrix,mode,TransformVisitor::WORLD_TO_LOCAL,this);
for(NodePath::iterator itr=_nodePath.begin();
itr!=_nodePath.end();
++itr)
{
if (*itr==node) return true; // don't account for matrix attached to specofied node
(*itr)->accept(tv);
}
return true;
}