diff --git a/include/osg/DCS b/include/osg/DCS deleted file mode 100644 index c947b4ef0..000000000 --- a/include/osg/DCS +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef OSG_DCS -#define OSG_DCS 1 - -#include -#include - -namespace osg { - -/** DCS - Dynamic Coordinate System a is group which all children - are transformed by the the DCS's osg::Matrix. Typical uses - of the DCS is for positioning objects within a scene or - producing trakerball functionality. -*/ -class SG_EXPORT DCS : public Group -{ - public : - DCS(); - DCS(const Matrix& matix); - - virtual Object* clone() const { return new DCS(); } - virtual bool isSameKindAs(Object* obj) { return dynamic_cast(obj)!=NULL; } - virtual const char* className() const { return "DCS"; } - virtual void accept(NodeVisitor& nv) { nv.apply(*this); } - - void setMatrix(const Matrix& mat ); - Matrix* getMatrix() { return _mat; } - - void preTranslate( float tx, float ty, float tz ); - void preRotate( float deg, float x, float y, float z ); - - bool computeBound(); - - protected : - - virtual ~DCS(); - - virtual bool readLocalData(Input& fr); - virtual bool writeLocalData(Output& fw); - - Matrix *_mat; -}; - -}; - -#endif diff --git a/include/osg/DynamicLibrary b/include/osg/DynamicLibrary deleted file mode 100644 index 6b5f9c49f..000000000 --- a/include/osg/DynamicLibrary +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef OSG_DYNAMICLIBRARY -#define OSG_DYNAMICLIBRARY 1 - -#include -#include - -#ifdef WIN32 -//#include -#endif - -namespace osg { - -/** DynamicLibrary - encapsulates the loading and unloading of dynamic libraries, - typically used for loading ReaderWriter plug-ins. -*/ -class SG_EXPORT DynamicLibrary : public Referenced -{ - public: - - #ifdef WIN32 - // from Snados.h - typedef void* HANDLE; - // from Delayimp.h - typedef void* PROC_ADDRESS; - #else - typedef void* HANDLE; - typedef void* PROC_ADDRESS; - #endif - - static DynamicLibrary* loadLibrary(const std::string& libraryName); - - const std::string& getName() const { return _name; } - const std::string& getFullName() const { return _fullName; } - HANDLE getHandle() const { return _handle; } - - PROC_ADDRESS getProcAddress(const std::string& procName); - - protected: - - DynamicLibrary(const std::string& name,HANDLE handle); - ~DynamicLibrary(); - - HANDLE _handle; - std::string _name; - std::string _fullName; - -}; - -}; - -#endif // __DYNAMIC_LIBRARY_H diff --git a/include/osg/ExtensionSupported b/include/osg/ExtensionSupported deleted file mode 100644 index f1dabc999..000000000 --- a/include/osg/ExtensionSupported +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef OSG_EXTENSIONSUPPORTED -#define OSG_EXTENSIONSUPPORTED 1 - -#include - -namespace osg { - -/** return true if OpenGL "extension" is supported. - note: Must only called within a valid OpenGL context, - undefined behaviour may occur otherwise.*/ -SG_EXPORT extern bool ExtensionSupported(const char *extension); - -}; - -#endif diff --git a/include/osg/Field b/include/osg/Field deleted file mode 100644 index 6e9f81e3d..000000000 --- a/include/osg/Field +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef OSG_FIELD -#define OSG_FIELD 1 - -#include -#include -#include - -namespace osg { - - -class SG_EXPORT Field -{ - public: - - enum { - MIN_CACHE_SIZE = 256 - }; - - Field(); - Field(const Field& field); - virtual ~Field(); - - virtual Field& operator = (const Field& ic); - - void reset(); - void addChar(char c); - int getNoCharacters() const { return _fieldCacheSize; } - - void setWithinQuotes(bool withinQuotes=true); - bool getWithinQuotes(); - - void setNoNestedBrackets(int no); - int getNoNestedBrackets(); - - enum FieldType - { - OPEN_BRACKET, - CLOSE_BRACKET, - STRING, - WORD, - REAL, - INTEGER, - BLANK, - UNINTIALISED - }; - - FieldType getFieldType() const; - - bool isValid() const; - - bool isOpenBracket() const; - bool isCloseBracket() const; - - bool isWord() const; - bool matchWord(const char* str) const; - bool matchWord(const char* str,int noCharacters) const; - - bool isString() const; - bool matchString(const char* str) const; - bool matchString(const char* str,int noCharacters) const; - bool isQuotedString() const; - - const char* getStr() const; - char* takeStr(); - - bool isInt() const; - bool matchInt(int i) const; - bool getInt(int& i) const; - - bool isFloat() const; - bool matchFloat(float f) const; - bool getFloat(float& f) const; - - bool isDouble() const; - bool matchDouble(double f) const; - bool getDouble(double& d) const; - - static FieldType calculateFieldType(const char* str,bool withinQuotes=false); - - protected: - - void _init(); - void _free(); - void _copy(const Field& ic); - - int _fieldCacheCapacity; - int _fieldCacheSize; - char* _fieldCache; - - mutable FieldType _fieldType; - - bool _withinQuotes; - - int _noNestedBrackets; - -}; - -}; - -#endif // __SG_FIELD_H diff --git a/include/osg/FieldReader b/include/osg/FieldReader deleted file mode 100644 index e2941897e..000000000 --- a/include/osg/FieldReader +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef OSG_FIELDREADER -#define OSG_FIELDREADER 1 - -#include -#include -#include - -#ifdef OSG_USE_IO_DOT_H -#include -#else -#include -using namespace std; -#endif - -namespace osg { - -class Field; - -class SG_EXPORT FieldReader -{ - public: - - FieldReader(); - FieldReader(const FieldReader& ic); - virtual ~FieldReader(); - - virtual FieldReader& operator = (const FieldReader& ic); - - void attach(istream* input); - void detach(); - - virtual bool eof() const; - - bool readField(Field& fieldPtr); - void ignoreField(); - - /** no of unmatched `{' encounterd so far in file*/ - int getNoNestedBrackets() const; - - private: - - bool _readField(Field* fieldPtr); - - void _init(); - void _free(); - void _copy(const FieldReader& ic); - - istream* _fin; - bool _eof; - - bool findStartOfNextField(); - - int _noNestedBrackets; - - bool _delimatorEatLookUp[256]; - bool _delimatorKeepLookUp[256]; - -}; - -}; - -#endif // __SG_FIELD_READER_H diff --git a/include/osg/FieldReaderIterator b/include/osg/FieldReaderIterator deleted file mode 100644 index 2d91dc5dd..000000000 --- a/include/osg/FieldReaderIterator +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef OSG_FIELDREADERITERATOR -#define OSG_FIELDREADERITERATOR 1 - -#include -#include - -namespace osg { - - -class SG_EXPORT FieldReaderIterator -{ - public: - - enum { - MINIMUM_FIELD_READER_QUEUE_SIZE = 10 - }; - - FieldReaderIterator(); - FieldReaderIterator(const FieldReaderIterator& ic); - virtual ~FieldReaderIterator(); - - virtual FieldReaderIterator& operator = (const FieldReaderIterator& ic); - - void attach(istream* input); - void detach(); - - virtual bool eof() const; - - FieldReader& getFieldReader() { return _reader; } - - void insert(int pos,Field* field); - void insert(int pos,const char* str); - - Field& operator [] (int pos); - Field& field (int pos); - - FieldReaderIterator& operator ++ (); - FieldReaderIterator& operator += (int no); - -/** increments the itetor of the next simple field or - whole block if the current field[0] is an open bracket */ - void advanceOverCurrentFieldOrBlock(); - void advanceToEndOfCurrentBlock(); - void advanceToEndOfBlock(int noNestBrackets); - - bool matchSequence(const char* str); - - private: - - void _init(); - void _free(); - void _copy(const FieldReaderIterator& ic); - - FieldReader _reader; - - Field _blank; - - Field* _previousField; - - Field** _fieldQueue; - int _fieldQueueSize; - int _fieldQueueCapacity; - -}; - -}; - -#endif // __OSG_FIELD_READER_QUEUE_H diff --git a/include/osg/FileNameUtils b/include/osg/FileNameUtils deleted file mode 100644 index e61face84..000000000 --- a/include/osg/FileNameUtils +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef OSG_FILENAMEUTILS -#define OSG_FILENAMEUTILS 1 - -#include - -#include - -namespace osg { - -SG_EXPORT extern std::string getFilePath(const std::string& filename); -SG_EXPORT extern std::string getFileExtension(const std::string& filename); -SG_EXPORT extern std::string getLowerCaseFileExtension(const std::string& filename); -SG_EXPORT extern std::string getSimpleFileName(const std::string& fileName); -SG_EXPORT extern std::string getStrippedName(const std::string& fileName); - -}; - -#endif diff --git a/include/osg/GeoState b/include/osg/GeoState deleted file mode 100644 index a634190a9..000000000 --- a/include/osg/GeoState +++ /dev/null @@ -1,150 +0,0 @@ -#ifndef OSG_GEOSTATE -#define OSG_GEOSTATE 1 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace osg { - -class Input; -class Output; - -/** -Encapsulates OpenGL state modes and attributes. -Used to specificy textures etc of osg::GeoSet's which hold references -to a single osg::GeoState. GeoState can be shared between GeoSet's -and is recommend if possible as it minimize expensive state changes -in the graphics pipeline. -*/ -class SG_EXPORT GeoState : public Object -{ - public : - - enum AttributeType - { - ANTIALIAS, - FACE_CULL, - FOG, - LIGHTING, - MATERIAL, - POINT, - POLYGON_OFFSET, - TEXENV, - TEXGEN, - TEXMAT, - TEXTURE, - TRANSPARENCY, - WIREFRAME, - ALPHAFUNC - }; - - enum AttributeMode - { - INHERIT, - OFF, - ON, - OVERRIDE_OFF, - OVERRIDE_ON, - }; - - GeoState(); - static GeoState* instance(); - virtual Object* clone() const { return new GeoState(); } - virtual bool isSameKindAs(Object* obj) { return dynamic_cast(obj)!=NULL; } - const char* className() const { return "GeoState"; } - - /** set all the modes to on or off so that it defines a - complete state, typically used for a default global state.*/ - void setGlobalDefaults(); - - /** set all the modes to inherit, typically used to signifiy - nodes which inherit all of their modes for the global state.*/ - void setAllToInherit(); - - void setMode(AttributeType type, AttributeMode mode); - AttributeMode getMode(AttributeType type) const; - - void setAttribute(AttributeType type, Object *attribute); - Object* getAttribute(AttributeType type) const; - - bool isTransparent() { return _transparencing==ON; } - - void apply(); - void apply(GeoState* global,GeoState* prev); - - bool check(); - - static AttributeMode combineMode(const AttributeMode g,const AttributeMode p,const AttributeMode c) - { - AttributeMode gp = mergeMode(g,p); - AttributeMode gc = mergeMode(g,c); - if (gc==gp) return INHERIT; - else return gc; - } - - static AttributeMode mergeMode(const AttributeMode lhs,const AttributeMode rhs) - { - AttributeMode mode; - if (rhs==INHERIT || lhs==OVERRIDE_OFF || lhs==OVERRIDE_ON) mode = lhs; - else mode = rhs; - if (mode==OVERRIDE_OFF) return OFF; - else if (mode==OVERRIDE_OFF) return ON; - return mode; - } - - protected : - - - virtual ~GeoState(); - - GeoState(const GeoState&):Object() {} - GeoState& operator = (const GeoState&) { return *this; } - - virtual bool readLocalData(Input& fr); - virtual bool writeLocalData(Output& fw); - - bool matchModeStr(const char* str, AttributeMode& mode); - const char* getModeStr(AttributeMode flag); - - // Modes - AttributeMode _transparencing; - AttributeMode _face_culling; - AttributeMode _lighting; - AttributeMode _texturing; - AttributeMode _fogging; - AttributeMode _texgening; - AttributeMode _antialiasing; - AttributeMode _colortable; - AttributeMode _pointSmoothing; - AttributeMode _polygonOffsetting; - AttributeMode _alphaTesting; - - // Attributes - ref_ptr _texture; - ref_ptr _texgen; - ref_ptr _material; - ref_ptr _texenv; - ref_ptr _transparency; - ref_ptr _texmat; - ref_ptr _fog; - ref_ptr _point; - ref_ptr _polygonOffset; - ref_ptr _cullFace; - ref_ptr _alphaFunc; -}; - -}; - -#endif diff --git a/include/osg/Input b/include/osg/Input deleted file mode 100644 index bb763af4f..000000000 --- a/include/osg/Input +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef OSG_INPUT -#define OSG_INPUT 1 - -#include - -#include -#include - -namespace osg { - -class Object; -class Image; -class Node; - -/** Class for managing the reading of ASCII .osg files.*/ -class SG_EXPORT Input : public FieldReaderIterator -{ - public: - -// Will extend to handle #DEF and use -// functionality similar to Inventor, -// and add the ability to handle #include -// from within the OSG file format. - - Input(); - virtual ~Input(); - - virtual Object* readObject(); - virtual Object* readObject(const std::string& fileName); - - virtual Image* readImage(); - virtual Image* readImage(const std::string& fileName); - - virtual Node* readNode(); - virtual Node* readNode(const std::string& fileName); - - virtual Object* getObjectForUniqueID(const std::string& uniqueID); - virtual void regisiterUniqueIDForObject(const std::string& uniqueID,Object* obj); - - private: - - typedef std::map UniqueIDToObjectMapping; - UniqueIDToObjectMapping _uniqueIDToObjectMap; - -}; - -}; - -#endif // __SG_INPUT_H diff --git a/include/osg/Lighting b/include/osg/Lighting deleted file mode 100644 index 776ecd9c3..000000000 --- a/include/osg/Lighting +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef OSG_LIGHTING -#define OSG_LIGHTING 1 - -#include - -namespace osg { - -/** Class to globally control OpenGL's lighting.*/ - -class SG_EXPORT Lighting -{ - public : - /** Enable lighting.*/ - static void enable(); - /** Disable lighting.*/ - static void disable(); -}; - -}; - -#endif diff --git a/include/osg/OSG b/include/osg/OSG deleted file mode 100644 index 7ee651ef6..000000000 --- a/include/osg/OSG +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef OSG_OSG -#define OSG_OSG 1 - -#include - -namespace osg { - -SG_EXPORT extern void Init( void ); -SG_EXPORT extern void SetFilePath( const char *_path ); -SG_EXPORT extern char *FindFile( const char *file ); -SG_EXPORT extern char *findDSO( const char *name ); - -}; - -#endif diff --git a/include/osg/Output b/include/osg/Output deleted file mode 100644 index a10350c95..000000000 --- a/include/osg/Output +++ /dev/null @@ -1,98 +0,0 @@ -#ifndef OSG_OUTPUT -#define OSG_OUTPUT 1 - -#include - -#include -#include - -#ifdef OSG_USE_IO_DOT_H -#include -#else -#include -using namespace std; -#endif - -namespace osg { - -class Object; - -/** ofstream wrapper class for adding support for indenting. - Used in output of .osg ASCII files to improve their readability.*/ -class SG_EXPORT Output : public ofstream -{ - public: - - Output(); - virtual ~Output(); - - Output& indent(); - - int getIndentStep() const { return _indentStep; } - void setIndentStep(int step) { _indentStep = step; } - - int getIndent() const { return _indent; } - void setIndent(int indent) { _indent = indent; } - - int getNumIndicesPerLine() const { return _numIndicesPerLine; } - void setNumIndicesPerLine(int num) { _numIndicesPerLine = num; } - - void moveIn(); - void moveOut(); - - bool getUniqueIDForObject(Object* obj,std::string& uniqueID); - bool createUniqueIDForObject(Object* obj,std::string& uniqueID); - bool registerUniqueIDForObject(Object* obj,std::string& uniqueID); - - - protected: - - // prevent copy construction and assignment. - Output(const Output&) : ofstream() {} - Output& operator = (const Output&) { return *this; } - - virtual void _init(); - virtual void _free(); - - int _indent; - int _indentStep; - - int _numIndicesPerLine; - - typedef std::map UniqueIDToLabelMapping; - UniqueIDToLabelMapping _objectToUniqueIDMap; - -}; - -template -bool writeArrayBlock(Output& fw,T* start,T* finish) -{ - fw.indent() << "{" << endl; - fw.moveIn(); - int numIndicesThisLine = 0; - for(T* itr=start;itr!=finish;++itr) - { - if (numIndicesThisLine>=fw.getNumIndicesPerLine()) - { - fw << endl; - numIndicesThisLine = 0; - } - - if (numIndicesThisLine==0) fw.indent(); - else fw << " "; - - fw << *itr; - - ++numIndicesThisLine; - - } - fw << endl; - fw.moveOut(); - fw.indent() << "}" << endl; - return true; -} - - -}; - -#endif // __SG_OUTPUT_H diff --git a/include/osg/Registry b/include/osg/Registry deleted file mode 100644 index 81f915155..000000000 --- a/include/osg/Registry +++ /dev/null @@ -1,168 +0,0 @@ -#ifndef OSG_REGISTRY -#define OSG_REGISTRY 1 - -#include -#include - -#include -#include - -namespace osg { - -// forward declare referenced classes to help avoid mutiple includes -class Object; -class Image; -class Node; -class Input; - -SG_EXPORT extern Object* loadObjectFile(const char *name); -SG_EXPORT extern Image* loadImageFile(const char *name); -SG_EXPORT extern Node* loadNodeFile(const char *name); - -SG_EXPORT extern bool saveObjectFile(Object& object, const char *name); -SG_EXPORT extern bool saveImageFile(Image& image, const char *name); -SG_EXPORT extern bool saveNodeFile(Node& node, const char *name); - -/** pure virtual base class for reading and writing of non native formats. */ -class SG_EXPORT ReaderWriter : public Referenced -{ - public: - virtual ~ReaderWriter() {} - virtual const char* className() = 0; - virtual bool acceptsExtension(const std::string& /*extension*/) { return false; } - - virtual Object* readObject(const std::string& /*fileName*/) { return NULL; } - virtual Image* readImage(const std::string& /*fileName*/) { return NULL; } - virtual Node* readNode(const std::string& /*fileName*/) { return NULL; } - - virtual bool writeObject(Object& /*obj*/,const std::string& /*fileName*/) {return false; } - virtual bool writeImage(Image& /*image*/,const std::string& /*fileName*/) {return false; } - virtual bool writeNode(Node& /*node*/,const std::string& /*fileName*/) { return false; } -}; - -/** - Registry is a singleton factory which stores - the Objects types available at runtime for loading, - and any Object reader or writers which are linked in - at runtime for reading non-native file formats. - - The RegisterObjectProxy defined in Object.h can be - used to automatically register at runtime a Object - with the Registry. - - The RegisterReaderWriterProxy defined in ReaderWriter.h can - be used to automatically register at runtime a reader/writer - with the Registry. -*/ -class SG_EXPORT Registry -{ - public: - - ~Registry(); - - static Registry* instance(); - - void addPrototype(Object* obj); - void removePrototype(Object* obj); - - void addReaderWriter(ReaderWriter* rw); - void removeReaderWriter(ReaderWriter* rw); - - /** create the platform specific library name associated with file.*/ - std::string createLibraryNameForFile(const std::string& fileName); - - /** create the platform specific library name associated with file extension.*/ - std::string createLibraryNameForExt(const std::string& ext); - - /** find the library in the SG_LIBRARY_PATH and load it.*/ - bool loadLibrary(const std::string& fileName); - /** close the attached library with specified name.*/ - bool closeLibrary(const std::string& fileName); - - Object* readObject(Input& fr); - Object* readObject(const std::string& fileName); - bool writeObject(Object& obj, const std::string& fileName); - - Image* readImage(Input& fr); - Image* readImage(const std::string& fileName); - bool writeImage(Image& obj, const std::string& fileName); - - Node* readNode(Input& fr); - Node* readNode(const std::string& fileName); - bool writeNode(Node& node, const std::string& fileName); - - - private: - - typedef std::vector > PrototypeList; - typedef std::vector > ReaderWriterList; - typedef std::vector > DynamicLibraryList; - - /** constructor is private, as its a singleton, preventing - construction other than via the instance() method and - therefore ensuring only one copy is ever constructed*/ - Registry(); - - /** get the attached library with specified name.*/ - DynamicLibraryList::iterator getLibraryItr(const std::string& fileName); - DynamicLibrary* getLibrary(const std::string& fileName); - - PrototypeList _protoList; - ReaderWriterList _rwList; - DynamicLibraryList _dlList; - - std::vector _nodeProtoList; - std::vector _imageProtoList; - - bool _openingLibrary; - -}; - -/** Proxy class for automatic registration of reader/writers with the - Registry.*/ -template -class RegisterObjectProxy -{ - public: - RegisterObjectProxy() - { - _obj = new T; - _obj->ref(); - Registry::instance()->addPrototype(_obj); - } - ~RegisterObjectProxy() - { - Registry::instance()->removePrototype(_obj); - _obj->unref(); - } - - protected: - T* _obj; -}; - -/** Proxy class for automatic registration of reader/writers with the - Registry.*/ -template -class RegisterReaderWriterProxy -{ - public: - RegisterReaderWriterProxy() - { - _rw = new T; - _rw->ref(); - Registry::instance()->addReaderWriter(_rw); - } - - ~RegisterReaderWriterProxy() - { - Registry::instance()->removeReaderWriter(_rw); - _rw->unref(); - } - - protected: - T* _rw; -}; - -}; - -#endif // __SG_OBJECT_FACTORY_H diff --git a/include/osg/Scene b/include/osg/Scene deleted file mode 100644 index 45811deb7..000000000 --- a/include/osg/Scene +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef OSG_SCENE -#define OSG_SCENE 1 - -#include -#include - -namespace osg { - -/** The top level group node in a scene graph. */ -class SG_EXPORT Scene : public Group -{ - public : - Scene(); - - virtual Object* clone() const { return new Scene(); } - virtual bool isSameKindAs(Object* obj) { return dynamic_cast(obj)!=NULL; } - virtual const char* className() const { return "Scene"; } - virtual void accept(NodeVisitor& nv) { nv.apply(*this); } - - /** set the scene's GeoState.*/ - void setGState(osg::GeoState* gstate); - - /** return the scene's GeoState.*/ - osg::GeoState* getGState() { return _gstate; } - - protected : - - virtual ~Scene(); - - virtual bool readLocalData(Input& fr); - virtual bool writeLocalData(Output& fw); - - osg::GeoState* _gstate; - -}; - -}; - -#endif diff --git a/include/osg/Seg b/include/osg/Seg deleted file mode 100644 index 50a999a24..000000000 --- a/include/osg/Seg +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef OSG_SEG -#define OSG_SEG 1 - -#include -#include -#include -#include -#include -#include - -namespace osg { - -/** Segment class for representing a line segment.*/ -class SG_EXPORT Seg : public Referenced -{ - public: - - Seg() {}; - Seg(const Seg& seg) : Referenced(),_s(seg._s),_e(seg._e) {} - Seg(const Vec3& s,const Vec3& e) : _s(s),_e(e) {} - virtual ~Seg() {} - - Seg& operator = (const Seg& seg) { _s = seg._s; _e = seg._e; return *this; } - - void set(const Vec3& s,const Vec3& e) { _s=s; _e=e; } - - const Vec3& start() const { return _s; } - Vec3& start() { return _s; } - - const Vec3& end() const { return _e; } - Vec3& end() { return _e; } - - /** return true if segment intersects BoundingBox.*/ - bool intersect(const BoundingBox& bb) const; - - /** return true if segment intersects BoundingSphere and return the intersection ratio's.*/ - bool intersect(const BoundingBox& bb,float& r1,float& r2) const; - - /** return true if segment intersects BoundingSphere.*/ - bool intersect(const BoundingSphere& bs) const; - - /** return true if segment intersects BoundingSphere and return the intersection ratio's.*/ - bool intersect(const BoundingSphere& bs,float& r1,float& r2) const; - - /** return true if segment intersects triangle and set ratio long segment. */ - bool intersect(const Vec3& v1,const Vec3& v2,const Vec3& v3,float& r); - - /** post multiply a segment by matrix.*/ - void mult(const Seg& seg,const Matrix& m) { _s = seg._s*m; _e = seg._e*m; } - /** pre multiply a segment by matrix.*/ - void mult(const Matrix& m,const Seg& seg) { _s = m*seg._s; _e = m*seg._e; } - - protected: - - static bool intersectAndClip(Vec3& s,Vec3& e,const BoundingBox& bb); - - Vec3 _s; - Vec3 _e; -}; - -}; - -#endif diff --git a/include/osg/Sequence b/include/osg/Sequence deleted file mode 100644 index f23aad78d..000000000 --- a/include/osg/Sequence +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef OSG_SEQUENCE -#define OSG_SEQUENCE 1 - -#include - -namespace osg { - -/** Sequence - Switch node which allows iterators between children. - - Note: has not been implemented yet! -*/ -class SG_EXPORT Sequence : public Group -{ - public : - Sequence() {} - - virtual Object* clone() const { return new Sequence(); } - virtual bool isSameKindAs(Object* obj) { return dynamic_cast(obj)!=NULL; } - virtual const char* className() const { return "Sequence"; } - virtual void accept(NodeVisitor& nv) { nv.apply(*this); } - - protected : - virtual ~Sequence() {} -}; - -}; - -#endif diff --git a/include/osgUtil/RenderVisitor b/include/osgUtil/RenderVisitor deleted file mode 100644 index 8246da666..000000000 --- a/include/osgUtil/RenderVisitor +++ /dev/null @@ -1,196 +0,0 @@ -#ifndef OSGUTIL_RENDERVISITOR -#define OSGUTIL_RENDERVISITOR 1 - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include - -namespace osgUtil { - -/** Container class for encapsulating the viewing state in local - coordinates, during the cull traversal. -*/ -class OSGUTIL_EXPORT ViewState : public osg::Referenced -{ - public: - - ViewState(); - - osg::Matrix* _matrix; - osg::Matrix* _inverse; - osg::Vec3 _eyePoint; - osg::Vec3 _centerPoint; - osg::Vec3 _lookVector; - osg::Vec3 _upVector; - osg::Vec3 _frustumTopNormal; - osg::Vec3 _frustumBottomNormal; - osg::Vec3 _frustumLeftNormal; - osg::Vec3 _frustumRightNormal; - float _ratio; - - bool _viewFrustumCullingActive; - bool _smallFeatureCullingActive; - - bool isCulled(const osg::BoundingSphere& sp); - bool isCulled(const osg::BoundingBox& bb); - - protected: - - ~ViewState(); - -}; - - -/** - * Basic NodeVisitor implementation for rendering a scene. - * This visitor traverses the scene graph, collecting transparent and - * opaque osg::GeoSets into a depth sorted transparent bin and a state - * sorted opaque bin. The opaque bin is rendered first, and then the - * transparent bin in rendered in order from the furthest osg::GeoSet - * from the eye to the one nearest the eye. - */ -class OSGUTIL_EXPORT RenderVisitor : public osg::NodeVisitor -{ - public: - - RenderVisitor(); - virtual ~RenderVisitor(); - - void reset(); - - virtual void apply(osg::Node&); - virtual void apply(osg::Geode& node); - virtual void apply(osg::Billboard& node); - virtual void apply(osg::LightSource& node); - - virtual void apply(osg::Group& node); - virtual void apply(osg::DCS& node); - virtual void apply(osg::Switch& node); - virtual void apply(osg::LOD& node); - virtual void apply(osg::Scene& node); - - void setGlobalState(osg::GeoState* global); - - void setPerspective(const osg::Camera& camera); - void setPerspective(float fovy,float aspect,float znear,float zfar); - - void setLookAt(const osg::Camera& camera); - void setLookAt(const osg::Vec3& eye,const osg::Vec3& center,const osg::Vec3& upVector); - void setLookAt(double eyeX,double eyeY,double eyeZ, - double centerX,double centerY,double centerZ, - double upX,double upY,double upZ); - - - void setLODBias(float bias) { _LODBias = bias; } - float getLODBias() { return _LODBias; } - - enum TransparencySortMode { - LOOK_VECTOR_DISTANCE, - OBJECT_EYE_POINT_DISTANCE - }; - - void setTransparencySortMode(TransparencySortMode tsm) { _tsm = tsm; } - - enum CullingType { - VIEW_FRUSTUM_CULLING, - SMALL_FEATURE_CULLING - }; - - /** - * Enables/disables the specified culling type. - * @param ct The culling type to enable/disable. - * @param active true enables the culling type, false disables. - */ - void setCullingActive(CullingType ct, bool active); - - /** - * Returns the state of the specified culling type. - * @result true, if culling type is enabled, false otherwise. - */ - bool getCullingActive(CullingType ct); - - /** - * Calculates the near_plane and the far_plane for the current - * camera view depending on the objects currently stored in the - * opaque and transparent bins. - * @param near_plane reference to a variable that can store the - * near plane result. - * @param far_plane reference to a variable that can store the - * far plane result. - * @result true, if near_plane and far_plane contain valid values, - * false otherwise. - */ - bool calcNearFar(double& near_plane, double& far_plane); - - /** - * Renders the osg::GeoSets that were collected in the opaque and - * transparent bins before. - */ - void render(); - - protected: - - void pushMatrix(const osg::Matrix& matrix); - void popMatrix(); - - osg::Matrix* getCurrentMatrix(); - osg::Matrix* getInverseCurrentMatrix(); - const osg::Vec3& getEyeLocal(); - const osg::Vec3& getCenterLocal(); - const osg::Vec3& getLookVectorLocal(); - - - bool _viewFrustumCullingActive; - bool _smallFeatureCullingActive; - - bool isCulled(const osg::BoundingSphere& sp); - bool isCulled(const osg::BoundingBox& bb); - - typedef std::pair MatrixGeoSet; - - typedef std::vector ViewStateStack; - ViewStateStack _viewStateStack; - ViewState* _tvs; - ViewState* _cvs; - - - typedef std::multimap OpaqueList; - typedef std::multimap TransparentList; - typedef std::map LightList; - - OpaqueList _opaqueGeoSets; - TransparentList _transparentGeoSets; - LightList _lights; - - osg::GeoState* _globalState; - float _LODBias; - - float _fovy; - float _aspect; - float _znear; - float _zfar; - - void calculateClippingPlanes(); - - // frustum clipping normals. - osg::Vec3 _frustumTop; - osg::Vec3 _frustumBottom; - osg::Vec3 _frustumLeft; - osg::Vec3 _frustumRight; - - TransparencySortMode _tsm; -}; - -}; - -#endif - diff --git a/src/osg/DCS.cpp b/src/osg/DCS.cpp deleted file mode 100644 index 8d61f4180..000000000 --- a/src/osg/DCS.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include "osg/DCS" -#include "osg/Registry" -#include "osg/Input" -#include "osg/Output" - -using namespace osg; - -RegisterObjectProxy g_DCSProxy; - -DCS::DCS() -{ - _mat = new Matrix( - 1.0, 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0, - 0.0, 0.0, 0.0, 1.0 ); - - _mat->ref(); -} - - -DCS::DCS(const Matrix& mat ) -{ - _mat = new Matrix(mat); - _mat->ref(); -} - - -DCS::~DCS() -{ - _mat->unref(); -} - -void DCS::setMatrix(const Matrix& mat ) -{ - *_mat = mat; - dirtyBound(); -} - -void DCS::preTranslate( float tx, float ty, float tz ) -{ - _mat->preTrans( tx, ty, tz ); - dirtyBound(); -} - -void DCS::preRotate( float deg, float x, float y, float z ) -{ - _mat->preRot( deg, x, y, z ); - dirtyBound(); -} - -bool DCS::readLocalData(Input& fr) -{ - bool iteratorAdvanced = false; - - if (Matrix* tmpMatrix = static_cast(Matrix::instance()->readClone(fr))) - { - - if (_mat) _mat->unref(); - _mat = tmpMatrix; - _mat->ref(); - - iteratorAdvanced = true; - } - - if (Group::readLocalData(fr)) iteratorAdvanced = true; - - return iteratorAdvanced; -} - - -bool DCS::writeLocalData(Output& fw) -{ - if (_mat) _mat->write(fw); - - - return Group::writeLocalData(fw); -} - -bool DCS::computeBound( void ) -{ - if (!Group::computeBound()) return false; - - Vec3 xdash = _bsphere._center; - xdash.x() += _bsphere._radius; - xdash = xdash*(*_mat); - - Vec3 ydash = _bsphere._center; - ydash.y() += _bsphere._radius; - ydash = ydash*(*_mat); - - Vec3 zdash = _bsphere._center; - zdash.y() += _bsphere._radius; - zdash = zdash*(*_mat); - - _bsphere._center = _bsphere._center*(*_mat); - - xdash -= _bsphere._center; - float len_xdash = xdash.length(); - - ydash -= _bsphere._center; - float len_ydash = ydash.length(); - - zdash -= _bsphere._center; - float len_zdash = zdash.length(); - - _bsphere._radius = len_xdash; - if (_bsphere._radius -#include -#include -#else -#include -#include -#endif - -#ifndef OSG_USE_IO_DOT_H -#include -using namespace std; -#endif - -#include "osg/DynamicLibrary" -#include "osg/OSG" -#include "osg/Notify" - -using namespace osg; - -DynamicLibrary::DynamicLibrary(const std::string& name,HANDLE handle) -{ - _name = name; - _handle = handle; -} - -DynamicLibrary::~DynamicLibrary() -{ - if (_handle) - { -#ifdef WIN32 - FreeLibrary((HMODULE)_handle); -#else - dlclose(_handle); -#endif - } -} - -DynamicLibrary* DynamicLibrary::loadLibrary(const std::string& libraryName) -{ - - char* fullLibraryName = osg::findDSO( libraryName.c_str() ); - if (fullLibraryName==NULL) return NULL; - -#ifdef WIN32 - HANDLE handle = LoadLibrary( fullLibraryName ); - if (handle) return new DynamicLibrary(libraryName,handle); - notify(WARN) << "DynamicLibrary::failed loading "< -#include - -// copied form glut_ext.c -// to be rewritten... Robert Osfield, November 2000. -bool osg::ExtensionSupported(const char *extension) -{ - static const GLubyte *extensions = NULL; - const GLubyte *start; - GLubyte *where, *terminator; - - /* Extension names should not have spaces. */ - where = (GLubyte *) strchr(extension, ' '); - if (where || *extension == '\0') - return 0; - - if (!extensions) { - extensions = glGetString(GL_EXTENSIONS); - } - /* It takes a bit of care to be fool-proof about parsing the - OpenGL extensions string. Don't be fooled by sub-strings, - etc. */ - start = extensions; - for (;;) { - /* If your application crashes in the strstr routine below, - you are probably calling glutExtensionSupported without - having a current window. Calling glGetString without - a current OpenGL context has unpredictable results. - Please fix your program. */ - where = (GLubyte *) strstr((const char *) start, extension); - if (!where) - break; - terminator = where + strlen(extension); - if (where == start || *(where - 1) == ' ') { - if (*terminator == ' ' || *terminator == '\0') { - return true; - } - } - start = terminator; - } - return false; -} diff --git a/src/osg/Field.cpp b/src/osg/Field.cpp deleted file mode 100644 index 03fa7c61a..000000000 --- a/src/osg/Field.cpp +++ /dev/null @@ -1,422 +0,0 @@ -#include "osg/Field" - -using namespace osg; - -Field::Field() -{ - _init(); -} - - -Field::Field(const Field& ic) -{ - _copy(ic); -} - - -Field::~Field() -{ - _free(); -} - - -Field& Field::operator = (const Field& ic) -{ - if (this==&ic) return *this; - _free(); - _copy(ic); - return *this; -} - - -void Field::_free() -{ -// free all data - if (_fieldCache) delete [] _fieldCache; - - _init(); - -} - - -void Field::_init() -{ - - _fieldCacheCapacity = 256; - _fieldCacheSize = 0; - _fieldCache = NULL; - - _fieldType = UNINTIALISED; - - _withinQuotes = false; - - _noNestedBrackets = 0; - -} - - -void Field::_copy(const Field& ic) -{ - -// copy string cache. - if (ic._fieldCache) - { - _fieldCacheCapacity = ic._fieldCacheCapacity; - _fieldCacheSize = ic._fieldCacheSize; - _fieldCache = new char [_fieldCacheCapacity]; - strncpy(_fieldCache,ic._fieldCache,_fieldCacheCapacity); - } - else - { - _fieldCacheCapacity = 0; - _fieldCacheSize = 0; - _fieldCache = NULL; - } - - _fieldType = ic._fieldType; - - _withinQuotes = ic._withinQuotes; - - _noNestedBrackets = ic._noNestedBrackets; -} - - -void Field::setWithinQuotes(bool withinQuotes) -{ - _withinQuotes=withinQuotes; - _fieldType = UNINTIALISED; -} - - -bool Field::getWithinQuotes() -{ - return _withinQuotes; -} - - -void Field::setNoNestedBrackets(int no) -{ - _noNestedBrackets=no; -} - - -int Field::getNoNestedBrackets() -{ - return _noNestedBrackets; -} - - -const char* Field::getStr() const -{ - if (_fieldCacheSize!=0) return _fieldCache; - else return NULL; -} - - -char* Field::takeStr() -{ - char* field = _fieldCache; - - _fieldCache = NULL; - _fieldCacheSize = 0; - - _fieldType = UNINTIALISED; - _withinQuotes = false; - - return field; -} - - -void Field::reset() -{ - _fieldCacheSize = 0; - if (_fieldCache) - { - _fieldCache[_fieldCacheSize] = 0; - } - - _withinQuotes = false; - _noNestedBrackets = 0; -} - - -void Field::addChar(char c) -{ - if (_fieldCache==NULL) - { - if (_fieldCacheCapacity=_fieldCacheCapacity-1) - { - if (_fieldCacheCapacity=_fieldCacheCapacity-1) _fieldCacheCapacity *= 2; - char* tmp_str = _fieldCache; - _fieldCache = new char[_fieldCacheCapacity]; - strncpy(_fieldCache,tmp_str,_fieldCacheSize); - delete [] tmp_str; - - } - _fieldCache[_fieldCacheSize++] = c; - _fieldCache[_fieldCacheSize] = 0; - _fieldType = UNINTIALISED; -} - - -Field::FieldType Field::getFieldType() const -{ - if (_fieldType==UNINTIALISED && _fieldCache) - { - _fieldType = calculateFieldType(_fieldCache,_withinQuotes); - } - return _fieldType; -} - - -bool Field::isValid() const -{ - if (_fieldCacheSize>0 && !_withinQuotes) return true; - else return false; -} - - -bool Field::isOpenBracket() const -{ - if (_fieldCacheSize==1) return _fieldCache[0]=='{'; - else return false; -} - - -bool Field::isCloseBracket() const -{ - if (_fieldCacheSize==1) return _fieldCache[0]=='}'; - else return false; -} - - -bool Field::isWord() const -{ - getFieldType(); - return (_fieldType==WORD); -} - - -bool Field::matchWord(const char* str) const -{ - getFieldType(); - return _fieldType==WORD && strcmp(_fieldCache,str)==0; -} - - -bool Field::matchWord(const char* str,int noCharacters) const -{ - getFieldType(); - return _fieldType==WORD && strncmp(_fieldCache,str,noCharacters)==0; -} - - -bool Field::isString() const -{ - return getNoCharacters()!=0; -} - - -bool Field::matchString(const char* str) const -{ - return strcmp(_fieldCache,str)==0; -} - - -bool Field::matchString(const char* str,int noCharacters) const -{ - return strncmp(_fieldCache,str,noCharacters)==0; -} - - -bool Field::isQuotedString() const -{ - return _withinQuotes; -} - - -bool Field::isInt() const -{ - getFieldType(); - return _fieldType==INTEGER; -} - - -bool Field::matchInt(int i) const -{ - getFieldType(); - if (_fieldType==INTEGER) - { - return atoi(_fieldCache)==i; - } - else - { - return false; - } -} - - -bool Field::getInt(int& i) const -{ - getFieldType(); - if (_fieldType==INTEGER) - { - i = atoi(_fieldCache); - return true; - } - else - { - return false; - } -} - - -bool Field::isFloat() const -{ - getFieldType(); - return _fieldType==REAL || _fieldType==INTEGER; -} - - -bool Field::matchFloat(float f) const -{ - getFieldType(); - if (_fieldType==REAL || _fieldType==INTEGER) - { - return (float)atof(_fieldCache)==f; - } - else - { - return false; - } -} - - -bool Field::getFloat(float& f) const -{ - getFieldType(); - if (_fieldType==REAL || _fieldType==INTEGER) - { - f = (float)atof(_fieldCache); - return true; - } - else - { - return false; - } -} - - -bool Field::isDouble() const -{ - getFieldType(); - return _fieldType==REAL || _fieldType==INTEGER; -} - - -bool Field::matchDouble(double d) const -{ - getFieldType(); - if (_fieldType==REAL || _fieldType==INTEGER) - { - return atof(_fieldCache)==d; - } - else - { - return false; - } -} - - -bool Field::getDouble(double& d) const -{ - getFieldType(); - if (_fieldType==REAL || _fieldType==INTEGER) - { - d = atof(_fieldCache); - return true; - } - else - { - return false; - } -} - - -Field::FieldType Field::calculateFieldType(const char* str,bool withinQuotes) -{ - if (str==NULL) return BLANK; - if (*str==0) return BLANK; - - if (withinQuotes) return STRING; - - bool hadPlusMinus = false; - bool hadDecimalPlace = false; - bool hadExponent = false; - bool couldBeInt = true; - bool couldBeFloat = true; - int noZeroToNine = 0; - - const char* ptr = str; - while (*ptr!=0 && couldBeFloat) - { - if (*ptr=='+' || *ptr=='-') - { - if (hadPlusMinus) - { - couldBeInt = false; - couldBeFloat = false; - } else hadPlusMinus = true; - } - else if (*ptr>='0' && *ptr<='9') - { - noZeroToNine++; - } - else if (*ptr=='.') - { - if (hadDecimalPlace) - { - couldBeInt = false; - couldBeFloat = false; - } - else - { - hadDecimalPlace = true; - couldBeInt = false; - } - } - else if (*ptr=='e' || *ptr=='E') - { - if (hadExponent || noZeroToNine==0) - { - couldBeInt = false; - couldBeFloat = false; - } - else - { - hadExponent = true; - couldBeInt = false; - hadDecimalPlace = false; - hadPlusMinus = false; - noZeroToNine=0; - } - } - else - { - couldBeInt = false; - couldBeFloat = false; - } - ++ptr; - } - - if (couldBeInt && noZeroToNine>0) return INTEGER; - if (couldBeFloat && noZeroToNine>0) return REAL; - if (str[0]=='{') return OPEN_BRACKET; - if (str[0]=='}') return CLOSE_BRACKET; - return WORD; -} diff --git a/src/osg/FieldReader.cpp b/src/osg/FieldReader.cpp deleted file mode 100644 index 9423962ff..000000000 --- a/src/osg/FieldReader.cpp +++ /dev/null @@ -1,269 +0,0 @@ -#include "osg/FieldReader" -#include "osg/Field" - -using namespace osg; - -FieldReader::FieldReader() -{ - _init(); -} - - -FieldReader::FieldReader(const FieldReader& ic) -{ - _copy(ic); -} - - -FieldReader::~FieldReader() -{ - _free(); -} - - -FieldReader& FieldReader::operator = (const FieldReader& ic) -{ - if (this==&ic) return *this; - _free(); - _copy(ic); - return *this; -} - - -void FieldReader::_free() -{ -// free all data - - _init(); - -} - - -void FieldReader::_init() -{ - _fin = NULL; - _eof = true; - - _noNestedBrackets = 0; - - int i; - for(i=0;i<256;++i) _delimatorEatLookUp[i]=false; - _delimatorEatLookUp[' '] = true; - _delimatorEatLookUp['\t'] = true; - _delimatorEatLookUp['\n'] = true; - _delimatorEatLookUp['\r'] = true; - - for(i=0;i<256;++i) _delimatorKeepLookUp[i]=false; - _delimatorKeepLookUp['{'] = true; - _delimatorKeepLookUp['}'] = true; - _delimatorKeepLookUp['"'] = true; - _delimatorKeepLookUp['\''] = true; - -} - - -void FieldReader::_copy(const FieldReader& ic) -{ - - _fin = ic._fin; - _eof = ic._eof; - - _noNestedBrackets = ic._noNestedBrackets; - - int i; - for(i=0;i<256;++i) _delimatorEatLookUp[i]=ic._delimatorEatLookUp[i]; - for(i=0;i<256;++i) _delimatorKeepLookUp[i]=ic._delimatorKeepLookUp[i]; -} - - -void FieldReader::attach(istream* input) -{ - _fin = input; - - if (_fin) - { - _eof = _fin->eof()!=0; - } - else - { - _eof = true; - } -} - - -void FieldReader::detach() -{ - _fin = NULL; - _eof = true; -} - - -bool FieldReader::eof() const -{ - return _eof; -} - - -bool FieldReader::findStartOfNextField() -{ - int ch = 0; - while (true) - { - ch = _fin->peek(); - if (ch==EOF) - { - _eof = true; - return false; - } - else if (_delimatorEatLookUp[ch]) - { - _fin->ignore(1); - } - else - { - return true; - } - } -} - - -bool FieldReader::readField(Field& fieldPtr) -{ - return _readField(&fieldPtr); -} - - -void FieldReader::ignoreField() -{ - _readField(NULL); -} - - -bool FieldReader::_readField(Field* fieldPtr) -{ - if (fieldPtr) fieldPtr->reset(); - - if (!eof() && findStartOfNextField()) - { - - int ch = _fin->peek(); - if (ch==EOF) - { - _eof = true; - if (fieldPtr) fieldPtr->setNoNestedBrackets(getNoNestedBrackets()); - return fieldPtr && fieldPtr->getNoCharacters()!=0; - } - else if (ch=='"') - { - if (fieldPtr) - { - fieldPtr->setWithinQuotes(true); - fieldPtr->setNoNestedBrackets(getNoNestedBrackets()); - } - _fin->ignore(1); - char c; - while (true) - { - ch = _fin->peek(); - if (ch==EOF) - { - _eof = true; - return fieldPtr && fieldPtr->getNoCharacters()!=0; - } - c = ch; - if (ch=='"') - { - _fin->ignore(1); - //return fieldPtr && fieldPtr->getNoCharacters()!=0; - return fieldPtr!=NULL; - } - else - { - _fin->get(c); - if (fieldPtr) fieldPtr->addChar(c); - } - } - } - else if (ch=='\'') - { - if (fieldPtr) - { - fieldPtr->setWithinQuotes(true); - fieldPtr->setNoNestedBrackets(getNoNestedBrackets()); - } - _fin->ignore(1); - char c; - while (true) - { - ch = _fin->peek(); - if (ch==EOF) - { - _eof = true; - return fieldPtr && fieldPtr->getNoCharacters()!=0; - } - c = ch; - if (ch=='\'') - { - _fin->ignore(1); - //return fieldPtr && fieldPtr->getNoCharacters()!=0; - return fieldPtr!=NULL; - } - else - { - _fin->get(c); - if (fieldPtr) fieldPtr->addChar(c); - } - } - } - else if (_delimatorKeepLookUp[ch]) - { - char c; - _fin->get(c); - if (fieldPtr) fieldPtr->addChar(c); - if (c=='{') ++_noNestedBrackets; - else if (c=='}') --_noNestedBrackets; - if (fieldPtr) fieldPtr->setNoNestedBrackets(getNoNestedBrackets()); - return fieldPtr && fieldPtr->getNoCharacters()!=0; - } - else - { - if (fieldPtr) fieldPtr->setNoNestedBrackets(getNoNestedBrackets()); - char c; - while (true) - { - ch = _fin->peek(); - if (ch==EOF) - { - _eof = true; - return fieldPtr && fieldPtr->getNoCharacters()!=0; - } - c = ch; - if (_delimatorEatLookUp[c]) - { - _fin->ignore(1); - return fieldPtr && fieldPtr->getNoCharacters()!=0; - } - if (_delimatorKeepLookUp[c]) - { - return fieldPtr && fieldPtr->getNoCharacters()!=0; - } - else - { - _fin->get(c); - if (fieldPtr) fieldPtr->addChar(c); - } - } - } - - } - else - { - return false; - } -} - - -int FieldReader::getNoNestedBrackets() const -{ - return _noNestedBrackets; -} diff --git a/src/osg/FieldReaderIterator.cpp b/src/osg/FieldReaderIterator.cpp deleted file mode 100644 index 5491548ec..000000000 --- a/src/osg/FieldReaderIterator.cpp +++ /dev/null @@ -1,361 +0,0 @@ -#include "osg/FieldReaderIterator" - -using namespace osg; - -FieldReaderIterator::FieldReaderIterator() -{ - _init(); -} - - -FieldReaderIterator::FieldReaderIterator(const FieldReaderIterator& ic) -{ - _copy(ic); -} - - -FieldReaderIterator::~FieldReaderIterator() -{ - _free(); -} - - -FieldReaderIterator& FieldReaderIterator::operator = (const FieldReaderIterator& ic) -{ - if (this==&ic) return *this; - _free(); - _copy(ic); - return *this; -} - - -void FieldReaderIterator::_free() -{ -// free all data - if (_previousField) - { - delete _previousField; - } - if (_fieldQueue) - { - for(int i=0;i<_fieldQueueCapacity;++i) - { - if (_fieldQueue[i]) delete _fieldQueue[i]; - _fieldQueue[i] = NULL; - } - delete [] _fieldQueue; - } - _init(); - -} - - -void FieldReaderIterator::_init() -{ - _previousField = NULL; - _fieldQueue = NULL; - _fieldQueueSize = 0; - _fieldQueueCapacity = 0; - -} - - -void FieldReaderIterator::_copy(const FieldReaderIterator& ic) -{ - _reader = ic._reader; - - if (ic._previousField) - { - _previousField = new Field(*ic._previousField); - } - - if (ic._fieldQueue && ic._fieldQueueCapacity>0) - { - _fieldQueue = new Field* [ic._fieldQueueCapacity]; - for(int i=0;i_fieldQueueSize) pos=_fieldQueueSize; - - int i; - if (_fieldQueueSize>=_fieldQueueCapacity) // need to reallocate the stack - { - int newCapacity = _fieldQueueCapacity*2; - if (newCapacity=newCapacity) newCapacity*=2; - Field** newFieldStack = new Field* [newCapacity]; - for(i=0;i<_fieldQueueCapacity;++i) - { - newFieldStack[i] = _fieldQueue[i]; - } - for(;i=pos;++i) - { - _fieldQueue[i+1]=_fieldQueue[i]; - } - _fieldQueue[pos] = field; - ++_fieldQueueSize; -} - - -void FieldReaderIterator::insert(int pos,const char* str) -{ - if (str) - { - Field* field = new Field; - while(*str!=0) - { - field->addChar(*str); - ++str; - } - insert(pos,field); - } -} - - -Field& FieldReaderIterator::operator [] (int pos) -{ - return field(pos); -} - - -Field& FieldReaderIterator::field (int pos) -{ - if (pos<0) - { - _blank.setNoNestedBrackets(_reader.getNoNestedBrackets()); - return _blank; - } // can directly access field - else if (pos<_fieldQueueSize) - { - return *_fieldQueue[pos]; - } // need to read the new fields. - else - { - if (pos>=_fieldQueueCapacity) // need to reallocate the stack - { - int newCapacity = _fieldQueueCapacity*2; - if (newCapacity=newCapacity) newCapacity*=2; - Field** newFieldStack = new Field* [newCapacity]; - int i; - for(i=0;i<_fieldQueueCapacity;++i) - { - newFieldStack[i] = _fieldQueue[i]; - } - for(;i=_fieldQueueSize) - { - if (_fieldQueue[_fieldQueueSize]==NULL) _fieldQueue[_fieldQueueSize] = new Field; - if (_reader.readField(*_fieldQueue[_fieldQueueSize])) - { - ++_fieldQueueSize; - } - } - if (pos<_fieldQueueSize) - { - return *_fieldQueue[pos]; - } - else - { - _blank.setNoNestedBrackets(_reader.getNoNestedBrackets()); - return _blank; - } - } -} - - -FieldReaderIterator& FieldReaderIterator::operator ++ () -{ - return (*this)+=1; -} - - -FieldReaderIterator& FieldReaderIterator::operator += (int no) -{ - if (no>_fieldQueueSize) - { - while (!_reader.eof() && no>_fieldQueueSize) - { - _reader.ignoreField(); - --no; - } - _fieldQueueSize=0; - } - else if (no>0) - { - Field** tmpFields = new Field* [no]; - int i; - for(i=0;i=entry) - { - ++(*this); - } -} - - -void FieldReaderIterator::advanceToEndOfBlock(int noNestedBrackets) -{ - while(!eof() && field(0).getNoNestedBrackets()>=noNestedBrackets) - { - ++(*this); - } -} - - -bool FieldReaderIterator::matchSequence(const char* str) -{ - if (str==NULL) return false; - if (*str==0) return false; - int fieldCount = 0; - const char* end = str; - while((*end)!=0 && (*end)==' ') ++end; - const char* start = end; - while((*start)!=0) - { - if (*end!=' ' && *end!=0) - { - ++end; - } - else - { - if (start!=end) - { - if (end-start>1 && *start=='%') - { - const char type = *(start+1); - switch(type) - { - case('i') : // expecting an integer - { - if (!field(fieldCount).isInt()) return false; - break; - } - case('f') : // expecting an floating point number - { - if (!field(fieldCount).isFloat()) return false; - break; - } - case('s') : // expecting an quoted string - { - if (!field(fieldCount).isQuotedString()) return false; - break; - } - default : // expecting an word - { - if (!field(fieldCount).isWord()) return false; - break; - } - } - - } - else - { - if (*start=='{') - { - if (!field(fieldCount).isOpenBracket()) return false; - } - else if (*start=='}') - { - if (!field(fieldCount).isCloseBracket()) return false; - } - else - { - if (!field(fieldCount).matchWord(start,end-start)) return false; - } - } - fieldCount++; - } - while((*end)==' ') ++end; - start = end; - } - } - return true; -} diff --git a/src/osg/FileNameUtils.cpp b/src/osg/FileNameUtils.cpp deleted file mode 100644 index 63aa9dbb9..000000000 --- a/src/osg/FileNameUtils.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "osg/FileNameUtils" - -std::string osg::getFilePath(const std::string& fileName) -{ - std::string::size_type slash = fileName.find_last_of('/'); - if (slash==std::string::npos) return std::string(""); - return std::string(fileName.begin(),fileName.begin()+slash+1); -} - -std::string osg::getSimpleFileName(const std::string& fileName) -{ - std::string::size_type slash = fileName.find_last_of('/'); - if (slash==std::string::npos) return fileName; - return std::string(fileName.begin()+slash+1,fileName.end()); -} - -std::string osg::getFileExtension(const std::string& fileName) -{ - std::string::size_type dot = fileName.find_last_of('.'); - if (dot==std::string::npos) return std::string(""); - return std::string(fileName.begin()+dot+1,fileName.end()); -} - -std::string osg::getLowerCaseFileExtension(const std::string& filename) -{ - std::string ext = osg::getFileExtension(filename); - for(std::string::iterator itr=ext.begin(); - itr!=ext.end(); - ++itr) - { - *itr = (char)tolower(*itr); - } - return ext; -} - -std::string osg::getStrippedName(const std::string& fileName) -{ - std::string::size_type slash = fileName.find_last_of('/'); - std::string::size_type dot = fileName.find_last_of('.'); - if (slash==std::string::npos) { - if (dot==std::string::npos) return fileName; - else return std::string(fileName.begin(),fileName.begin()+dot); - } - else - { - if (dot==std::string::npos) return std::string(fileName.begin()+slash+1,fileName.end()); - else return std::string(fileName.begin()+slash+1,fileName.begin()+dot); - } -} - diff --git a/src/osg/GeoState.cpp b/src/osg/GeoState.cpp deleted file mode 100644 index a7dcc04d9..000000000 --- a/src/osg/GeoState.cpp +++ /dev/null @@ -1,850 +0,0 @@ -#include - -#include "osg/GeoState" -#include "osg/Input" -#include "osg/Output" -#include "osg/Notify" - -using namespace osg; - -GeoState::GeoState() -{ - - _transparencing = INHERIT; - _face_culling = INHERIT; - _lighting = INHERIT; - _texturing = INHERIT; - _fogging = INHERIT; - _texgening = INHERIT; - _antialiasing = INHERIT; - _colortable = INHERIT; - _pointSmoothing = INHERIT; - _polygonOffsetting = INHERIT; - _alphaTesting = INHERIT; - - _transparency = 0L; - _cullFace = 0L; - _texture = 0L; - _fog = 0L; - _texgen = 0L; - _material = 0L; - _texenv = 0L; - _texmat = 0L; - _point = 0L; - _polygonOffset = 0L; - _alphaFunc = 0L; -} - - -GeoState::~GeoState() -{ - // note, all attached state attributes will be automatically - // unreferenced by ref_ptr<> and therefore there is now need to - // delete the memory manually. -} - - -GeoState* GeoState::instance() -{ - static ref_ptr s_geostate(new GeoState); - return s_geostate.get(); -} - -void GeoState::setGlobalDefaults() -{ - _transparencing = OFF; - _face_culling = ON; - _lighting = OFF; - _texturing = OFF; - _fogging = OFF; - _texgening = OFF; - _antialiasing = OFF; - _colortable = OFF; - _pointSmoothing = OFF; - _polygonOffsetting = OFF; - _alphaTesting = OFF; - - _transparency = new Transparency; - _cullFace = new CullFace; - _texture = 0L; - _fog = 0L; - _texgen = 0L; - _material = new Material; - _material->setColorMode(Material::AMBIENT_AND_DIFFUSE); - _texenv = 0L; - _texmat = 0L; - _point = 0L; - _polygonOffset = 0L; - _alphaFunc = new AlphaFunc; - -} - -void GeoState::setAllToInherit() -{ - _transparencing = INHERIT; - _face_culling = INHERIT; - _lighting = INHERIT; - _texturing = INHERIT; - _fogging = INHERIT; - _texgening = INHERIT; - _antialiasing = INHERIT; - _colortable = INHERIT; - _pointSmoothing = INHERIT; - _polygonOffsetting = INHERIT; - _alphaTesting = INHERIT; - - _transparency = 0L; - _cullFace = 0L; - _texture = 0L; - _fog = 0L; - _texgen = 0L; - _material = 0L; - _texenv = 0L; - _texmat = 0L; - _point = 0L; - _polygonOffset = 0L; - _alphaFunc = 0L; -} - -bool GeoState::readLocalData(Input& fr) -{ - bool iteratorAdvanced = false; - - AttributeMode mode; - if (fr[0].matchWord("transparency") && matchModeStr(fr[1].getStr(),mode)) - { - _transparencing = mode; - fr+=2; - iteratorAdvanced = true; - } - if (Transparency* transTmp = static_cast(Transparency::instance()->readClone(fr))) - { - _transparency = transTmp; - iteratorAdvanced = true; - } - - if (fr[0].matchWord("antialiasing") && matchModeStr(fr[1].getStr(),mode)) - { - _antialiasing = mode; - fr+=2; - iteratorAdvanced = true; - } - - if (fr[0].matchWord("face_culling") && matchModeStr(fr[1].getStr(),mode)) - { - _face_culling = mode; - fr+=2; - iteratorAdvanced = true; - } - if (CullFace* cullTmp = static_cast(CullFace::instance()->readClone(fr))) - { - _cullFace = cullTmp; - iteratorAdvanced = true; - } - - if (fr[0].matchWord("lighting") && matchModeStr(fr[1].getStr(),mode)) - { - _lighting = mode; - fr+=2; - iteratorAdvanced = true; - } - - if (fr[0].matchWord("texturing") && matchModeStr(fr[1].getStr(),mode)) - { - _texturing = mode; - fr+=2; - iteratorAdvanced = true; - } - if (Texture* textTmp = static_cast(Texture::instance()->readClone(fr))) - { - _texture = textTmp; - iteratorAdvanced = true; - } - - if (fr[0].matchWord("fogging") && matchModeStr(fr[1].getStr(),mode)) - { - _fogging = mode; - fr+=2; - iteratorAdvanced = true; - } - if (Fog* fogTmp = static_cast(Fog::instance()->readClone(fr))) - { - _fog = fogTmp; - iteratorAdvanced = true; - } - - if (fr[0].matchWord("colortable") && matchModeStr(fr[1].getStr(),mode)) - { - _colortable = mode; - fr+=2; - iteratorAdvanced = true; - } - - if (fr[0].matchWord("texgening") && matchModeStr(fr[1].getStr(),mode)) - { - _texgening = mode; - fr+=2; - iteratorAdvanced = true; - } - if (TexGen* tmpTexgen = static_cast(TexGen::instance()->readClone(fr))) - { - _texgen = tmpTexgen; - iteratorAdvanced = true; - } - - if (fr[0].matchWord("point_smoothing") && matchModeStr(fr[1].getStr(),mode)) - { - _pointSmoothing = mode; - fr+=2; - iteratorAdvanced = true; - } - - if (Point* tmpPoint = static_cast(Point::instance()->readClone(fr))) - { - _point = tmpPoint; - iteratorAdvanced = true; - } - - if (fr[0].matchWord("polygon_offset") && matchModeStr(fr[1].getStr(),mode)) - { - _polygonOffsetting = mode; - fr+=2; - iteratorAdvanced = true; - } - - if (PolygonOffset* tmpPolygonOffset = static_cast(PolygonOffset::instance()->readClone(fr))) - { - _polygonOffset = tmpPolygonOffset; - iteratorAdvanced = true; - } - - - if (fr[0].matchWord("alpha_test") && matchModeStr(fr[1].getStr(),mode)) - { - _alphaTesting = mode; - fr+=2; - iteratorAdvanced = true; - } - if (AlphaFunc* tmpAlphaFunc = static_cast(AlphaFunc::instance()->readClone(fr))) - { - _alphaFunc = tmpAlphaFunc; - iteratorAdvanced = true; - } - - - if (Material* tmpMaterial = static_cast(Material::instance()->readClone(fr))) - { - _material = tmpMaterial; - iteratorAdvanced = true; - } - - -/* - * Decided that texmatting does not make sense. If a Texture matrix - * is present, just apply it. No need for a mode. Don. - * - if (fr[0].matchWord("texmating") && matchModeStr(fr[1].getStr(),mode)) { - _texmating = mode; - fr+=2; - iteratorAdvanced = true; - } -*/ - - return iteratorAdvanced; -} - - -bool GeoState::writeLocalData(Output& fw) -{ - fw.indent() << "transparency " << getModeStr(_transparencing) << endl; - if (_transparency.valid()) _transparency->write(fw); - - fw.indent() << "antialiasing " << getModeStr(_antialiasing) << endl; - - fw.indent() << "face_culling " << getModeStr(_face_culling) << endl; - if (_cullFace.valid()) _cullFace->write(fw); - - fw.indent() << "lighting " << getModeStr(_lighting) << endl; - - fw.indent() << "texturing " << getModeStr(_texturing) << endl; - if (_texture.valid()) _texture->write(fw); - - fw.indent() << "fogging " << getModeStr(_fogging) << endl; - if (_fog.valid()) _fog->write(fw); - - fw.indent() << "colortable " << getModeStr(_colortable) << endl; - - fw.indent() << "texgening " << getModeStr(_texgening) << endl; - if (_texgen.valid()) _texgen->write(fw); - - if (_texenv.valid()) _texenv->write(fw); - - fw.indent() << "point_smoothing " << getModeStr(_pointSmoothing) << endl; - if (_point.valid()) _point->write(fw); - - fw.indent() << "polygon_offset " << getModeStr(_polygonOffsetting) << endl; - if (_polygonOffset.valid()) _polygonOffset->write(fw); - - fw.indent() << "alpha_test " << getModeStr(_alphaTesting) << endl; - if (_alphaFunc.valid()) _alphaFunc->write(fw); - - if (_material.valid()) _material->write(fw); - -/* - fw.indent() << "texmating " << getModeStr(_texmating) << endl; -*/ - - return true; -} - -bool GeoState::matchModeStr(const char* str,AttributeMode& mode) -{ - if (strcmp(str,"INHERIT")==0) mode = INHERIT; - else if (strcmp(str,"ON")==0) mode = ON; - else if (strcmp(str,"OFF")==0) mode = OFF; - else if (strcmp(str,"OVERRIDE_ON")==0) mode = OVERRIDE_ON; - else if (strcmp(str,"OVERRIDE_OFF")==0) mode = OVERRIDE_OFF; - else return false; - return true; -} - - -const char* GeoState::getModeStr(AttributeMode mode) -{ - switch(mode) - { - case(INHERIT): return "INHERIT"; - case(ON): return "ON"; - case(OFF): return "OFF"; - case(OVERRIDE_ON): return "OVERRIDE_ON"; - case(OVERRIDE_OFF): return "OVERRIDE_OFF"; - } - return ""; -} - - -void GeoState::setMode( AttributeType type, AttributeMode mode ) -{ - switch( type ) - { - case ANTIALIAS : _antialiasing = mode; break; - case FACE_CULL: _face_culling = mode; break; - case FOG : _fogging = mode; break; - case LIGHTING: _lighting = mode; break; - case POINT : _pointSmoothing = mode; break; - case POLYGON_OFFSET : _polygonOffsetting = mode; break; - case TEXGEN : _texgening = mode; break; - case TEXTURE : _texturing = mode; break; - case TRANSPARENCY: _transparencing = mode; break; - case ALPHAFUNC: _alphaTesting = mode; break; - default : notify(WARN) << "GeoState::setMode("<<(int)type<<","<<(int)mode<<") not handled."<(attribute); break; - case FOG : _fog = dynamic_cast(attribute); break; - case LIGHTING: break; /*_light = (Light *)attribute;*/ - case MATERIAL: _material = dynamic_cast(attribute); break; - case POINT : _point = dynamic_cast(attribute); break; - case POLYGON_OFFSET: _polygonOffset = dynamic_cast(attribute); break; - case TEXENV : _texenv = dynamic_cast(attribute); break; - case TEXGEN : _texgen = dynamic_cast(attribute); break; - case TEXMAT : _texmat = dynamic_cast(attribute); break; - case TEXTURE : _texture = dynamic_cast(attribute); break; - case TRANSPARENCY: _transparency = dynamic_cast(attribute); break; - case ALPHAFUNC: _alphaFunc = dynamic_cast(attribute); break; - default : notify(WARN) << "GeoState::setAttribute("<<(int)type<<","<apply(); - - if( _cullFace.valid()) - _cullFace->apply(); - - if( _texenv.valid()) - _texenv->apply(); - - if( _texgen.valid()) - _texgen->apply(); - - if( _texture.valid()) - _texture->apply(); - - if( _material.valid()) - _material->apply(); - - if( _fog.valid()) - _fog->apply(); - - if( _texmat.valid()) - _texmat->apply(); - - if( _point.valid()) - _point->apply(); - - if( _polygonOffset.valid()) - _polygonOffset->apply(); - - if( _alphaFunc.valid()) - _alphaFunc->apply(); -} - - - -void GeoState::apply(GeoState* global,GeoState* prev) -{ - if (global==NULL || prev==NULL) - { - apply(); - return; - } - - switch(GeoState::combineMode(global->_transparencing,prev->_transparencing,_transparencing)) - { - case(ON): - case(OVERRIDE_ON): - Transparency::enable(); - break; - case(OFF): - case(OVERRIDE_OFF): - Transparency::disable(); - break; - case(INHERIT): - break; - } - - - switch(GeoState::combineMode(global->_face_culling,prev->_face_culling,_face_culling)) - { - case(ON): - case(OVERRIDE_ON): - CullFace::enable(); - break; - case(OFF): - case(OVERRIDE_OFF): - CullFace::disable(); - break; - case(INHERIT): - break; - } - - switch(GeoState::combineMode(global->_lighting,prev->_lighting,_lighting)) - { - case(ON): - case(OVERRIDE_ON): - Lighting::enable(); - break; - case(OFF): - case(OVERRIDE_OFF): - Lighting::disable(); - break; - case(INHERIT): - break; - } - - switch(GeoState::combineMode(global->_texturing,prev->_texturing,_texturing)) - { - case(ON): - case(OVERRIDE_ON): - Texture::enable(); - break; - case(OFF): - case(OVERRIDE_OFF): - Texture::disable(); - break; - case(INHERIT): - break; - } - - switch(GeoState::combineMode(global->_texgening,prev->_texgening,_texgening)) - { - case(ON): - case(OVERRIDE_ON): - TexGen::enable(); - break; - case(OFF): - case(OVERRIDE_OFF): - TexGen::disable(); - break; - case(INHERIT): - break; - } - - switch(GeoState::combineMode(global->_fogging,prev->_fogging,_fogging)) - { - case(ON): - case(OVERRIDE_ON): - Fog::enable(); - break; - case(OFF): - case(OVERRIDE_OFF): - Fog::disable(); - break; - case(INHERIT): - break; - } - - switch(GeoState::combineMode(global->_pointSmoothing,prev->_pointSmoothing,_pointSmoothing)) - { - case(ON): - case(OVERRIDE_ON): - Point::enableSmooth(); - break; - case(OFF): - case(OVERRIDE_OFF): - Point::disableSmooth(); - break; - case(INHERIT): - break; - } - - switch(GeoState::combineMode(global->_polygonOffsetting,prev->_polygonOffsetting,_polygonOffsetting)) - { - case(ON): - case(OVERRIDE_ON): - PolygonOffset::enable(); - break; - case(OFF): - case(OVERRIDE_OFF): - PolygonOffset::disable(); - break; - case(INHERIT): - break; - } - - switch(GeoState::combineMode(global->_alphaTesting,prev->_alphaTesting,_alphaTesting)) - { - case(ON): - case(OVERRIDE_ON): - AlphaFunc::enable(); - break; - case(OFF): - case(OVERRIDE_OFF): - AlphaFunc::disable(); - break; - case(INHERIT): - break; - } - - if (prev->_transparency!=_transparency) - { - osg::Transparency* new_transparency; - if (_transparency.valid()) new_transparency = _transparency.get(); - else new_transparency = global->_transparency.get(); - if (new_transparency) new_transparency->apply(); - } - - if (prev->_cullFace!=_cullFace) - { - osg::CullFace* new_cullFace; - if (_cullFace.valid()) new_cullFace = _cullFace.get(); - else new_cullFace = global->_cullFace.get(); - if (new_cullFace) new_cullFace->apply(); - } - - if (prev->_texenv!=_texenv) - { - osg::TexEnv* new_texenv; - if (_texenv.valid()) new_texenv = _texenv.get(); - else new_texenv = global->_texenv.get(); - if (new_texenv) new_texenv->apply(); - } - - if (prev->_texgen!=_texgen) - { - osg::TexGen* new_texgen; - if (_texgen.valid()) new_texgen = _texgen.get(); - else new_texgen = global->_texgen.get(); - if (new_texgen) new_texgen->apply(); - } - - if (prev->_texture!=_texture) - { - osg::Texture* new_texture; - if (_texture.valid()) new_texture = _texture.get(); - else new_texture = global->_texture.get(); - if (new_texture) new_texture->apply(); - } - - if (prev->_material!=_material) - { - osg::Material* new_material; - if (_material.valid()) new_material = _material.get(); - else new_material = global->_material.get(); - if (new_material) new_material->apply(); - } - - if (prev->_fog!=_fog) - { - osg::Fog* new_fog; - if (_fog.valid()) new_fog = _fog.get(); - else new_fog = global->_fog.get(); - if (new_fog) new_fog->apply(); - } - - if (prev->_texmat!=_texmat) - { - osg::TexMat* new_texmat; - if (_texmat.valid()) new_texmat = _texmat.get(); - else new_texmat = global->_texmat.get(); - if (new_texmat) new_texmat->apply(); - } - - if (prev->_point!=_point) - { - osg::Point* new_point; - if (_point.valid()) new_point = _point.get(); - else new_point = global->_point.get(); - if (new_point) new_point->apply(); - } - - if (prev->_polygonOffset!=_polygonOffset) - { - osg::PolygonOffset* new_polygonOffset; - if (_polygonOffset.valid()) new_polygonOffset = _polygonOffset.get(); - else new_polygonOffset = global->_polygonOffset.get(); - if (new_polygonOffset) new_polygonOffset->apply(); - } - - if (prev->_alphaFunc!=_alphaFunc) - { - osg::AlphaFunc* new_AlphaFunc; - if (_alphaFunc.valid()) new_AlphaFunc = _alphaFunc.get(); - else new_AlphaFunc = global->_alphaFunc.get(); - if (new_AlphaFunc) new_AlphaFunc->apply(); - } -} - -bool GeoState::check() -{ - return true; -} - - -/* -#if 0 // [ NOTES on how apply should work - -Each Scene must have a global initial GeoState, current GeoState, and current request state. The current definition of GeoState -should really become an GeoState. The global initial State can have modes set to - - SG_ON, - SG_OFF, - -and may be or'ed with - -SG_OVERRIDE. - -All attributes are set to the default. Defaults can be set at start up by querying hardware -and determining best parameters (for example, do we have hardware texture mapping?, if so enable texture and create a texture environment). - -The current GeoState and the request GeoState begin as a copy of the initial state. The request state is subsequently changed by each GeoState, -during traversal. It is the current state that will actually issue the GL commands at apply time. - -Attributes for the GeoStates may be - -SG_ON -explicitely -SG_OFF -explicitely -SG_INHERIT - -and may be or'ed with - -SG_PERSIST - -During traversal, each GeoState's attribute set to INHERIT does nothing. Each attribute set to ON or OFF sets the subsequent request state -to the same before drawing and unsets it after. If the attribute is or'ed with SG_PERSIST, then the mode is not unset after drawing. -Just before drawing the request state is compared to the current state. If an attribute or mode has changed, it is changed in the current -state then applied. Only at this application will the actual GL calls be issued. - -For exammple, if two subsequent geosets have lighting on the sequence will be as follows - -geostate 1 sets lighting on in request state -at draw: -if current state has lighting off it is changed to on and applied. -geostate1 unsets lighting in request state. - -geosate2 resets lighting to on in request state -at draw: -current state has lighting set to on from previous draw therefore nothing changes - -geostate2 - -Addendum 10/22 - Use this method for traversal. Currently we shall do dumb apply(). -Upon implementation of a CULL traversal, which creates a DRAW display list, then we -shall implement the "smart" state change described above. - -#endif // ] -*/ diff --git a/src/osg/Input.cpp b/src/osg/Input.cpp deleted file mode 100644 index 4789d14cf..000000000 --- a/src/osg/Input.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include "osg/Input" -#include "osg/Registry" -#include "osg/Object" - -#ifdef __sgi -using std::string; -#endif - -using namespace osg; - -// Will extend to handle #DEF and use -// functionality similar to Inventor, -// and add the ability to handle #include -// from within the OSG file format. -Input::Input() -{ -} - - -Input::~Input() -{ -} - -Object* Input::getObjectForUniqueID(const std::string& uniqueID) -{ - UniqueIDToObjectMapping::iterator fitr = _uniqueIDToObjectMap.find(uniqueID); - if (fitr != _uniqueIDToObjectMap.end()) return (*fitr).second; - else return NULL; -} - -void Input::regisiterUniqueIDForObject(const std::string& uniqueID,Object* obj) -{ - _uniqueIDToObjectMap[uniqueID] = obj; -} - -Object* Input::readObject() -{ - return Registry::instance()->readObject(*this); -} - - -Object* Input::readObject(const string& fileName) -{ - return Registry::instance()->readObject(fileName); -} - - -Image* Input::readImage() -{ - return Registry::instance()->readImage(*this); -} - - -Image* Input::readImage(const string& fileName) -{ - return Registry::instance()->readImage(fileName); -} - - -Node* Input::readNode() -{ - return Registry::instance()->readNode(*this); -} - - -Node* Input::readNode(const string& fileName) -{ - return Registry::instance()->readNode(fileName); -} diff --git a/src/osg/OSG.cpp b/src/osg/OSG.cpp deleted file mode 100644 index 2a5e560cb..000000000 --- a/src/osg/OSG.cpp +++ /dev/null @@ -1,228 +0,0 @@ -#ifndef WIN32 -#include -#include -#else -#include -#include -#include -#endif - -#include -#include - -#include "osg/Notify" -#include "osg/OSG" -#include "osg/Node" -#include "osg/Geode" -#include "osg/Group" -#include "osg/Input" -#include "osg/Output" -#include "osg/Registry" - -using namespace osg; - -#ifdef WIN32 -char *PathDelimitor = ";"; -static const char *s_default_file_path = ".;D:/OpenSceneGraph/Data;D:/OpenSceneGraph/Data/Images;D:/OpenSceneGraph/lib"; -//static char *s_filePath = (char *)s_default_file_path; -static char *s_filePath = ".;"; -#else -char *PathDelimitor = ":"; -static const char *s_default_file_path = ".:"; -#ifdef __sgi -static const char *s_default_dso_path = "/usr/lib32/osgPlugins/"; -#else -static const char *s_default_dso_path = "/usr/lib/osgPlugins/"; -#endif -static char *s_filePath = ".:"; -//static char *s_filePath = s_default_file_path; -#endif - - -#include -#include - -using std::vector; -using std::find_if; - -void osg::Init( void ) -{ - char *ptr; - if( (ptr = getenv( "OSGFILEPATH" )) ) - { - notify(DEBUG) << "osg::Init("< - -#include "osg/Output" -#include "osg/Object" - -using namespace osg; - -Output::Output() -{ - _init(); -} - - -Output::~Output() -{ - _free(); -} - -void Output::_init() -{ - _indent = 0; - _indentStep = 2; - _numIndicesPerLine = 10; -} - - -void Output::_free() -{ -// should I be calling ofstream's free as well??? -} - - -Output& Output::indent() -{ - for(int i=0;i<_indent;++i) *this<<' '; - return *this; -} - -void Output::moveIn() -{ - _indent += _indentStep; -} - - -void Output::moveOut() -{ - _indent -= _indentStep; - if (_indent<0) _indent=0; -} - -bool Output::getUniqueIDForObject(Object* obj,std::string& uniqueID) -{ - UniqueIDToLabelMapping::iterator fitr = _objectToUniqueIDMap.find(obj); - if (fitr != _objectToUniqueIDMap.end()) - { - uniqueID = (*fitr).second; - return true; - } - else return false; -} - -bool Output::createUniqueIDForObject(Object* obj,std::string& uniqueID) -{ - char str[256]; - sprintf(str,"%s_%i",obj->className(),_objectToUniqueIDMap.size()); - uniqueID = str; - return true; -} - -bool Output::registerUniqueIDForObject(Object* obj,std::string& uniqueID) -{ - _objectToUniqueIDMap[obj] = uniqueID; - return true; -} - diff --git a/src/osg/ReaderWriterOSG.cpp b/src/osg/ReaderWriterOSG.cpp deleted file mode 100644 index 328230e10..000000000 --- a/src/osg/ReaderWriterOSG.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#include "osg/Registry" - -#include "osg/Object" -#include "osg/Image" -#include "osg/Node" -#include "osg/Group" - -#include "osg/Input" -#include "osg/Output" - -#ifdef __sgi -using std::string; -#endif - -using namespace osg; - -class DefaultReaderWriter : public ReaderWriter -{ - public: - virtual const char* className() { return "Default OSG Reader/Writer"; } - virtual bool acceptsExtension(const string& extension) { return extension=="osg" || extension=="OSG"; } - - virtual Object* readObject(const string& fileName) { return readNode(fileName); } - virtual Node* readNode(const string& fileName) - { - ifstream fin(fileName.c_str()); - if (fin) - { - Input fr; - fr.attach(&fin); - - Group* group = new Group; - group->setName("import group"); - -// load all nodes in file, placing them in a group. - while(!fr.eof()) - { - Node *node = fr.readNode(); - if (node) group->addChild(node); - else fr.advanceOverCurrentFieldOrBlock(); - } - - if (group->getNumChildren()>1) - { - return group; - } - else if (group->getNumChildren()==1) - { -// only one node loaded so just return that one node, -// and delete the redundent group. Note, the -// child must be referenced before defrencing -// the group so to avoid delete its children. - Node* node = group->getChild(0); - node->ref(); - group->unref(); - return node; - } // group->getNumChildren()==0 - else - { - return 0L; - } - - } - else - { - return 0L; - } - } - - virtual bool writeObject(Object& obj,const string& fileName) - { - Output fout; - fout.open(fileName.c_str()); - if (fout) - { - obj.write(fout); - fout.close(); - return true; - } - return false; - } - - virtual bool writeNode(Node& node,const string& fileName) - { - Output fout; - fout.open(fileName.c_str()); - if (fout) - { - - node.write(fout); - fout.close(); - return true; - } - return false; - } - -}; - -// now register with Registry to instantiate the above -// reader/writer. -RegisterReaderWriterProxy g_defaultReaderWriterProxy; diff --git a/src/osg/ReaderWriterRGB.cpp b/src/osg/ReaderWriterRGB.cpp deleted file mode 100644 index efdad25b6..000000000 --- a/src/osg/ReaderWriterRGB.cpp +++ /dev/null @@ -1,380 +0,0 @@ -#include "osg/Image" -#include "osg/Input" -#include "osg/Output" -#include "osg/Notify" -#include "osg/FileNameUtils" - -#include "osg/Registry" - -#include -#include -#include -#include - -#include "osg/GL" -#include -#include -#include - -#ifndef SEEK_SET -# define SEEK_SET 0 -#endif - -using namespace osg; - -typedef struct _rawImageRec -{ - unsigned short imagic; - unsigned short type; - unsigned short dim; - unsigned short sizeX, sizeY, sizeZ; - unsigned long min, max; - unsigned long wasteBytes; - char name[80]; - unsigned long colorMap; - FILE *file; - unsigned char *tmp, *tmpR, *tmpG, *tmpB, *tmpA; - unsigned long rleEnd; - GLuint *rowStart; - GLint *rowSize; -} rawImageRec; - -static void ConvertShort(unsigned short *array, long length) -{ - unsigned long b1, b2; - unsigned char *ptr; - - ptr = (unsigned char *)array; - while (length--) - { - b1 = *ptr++; - b2 = *ptr++; - *array++ = (unsigned short) ((b1 << 8) | (b2)); - } -} - - -static void ConvertLong(GLuint *array, long length) -{ - unsigned long b1, b2, b3, b4; - unsigned char *ptr; - - ptr = (unsigned char *)array; - while (length--) - { - b1 = *ptr++; - b2 = *ptr++; - b3 = *ptr++; - b4 = *ptr++; - *array++ = (b1 << 24) | (b2 << 16) | (b3 << 8) | (b4); - } -} - - -static rawImageRec *RawImageOpen(const char *fileName) -{ - union - { - int testWord; - char testByte[4]; - } endianTest; - rawImageRec *raw; - GLenum swapFlag; - int x; - - endianTest.testWord = 1; - if (endianTest.testByte[0] == 1) - { - swapFlag = GL_TRUE; - } - else - { - swapFlag = GL_FALSE; - } - - raw = (rawImageRec *)malloc(sizeof(rawImageRec)); - if (raw == NULL) - { - notify(WARN)<< "Out of memory!"<file = fopen(fileName, "rb")) == NULL) - { - perror(fileName); - return NULL; - } - - fread(raw, 1, 12, raw->file); - - if (swapFlag) - { - ConvertShort(&raw->imagic, 6); - } - - raw->tmp = raw->tmpR = raw->tmpG = raw->tmpB = raw->tmpA = 0L; - - raw->tmp = (unsigned char *)malloc(raw->sizeX*256); - if (raw->tmp == NULL ) - { - notify(FATAL)<< "Out of memory!"<sizeZ >= 1 ) - { - if( (raw->tmpR = (unsigned char *)malloc(raw->sizeX)) == NULL ) - { - notify(FATAL)<< "Out of memory!"<tmp ); - return NULL; - } - } - if( raw->sizeZ >= 2 ) - { - if( (raw->tmpG = (unsigned char *)malloc(raw->sizeX)) == NULL ) - { - notify(FATAL)<< "Out of memory!"<tmp ); - free( raw->tmpR ); - return NULL; - } - } - if( raw->sizeZ >= 3 ) - { - if( (raw->tmpB = (unsigned char *)malloc(raw->sizeX)) == NULL ) - { - notify(FATAL)<< "Out of memory!"<tmp ); - free( raw->tmpR ); - free( raw->tmpG ); - return NULL; - } - } - if (raw->sizeZ >= 4) - { - if( (raw->tmpA = (unsigned char *)malloc(raw->sizeX)) == NULL ) - { - notify(FATAL)<< "Out of memory!"<tmp ); - free( raw->tmpR ); - free( raw->tmpG ); - free( raw->tmpB ); - return NULL; - } - } - - if ((raw->type & 0xFF00) == 0x0100) - { - x = raw->sizeY * raw->sizeZ * sizeof(GLuint); - raw->rowStart = (GLuint *)malloc(x); - raw->rowSize = (GLint *)malloc(x); - if (raw->rowStart == NULL || raw->rowSize == NULL) - { - notify(FATAL)<< "Out of memory!"<rleEnd = 512 + (2 * x); - fseek(raw->file, 512, SEEK_SET); - fread(raw->rowStart, 1, x, raw->file); - fread(raw->rowSize, 1, x, raw->file); - if (swapFlag) - { - ConvertLong(raw->rowStart, (long) (x/sizeof(GLuint))); - ConvertLong((GLuint *)raw->rowSize, (long) (x/sizeof(GLint))); - } - } - return raw; -} - - -static void RawImageClose(rawImageRec *raw) -{ - fclose(raw->file); - free(raw->tmp); - if( raw->tmpR ) - free(raw->tmpR); - if( raw->tmpG ) - free(raw->tmpG); - if( raw->tmpB ) - free(raw->tmpB); - if( raw->tmpA ) - free(raw->tmpA); - - free(raw); -} - - -static void RawImageGetRow(rawImageRec *raw, unsigned char *buf, int y, int z) -{ - unsigned char *iPtr, *oPtr, pixel; - int count, done = 0; - - if ((raw->type & 0xFF00) == 0x0100) - { - fseek(raw->file, (long) raw->rowStart[y+z*raw->sizeY], SEEK_SET); - fread(raw->tmp, 1, (unsigned int)raw->rowSize[y+z*raw->sizeY], - raw->file); - - iPtr = raw->tmp; - oPtr = buf; - while (!done) - { - pixel = *iPtr++; - count = (int)(pixel & 0x7F); - if (!count) - { - done = 1; - return; - } - if (pixel & 0x80) - { - while (count--) - { - *oPtr++ = *iPtr++; - } - } - else - { - pixel = *iPtr++; - while (count--) - { - *oPtr++ = pixel; - } - } - } - } - else - { - fseek(raw->file, 512+(y*raw->sizeX)+(z*raw->sizeX*raw->sizeY), - SEEK_SET); - fread(buf, 1, raw->sizeX, raw->file); - } -} - - -static void RawImageGetData(rawImageRec *raw, unsigned char **data ) -{ - unsigned char *ptr; - int i, j; - -// // round the width to a factor 4 -// int width = (int)(floorf((float)raw->sizeX/4.0f)*4.0f); -// if (width!=raw->sizeX) width += 4; - - *data = (unsigned char *)malloc(2 * (raw->sizeX+1)*(raw->sizeY+1)*4); -// *data = (unsigned char *)malloc(2 * (width+1)*(raw->sizeY+1)*4); - - ptr = *data; - for (i = 0; i < (int)(raw->sizeY); i++) - { - if( raw->sizeZ >= 1 ) - RawImageGetRow(raw, raw->tmpR, i, 0); - if( raw->sizeZ >= 2 ) - RawImageGetRow(raw, raw->tmpG, i, 1); - if( raw->sizeZ >= 3 ) - RawImageGetRow(raw, raw->tmpB, i, 2); - if( raw->sizeZ >= 4 ) - RawImageGetRow(raw, raw->tmpA, i, 3); - for (j = 0; j < (int)(raw->sizeX); j++) - { - if( raw->sizeZ >= 1 ) - *ptr++ = *(raw->tmpR + j); - if( raw->sizeZ >= 2 ) - *ptr++ = *(raw->tmpG + j); - if( raw->sizeZ >= 3 ) - *ptr++ = *(raw->tmpB + j); - if( raw->sizeZ >= 4 ) - *ptr++ = *(raw->tmpA + j); - } -// // pad the image width with blanks to bring it up to the rounded width. -// for(;junref(); - return geode; - } - else - { - return NULL; - } - } - - - virtual Image* readImage(const std::string& fileName) - { - std::string ext = getLowerCaseFileExtension(fileName); - if (!acceptsExtension(ext)) return NULL; - - rawImageRec *raw; - - if( (raw = RawImageOpen(fileName.c_str())) == NULL ) - { - notify(FATAL)<< "Unable to open \""<sizeX; - int t = raw->sizeY; - int r = 1; - -#if 0 - int internalFormat = raw->sizeZ == 3 ? GL_RGB5 : - raw->sizeZ == 4 ? GL_RGB5_A1 : GL_RGB; -#else - int internalFormat = raw->sizeZ; -#endif - unsigned int pixelFormat = - raw->sizeZ == 1 ? GL_LUMINANCE : - raw->sizeZ == 2 ? GL_LUMINANCE_ALPHA : - raw->sizeZ == 3 ? GL_RGB : - raw->sizeZ == 4 ? GL_RGBA : (GLenum)-1; - - unsigned int dataType = GL_UNSIGNED_BYTE; - - unsigned char *data; - RawImageGetData(raw, &data); - RawImageClose(raw); - - Image* image = new Image(); - image->setFileName(fileName.c_str()); - image->setImage(s,t,r, - internalFormat, - pixelFormat, - dataType, - data); - - notify(INFO) << "image read ok "< g_readerWriter_RGB_Proxy; diff --git a/src/osg/Registry.cpp b/src/osg/Registry.cpp deleted file mode 100644 index cb0c1a6b6..000000000 --- a/src/osg/Registry.cpp +++ /dev/null @@ -1,543 +0,0 @@ -#include "osg/Registry" - -#include "osg/Notify" -#include "osg/Object" -#include "osg/Image" -#include "osg/Node" -#include "osg/Group" - -#include "osg/Input" -#include "osg/Output" -#include "osg/FileNameUtils" - -#include - -#include -#include - -using namespace osg; - -Object* osg::loadObjectFile(const char *name) -{ - return Registry::instance()->readObject(name); -} -Image* osg::loadImageFile(const char *name) -{ - return Registry::instance()->readImage(name); -} - -Node* osg::loadNodeFile(const char *name) -{ - return Registry::instance()->readNode(name); -} - -bool osg::saveObjectFile(Object& object,const char *name) -{ - return Registry::instance()->writeObject(object,name); -} - -bool osg::saveImageFile(Image& image,const char *name) -{ - return Registry::instance()->writeImage(image,name); -} - -bool osg::saveNodeFile(Node& node,const char *name) -{ - return Registry::instance()->writeNode(node,name); -} - -// definition of the Registry -Registry::Registry() -{ - notify(INFO) << "Constructing osg::Registry"<className()<<")"<(obj)) - { - _nodeProtoList.push_back(newPos); - } - if (dynamic_cast(obj)) - { - _imageProtoList.push_back(newPos); - } -} - -void Registry::removePrototype(Object* obj) -{ - if (obj==0L) return; - - notify(INFO) << "osg::Registry::removePrototype()"<className()<<")"<ref(); - _dlList.push_back(dl); - return true; - } - return false; -} - -bool Registry::closeLibrary(const std::string& fileName) -{ - DynamicLibraryList::iterator ditr = getLibraryItr(fileName); - if (ditr!=_dlList.end()) - { - (*ditr)->unref(); - _dlList.erase(ditr); - return true; - } - return false; -} - -Registry::DynamicLibraryList::iterator Registry::getLibraryItr(const std::string& fileName) -{ - DynamicLibraryList::iterator ditr = _dlList.begin(); - for(;ditr!=_dlList.end();++ditr) - { - if ((*ditr)->getName()==fileName) return ditr; - } - return _dlList.end(); -} - -DynamicLibrary* Registry::getLibrary(const std::string& fileName) -{ - DynamicLibraryList::iterator ditr = getLibraryItr(fileName); - if (ditr!=_dlList.end()) return ditr->get(); - else return NULL; -} - - -Object* Registry::readObject(Input& fr) -{ - - if (fr[0].matchWord("Use")) - { - if (fr[1].isString()) { - Object* obj = fr.getObjectForUniqueID(fr[1].getStr()); - if (obj) fr+=2; - return obj; - } - else return NULL; - - } - - for(unsigned int i=0;i<_protoList.size();++i) - { - Object* obj = _protoList[i]->readClone(fr); - if (obj) return obj; - } - return 0L; -} - - -Object* Registry::readObject(const std::string& fileName) -{ - char *file = FindFile( fileName.c_str() ); - if (file==NULL) return NULL; - - // record the existing reader writer. - std::set rwOriginal; - - // first attempt to load the file from existing ReaderWriter's - for(ReaderWriterList::iterator itr=_rwList.begin(); - itr!=_rwList.end(); - ++itr) - { - rwOriginal.insert(itr->get()); - Object* obj = (*itr)->readObject(file); - if (obj) return obj; - } - - // now look for a plug-in to load the file. - std::string libraryName = createLibraryNameForFile(fileName); - if (Registry::instance()->loadLibrary(libraryName)) - { - for(ReaderWriterList::iterator itr=_rwList.begin(); - itr!=_rwList.end(); - ++itr) - { - if (rwOriginal.find(itr->get())==rwOriginal.end()) - { - Object* obj = (*itr)->readObject(file); - if (obj) return obj; - } - } - } - else - { - notify(NOTICE)<<"Warning: Could not find plugin to read file with extension ." - < rwOriginal; - - // first attempt to load the file from existing ReaderWriter's - for(ReaderWriterList::iterator itr=_rwList.begin(); - itr!=_rwList.end(); - ++itr) - { - rwOriginal.insert(itr->get()); - if ((*itr)->writeObject(obj,fileName)) return true; - } - - // now look for a plug-in to save the file. - std::string libraryName = createLibraryNameForFile(fileName); - if (loadLibrary(libraryName)) - { - for(ReaderWriterList::iterator itr=_rwList.begin(); - itr!=_rwList.end(); - ++itr) - { - if (rwOriginal.find(itr->get())==rwOriginal.end()) - { - if ((*itr)->writeObject(obj,fileName)) return true; - } - } - } - else - { - notify(NOTICE)<<"Warning: Could not find plugin to write file with extension ." - <(fr.getObjectForUniqueID(fr[1].getStr())); - if (image) fr+=2; - return image; - } - else return NULL; - - } - - for(std::vector::iterator itr=_imageProtoList.begin(); - itr!=_imageProtoList.end(); - ++itr) - { - int i=*itr; - Object* obj = _protoList[i]->readClone(fr); - if (obj) - { - Image* image = static_cast(obj); - return image; - } - } - return 0L; -} - - -Image* Registry::readImage(const std::string& fileName) -{ - char *file = FindFile( fileName.c_str() ); - if (file==NULL) return NULL; - - // record the existing reader writer. - std::set rwOriginal; - - // first attempt to load the file from existing ReaderWriter's - for(ReaderWriterList::iterator itr=_rwList.begin(); - itr!=_rwList.end(); - ++itr) - { - rwOriginal.insert(itr->get()); - Image* image = (*itr)->readImage(file); - if (image) return image; - } - - // now look for a plug-in to load the file. - std::string libraryName = createLibraryNameForFile(fileName); - if (loadLibrary(libraryName)) - { - for(ReaderWriterList::iterator itr=_rwList.begin(); - itr!=_rwList.end(); - ++itr) - { - if (rwOriginal.find(itr->get())==rwOriginal.end()) - { - Image* image = (*itr)->readImage(file); - if (image) return image; - } - } - } - else - { - notify(NOTICE)<<"Warning: Could not find plugin to read file with extension ." - < rwOriginal; - - // first attempt to load the file from existing ReaderWriter's - for(ReaderWriterList::iterator itr=_rwList.begin(); - itr!=_rwList.end(); - ++itr) - { - rwOriginal.insert(itr->get()); - if ((*itr)->writeImage(image,fileName)) return true; - } - - // now look for a plug-in to save the file. - std::string libraryName = createLibraryNameForFile(fileName); - if (loadLibrary(libraryName)) - { - for(ReaderWriterList::iterator itr=_rwList.begin(); - itr!=_rwList.end(); - ++itr) - { - if (rwOriginal.find(itr->get())==rwOriginal.end()) - { - if ((*itr)->writeImage(image,fileName)) return true; - } - } - } - else - { - notify(NOTICE)<<"Warning: Could not find plugin to write file with extension ." - <(fr.getObjectForUniqueID(fr[1].getStr())); - if (node) fr+=2; - return node; - } - else return NULL; - - } - - std::vector::iterator itr=_nodeProtoList.begin(); - for(;itr!=_nodeProtoList.end();++itr) - { - int i=*itr; - Object* obj = _protoList[i]->readClone(fr); - if (obj) - { - Node* node = static_cast(obj); - return node; - } - } - return 0L; -} - - -Node* Registry::readNode(const std::string& fileName) -{ - - char *file = FindFile( fileName.c_str() ); - if (file==NULL) return NULL; - - // record the existing reader writer. - std::set rwOriginal; - - // first attempt to load the file from existing ReaderWriter's - for(ReaderWriterList::iterator itr=_rwList.begin(); - itr!=_rwList.end(); - ++itr) - { - rwOriginal.insert(itr->get()); - Node* node = (*itr)->readNode(file); - if (node) return node; - } - - // now look for a plug-in to load the file. - std::string libraryName = createLibraryNameForFile(fileName); - notify(INFO) << "Now checking for plug-in "<get())==rwOriginal.end()) - { - Node* node = (*itr)->readNode(file); - if (node) return node; - } - } - } - else - { - notify(NOTICE)<<"Warning: Could not find plugin to read file with extension ." - < rwOriginal; - - // first attempt to load the file from existing ReaderWriter's - for(ReaderWriterList::iterator itr=_rwList.begin(); - itr!=_rwList.end(); - ++itr) - { - rwOriginal.insert(itr->get()); - if ((*itr)->writeNode(node,fileName)) return true; - } - - // now look for a plug-in to save the file. - std::string libraryName = createLibraryNameForFile(fileName); - if (Registry::instance()->loadLibrary(libraryName)) - { - for(ReaderWriterList::iterator itr=_rwList.begin(); - itr!=_rwList.end(); - ++itr) - { - if (rwOriginal.find(itr->get())==rwOriginal.end()) - { - if ((*itr)->writeNode(node,fileName)) return true; - } - } - } - else - { - notify(NOTICE)<<"Warning: Could not find plugin to write file with extension ." - < g_SceneProxy; - -Scene::Scene() -{ - _gstate = NULL; -} - -Scene::~Scene() -{ - if (_gstate) _gstate->unref(); -} - -void Scene::setGState(osg::GeoState* gstate) -{ - if (gstate==_gstate) return; - - if (_gstate) _gstate->unref(); - - _gstate = gstate; - if (_gstate) _gstate->ref(); -} - -bool Scene::readLocalData(Input& fr) -{ - bool iteratorAdvanced = false; - - if (fr[0].matchWord("Use")) - { - if (fr[1].isString()) { - GeoState* geostate = dynamic_cast(fr.getObjectForUniqueID(fr[1].getStr())); - if (geostate) { - fr+=2; - _gstate = geostate; - _gstate->ref(); - iteratorAdvanced = true; - } - } - } - - if (GeoState* readState = static_cast(GeoState::instance()->readClone(fr))) - { - _gstate = readState; - _gstate->ref(); - iteratorAdvanced = true; - } - - if (Group::readLocalData(fr)) iteratorAdvanced = true; - - return iteratorAdvanced; -} - -bool Scene::writeLocalData(Output& fw) -{ - if (_gstate) - { - _gstate->write(fw); - } - - Group::writeLocalData(fw); - - return true; -} diff --git a/src/osg/Seg.cpp b/src/osg/Seg.cpp deleted file mode 100644 index 337575580..000000000 --- a/src/osg/Seg.cpp +++ /dev/null @@ -1,270 +0,0 @@ -#include "osg/Seg" - -using namespace osg; - -bool Seg::intersectAndClip(Vec3& s,Vec3& e,const BoundingBox& bb) -{ - // compate s and e against the xMin to xMax range of bb. - if (s.x()<=e.x()) - { - - // trivial reject of segment wholely outside. - if (e.x()bb.xMax()) return false; - - if (s.x()bb.xMax()) - { - // clip e to xMax. - e = s+(e-s)*(bb.xMax()-s.x())/(e.x()-s.x()); - } - } - else - { - if (s.x()bb.xMax()) return false; - - if (e.x()bb.xMax()) - { - // clip e to xMax. - s = s+(e-s)*(bb.xMax()-s.x())/(e.x()-s.x()); - } - } - - // compate s and e against the yMin to yMax range of bb. - if (s.y()<=e.y()) - { - - // trivial reject of segment wholely outside. - if (e.y()bb.yMax()) return false; - - if (s.y()bb.yMax()) - { - // clip e to yMax. - e = s+(e-s)*(bb.yMax()-s.y())/(e.y()-s.y()); - } - } - else - { - if (s.y()bb.yMax()) return false; - - if (e.y()bb.yMax()) - { - // clip e to yMax. - s = s+(e-s)*(bb.yMax()-s.y())/(e.y()-s.y()); - } - } - - // compate s and e against the zMin to zMax range of bb. - if (s.z()<=e.z()) - { - - // trivial reject of segment wholely outside. - if (e.z()bb.zMax()) return false; - - if (s.z()bb.zMax()) - { - // clip e to zMax. - e = s+(e-s)*(bb.zMax()-s.z())/(e.z()-s.z()); - } - } - else - { - if (s.z()bb.zMax()) return false; - - if (e.z()bb.zMax()) - { - // clip e to zMax. - s = s+(e-s)*(bb.zMax()-s.z())/(e.z()-s.z()); - } - } - - return true; -} - -bool Seg::intersect(const BoundingBox& bb) const -{ - if (!bb.isValid()) return false; - - Vec3 s=_s,e=_e; - return intersectAndClip(s,e,bb); -} - -bool Seg::intersect(const BoundingBox& bb,float& r1,float& r2) const -{ - if (!bb.isValid()) return false; - - Vec3 s=_s,e=_e; - return intersectAndClip(s,e,bb); -} - -bool Seg::intersect(const BoundingSphere& bs,float& r1,float& r2) const -{ - Vec3 sm = _s-bs._center; - float c = sm.length2()-bs._radius*bs._radius; - - Vec3 se = _e-_s; - float a = se.length2(); - - float b = sm*se*2.0f; - - float d = b*b-4.0f*a*c; - - if (d<0.0f) return false; - - d = sqrtf(d); - - float div = 1.0f/(2.0f*a); - - r1 = (-b-d)*div; - r2 = (-b+d)*div; - - if (r1<=0.0f && r2<=0.0f) return false; - - if (r1>=1.0f && r2>=1.0f) return false; - - return true; -} - -bool Seg::intersect(const BoundingSphere& bs) const -{ - Vec3 sm = _s-bs._center; - float c = sm.length2()-bs._radius*bs._radius; - if (c<0.0f) return true; - - Vec3 se = _e-_s; - float a = se.length2(); - - float b = (sm*se)*2.0f; - - float d = b*b-4.0f*a*c; - - if (d<0.0f) return false; - - d = sqrtf(d); - - float div = 1.0f/(2.0f*a); - - float r1 = (-b-d)*div; - float r2 = (-b+d)*div; - - if (r1<=0.0f && r2<=0.0f) return false; - - if (r1>=1.0f && r2>=1.0f) return false; - - return true; -} - -bool Seg::intersect(const Vec3& v1,const Vec3& v2,const Vec3& v3,float& r) -{ - if (v1==v2 || v2==v3 || v1==v3) return false; - - Vec3 vse = _e-_s; - - Vec3 v12 = v2-v1; - Vec3 n12 = v12^vse; - float ds12 = (_s-v1)*n12; - float d312 = (v3-v1)*n12; - if (d312>=0.0f) - { - if (ds12<0.0f) return false; - if (ds12>d312) return false; - } - else // d312 < 0 - { - if (ds12>0.0f) return false; - if (ds12=0.0f) - { - if (ds23<0.0f) return false; - if (ds23>d123) return false; - } - else // d123 < 0 - { - if (ds23>0.0f) return false; - if (ds23=0.0f) - { - if (ds31<0.0f) return false; - if (ds31>d231) return false; - } - else // d231 < 0 - { - if (ds31>0.0f) return false; - if (ds31length) return false; - - r = d/length; - - return true; -} diff --git a/src/osg/Sequence.cpp b/src/osg/Sequence.cpp deleted file mode 100644 index 5e1d48e6b..000000000 --- a/src/osg/Sequence.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "osg/Sequence" -#include "osg/Registry" - -using namespace osg; - -RegisterObjectProxy g_SequenceProxy; - -// to be written :-) diff --git a/src/osgPlugins/flt/export.h b/src/osgPlugins/flt/export.h deleted file mode 100644 index c617d008e..000000000 --- a/src/osgPlugins/flt/export.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef __FLT_EXPORT_H -#define __FLT_EXPORT_H - -#define FLT_DLL - -#ifdef WIN32 -#pragma warning( disable : 4251 ) -#pragma warning( disable : 4275 ) -#pragma warning( disable : 4786 ) -#endif - -#if defined(FLT_DLL) && defined(_MSC_VER) -# ifdef FLT_LIBRARY -# define FLT_EXPORT __declspec(dllexport) -# else -# define FLT_EXPORT __declspec(dllimport) -# endif /* FLT_LIBRARY */ -#else -# define FLT_EXPORT -#endif /* FLT_DLL && _MSC_VER */ - -#endif diff --git a/src/osgPlugins/osgtgz/osgtgz.cpp b/src/osgPlugins/osgtgz/osgtgz.cpp deleted file mode 100644 index e687b7a43..000000000 --- a/src/osgPlugins/osgtgz/osgtgz.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "osg/FileNameUtils" - -using namespace osg; - -#ifdef __sgi -static int dirent_select( dirent *dent ) -#else -static int dirent_select( const dirent *dent ) -#endif -{ - if( strlen( dent->d_name) < 4 ) - return 0; - - return !strncmp( ".osg", &dent->d_name[strlen(dent->d_name)-4], 4 ); -} - -class sgReaderWriterOSGTGZ : public ReaderWriter { - public: - virtual const char* className() { return "Default OSGTGZ Database Reader/Writer"; } - virtual bool acceptsExtension(const std::string& extension) { return extension=="osgtgz"; } - - virtual Node* readNode(const std::string& fileName) - { - std::string ext = getLowerCaseFileExtension(fileName); - if (!acceptsExtension(ext)) return NULL; - - osg::notify(osg::INFO)<< "sgReaderWriterOSGTGZ::readNode( "<d_name ); - grp->addChild( node ); - } - - sprintf( command, "rm -rf %s", dirname ); - system( command ); - - if( grp->getNumChildren() == 0 ) - { - grp->unref(); - return NULL; - } - - else - return grp; - } - - virtual bool writeNode(Node& obj,const std::string& fileName) { - return false; - } - -}; - -// now register with sgRegistry to instantiate the above -// reader/writer. -RegisterReaderWriterProxy g_readerWriter_OSGTGZ_Proxy; diff --git a/src/osgUtil/RenderVisitor.cpp b/src/osgUtil/RenderVisitor.cpp deleted file mode 100644 index 1801738f1..000000000 --- a/src/osgUtil/RenderVisitor.cpp +++ /dev/null @@ -1,799 +0,0 @@ -#include "osgUtil/RenderVisitor" -#include "osg/DCS" -#include "osg/Geode" -#include "osg/LOD" -#include "osg/Billboard" -#include "osg/LightSource" -#include "osg/Notify" - -#include -#include - -#ifndef OSG_USE_IO_DOT_H -#include -using namespace std; -#endif - -using namespace osg; -using namespace osgUtil; - -static bool g_debugging = false; - -ViewState::ViewState() -{ - _matrix = NULL; - _inverse = NULL; - _ratio = 0.002f; - _viewFrustumCullingActive=true; - _smallFeatureCullingActive=true; -} - -ViewState::~ViewState() -{ - if (_matrix) _matrix->unref(); - if (_inverse) _inverse->unref(); -} - - -bool ViewState::isCulled(const BoundingSphere& sp) -{ - if (!sp.isValid()) return true; - - - Vec3 delta = sp._center-_eyePoint; - if (_smallFeatureCullingActive) - { - if (sp._radiussp._radius) - { - return true; - } - if (delta*_frustumBottomNormal>sp._radius) - { - return true; - } - if (delta*_frustumLeftNormal>sp._radius) - { - return true; - } - if (delta*_frustumRightNormal>sp._radius) - { - return true; - } - } - return false; -} - -bool ViewState::isCulled(const BoundingBox& bb) -{ - if (!bb.isValid()) return true; - - if (_viewFrustumCullingActive) - { - unsigned int c; - for(c=0;c<8;++c) - { - if ((bb.corner(c)-_eyePoint)*_frustumLeftNormal<=0.0f) break; - } - // if all corners have been checked, therefore all points are - // and the far side of the left clipping plane and hence should be culled. - if (c==8) return true; - - for(c=0;c<8;++c) - { - if ((bb.corner(c)-_eyePoint)*_frustumRightNormal<=0.0f) break; - } - // if all corners have been checked, therefore all points are - // and the far side of the right clipping plane and hence should be culled. - if (c==8) return true; - - for(c=0;c<8;++c) - { - if ((bb.corner(c)-_eyePoint)*_frustumTopNormal<=0.0f) break; - } - // if all corners have been checked, therefore all points are - // and the far side of the top clipping plane and hence should be culled. - if (c==8) return true; - - - for(c=0;c<8;++c) - { - if ((bb.corner(c)-_eyePoint)*_frustumBottomNormal<=0.0f) break; - } - // if all corners have been checked, therefore all points are - // and the far side of the bottom clipping plane and hence should be culled. - if (c==8) return true; - } - - return false; -} - -RenderVisitor::RenderVisitor() -{ - // overide the default node visitor mode. - setTraverseMode(NodeVisitor::TRAVERSE_ACTIVE_CHILDREN); - - _globalState=NULL; - _LODBias = 1.0f; - - _fovy=60.0f; - _aspect=1.0f; - _znear=1.0f; - _zfar=1000.0f; - - _tvs = new ViewState; - _tvs->_eyePoint.set(0.0f,0.0f,1.0f); - _tvs->_centerPoint.set(0.0f,0.0f,0.0f); - _tvs->_lookVector.set(0.0f,0.0f,-1.0f); - _tvs->_upVector.set(0.0f,1.0f,0.0f); - _tvs->ref(); - - _cvs = _tvs; - _cvs->ref(); - - _tsm = LOOK_VECTOR_DISTANCE; - _tsm = OBJECT_EYE_POINT_DISTANCE; - - _viewFrustumCullingActive=true; - _smallFeatureCullingActive=true; - - calculateClippingPlanes(); -} - -RenderVisitor::~RenderVisitor() -{ - reset(); - // if a global geostate is attached simply unref it. - if (_globalState) - { - _globalState->unref(); - _globalState = NULL; - } - if (_tvs) _tvs->unref(); - if (_cvs) _cvs->unref(); -} - -void RenderVisitor::reset() -{ - - // - // first unref all referenced objects and then empty the containers. - // - std::for_each(_viewStateStack.begin(),_viewStateStack.end(),UnrefOp()); - _viewStateStack.erase(_viewStateStack.begin(),_viewStateStack.end()); - if (_cvs!=_tvs) - { - if (_cvs) _cvs->unref(); - _cvs = _tvs; - _cvs->ref(); - } - - for(std::multimap::iterator titr= _transparentGeoSets.begin(); - titr!= _transparentGeoSets.end(); - ++titr) - { - if ((*titr).second.first) (*titr).second.first->unref(); - } - _transparentGeoSets.erase(_transparentGeoSets.begin(),_transparentGeoSets.end()); - - for(std::multimap::iterator oitr= _opaqueGeoSets.begin(); - oitr!= _opaqueGeoSets.end(); - ++oitr) - { - if ((*oitr).second.first) (*oitr).second.first->unref(); - } - _opaqueGeoSets.erase(_opaqueGeoSets.begin(),_opaqueGeoSets.end()); - - _lights.erase(_lights.begin(),_lights.end()); - -} - -void RenderVisitor::setGlobalState(GeoState* global) -{ - if (global==_globalState) return; - if (_globalState) _globalState->unref(); - _globalState = global; - _globalState->ref(); -} - - -void RenderVisitor::setPerspective(const osg::Camera& camera) -{ - _fovy=camera.getFieldOfViewY(); - _aspect=camera.getAspectRatio(); - _znear=camera.getNearPlane(); - _zfar=camera.getFarPlane(); - - calculateClippingPlanes(); -} - -void RenderVisitor::setPerspective(float fovy,float aspect,float znear,float zfar) -{ - _fovy=fovy; - _aspect=aspect; - _znear=znear; - _zfar=zfar; - - calculateClippingPlanes(); -} - -void RenderVisitor::setLookAt(const Camera& camera) -{ - setLookAt(camera.getEyePoint(),camera.getLookPoint(),camera.getUpVector()); -} - -void RenderVisitor::setLookAt(const Vec3& eye,const Vec3& center,const Vec3& upVector) -{ - _tvs->_eyePoint = eye; - - _tvs->_centerPoint = center; - - _tvs->_lookVector = center-eye; - _tvs->_lookVector.normalize(); - - _tvs->_upVector = upVector; - - calculateClippingPlanes(); -} - - -void RenderVisitor::setLookAt(double eyeX,double eyeY,double eyeZ, - double centerX,double centerY,double centerZ, - double upX,double upY,double upZ) -{ - _tvs->_eyePoint[0] = eyeX; - _tvs->_eyePoint[1] = eyeY; - _tvs->_eyePoint[2] = eyeZ; - - _tvs->_centerPoint[0] = centerX; - _tvs->_centerPoint[1] = centerY; - _tvs->_centerPoint[2] = centerZ; - - _tvs->_lookVector[0] = centerX-eyeX; - _tvs->_lookVector[1] = centerY-eyeY; - _tvs->_lookVector[2] = centerZ-eyeZ; - _tvs->_lookVector.normalize(); - - _tvs->_upVector[0] = upX; - _tvs->_upVector[1] = upY; - _tvs->_upVector[2] = upZ; - - calculateClippingPlanes(); -} - -void RenderVisitor::setCullingActive(CullingType ct,bool active) -{ - switch(ct) - { - case(VIEW_FRUSTUM_CULLING):_viewFrustumCullingActive=active;break; - case(SMALL_FEATURE_CULLING):_smallFeatureCullingActive=active;break; - } -} - -bool RenderVisitor::getCullingActive(CullingType ct) -{ - switch(ct) - { - case(VIEW_FRUSTUM_CULLING):return _viewFrustumCullingActive; - case(SMALL_FEATURE_CULLING):return _smallFeatureCullingActive; - } - return false; -} - -void RenderVisitor::calculateClippingPlanes() -{ - float half_fovy = _fovy*0.5f; - float s = sinf(half_fovy*M_PI/180.0f); - float c = cosf(half_fovy*M_PI/180.0f); - - Vec3 lv = _tvs->_lookVector; - Vec3 up = _tvs->_upVector; - Vec3 sv = lv ^ up; - sv.normalize(); - - _tvs->_frustumTopNormal = -lv*s + up*c; - _tvs->_frustumTopNormal.normalize(); - - _tvs->_frustumBottomNormal = -lv*s - up*c; - _tvs->_frustumBottomNormal.normalize(); - - _tvs->_frustumLeftNormal = -sv*c - lv*(s*_aspect); - _tvs->_frustumLeftNormal.normalize(); - - _tvs->_frustumRightNormal = sv*c - lv*(s*_aspect); - _tvs->_frustumRightNormal.normalize(); - -// notify(INFO) << "_frustumTopNormal = "<<_tvs->_frustumTopNormal[0]<<"\t"<<_tvs->_frustumTopNormal[1]<<"\t"<<_tvs->_frustumTopNormal[2]<_frustumBottomNormal[1]<<"\t"<<_tvs->_frustumBottomNormal[2]<_frustumLeftNormal[1]<<"\t"<<_tvs->_frustumLeftNormal[2]<_frustumRightNormal[1]<<"\t"<<_tvs->_frustumRightNormal[2]<ref(); - nvs->_viewFrustumCullingActive=_viewFrustumCullingActive; - nvs->_smallFeatureCullingActive=_smallFeatureCullingActive; - - if (_cvs && _cvs->_matrix) - { - nvs->_matrix = new Matrix; - nvs->_matrix->mult(matrix,*(_cvs->_matrix)); - } - else - { - nvs->_matrix = new Matrix(matrix); - } - nvs->_matrix->ref(); - - Matrix* inverse_world = new Matrix; - inverse_world->ref(); - inverse_world->invert(*(nvs->_matrix)); - nvs->_inverse = inverse_world; - - nvs->_eyePoint = _tvs->_eyePoint*(*inverse_world); - nvs->_centerPoint = _tvs->_centerPoint*(*inverse_world); - - nvs->_lookVector = nvs->_centerPoint - nvs->_eyePoint; - nvs->_lookVector.normalize(); - - nvs->_frustumTopNormal = (_tvs->_eyePoint + _tvs->_frustumTopNormal)*(*inverse_world)-nvs->_eyePoint; - nvs->_frustumTopNormal.normalize(); - - nvs->_frustumBottomNormal = (_tvs->_eyePoint + _tvs->_frustumBottomNormal)*(*inverse_world)-nvs->_eyePoint; - nvs->_frustumBottomNormal.normalize(); - - nvs->_frustumLeftNormal = (_tvs->_eyePoint + _tvs->_frustumLeftNormal)*(*inverse_world)-nvs->_eyePoint; - nvs->_frustumLeftNormal.normalize(); - - nvs->_frustumRightNormal = (_tvs->_eyePoint + _tvs->_frustumRightNormal)*(*inverse_world)-nvs->_eyePoint; - nvs->_frustumRightNormal.normalize(); - - if (_cvs) _cvs->unref(); - - _cvs = nvs; - - if (_cvs) _cvs->ref(); - _viewStateStack.push_back(nvs); -} - -void RenderVisitor::popMatrix() -{ - // pop the top of the view stack and unref it. - ViewState* pvs = _viewStateStack.back(); - _viewStateStack.pop_back(); - pvs->unref(); - - // unref previous cvs - if (_cvs) _cvs->unref(); - - // to new cvs and ref it. - if (_viewStateStack.empty()) - { - _cvs = _tvs; - if (_cvs) _cvs->ref(); - } - else - { - _cvs = _viewStateStack.back(); - if (_cvs) _cvs->ref(); - } - -} - -Matrix* RenderVisitor::getCurrentMatrix() -{ - return _cvs->_matrix; -} - -Matrix* RenderVisitor::getInverseCurrentMatrix() -{ - return _cvs->_inverse; -} - -const Vec3& RenderVisitor::getEyeLocal() -{ - return _cvs->_eyePoint; -} - -const Vec3& RenderVisitor::getCenterLocal() -{ - return _cvs->_centerPoint; -} - -const Vec3& RenderVisitor::getLookVectorLocal() -{ - return _cvs->_lookVector; -} - -bool RenderVisitor::isCulled(const BoundingSphere& sp) -{ - return _cvs->isCulled(sp); -} - -bool RenderVisitor::isCulled(const BoundingBox& bb) -{ - return _cvs->isCulled(bb); -} - -void RenderVisitor::apply(Node& node) -{ - if (isCulled(node.getBound())) return; - - traverse(node); -} - -void RenderVisitor::apply(Geode& node) -{ - if (isCulled(node.getBound())) return; - - Matrix* matrix = getCurrentMatrix(); - for(int i=0;igetBound())) continue; - - GeoState* gstate = gset->getGeoState(); - bool isTransparent = gstate && gstate->isTransparent(); - if (isTransparent) - { - - Vec3 center; - if (matrix) - { - center = (gset->getBound().center())*(*matrix); - } - else - { - center = gset->getBound().center(); - } - Vec3 delta_center = center-_tvs->_eyePoint; - - if (g_debugging) - { - notify(INFO) << "center ["<_lookVector.x()<<","<<_tvs->_lookVector.y()<<","<<_tvs->_lookVector.z()<<"]"<_lookVector*delta_center;break; - case(OBJECT_EYE_POINT_DISTANCE): - default: depth = delta_center.length2();break; - } - - if (matrix) matrix->ref(); - _transparentGeoSets.insert( - std::pair(depth,MatrixGeoSet(matrix,gset)) - ); - } - else - { - if (matrix) matrix->ref(); - _opaqueGeoSets.insert( - std::pair(gstate,MatrixGeoSet(matrix,gset)) - ); - } - } -} - -void RenderVisitor::apply(Billboard& node) -{ - if (isCulled(node.getBound())) return; - - Vec3 eye_local = getEyeLocal(); - - for(int i=0;igetBound())) continue; - - Matrix local_mat; - node.calcTransform(eye_local,pos,local_mat); - - Matrix* matrix = NULL; - if (_cvs->_matrix) - { - matrix = new Matrix(); - matrix->mult(local_mat,*(_cvs->_matrix)); - } - else - { - matrix = new Matrix(local_mat); - } - - GeoState* gstate = gset->getGeoState(); - bool isTransparent = gstate && gstate->isTransparent(); - if (isTransparent) - { - - Vec3 center; - if (matrix) - { - center = (gset->getBound().center())*(*matrix); - } - else - { - center = gset->getBound().center(); - } - Vec3 delta_center = center-_tvs->_eyePoint; - - if (g_debugging) - { - notify(INFO) << "center ["<_lookVector.x()<<","<<_tvs->_lookVector.y()<<","<<_tvs->_lookVector.z()<<"]"<_lookVector*delta_center;break; - case(OBJECT_EYE_POINT_DISTANCE): - default: depth = delta_center.length2();break; - } - - if (matrix) matrix->ref(); - _transparentGeoSets.insert( - std::pair(depth,MatrixGeoSet(matrix,gset)) - ); - } - else - { - if (matrix) matrix->ref(); - _opaqueGeoSets.insert( - std::pair(gstate,MatrixGeoSet(matrix,gset)) - ); - } - - } -} - -void RenderVisitor::apply(LightSource& node) -{ - Matrix* matrix = getCurrentMatrix(); - Light* light = node.getLight(); - if (light) - { - if (matrix) matrix->ref(); - _lights.insert(std::pair(matrix,light)); - } -} - -void RenderVisitor::apply(Group& node) -{ - if (isCulled(node.getBound())) return; - - traverse(node); -} - - -void RenderVisitor::apply(DCS& node) -{ - if (isCulled(node.getBound())) return; - - pushMatrix(*node.getMatrix()); - - traverse(node); - - popMatrix(); -} - - -void RenderVisitor::apply(Switch& node) -{ - apply((Group&)node); -} - - -void RenderVisitor::apply(LOD& node) -{ - if (isCulled(node.getBound())) return; - - int eval = node.evaluate(getEyeLocal(),_LODBias); - if (eval<0) - { - //notify(INFO) << "culled LOD"<accept(*this); - } - -} - - -void RenderVisitor::apply(Scene& node) -{ - apply((Group&)node); -} - - -bool RenderVisitor::calcNearFar(double& near_plane,double& far_plane) -{ - if (_opaqueGeoSets.empty() && _transparentGeoSets.empty()) return false; - - near_plane = FLT_MAX; - far_plane = -FLT_MAX; - - Vec3 eyePoint = getEyeLocal(); - Vec3 lookVector = getLookVectorLocal(); - - for(OpaqueList::iterator oitr = _opaqueGeoSets.begin(); - oitr != _opaqueGeoSets.end(); - ++oitr) - { - Matrix* matrix = (oitr->second).first; - GeoSet* gset = (oitr->second).second; - const BoundingBox& bb = gset->getBound(); - for(int c=0;c<8;++c) - { - float d; - if (matrix) d = ((bb.corner(c)*(*matrix))-eyePoint)*lookVector; - else d = (bb.corner(c)-eyePoint)*lookVector; - if (dfar_plane) far_plane = d; - } - } - - for(TransparentList::iterator titr = _transparentGeoSets.begin(); - titr != _transparentGeoSets.end(); - ++titr) - { - Matrix* matrix = (titr->second).first; - GeoSet* gset = (titr->second).second; - const BoundingBox& bb = gset->getBound(); - for(int c=0;c<8;++c) - { - float d; - if (matrix) d = ((bb.corner(c)*(*matrix))-eyePoint)*lookVector; - else d = (bb.corner(c)-eyePoint)*lookVector; - if (dfar_plane) far_plane = d; - } - } - - return true; -} - -void RenderVisitor::render() -{ - - Matrix* prevMatrix = NULL; - Matrix* currMatrix = NULL; - - GeoState* currGeoState = NULL; - GeoState* prevGeoState = NULL; - - if (g_debugging) notify(INFO) << "start of render"<apply(); - prevGeoState=_globalState; - } - - - // apply the lists. - for(LightList::iterator litr=_lights.begin(); - litr!=_lights.end(); - ++litr) - { - currMatrix = litr->first; - if (currMatrix!=prevMatrix) - { - if (prevMatrix) glPopMatrix(); - if (currMatrix) - { - glPushMatrix(); - glMultMatrixf( (GLfloat *)(currMatrix->_mat) ); - } - prevMatrix = currMatrix; - } - (litr->second)->apply(); - } - - // draw the opaque bin. - for(std::multimap::iterator oitr= _opaqueGeoSets.begin(); - oitr!= _opaqueGeoSets.end(); - ++oitr) - { - if (g_debugging) - { - notify(INFO) << " drawing opaque matrix["<<(*oitr).second.first<<"]" - << " geoset["<<(*oitr).second.second<<"]" - << " geostate["<<(*oitr).second.second->getGeoState()<<"]"<_mat) ); - } - prevMatrix = currMatrix; - } - - currGeoState = (*oitr).first; - if (currGeoState!=prevGeoState) - { - if (currGeoState) currGeoState->apply(_globalState,prevGeoState); - prevGeoState = currGeoState; - } - - (*oitr).second.second->draw(); - } - - -// glPushAttrib( GL_DEPTH_TEST ); -// glDisable( GL_DEPTH_TEST ); - - // render the transparent geoset in reverse order, so to render the - // deepest transparent objects, relative to the look vector, first. - for(std::multimap::reverse_iterator titr= _transparentGeoSets.rbegin(); - titr!= _transparentGeoSets.rend(); - ++titr) - { - if (g_debugging) - { - notify(INFO) << " drawing transparent matrix["<<(*titr).second.first<<"]" - << " geoset["<<(*titr).second.second<<"]" - << " geostate["<<(*titr).second.second->getGeoState()<<"]" - << " depth["<<(*titr).first<<"]"<_mat) ); - } - prevMatrix = currMatrix; - } - - currGeoState = (*titr).second.second->getGeoState(); - if (currGeoState!=prevGeoState) - { - if (currGeoState) currGeoState->apply(_globalState,prevGeoState); - prevGeoState = currGeoState; - } - - (*titr).second.second->draw(); - } - -// glPopAttrib(); - - - if (currMatrix) glPopMatrix(); - - if (g_debugging) - { - notify(INFO) << "end of render"<