Fixes for IRIX build.

Updates to the osg::Transform, adding preMult and postMult methods and
deprecating the old preRotate,preTranslate,preScale.

Updated the rest of the OSG so that it nolonger uses the deprecated
osg::Transform nodes.

Renamed osgUtil::SceneView::setGlobalState() to
osgUtil::SceneView::setGlobalStateSet() so that the name reflects its
functionality better.  Updated osgGLUT::Viewer etc to cope with new
name change.
This commit is contained in:
Robert Osfield
2001-11-14 14:09:07 +00:00
parent 34555f61d6
commit a434abafd7
22 changed files with 1420 additions and 1444 deletions

View File

@@ -185,6 +185,10 @@ SOURCE=..\..\src\osgUtil\Tesselator.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\osgUtil\TransformCallback.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\osgUtil\TrackballManipulator.cpp
# End Source File
# Begin Source File
@@ -313,6 +317,10 @@ SOURCE=..\..\include\osgUtil\Tesselator
# End Source File
# Begin Source File
SOURCE=..\..\include\osgUtil\TransformCallback
# End Source File
# Begin Source File
SOURCE=..\..\include\osgUtil\TrackballManipulator
# End Source File
# Begin Source File

View File

@@ -71,26 +71,32 @@
namespace osg {
#ifdef USE_DEGREES_INTERNALLY
inline double inDegrees(double angle) { return angle; }
inline double inRadians(double angle) { return angle*180.0/M_PI; }
inline double inDegrees(double angle) { return angle; }
inline double inRadians(double angle) { return angle*180.0/M_PI; }
#else
inline double inDegrees(double angle) { return angle*M_PI/180.0; }
inline double inRadians(double angle) { return angle; }
inline double inDegrees(double angle) { return angle*M_PI/180.0; }
inline double inRadians(double angle) { return angle; }
#endif
inline double DegreesToRadians(double angle) { return angle*M_PI/180.0; }
inline double RadiansToDegrees(double angle) { return angle*180.0/M_PI; }
#ifdef WIN32
inline bool isNaN(float v) { return ::_isnan(v)!=0; }
inline bool isNaN(double v) { return ::_isnan(v)!=0; }
inline bool isInfinite(float v) { return !::_finite(v); }
inline bool isInfinite(double v) { return !::_finite(v); }
inline bool isNaN(float v) { return ::_isnan(v)!=0; }
inline bool isNaN(double v) { return ::_isnan(v)!=0; }
inline bool isInfinite(float v) { return !::_finite(v); }
inline bool isInfinite(double v) { return !::_finite(v); }
#elseif __sgi
inline bool isNaN(float v) { return ::isnan(v); }
inline bool isNaN(double v) { return ::isnan(v); }
// can't find a function to test for infiniting on sgi yet..
inline bool isInfinite(float v) { return false; }
inline bool isInfinite(double v) { return false; }
#else
inline bool isNaN(float v) { return ::isnan(v); }
inline bool isNaN(double v) { return ::isnan(v); }
inline bool isInfinite(float v) { return ::isinf(v); }
inline bool isInfinite(double v) { return ::isinf(v); }
inline bool isNaN(float v) { return ::isnan(v); }
inline bool isNaN(double v) { return ::isnan(v); }
inline bool isInfinite(float v) { return ::isinf(v); }
inline bool isInfinite(double v) { return ::isinf(v); }
#endif
};

View File

@@ -17,7 +17,7 @@ using namespace std;
#endif
// temporary #define to keep backwards compatibility.
#define USE_DEPRECATED_MATRIX_METHODS
//#define USE_DEPRECATED_MATRIX_METHODS
namespace osg {

View File

@@ -41,15 +41,34 @@ class SG_EXPORT Transform : public Group
/** Get the Transform Type.*/
inline const Type getType() const { return _type; }
void setMatrix(const Matrix& mat );
inline Matrix& getMatrix() { return *_matrix; }
inline const Matrix& getMatrix() const { return *_matrix; }
void preMult( const Matrix& mat );
inline void setMatrix(const Matrix& mat )
{
(*_matrix) = mat;
dirtyBound();
}
/** preMult trasforms relative to the childrens coordinate system.*/
inline void preMult( const Matrix& mat )
{
(*_matrix) = mat * (*_matrix);
dirtyBound();
}
/** postMult trasforms relative to the parents coordinate system.*/
inline void postMult( const Matrix& mat )
{
(*_matrix) = (*_matrix) * mat;
dirtyBound();
}
#ifdef USE_DEPRECATED_MATRIX_METHODS
void preScale( const float sx, const float sy, const float sz );
void preTranslate( const float tx, const float ty, const float tz );
void preRotate( const float deg, const float x, const float y, const float z );
#endif
protected :

View File

@@ -45,14 +45,14 @@ class OSGDB_EXPORT ReaderWriter : public osg::Referenced
{
public:
enum Status
enum ReadStatus
{
FILE_NOT_HANDLED,
FILE_LOADED,
ERROR_IN_READING_FILE
};
ReadResult(Status status=FILE_NOT_HANDLED):_status(status) {}
ReadResult(ReadStatus status=FILE_NOT_HANDLED):_status(status) {}
ReadResult(const std::string& m):_status(ERROR_IN_READING_FILE),_message(m) {}
ReadResult(osg::Object* obj):_status(FILE_LOADED),_object(obj) {}
@@ -73,14 +73,14 @@ class OSGDB_EXPORT ReaderWriter : public osg::Referenced
const std::string& message() const { return _message; }
const Status status() const { return _status; }
const ReadStatus status() const { return _status; }
const bool success() const { return _status==FILE_LOADED; }
const bool error() const { return _status==ERROR_IN_READING_FILE; }
const bool notHandled() const { return _status==FILE_NOT_HANDLED; }
protected:
Status _status;
ReadStatus _status;
std::string _message;
osg::ref_ptr<osg::Object> _object;
};
@@ -89,14 +89,14 @@ class OSGDB_EXPORT ReaderWriter : public osg::Referenced
{
public:
enum Status
enum WriteStatus
{
FILE_NOT_HANDLED,
FILE_SAVED,
ERROR_IN_WRITING_FILE
};
WriteResult(Status status=FILE_NOT_HANDLED):_status(status) {}
WriteResult(WriteStatus status=FILE_NOT_HANDLED):_status(status) {}
WriteResult(const std::string& m):_status(ERROR_IN_WRITING_FILE),_message(m) {}
WriteResult(const WriteResult& rr):_status(rr._status),_message(rr._message) {}
@@ -104,14 +104,14 @@ class OSGDB_EXPORT ReaderWriter : public osg::Referenced
const std::string& message() const { return _message; }
const Status status() const { return _status; }
const WriteStatus status() const { return _status; }
const bool success() const { return _status==FILE_SAVED; }
const bool error() const { return _status==ERROR_IN_WRITING_FILE; }
const bool notHandled() const { return _status==FILE_NOT_HANDLED; }
protected:
Status _status;
WriteStatus _status;
std::string _message;
};

View File

@@ -37,9 +37,10 @@ class OSGTEXT_EXPORT Paragraph : public osg::Geode
void setAlignment(int alignment);
int getAlignment() { return _alignment; }
float getHeight() const;
static bool createFormatedText(unsigned int noCharsPerLine,const std::string& str,std::vector<std::string>& formatedText);
protected:
virtual ~Paragraph() {}

View File

@@ -84,9 +84,9 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced
/** Get the background color.*/
const osg::Vec4& getBackgroundColor() const { return _backgroundColor; }
void setGlobalState(osg::StateSet* state) { _globalState = state; }
osg::StateSet* getGlobalState() { return _globalState.get(); }
const osg::StateSet* getGlobalState() const { return _globalState.get(); }
void setGlobalStateSet(osg::StateSet* state) { _globalState = state; }
osg::StateSet* getGlobalStateSet() { return _globalState.get(); }
const osg::StateSet* getGlobalStateSet() const { return _globalState.get(); }
enum LightingMode {
HEADLIGHT, // default

View File

@@ -18,11 +18,11 @@
// Global variables - this is basically the stuff which will be animated
// ----------------------------------------------------------------------
class TransformCallback : public osg::NodeCallback{
class MyTransformCallback : public osg::NodeCallback{
public:
TransformCallback(osg::Transform* node,float angularVelocity)
MyTransformCallback(osg::Transform* node,float angularVelocity)
{
_nodeToOperateOn = node;
_angular_velocity = angularVelocity;
@@ -169,7 +169,7 @@ int main( int argc, char **argv )
myTransform->addChild( createCube() );
// move node in a circle at 90 degrees a sec.
myTransform->setAppCallback(new TransformCallback(myTransform,osg::inDegrees(90.0f)));
myTransform->setAppCallback(new MyTransformCallback(myTransform,osg::inDegrees(90.0f)));
// create the viewer and the model to it.
osgGLUT::Viewer viewer;

View File

@@ -12,6 +12,7 @@
#include <osgUtil/TrackballManipulator>
#include <osgUtil/FlightManipulator>
#include <osgUtil/DriveManipulator>
#include <osgUtil/TransformCallback>
#include <osgDB/Registry>
#include <osgDB/ReadFile>
@@ -41,65 +42,6 @@
// we apply them.
class TransformCallback : public osg::NodeCallback{
public:
TransformCallback(osg::Transform* node,float angularVelocity)
{
_nodeToOperateOn = node;
if (node)
{
_pivotPoint = node->getBound().center();
}
_angular_velocity = angularVelocity;
_previousTraversalNumber = -1;
_previous_t = _timer.tick();
}
virtual void operator() (osg::Node* node, osg::NodeVisitor* nv)
{
if (nv)
{
if (_nodeToOperateOn && node==_nodeToOperateOn)
{
// ensure that we do not operate on this node more than
// once during this traversal. This is an issue since node
// can be shared between multiple parents.
if (nv->getTraversalNumber()!=_previousTraversalNumber)
{
osg::Timer_t new_t = _timer.tick();
float delta_angle = _angular_velocity*_timer.delta_s(_previous_t,new_t);
_previous_t = new_t;
// update the specified dcs.
_nodeToOperateOn->preTranslate(_pivotPoint[0],_pivotPoint[1],_pivotPoint[2]);
_nodeToOperateOn->preRotate(delta_angle,0.0f,0.0f,1.0f);
_nodeToOperateOn->preTranslate(-_pivotPoint[0],-_pivotPoint[1],-_pivotPoint[2]);
_previousTraversalNumber = nv->getTraversalNumber();
}
}
}
// must continue subgraph traversal.
traverse(node,nv);
}
protected:
osg::Transform* _nodeToOperateOn;
float _angular_velocity;
osg::Vec3 _pivotPoint;
int _previousTraversalNumber;
osg::Timer _timer;
osg::Timer_t _previous_t;
};
/*
* Function to read several files (typically one) as specified on the command
* line, and return them in an osg::Node
@@ -425,9 +367,9 @@ int main( int argc, char **argv )
osg::Transform* dcs = new osg::Transform;
dcs->setStateSet(dstate);
dcs->preTranslate(0.0f,0.0f,z);
dcs->preScale(1.0f,1.0f,-1.0f);
dcs->preTranslate(0.0f,0.0f,-z);
dcs->preMult(osg::Matrix::trans(0.0f,0.0f,-z)*
osg::Matrix::scale(1.0f,1.0f,-1.0f)*
osg::Matrix::trans(0.0f,0.0f,z));
dcs->addChild(loadedModelTransform);
@@ -472,7 +414,8 @@ int main( int argc, char **argv )
osgGLUT::Viewer viewer;
viewer.addViewport( rootNode );
loadedModelTransform->setAppCallback(new TransformCallback(loadedModelTransform,osg::inDegrees(45.0f)));
osg::NodeCallback* nc = new osgUtil::TransformCallback(loadedModelTransform->getBound().center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(45.0f));
loadedModelTransform->setAppCallback(nc);
// register trackball, flight and drive.
viewer.registerCameraManipulator(new osgUtil::TrackballManipulator);

View File

@@ -416,7 +416,7 @@ public:
virtual float app(unsigned int viewport)
{
float ret;
ret=Viewer::app(viewport);
ret=osgGLUT::Viewer::app(viewport);
if(_hudSceneView.valid() && viewport>=_viewportList.size()-1)
{
_hudSceneView->app();
@@ -427,7 +427,7 @@ public:
virtual float cull(unsigned int viewport)
{
float ret;
ret=Viewer::cull(viewport);
ret=osgGLUT::Viewer::cull(viewport);
if(_hudSceneView.valid() && viewport>=_viewportList.size()-1)
_hudSceneView->cull();
return ret;
@@ -436,7 +436,7 @@ public:
virtual float draw(unsigned int viewport)
{
float ret;
ret=Viewer::draw(viewport);
ret=osgGLUT::Viewer::draw(viewport);
if(_hudSceneView.valid() && viewport>=_viewportList.size()-1)
_hudSceneView->draw();
return ret;
@@ -452,7 +452,7 @@ public:
virtual void reshape(GLint w, GLint h)
{
Viewer::reshape(w,h);
osgGLUT::Viewer::reshape(w,h);
if(_hudSceneView.valid())
{
@@ -463,7 +463,7 @@ public:
virtual bool open()
{
bool ret=Viewer::open();
bool ret=osgGLUT::Viewer::open();
// set the clear flag / after the visualReq.Visitor
if(_hudSceneView.valid())
@@ -536,7 +536,7 @@ protected:
}
return;
default:
Viewer::keyboard(key,x,y);
osgGLUT::Viewer::keyboard(key,x,y);
};
}
@@ -583,7 +583,7 @@ int main( int argc, char **argv )
// setup the sceneData
setScene(textGroup);
textGroup->preRotate(osg::inDegrees(90),1,0,0);
textGroup->preMult(osg::Matrix::rotate(osg::inDegrees(90.0f),1.0f,0.0f,0.0f));
rootNode->addChild(textGroup);
// setup the 2dNode

View File

@@ -115,7 +115,7 @@ osg::Node* createTexturedItem(const osg::Vec3& offset,osg::Texture* texture,osg:
// place and also to add individual texture set to it, so that
// that state is inherited down to its children.
osg::Transform* local_transform = new osg::Transform;
local_transform->preTranslate(offset.x(),offset.y(),offset.z());
local_transform->postMult(osg::Matrix::trans(offset));
// create the StateSet to store the texture data
osg::StateSet* stateset = new osg::StateSet;
@@ -140,7 +140,7 @@ osg::Node* createLayer(const osg::Vec3& offset,osg::Image* image,osg::Node* geom
if (image==NULL) return NULL;
osg::Transform* top_transform = new osg::Transform;
top_transform->preTranslate(offset.x(),offset.y(),offset.z());
top_transform->postMult(osg::Matrix::trans(offset));
osg::Vec3 local_offset(0.0f,0.0f,0.0f);
osg::Vec3 local_delta(3.0f,0.0f,0.0f);

View File

@@ -21,20 +21,7 @@ Transform::~Transform()
{
}
void Transform::setMatrix(const Matrix& mat )
{
(*_matrix) = mat;
dirtyBound();
}
void Transform::preMult( const Matrix& mat )
{
(*_matrix) = mat * (*_matrix);
dirtyBound();
}
#ifdef USE_DEPRECATED_MATRIX_METHODS
void Transform::preScale( const float sx, const float sy, const float sz )
{
(*_matrix) = Matrix::scale( sx, sy, sz ) * (*_matrix);
@@ -53,7 +40,7 @@ void Transform::preRotate( const float deg, const float x, const float y, const
(*_matrix) = Matrix::rotate( deg, x, y, z ) * (*_matrix);
dirtyBound();
}
#endif
const bool Transform::computeBound() const
{
if (!Group::computeBound()) return false;

View File

@@ -954,18 +954,18 @@ void Viewer::keyboard(unsigned char key, int x, int y)
backface = 1 - backface;
if( backface )
sceneView->getGlobalState()->setMode(GL_CULL_FACE,osg::StateAttribute::ON);
sceneView->getGlobalStateSet()->setMode(GL_CULL_FACE,osg::StateAttribute::ON);
else
sceneView->getGlobalState()->setMode(GL_CULL_FACE,osg::StateAttribute::OVERRIDE_OFF);
sceneView->getGlobalStateSet()->setMode(GL_CULL_FACE,osg::StateAttribute::OVERRIDE_OFF);
break;
case 'l' :
lighting = 1 - lighting ;
if( lighting )
sceneView->getGlobalState()->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE_ON);
sceneView->getGlobalStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE_ON);
else
sceneView->getGlobalState()->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE_OFF);
sceneView->getGlobalStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE_OFF);
break;
case 'L' :
@@ -984,8 +984,8 @@ void Viewer::keyboard(unsigned char key, int x, int y)
texture = 1 - texture;
if (texture)
{
sceneView->getGlobalState()->setModeToInherit(GL_TEXTURE_2D);
// sceneView->getGlobalState()->setAttributeToInherit(osg::StateAttribute::TEXTURE);
sceneView->getGlobalStateSet()->setModeToInherit(GL_TEXTURE_2D);
// sceneView->getGlobalStateSet()->setAttributeToInherit(osg::StateAttribute::TEXTURE);
}
else
{
@@ -993,8 +993,8 @@ void Viewer::keyboard(unsigned char key, int x, int y)
// thus causing them to all use the same texture attribute, hence
// preventing a state attribute change due to unused textures.
static osg::ref_ptr<osg::Texture> blank_texture = new osg::Texture;
sceneView->getGlobalState()->setMode(GL_TEXTURE_2D,osg::StateAttribute::OVERRIDE_OFF);
// sceneView->getGlobalState()->setAttribute(blank_texture.get(),true);
sceneView->getGlobalStateSet()->setMode(GL_TEXTURE_2D,osg::StateAttribute::OVERRIDE_OFF);
// sceneView->getGlobalStateSet()->setAttribute(blank_texture.get(),true);
}
break;
@@ -1007,7 +1007,7 @@ void Viewer::keyboard(unsigned char key, int x, int y)
polymode = (polymode+1)%3;
osg::PolygonMode* polyModeObj = new osg::PolygonMode;
polyModeObj->setMode(osg::PolygonMode::FRONT_AND_BACK,polymodes[polymode]);
sceneView->getGlobalState()->setAttribute(polyModeObj);
sceneView->getGlobalStateSet()->setAttribute(polyModeObj);
}
break;

File diff suppressed because it is too large Load Diff

View File

@@ -157,7 +157,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterOBJ::readNode(const std::string& fil
// note obj_x -> osg_x,
// obj_y -> osg_z,
// obj_z -> osg_y,
xform->preTranslate(obj->position[0], obj->position[2], obj->position[1]);
xform->setMatrix(osg::Matrix::trans(obj->position[0], obj->position[2], obj->position[1]));
osg_top = xform;
}
else

View File

@@ -170,11 +170,11 @@ class ReaderWriterPFB : public osgDB::ReaderWriter
if (root)
{
if (pfdStoreFile(root,fileName.c_str())!=0) return WriteResult::FILE_SAVED;
else return "Unable to write file from performer.";
else return std::string("Unable to write file from performer.");
}
else
{
return "Unable to convert scene to performer, cannot write file.";
return std::string("Unable to convert scene to performer, cannot write file.");
}
}

View File

@@ -1,11 +1,11 @@
/* --------------------------------------------------------------------------
*
* openscenegraph textLib / FTGL
* openscenegraph textLib / FTGL
*
* --------------------------------------------------------------------------
*
* prog: max rheiner;mrn@paus.ch
* date: 4/25/2001 (m/d/y)
*
* prog: max rheiner;mrn@paus.ch
* date: 4/25/2001 (m/d/y)
*
* ----------------------------------------------------------------------------
*
@@ -61,136 +61,136 @@ std::string findFontFile(const std::string& str)
Font::
Font()
{
_init=false;
_font=NULL;
_created=false;
_init=false;
_font=NULL;
_created=false;
_pointSize=14;
_res=72;
_pointSize=14;
_res=72;
}
bool Font::
init(const std::string& font)
{
_font=NULL;
_created=false;
_font=NULL;
_created=false;
open(font);
open(font);
if(_font!=NULL)
return true;
else
return false;
if(_font!=NULL)
return true;
else
return false;
}
Font::
~Font()
{
clear();
clear();
}
bool Font::
open(const std::string& font)
{
clear();
clear();
std::string filename = findFontFile(font);
if (filename.empty()) return false;
_font=createFontObj();
if( _font!=NULL && _font->Open(filename.c_str()) )
{
_init=true;
_fontName=font;
return true;
}
else
return false;
_font=createFontObj();
if( _font!=NULL && _font->Open(filename.c_str()) )
{
_init=true;
_fontName=font;
return true;
}
else
return false;
}
bool Font::
create(int pointSize,const unsigned int res)
{
_pointSize=pointSize;
_res=res;
_pointSize=pointSize;
_res=res;
return create();
return create();
}
bool Font::
create()
{
if(_init)
{
if(_font->FaceSize(_pointSize,_res))
{
_created=true;
return true;
}
else
return false;
}
else
return false;
if(_init)
{
if(_font->FaceSize(_pointSize,_res))
{
_created=true;
return true;
}
else
return false;
}
else
return false;
}
void Font::
output(const char* text)
{
if(_created)
_font->render(text);
else
create(_pointSize);
if(_created)
_font->render(text);
else
create(_pointSize);
}
void Font::
clear()
{
_init=false;
if(_font)
{
delete _font;
_font=NULL;
}
_init=false;
if(_font)
{
delete _font;
_font=NULL;
}
_fontName="";
_fontName="";
}
float Font::
getWidth(const char* text) const
{
if(_init && _created)
return _font->Advance(text);
else
return -1;
if(_init && _created)
return _font->Advance(text);
else
return -1;
}
int Font::
getHeight() const
{
if(_init && _created)
return _pointSize;
else
return -1;
if(_init && _created)
return _pointSize;
else
return -1;
}
int Font::
getDescender() const
{
if(_init && _created)
return _font->Descender();
else
return -1;
if(_init && _created)
return _font->Descender();
else
return -1;
}
int Font::
getAscender() const
{
if(_init && _created)
return _font->Ascender();
else
return -1;
if(_init && _created)
return _font->Ascender();
else
return -1;
}
@@ -201,22 +201,22 @@ getAscender() const
// BitmapFont
BitmapFont::
BitmapFont(const std::string& font,
int point_size):
BitmapFont(const std::string& font,
int point_size):
RasterFont()
{
if(init(font))
{
}
_pointSize=point_size;
if(init(font))
{
}
_pointSize=point_size;
}
FTFont* BitmapFont::
createFontObj(void)
{
return (FTFont*)(new FTGLBitmapFont);
return (FTFont*)(new FTGLBitmapFont);
}
// BitmapFont
///////////////////////////////////////////////////////////////////////////////
@@ -224,23 +224,23 @@ createFontObj(void)
// PixmapFont
PixmapFont::
PixmapFont(const std::string& font,
int point_size):
PixmapFont(const std::string& font,
int point_size):
RasterFont(font)
{
if(init(font))
{
}
_pointSize=point_size;
if(init(font))
{
}
_pointSize=point_size;
}
FTFont* PixmapFont::
createFontObj(void)
{
return (FTFont*)(new FTGLPixmapFont);
return (FTFont*)(new FTGLPixmapFont);
}
// PixmapFont
///////////////////////////////////////////////////////////////////////////////
@@ -248,23 +248,23 @@ createFontObj(void)
// PixmapFont
TextureFont::
TextureFont(const std::string& font,
int point_size):
TextureFont(const std::string& font,
int point_size):
RasterFont(font)
{
if(init(font))
{
}
_pointSize=point_size;
if(init(font))
{
}
_pointSize=point_size;
}
FTFont* TextureFont::
createFontObj(void)
{
return (FTFont*)(new FTGLTextureFont);
return (FTFont*)(new FTGLTextureFont);
}
// PixmapFont
///////////////////////////////////////////////////////////////////////////////
@@ -272,25 +272,25 @@ createFontObj(void)
// _FTGLOutlineFont
OutlineFont::
OutlineFont(const std::string& font,
int point_size,
double precision):
OutlineFont(const std::string& font,
int point_size,
double precision):
VectorFont(font)
{
if(init(font))
{
}
_pointSize=point_size;
_precision=precision;
if(init(font))
{
}
_pointSize=point_size;
_precision=precision;
}
FTFont* OutlineFont::
createFontObj(void)
{
return (FTFont*)(new FTGLOutlineFont);
return (FTFont*)(new FTGLOutlineFont);
}
// _FTGLOutlineFont
///////////////////////////////////////////////////////////////////////////////
@@ -298,24 +298,24 @@ createFontObj(void)
// PolygonFont
PolygonFont::
PolygonFont(const std::string& font,
int point_size,
double precision):
PolygonFont(const std::string& font,
int point_size,
double precision):
VectorFont(font)
{
if(init(font))
{
}
_pointSize=point_size;
_precision=precision;
if(init(font))
{
}
_pointSize=point_size;
_precision=precision;
}
FTFont* PolygonFont::
createFontObj(void)
{
return (FTFont*)(new FTGLPolygonFont);
return (FTFont*)(new FTGLPolygonFont);
}
// PolygonFont
///////////////////////////////////////////////////////////////////////////////

View File

@@ -42,7 +42,7 @@ TARGET_INCLUDE_FILES = \
osgText/Text\
osgText/Version
C++FLAGS += -I ../../include -I /usr/include/freetype2 -I /usr/local/include/freetype2
C++FLAGS += -I../../include -I/usr/include/freetype2 -I/usr/local/include/freetype2
include ../../Make/makerules

View File

@@ -98,55 +98,15 @@ void Paragraph::createDrawables()
typedef vector<std::string> TextList;
TextList formatedText;
std::string::size_type start = 0;
std::string::size_type last_space = 0;
std::string::size_type current_line_length = 0;
for(std::string::size_type current=0;
current<_text.size();
++current)
{
const char c = _text[current];
if (c==' ') last_space = current;
if (c=='\n')
{
formatedText.push_back(std::string(_text,start,current-start));
start = current+1;
last_space = start;
current_line_length = 0;
}
else if (current_line_length==_maxCharsPerLine)
{
if (last_space>start)
{
formatedText.push_back(std::string(_text,start,last_space-start));
start = last_space+1;
}
else
{
formatedText.push_back(std::string(_text,start,current-start));
start = current+1;
}
last_space = start;
current_line_length = 0;
}
else ++current_line_length;
}
if (start<_text.size())
{
formatedText.push_back(std::string(_text,start,_text.size()-start));
}
createFormatedText(_maxCharsPerLine,_text,formatedText);
// now create the text drawables from the formate text list.
for(TextList::iterator itr=formatedText.begin();
itr!=formatedText.end();
++itr)
{
osgText::Text* textDrawable = new osgText::Text(_font.get());
textDrawable->setAlignment(_alignment);
textDrawable->setPosition(pos);
@@ -162,3 +122,54 @@ void Paragraph::createDrawables()
}
}
bool Paragraph::createFormatedText(unsigned int noCharsPerLine,const std::string& str,std::vector<std::string>& formatedText)
{
if (str.empty()) return false;
std::string::size_type start = 0;
std::string::size_type last_space = 0;
std::string::size_type current_line_length = 0;
for(std::string::size_type current=0;
current<str.size();
++current)
{
const char c = str[current];
if (c==' ') last_space = current;
if (c=='\n')
{
formatedText.push_back(std::string(str,start,current-start));
start = current+1;
last_space = start;
current_line_length = 0;
}
else if (current_line_length==noCharsPerLine)
{
if (last_space>start)
{
formatedText.push_back(std::string(str,start,last_space-start));
start = last_space+1;
current_line_length = current-start;
}
else
{
formatedText.push_back(std::string(str,start,current-start));
start = current+1;
current_line_length = 0;
}
last_space = start;
}
else ++current_line_length;
}
if (start<str.size())
{
formatedText.push_back(std::string(str,start,str.size()-start));
}
return true;
}

View File

@@ -1,11 +1,11 @@
/* --------------------------------------------------------------------------
*
* openscenegraph textLib / FTGL
* openscenegraph textLib / FTGL
*
* --------------------------------------------------------------------------
*
* prog: max rheiner;mrn@paus.ch
* date: 4/25/2001 (m/d/y)
*
* prog: max rheiner;mrn@paus.ch
* date: 4/25/2001 (m/d/y)
*
* ----------------------------------------------------------------------------
*
@@ -33,31 +33,31 @@ using namespace osgText;
Text::
Text()
{
setDefaults();
setDefaults();
}
Text::
Text(Font* font)
{
setDefaults();
setDefaults();
if(font && font->isOk())
{
_init=true;
_font=font;
if(font && font->isOk())
{
_init=true;
_font=font;
if(dynamic_cast<PolygonFont*>(_font.get()))
_fontType=POLYGON;
else if(dynamic_cast<BitmapFont*>(_font.get()))
_fontType=BITMAP;
else if(dynamic_cast<PixmapFont*>(_font.get()))
_fontType=PIXMAP;
else if(dynamic_cast<TextureFont*>(_font.get()))
_fontType=TEXTURE;
else if(dynamic_cast<OutlineFont*>(_font.get()))
_fontType=OUTLINE;
if(dynamic_cast<PolygonFont*>(_font.get()))
_fontType=POLYGON;
else if(dynamic_cast<BitmapFont*>(_font.get()))
_fontType=BITMAP;
else if(dynamic_cast<PixmapFont*>(_font.get()))
_fontType=PIXMAP;
else if(dynamic_cast<TextureFont*>(_font.get()))
_fontType=TEXTURE;
else if(dynamic_cast<OutlineFont*>(_font.get()))
_fontType=OUTLINE;
}
}
}
Text::
@@ -71,19 +71,19 @@ void Text::setFont(Font* font)
if(font && font->isOk())
{
_init=true;
_font=font;
_init=true;
_font=font;
if(dynamic_cast<PolygonFont*>(_font.get()))
_fontType=POLYGON;
else if(dynamic_cast<BitmapFont*>(_font.get()))
_fontType=BITMAP;
else if(dynamic_cast<PixmapFont*>(_font.get()))
_fontType=PIXMAP;
else if(dynamic_cast<TextureFont*>(_font.get()))
_fontType=TEXTURE;
else if(dynamic_cast<OutlineFont*>(_font.get()))
_fontType=OUTLINE;
if(dynamic_cast<PolygonFont*>(_font.get()))
_fontType=POLYGON;
else if(dynamic_cast<BitmapFont*>(_font.get()))
_fontType=BITMAP;
else if(dynamic_cast<PixmapFont*>(_font.get()))
_fontType=PIXMAP;
else if(dynamic_cast<TextureFont*>(_font.get()))
_fontType=TEXTURE;
else if(dynamic_cast<OutlineFont*>(_font.get()))
_fontType=OUTLINE;
_initAlignment = false;
dirtyBound();
@@ -94,348 +94,348 @@ void Text::setFont(Font* font)
void Text::
setDefaults()
{
_init=false;
_pos.set(0,0,0);
_alignmentPos.set(0,0,0);
_fontType=UNDEF;
_alignment=LEFT_BOTTOM;
_drawMode=DEFAULT;
_init=false;
_pos.set(0,0,0);
_alignmentPos.set(0,0,0);
_fontType=UNDEF;
_alignment=LEFT_BOTTOM;
_drawMode=DEFAULT;
_boundingBoxType=GLYPH;
_boundingBoxType=GEOMETRY;
_boundingBoxType=GLYPH;
_boundingBoxType=GEOMETRY;
_initAlignment=false;
_initAlignment=false;
_useDisplayList=false;
_useDisplayList=false;
}
const bool Text::
computeBound() const
{
if(!_init)
{
_bbox_computed=false;
return true;
}
if(!_init)
{
_bbox_computed=false;
return true;
}
// culling
if(_font->isCreated())
{ // ready to get the siz
_bbox.init();
// culling
if(_font->isCreated())
{ // ready to get the siz
_bbox.init();
Vec3 min,max;
calcBounds(&min,&max);
Vec3 min,max;
calcBounds(&min,&max);
_bbox.expandBy(min);
_bbox.expandBy(max);
_bbox.expandBy(min);
_bbox.expandBy(max);
_bbox_computed=true;
}
else
{ // have to wait for the init.
_bbox.init();
_bbox_computed=true;
}
else
{ // have to wait for the init.
_bbox.init();
// to be sure that the obj isn't culled
// _bbox.expandBy(_pos);
// to be sure that the obj isn't culled
// _bbox.expandBy(_pos);
_bbox.expandBy(_pos + Vec3(-100,-100,-100));
_bbox.expandBy(_pos + Vec3(100,100,100));
_bbox.expandBy(_pos + Vec3(-100,-100,-100));
_bbox.expandBy(_pos + Vec3(100,100,100));
/*
_bbox.expandBy(Vec3(-FLT_MAX,-FLT_MAX,-FLT_MAX));
_bbox.expandBy(Vec3(FLT_MAX,FLT_MAX,FLT_MAX));
*/
_bbox_computed=true;
/*
_bbox.expandBy(Vec3(-FLT_MAX,-FLT_MAX,-FLT_MAX));
_bbox.expandBy(Vec3(FLT_MAX,FLT_MAX,FLT_MAX));
*/
_bbox_computed=true;
}
return true;
}
return true;
}
void Text::drawImmediateMode(State& state)
{
if(!_init)
return;
if(!_font->isCreated())
{
_font->create();
dirtyBound();
}
if(!_init)
return;
if(!_font->isCreated())
{
_font->create();
dirtyBound();
}
if(!_initAlignment)
initAlignment();
// draw boundingBox
if(_drawMode & BOUNDINGBOX)
drawBoundingBox();
// draw alignment
if(_drawMode & ALIGNEMENT)
drawAlignment();
if(!_initAlignment)
initAlignment();
// draw boundingBox
if(_drawMode & BOUNDINGBOX)
drawBoundingBox();
// draw alignment
if(_drawMode & ALIGNEMENT)
drawAlignment();
// draw boundingBox
if(_drawMode & TEXT)
{
Vec3 drawPos(_pos+_alignmentPos);
glPushMatrix();
switch(_fontType)
{
case POLYGON:
glTranslatef(drawPos.x(),drawPos.y(),drawPos.z());
_font->output(_text.c_str());
break;
case OUTLINE:
glTranslatef(drawPos.x(),drawPos.y(),drawPos.z());
_font->output(_text.c_str());
break;
case BITMAP:
glRasterPos3f(drawPos.x(),drawPos.y(),drawPos.z());
_font->output(_text.c_str());
break;
case PIXMAP:
glRasterPos3f(drawPos.x(),drawPos.y(),drawPos.z());
_font->output(_text.c_str());
break;
case TEXTURE:
glTranslatef(drawPos.x(),drawPos.y(),drawPos.z());
_font->output(_text.c_str());
break;
// draw boundingBox
if(_drawMode & TEXT)
{
Vec3 drawPos(_pos+_alignmentPos);
glPushMatrix();
switch(_fontType)
{
case POLYGON:
glTranslatef(drawPos.x(),drawPos.y(),drawPos.z());
_font->output(_text.c_str());
break;
case OUTLINE:
glTranslatef(drawPos.x(),drawPos.y(),drawPos.z());
_font->output(_text.c_str());
break;
case BITMAP:
glRasterPos3f(drawPos.x(),drawPos.y(),drawPos.z());
_font->output(_text.c_str());
break;
case PIXMAP:
glRasterPos3f(drawPos.x(),drawPos.y(),drawPos.z());
_font->output(_text.c_str());
break;
case TEXTURE:
glTranslatef(drawPos.x(),drawPos.y(),drawPos.z());
_font->output(_text.c_str());
break;
};
glPopMatrix();
}
};
glPopMatrix();
}
}
void Text::
drawBoundingBox(void)
{
if(!_init)
return;
if(!_init)
return;
glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT );
glDisable(GL_TEXTURE_2D);
glColor3f(0,1,0);
glBegin(GL_LINE_LOOP);
glVertex3f(_bbox.xMin(),_bbox.yMin(),_bbox.zMin());
glVertex3f(_bbox.xMax(),_bbox.yMin(),_bbox.zMin());
glVertex3f(_bbox.xMax(),_bbox.yMax(),_bbox.zMin());
glVertex3f(_bbox.xMin(),_bbox.yMax(),_bbox.zMin());
glEnd();
glPopAttrib();
glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT );
glDisable(GL_TEXTURE_2D);
glColor3f(0,1,0);
glBegin(GL_LINE_LOOP);
glVertex3f(_bbox.xMin(),_bbox.yMin(),_bbox.zMin());
glVertex3f(_bbox.xMax(),_bbox.yMin(),_bbox.zMin());
glVertex3f(_bbox.xMax(),_bbox.yMax(),_bbox.zMin());
glVertex3f(_bbox.xMin(),_bbox.yMax(),_bbox.zMin());
glEnd();
glPopAttrib();
}
void Text::
drawAlignment(void)
{
if(!_init)
return;
if(!_init)
return;
double size=_font->getPointSize()/4;
double size=_font->getPointSize()/4;
glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT );
glDisable(GL_TEXTURE_2D);
glColor3f(1,0,0);
glBegin(GL_LINES);
glVertex3f(_pos.x() - size,_pos.y(),_pos.z());
glVertex3f(_pos.x() + size,_pos.y(),_pos.z());
glVertex3f(_pos.x(),_pos.y() - size,_pos.z());
glVertex3f(_pos.x(),_pos.y() + size,_pos.z());
glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT );
glDisable(GL_TEXTURE_2D);
glColor3f(1,0,0);
glBegin(GL_LINES);
glVertex3f(_pos.x() - size,_pos.y(),_pos.z());
glVertex3f(_pos.x() + size,_pos.y(),_pos.z());
glVertex3f(_pos.x(),_pos.y() - size,_pos.z());
glVertex3f(_pos.x(),_pos.y() + size,_pos.z());
glEnd();
glPopAttrib();
glEnd();
glPopAttrib();
}
void Text::
setPosition(const Vec3& pos)
{
_pos=pos;
_pos=pos;
}
void Text::
setPosition(const Vec2& pos)
{
setPosition(Vec3(pos.x(),pos.y(),0));
setPosition(Vec3(pos.x(),pos.y(),0));
}
void Text::
calcBounds(Vec3* min,Vec3* max) const
{
if(!_init)
return;
if(!_init)
return;
float h=_font->getHeight();
float w=_font->getWidth(_text.c_str());
float descender=_font->getDescender();
float h=_font->getHeight();
float w=_font->getWidth(_text.c_str());
float descender=_font->getDescender();
min->set(0,descender,0);
max->set(w,h + descender ,0);
min->set(0,descender,0);
max->set(w,h + descender ,0);
}
bool Text::
initAlignment(void)
{
if(!_init)
return false;
if(!_init)
return false;
// culling
if(_font->isCreated())
{ // ready to get the siz
_bbox.init();
// culling
if(_font->isCreated())
{ // ready to get the siz
_bbox.init();
Vec3 min,max;
initAlignment(&min,&max);
Vec3 min,max;
initAlignment(&min,&max);
_bbox.expandBy(min);
_bbox.expandBy(max);
_bbox.expandBy(min);
_bbox.expandBy(max);
_bbox_computed=true;
_bbox_computed=true;
_initAlignment=true;
}
else
{ // have to wait for the init.
_bbox.init();
_initAlignment=true;
}
else
{ // have to wait for the init.
_bbox.init();
// to be sure that the obj isn't culled
_bbox.expandBy(Vec3(-FLT_MAX,-FLT_MAX,-FLT_MAX));
_bbox.expandBy(Vec3(FLT_MAX,FLT_MAX,FLT_MAX));
// to be sure that the obj isn't culled
_bbox.expandBy(Vec3(-FLT_MAX,-FLT_MAX,-FLT_MAX));
_bbox.expandBy(Vec3(FLT_MAX,FLT_MAX,FLT_MAX));
_bbox_computed=true;
}
_bbox_computed=true;
}
return true;
return true;
}
void Text::
initAlignment(Vec3* min,Vec3* max)
{
if(!_init)
return;
if(!_init)
return;
float h=_font->getHeight();
float w=_font->getWidth(_text.c_str());
float descender=_font->getDescender();
float h=_font->getHeight();
float w=_font->getWidth(_text.c_str());
float descender=_font->getDescender();
min->set(0,descender,0);
max->set(w,h + descender ,0);
min->set(0,descender,0);
max->set(w,h + descender ,0);
switch(_boundingBoxType)
{
case GLYPH:
h+=descender;
switch(_alignment)
{
case LEFT_TOP:
_alignmentPos.set(0.0,h,0.0);
break;
case LEFT_CENTER:
_alignmentPos.set(0.0,h/2.0,0.0);
break;
case LEFT_BOTTOM:
_alignmentPos.set(0.0,0.0,0.0);
break;
switch(_boundingBoxType)
{
case GLYPH:
h+=descender;
switch(_alignment)
{
case LEFT_TOP:
_alignmentPos.set(0.0,h,0.0);
break;
case LEFT_CENTER:
_alignmentPos.set(0.0,h/2.0,0.0);
break;
case LEFT_BOTTOM:
_alignmentPos.set(0.0,0.0,0.0);
break;
case CENTER_TOP:
_alignmentPos.set(w/2.0,h,0.0);
break;
case CENTER_CENTER:
_alignmentPos.set(w/2.0,h/2.0,0.0);
break;
case CENTER_BOTTOM:
_alignmentPos.set(w/2.0,0.0,0.0);
break;
case CENTER_TOP:
_alignmentPos.set(w/2.0,h,0.0);
break;
case CENTER_CENTER:
_alignmentPos.set(w/2.0,h/2.0,0.0);
break;
case CENTER_BOTTOM:
_alignmentPos.set(w/2.0,0.0,0.0);
break;
case RIGHT_TOP:
_alignmentPos.set(w,h,0.0);
break;
case RIGHT_CENTER:
_alignmentPos.set(w,h/2.0,0.0);
break;
case RIGHT_BOTTOM:
_alignmentPos.set(w,0.0,0.0);
break;
};
_alignmentPos=-_alignmentPos;
case RIGHT_TOP:
_alignmentPos.set(w,h,0.0);
break;
case RIGHT_CENTER:
_alignmentPos.set(w,h/2.0,0.0);
break;
case RIGHT_BOTTOM:
_alignmentPos.set(w,0.0,0.0);
break;
};
_alignmentPos=-_alignmentPos;
*min+=_pos+_alignmentPos;
*max+=_pos+_alignmentPos;
break;
*min+=_pos+_alignmentPos;
*max+=_pos+_alignmentPos;
break;
case GEOMETRY:
switch(_alignment)
{
case LEFT_TOP:
_alignmentPos.set(0.0,h + descender,0.0);
break;
case LEFT_CENTER:
_alignmentPos.set(0.0,(max->y()-min->y()) /2.0 + descender,0.0);
break;
case LEFT_BOTTOM:
_alignmentPos.set(0.0,descender,0.0);
break;
case GEOMETRY:
switch(_alignment)
{
case LEFT_TOP:
_alignmentPos.set(0.0,h + descender,0.0);
break;
case LEFT_CENTER:
_alignmentPos.set(0.0,(max->y()-min->y()) /2.0 + descender,0.0);
break;
case LEFT_BOTTOM:
_alignmentPos.set(0.0,descender,0.0);
break;
case CENTER_TOP:
_alignmentPos.set(w/2.0,h + descender,0.0);
break;
case CENTER_CENTER:
_alignmentPos.set(w/2.0,(max->y()-min->y()) /2.0 + descender,0.0);
break;
case CENTER_BOTTOM:
_alignmentPos.set(w/2.0,descender,0.0);
break;
case CENTER_TOP:
_alignmentPos.set(w/2.0,h + descender,0.0);
break;
case CENTER_CENTER:
_alignmentPos.set(w/2.0,(max->y()-min->y()) /2.0 + descender,0.0);
break;
case CENTER_BOTTOM:
_alignmentPos.set(w/2.0,descender,0.0);
break;
case RIGHT_TOP:
_alignmentPos.set(w,h + descender,0.0);
break;
case RIGHT_CENTER:
_alignmentPos.set(w,(max->y()-min->y()) /2.0 + descender,0.0);
break;
case RIGHT_BOTTOM:
_alignmentPos.set(w,descender,0.0);
break;
};
_alignmentPos=-_alignmentPos;
case RIGHT_TOP:
_alignmentPos.set(w,h + descender,0.0);
break;
case RIGHT_CENTER:
_alignmentPos.set(w,(max->y()-min->y()) /2.0 + descender,0.0);
break;
case RIGHT_BOTTOM:
_alignmentPos.set(w,descender,0.0);
break;
};
_alignmentPos=-_alignmentPos;
*min+=_pos+_alignmentPos;
*max+=_pos+_alignmentPos;
break;
};
*min+=_pos+_alignmentPos;
*max+=_pos+_alignmentPos;
break;
};
switch(_fontType)
{
case BITMAP:
break;
case PIXMAP:
break;
switch(_fontType)
{
case BITMAP:
break;
case PIXMAP:
break;
};
};
}
void Text::
setAlignment(int alignment)
{
_alignment=alignment;
if(!_init || !_font->isCreated())
return;
_alignment=alignment;
if(!_init || !_font->isCreated())
return;
initAlignment();
initAlignment();
}
void Text::
setBoundingBox(int mode)
{
_boundingBoxType=mode;
if(!_init || !_font->isCreated())
return;
_boundingBoxType=mode;
if(!_init || !_font->isCreated())
return;
initAlignment();
initAlignment();
}
// Text

View File

@@ -26,6 +26,7 @@ C++FILES = \
StateSetManipulator.cpp\
Tesselator.cpp\
TrackballManipulator.cpp\
TransformCallback.cpp\
TriStripVisitor.cpp\
Version.cpp\
VisualsRequirementsVisitor.cpp\
@@ -68,6 +69,7 @@ TARGET_INCLUDE_FILES = \
osgUtil/StateSetManipulator\
osgUtil/Tesselator\
osgUtil/TrackballManipulator\
osgUtil/TransformCallback\
osgUtil/TriStripVisitor\
osgUtil/Version\
osgUtil/VisualsRequirementsVisitor\

View File

@@ -18,7 +18,7 @@ void SceneViewManipulator::setSceneView(SceneView* sv)
_sv=sv;
_cm->setNode(sv->getSceneData());
_cm->setCamera(sv->getCamera());
_gm->setStateSet(sv->getGlobalState());
_gm->setStateSet(sv->getGlobalStateSet());
}
SceneView *SceneViewManipulator::getSceneView()