Added support for reading and writing Sphere, Box, Cone, Cylinder and Grid shapes.

This commit is contained in:
Robert Osfield
2003-01-08 14:32:13 +00:00
parent e6b64a5550
commit ba34880464
13 changed files with 413 additions and 119 deletions

View File

@@ -287,8 +287,8 @@ class Cylinder : public Shape
Cylinder():
_center(0.0f,0.0f,0.0f),
_radius(-1.0f),
_height(0.0f) {}
_radius(1.0f),
_height(1.0f) {}
Cylinder(const osg::Vec3& center,float radius,float height):
_center(center),

View File

@@ -5,6 +5,10 @@
#ifndef OSGDB_FIELDREADERITERATOR
#define OSGDB_FIELDREADERITERATOR 1
#include <osg/Vec2>
#include <osg/Vec2>
#include <osg/Vec4>
#include <osgDB/Field>
#include <osgDB/FieldReader>
@@ -48,6 +52,22 @@ class OSGDB_EXPORT FieldReaderIterator
void advanceToEndOfBlock(int noNestBrackets);
bool matchSequence(const char* str);
bool readSequence(const char* keyword,std::string& value);
bool readSequence(const char* keyword,unsigned int& value);
bool readSequence(const char* keyword,int& value);
bool readSequence(const char* keyword,float& value);
bool readSequence(const char* keyword,osg::Vec2& value);
bool readSequence(const char* keyword,osg::Vec3& value);
bool readSequence(const char* keyword,osg::Vec4& value);
bool readSequence(std::string& value);
bool readSequence(unsigned int& value);
bool readSequence(int& value);
bool readSequence(float& value);
bool readSequence(osg::Vec2& value);
bool readSequence(osg::Vec3& value);
bool readSequence(osg::Vec4& value);
private:

View File

@@ -50,6 +50,7 @@ class OSGDB_EXPORT Output : public std::ofstream
void moveOut();
virtual bool writeObject(const osg::Object& obj);
bool getUniqueIDForObject(const osg::Object* obj,std::string& uniqueID);
bool createUniqueIDForObject(const osg::Object* obj,std::string& uniqueID);
@@ -68,6 +69,7 @@ class OSGDB_EXPORT Output : public std::ofstream
virtual const std::string getFileNameForOutput(const std::string& filename) const;
protected:
// prevent copy construction and assignment.
@@ -90,34 +92,6 @@ class OSGDB_EXPORT Output : public std::ofstream
};
template<class T>
bool writeArrayBlock(Output& fw,T* start,T* finish)
{
fw.indent() << "{" << std::endl;
fw.moveIn();
int numIndicesThisLine = 0;
for(T* itr=start;itr!=finish;++itr)
{
if (numIndicesThisLine>=fw.getNumIndicesPerLine())
{
fw << std::endl;
numIndicesThisLine = 0;
}
if (numIndicesThisLine==0) fw.indent();
else fw << " ";
fw << *itr;
++numIndicesThisLine;
}
fw << std::endl;
fw.moveOut();
fw.indent() << "}" << std::endl;
return true;
}
}
#endif // __SG_OUTPUT_H

View File

@@ -0,0 +1,173 @@
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
//Distributed under the terms of the GNU Library General Public License (LGPL)
//as published by the Free Software Foundation.
#ifndef OSGDB_PARAMETEROUTPUT
#define OSGDB_PARAMETEROUTPUT 1
#include <osgDB/Output>
namespace osgDB {
class OSGDB_EXPORT ParameterOutput
{
public:
ParameterOutput(Output& fw):
_fw(fw),
_numItemsPerLine(fw.getNumIndicesPerLine()),
_column(0) {}
ParameterOutput(Output& fw,int numItemsPerLine):
_fw(fw),
_numItemsPerLine(numItemsPerLine),
_column(0) {}
void begin()
{
_fw.indent() << "{"<<std::endl;
_fw.moveIn();
}
template<class T>
void write(const T& t)
{
if (_column==0) _fw.indent();
_fw << t;
++_column;
if (_column==_numItemsPerLine)
{
_fw << std::endl;
_column = 0;
}
else
{
_fw << " ";
}
}
template<class Iterator>
void write(Iterator first, Iterator last)
{
for(Iterator itr=first;
itr!=last;
++itr)
{
write(*itr);
}
}
template<class Iterator>
void writeAsInts(Iterator first, Iterator last)
{
for(Iterator itr=first;
itr!=last;
++itr)
{
write((int)*itr);
}
}
void newLine()
{
if (_column!=0) _fw << std::endl;
_column = 0;
}
void end()
{
if (_column!=0) _fw << std::endl;
_fw.moveOut();
_fw.indent() << "}"<<std::endl;
_column = 0;
}
Output& _fw;
int _numItemsPerLine;
int _column;
};
template<class Iterator>
void writeArray(Output& fw, Iterator first, Iterator last,int noItemsPerLine=0)
{
if (noItemsPerLine==0) noItemsPerLine=fw.getNumIndicesPerLine();
fw.indent() << "{"<<std::endl;
fw.moveIn();
int column=0;
for(Iterator itr=first;
itr!=last;
++itr)
{
if (column==0) fw.indent();
fw << *itr;
++column;
if (column==noItemsPerLine)
{
fw << std::endl;
column = 0;
}
else
{
fw << " ";
}
}
if (column!=0) fw << std::endl;
fw.moveOut();
fw.indent()<<"}"<<std::endl;
}
template<class Iterator>
void writeArrayAsInts(Output& fw, Iterator first, Iterator last,int noItemsPerLine=0)
{
if (noItemsPerLine==0) noItemsPerLine=fw.getNumIndicesPerLine();
fw.indent() << "{"<<std::endl;
fw.moveIn();
int column=0;
for(Iterator itr=first;
itr!=last;
++itr)
{
if (column==0) fw.indent();
fw << (int)*itr;
++column;
if (column==noItemsPerLine)
{
fw << std::endl;
column = 0;
}
else
{
fw << " ";
}
}
if (column!=0) fw << std::endl;
fw.moveOut();
fw.indent()<<"}"<<std::endl;
}
}
#endif // __SG_OUTPUT_H