Fixes for dumb VS6.0 compiler

This commit is contained in:
Robert Osfield
2005-11-10 19:32:37 +00:00
parent 06117353df
commit 435e4b828c
4 changed files with 247 additions and 240 deletions

View File

@@ -201,7 +201,7 @@ void MovieEventHandler::getUsage(osg::ApplicationUsage& usage) const
}
osg::Geometry* createTexturedQuadGeometry(const osg::Vec3& pos,float width,float height, osg::Image* image, bool useTextureRectangle)
osg::Geometry* myCreateTexturedQuadGeometry(const osg::Vec3& pos,float width,float height, osg::Image* image, bool useTextureRectangle)
{
if (useTextureRectangle)
{
@@ -327,7 +327,7 @@ int main(int argc, char** argv)
if (image)
{
geode->addDrawable(createTexturedQuadGeometry(pos,image->s(),image->t(),image, useTextureRectangle));
geode->addDrawable(myCreateTexturedQuadGeometry(pos,image->s(),image->t(),image, useTextureRectangle));
pos.z() += image->t()*1.5f;
}

View File

@@ -195,7 +195,8 @@ osg::Node* createModel(const std::string& shader, const std::string& textureFile
osg::Vec3 row(0.0f,0.0f,0.0);
unsigned int vert_no = 0;
for(unsigned int iy=0; iy<num_y; ++iy)
unsigned int iy;
for(iy=0; iy<num_y; ++iy)
{
osg::Vec3 column = row;
for(unsigned int ix=0;ix<num_x;++ix)
@@ -208,7 +209,7 @@ osg::Node* createModel(const std::string& shader, const std::string& textureFile
geom->setVertexArray(vertices);
for(unsigned int iy=0; iy<num_y-1; ++iy)
for(iy=0; iy<num_y-1; ++iy)
{
unsigned int element_no = 0;
osg::DrawElementsUInt* elements = new osg::DrawElementsUInt(GL_TRIANGLE_STRIP, num_x*2);
@@ -222,12 +223,8 @@ osg::Node* createModel(const std::string& shader, const std::string& textureFile
}
geom->setUseVertexBufferObjects(true);
return geode;
}
int main(int argc, char *argv[])

View File

@@ -12,9 +12,9 @@
/** Simulate the scene with double precision before passing it back to osg.
this permits us to scale down offsets from 0,0,0 with a few matrixtransforms,
in case the objects are too far from that center.
*/
this permits us to scale down offsets from 0,0,0 with a few matrixtransforms,
in case the objects are too far from that center.
*/
#ifndef DXF_SCENE
#define DXF_SCENE 1
@@ -31,8 +31,8 @@ class dxfLayerTable;
class bounds {
public:
bounds() : _min(DBL_MAX, DBL_MAX, DBL_MAX), _max(-DBL_MAX, -DBL_MAX, -DBL_MAX) {}
inline void expandBy(osg::Vec3d v) {
bounds() : _min(DBL_MAX, DBL_MAX, DBL_MAX), _max(-DBL_MAX, -DBL_MAX, -DBL_MAX) {}
inline void expandBy(osg::Vec3d v) {
if(v.x()<_min.x()) _min.x() = v.x();
if(v.x()>_max.x()) _max.x() = v.x();
@@ -41,75 +41,75 @@ public:
if(v.z()<_min.z()) _min.z() = v.z();
if(v.z()>_max.z()) _max.z() = v.z();
}
inline void makeMinValid() {
// we count on _min to offset the whole scene
// so, we make sure its at 0,0,0 if
// bounds are not set (anyway, the scene should be empty,
// if we need to set any value of _min to 0).
if (_min.x() == DBL_MAX) _min.x() = 0;
if (_min.y() == DBL_MAX) _min.y() = 0;
if (_min.z() == DBL_MAX) _min.z() = 0;
}
osg::Vec3d _min;
osg::Vec3d _max;
}
inline void makeMinValid() {
// we count on _min to offset the whole scene
// so, we make sure its at 0,0,0 if
// bounds are not set (anyway, the scene should be empty,
// if we need to set any value of _min to 0).
if (_min.x() == DBL_MAX) _min.x() = 0;
if (_min.y() == DBL_MAX) _min.y() = 0;
if (_min.z() == DBL_MAX) _min.z() = 0;
}
osg::Vec3d _min;
osg::Vec3d _max;
};
static inline
osg::Geometry* createLnGeometry( osg::PrimitiveSet::Mode lineType, osg::Vec3Array* vertices, osg::Vec4 color)
{
osg::Geometry* geom = new osg::Geometry;
geom->setVertexArray(vertices);
geom->addPrimitiveSet(new osg::DrawArrays(lineType, 0, vertices->size()));
osg::Geometry* geom = new osg::Geometry;
geom->setVertexArray(vertices);
geom->addPrimitiveSet(new osg::DrawArrays(lineType, 0, vertices->size()));
osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back(color);
geom->setColorArray(colors);
geom->setColorBinding(osg::Geometry::BIND_OVERALL);
osg::Vec3Array *norms = new osg::Vec3Array;
norms->push_back(osg::Vec3(0,0,1));
geom->setNormalArray(norms);
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
return geom;
osg::Vec3Array *norms = new osg::Vec3Array;
norms->push_back(osg::Vec3(0,0,1));
geom->setNormalArray(norms);
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
return geom;
}
static inline
osg::Geometry* createTriGeometry( osg::Vec3Array* vertices, osg::Vec3Array* normals, osg::Vec4 color)
{
osg::Geometry* geom = new osg::Geometry;
geom->setVertexArray(vertices);
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, vertices->size()));
osg::Geometry* geom = new osg::Geometry;
geom->setVertexArray(vertices);
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, vertices->size()));
osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back(color);
geom->setColorArray(colors);
geom->setColorBinding(osg::Geometry::BIND_OVERALL);
geom->setNormalArray(normals);
geom->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE);
return geom;
geom->setNormalArray(normals);
geom->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE);
return geom;
}
static inline
osg::Geometry* createQuadGeometry( osg::Vec3Array* vertices, osg::Vec3Array* normals, osg::Vec4 color)
{
osg::Geometry* geom = new osg::Geometry;
geom->setVertexArray(vertices);
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0, vertices->size()));
osg::Geometry* geom = new osg::Geometry;
geom->setVertexArray(vertices);
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0, vertices->size()));
osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back(color);
geom->setColorArray(colors);
geom->setColorBinding(osg::Geometry::BIND_OVERALL);
geom->setNormalArray(normals);
geom->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE);
return geom;
geom->setNormalArray(normals);
geom->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE);
return geom;
}
static inline
osg::Geode* createModel(std::string name, osg::Geometry* geom)
{
osg::Geode* geom_geode = new osg::Geode;
geom_geode->addDrawable(geom);
geom_geode->setName(name);
return geom_geode;
osg::Geode* geom_geode = new osg::Geode;
geom_geode->addDrawable(geom);
geom_geode->setName(name);
return geom_geode;
}
@@ -137,190 +137,197 @@ typedef std::map<unsigned short, VListList> MapVListList;
class sceneLayer : public osg::Referenced {
public:
sceneLayer(std::string name) : _name(name) {}
virtual ~sceneLayer() {}
void layer2osg(osg::Group* root, bounds &b)
{
osgLines(root, b);
osgTriangles(root, b);
osgQuads(root, b);
}
MapVListList _linestrips;
MapVList _lines;
MapVList _triangles;
MapVList _trinorms;
MapVList _quads;
MapVList _quadnorms;
sceneLayer(std::string name) : _name(name) {}
virtual ~sceneLayer() {}
void layer2osg(osg::Group* root, bounds &b)
{
osgLines(root, b);
osgTriangles(root, b);
osgQuads(root, b);
}
MapVListList _linestrips;
MapVList _lines;
MapVList _triangles;
MapVList _trinorms;
MapVList _quads;
MapVList _quadnorms;
protected:
std::string _name;
std::string _name;
osg::Vec4 getColor(unsigned short color);
void osgLines(osg::Group* root, bounds &b)
{
for (MapVListList::iterator mitr = _linestrips.begin();
mitr != _linestrips.end(); ++mitr) {
for (VListList::iterator itr = mitr->second.begin();
itr != mitr->second.end(); ++itr) {
if (itr->size()) {
osg::Vec3Array *coords = new osg::Vec3Array;
for (VList::iterator vitr = itr->begin();
vitr != itr->end(); ++vitr) {
osg::Vec3 v(vitr->x() - b._min.x(), vitr->y() - b._min.y(), vitr->z() - b._min.z());
coords->push_back(v);
}
root->addChild(createModel(_name, createLnGeometry(osg::PrimitiveSet::LINE_STRIP, coords, getColor(mitr->first))));
}
}
}
for (MapVList::iterator mitr = _lines.begin();
mitr != _lines.end(); ++mitr) {
osg::Vec3Array *coords = new osg::Vec3Array;
for (VList::iterator itr = mitr->second.begin();
itr != mitr->second.end(); ++itr) {
osg::Vec3 v(itr->x() - b._min.x(), itr->y() - b._min.y(), itr->z() - b._min.z());
coords->push_back(v);
}
root->addChild(createModel(_name, createLnGeometry(osg::PrimitiveSet::LINES, coords, getColor(mitr->first))));
}
}
osg::Vec4 getColor(unsigned short color);
void osgLines(osg::Group* root, bounds &b)
{
for(MapVListList::iterator mlitr = _linestrips.begin();
mlitr != _linestrips.end();
++mlitr)
{
for(VListList::iterator itr = mlitr->second.begin();
itr != mlitr->second.end();
++itr)
{
if (itr->size()) {
osg::Vec3Array *coords = new osg::Vec3Array;
for (VList::iterator vitr = itr->begin();
vitr != itr->end(); ++vitr) {
osg::Vec3 v(vitr->x() - b._min.x(), vitr->y() - b._min.y(), vitr->z() - b._min.z());
coords->push_back(v);
}
root->addChild(createModel(_name, createLnGeometry(osg::PrimitiveSet::LINE_STRIP, coords, getColor(mlitr->first))));
}
}
}
for (MapVList::iterator mitr = _lines.begin();
mitr != _lines.end(); ++mitr) {
osg::Vec3Array *coords = new osg::Vec3Array;
for (VList::iterator itr = mitr->second.begin();
itr != mitr->second.end(); ++itr) {
osg::Vec3 v(itr->x() - b._min.x(), itr->y() - b._min.y(), itr->z() - b._min.z());
coords->push_back(v);
}
root->addChild(createModel(_name, createLnGeometry(osg::PrimitiveSet::LINES, coords, getColor(mitr->first))));
}
}
void osgTriangles(osg::Group* root, bounds &b)
{
if (_triangles.size()) {
for (MapVList::iterator mitr = _triangles.begin();
mitr != _triangles.end(); ++mitr) {
osg::Vec3Array *coords = new osg::Vec3Array;
for (VList::iterator itr = mitr->second.begin();
itr != mitr->second.end(); ++itr) {
osg::Vec3 v(itr->x() - b._min.x(), itr->y() - b._min.y(), itr->z() - b._min.z());
coords->push_back(v);
}
osg::Vec3Array *norms = new osg::Vec3Array;
VList normlist = _trinorms[mitr->first];
for (VList::iterator itr = normlist.begin();
itr != normlist.end(); ++itr) {
norms->push_back(osg::Vec3(itr->x(), itr->y(), itr->z()));
}
root->addChild(createModel(_name, createTriGeometry(coords, norms, getColor(mitr->first))));
}
}
}
void osgQuads(osg::Group* root, bounds &b)
{
if (_quads.size()) {
for (MapVList::iterator mitr = _quads.begin();
mitr != _quads.end(); ++mitr) {
osg::Vec3Array *coords = new osg::Vec3Array;
for (VList::iterator itr = mitr->second.begin();
itr != mitr->second.end(); ++itr) {
osg::Vec3 v(itr->x() - b._min.x(), itr->y() - b._min.y(), itr->z() - b._min.z());
coords->push_back(v);
}
osg::Vec3Array *norms = new osg::Vec3Array;
VList normlist = _quadnorms[mitr->first];
for (VList::iterator itr = normlist.begin();
itr != normlist.end(); ++itr) {
norms->push_back(osg::Vec3(itr->x(), itr->y(), itr->z()));
}
root->addChild(createModel(_name, createQuadGeometry(coords, norms, getColor(mitr->first))));
}
}
}
void osgTriangles(osg::Group* root, bounds &b)
{
if (_triangles.size()) {
for (MapVList::iterator mitr = _triangles.begin();
mitr != _triangles.end(); ++mitr) {
osg::Vec3Array *coords = new osg::Vec3Array;
VList::iterator itr;
for (itr = mitr->second.begin();
itr != mitr->second.end(); ++itr)
{
osg::Vec3 v(itr->x() - b._min.x(), itr->y() - b._min.y(), itr->z() - b._min.z());
coords->push_back(v);
}
osg::Vec3Array *norms = new osg::Vec3Array;
VList normlist = _trinorms[mitr->first];
for (itr = normlist.begin();
itr != normlist.end(); ++itr)
{
norms->push_back(osg::Vec3(itr->x(), itr->y(), itr->z()));
}
root->addChild(createModel(_name, createTriGeometry(coords, norms, getColor(mitr->first))));
}
}
}
void osgQuads(osg::Group* root, bounds &b)
{
if (_quads.size()) {
for (MapVList::iterator mitr = _quads.begin();
mitr != _quads.end(); ++mitr) {
osg::Vec3Array *coords = new osg::Vec3Array;
for (VList::iterator itr = mitr->second.begin();
itr != mitr->second.end(); ++itr) {
osg::Vec3 v(itr->x() - b._min.x(), itr->y() - b._min.y(), itr->z() - b._min.z());
coords->push_back(v);
}
osg::Vec3Array *norms = new osg::Vec3Array;
VList normlist = _quadnorms[mitr->first];
for (VList::iterator itr = normlist.begin();
itr != normlist.end(); ++itr) {
norms->push_back(osg::Vec3(itr->x(), itr->y(), itr->z()));
}
root->addChild(createModel(_name, createQuadGeometry(coords, norms, getColor(mitr->first))));
}
}
}
};
class scene : public osg::Referenced {
public:
scene(dxfLayerTable* lt = NULL);
virtual ~scene() {}
void setLayerTable(dxfLayerTable* lt);
void pushMatrix(osg::Matrixd m, bool protect = false)
{
_mStack.push_back(_m);
if (protect) // equivalent to setMatrix
_m = m;
else
_m = _m * m;
}
void popMatrix()
{
_mStack.pop_back();
if (_mStack.size())
_m = _mStack.back();
else
_m.makeIdentity();
}
void ocs(osg::Matrixd r)
{
_r = r;
}
void blockOffset(osg::Vec3d t)
{
_t = t;
}
void ocs_clear()
{
_r.makeIdentity();
}
osg::Matrixd& backMatrix() { if (_mStack.size()) return _mStack.back(); else return _m; }
scene(dxfLayerTable* lt = NULL);
virtual ~scene() {}
void setLayerTable(dxfLayerTable* lt);
void pushMatrix(osg::Matrixd m, bool protect = false)
{
_mStack.push_back(_m);
if (protect) // equivalent to setMatrix
_m = m;
else
_m = _m * m;
}
void popMatrix()
{
_mStack.pop_back();
if (_mStack.size())
_m = _mStack.back();
else
_m.makeIdentity();
}
void ocs(osg::Matrixd r)
{
_r = r;
}
void blockOffset(osg::Vec3d t)
{
_t = t;
}
void ocs_clear()
{
_r.makeIdentity();
}
osg::Matrixd& backMatrix() { if (_mStack.size()) return _mStack.back(); else return _m; }
osg::Vec3d addVertex(osg::Vec3d v);
osg::Vec3d addNormal(osg::Vec3d v);
sceneLayer* findOrCreateSceneLayer(std::string l)
{
sceneLayer* ly = _layers[l].get();
if (!ly) {
ly = new sceneLayer(l);
_layers[l] = ly;
}
return ly;
}
unsigned short correctedColorIndex(std::string l, unsigned short color);
osg::Vec3d addVertex(osg::Vec3d v);
osg::Vec3d addNormal(osg::Vec3d v);
sceneLayer* findOrCreateSceneLayer(std::string l)
{
sceneLayer* ly = _layers[l].get();
if (!ly) {
ly = new sceneLayer(l);
_layers[l] = ly;
}
return ly;
}
unsigned short correctedColorIndex(std::string l, unsigned short color);
void addLine(std::string l, unsigned short color, osg::Vec3d s, osg::Vec3d e);
void addLineStrip(std::string l, unsigned short color, std::vector<osg::Vec3d> vertices);
void addLineLoop(std::string l, unsigned short color, std::vector<osg::Vec3d> vertices);
void addTriangles(std::string l, unsigned short color, std::vector<osg::Vec3d> vertices, bool inverted=false);
void addQuads(std::string l, unsigned short color, std::vector<osg::Vec3d> vertices, bool inverted=false);
osg::Group* scene2osg()
{
osg::Group* root = NULL;
osg::Group* child = NULL;
_b.makeMinValid();
osg::Vec3 v = osg::Vec3(_b._min.x(), _b._min.y(), _b._min.z());
double x = _b._min.x() - (double)v.x();
double y = _b._min.y() - (double)v.y();
double z = _b._min.z() - (double)v.z();
osg::Matrix m = osg::Matrix::translate(v);
root = new osg::MatrixTransform(m);
if (x || y || z) {
m = osg::Matrix::translate(x,y,z);
child = new osg::MatrixTransform(m);
root->addChild(child);
} else {
child = root;
}
// root = mt;
for (std::map<std::string, osg::ref_ptr<sceneLayer> >::iterator litr = _layers.begin();
litr != _layers.end(); ++litr) {
sceneLayer* ly = (*litr).second.get();
if (!ly) continue;
osg::Group* lg = new osg::Group;
lg->setName((*litr).first);
child->addChild(lg);
ly->layer2osg(lg, _b);
}
return root;
}
void addLine(std::string l, unsigned short color, osg::Vec3d s, osg::Vec3d e);
void addLineStrip(std::string l, unsigned short color, std::vector<osg::Vec3d> vertices);
void addLineLoop(std::string l, unsigned short color, std::vector<osg::Vec3d> vertices);
void addTriangles(std::string l, unsigned short color, std::vector<osg::Vec3d> vertices, bool inverted=false);
void addQuads(std::string l, unsigned short color, std::vector<osg::Vec3d> vertices, bool inverted=false);
osg::Group* scene2osg()
{
osg::Group* root = NULL;
osg::Group* child = NULL;
_b.makeMinValid();
osg::Vec3 v = osg::Vec3(_b._min.x(), _b._min.y(), _b._min.z());
double x = _b._min.x() - (double)v.x();
double y = _b._min.y() - (double)v.y();
double z = _b._min.z() - (double)v.z();
osg::Matrix m = osg::Matrix::translate(v);
root = new osg::MatrixTransform(m);
if (x || y || z) {
m = osg::Matrix::translate(x,y,z);
child = new osg::MatrixTransform(m);
root->addChild(child);
} else {
child = root;
}
// root = mt;
for (std::map<std::string, osg::ref_ptr<sceneLayer> >::iterator litr = _layers.begin();
litr != _layers.end(); ++litr) {
sceneLayer* ly = (*litr).second.get();
if (!ly) continue;
osg::Group* lg = new osg::Group;
lg->setName((*litr).first);
child->addChild(lg);
ly->layer2osg(lg, _b);
}
return root;
}
protected:
osg::Matrixd _m;
osg::Matrixd _r;
osg::Vec3d _t;
bounds _b;
std::map<std::string, osg::ref_ptr<sceneLayer> > _layers;
std::vector<osg::Matrixd> _mStack;
dxfLayerTable* _layerTable;
osg::Matrixd _m;
osg::Matrixd _r;
osg::Vec3d _t;
bounds _b;
std::map<std::string, osg::ref_ptr<sceneLayer> > _layers;
std::vector<osg::Matrixd> _mStack;
dxfLayerTable* _layerTable;
};

View File

@@ -635,7 +635,8 @@ void ConvertFromFLT::visitColorPalette(osg::Group& , ColorPaletteRecord* rec)
ColorPool* pColorPool = rec->getFltFile()->getColorPool();
int flightVersion = rec->getFlightVersion();
if ( flightVersion > 13 ) {
if ( flightVersion > 13 )
{
SColorPalette* pCol = (SColorPalette*)rec->getData();
int colors = (flightVersion >= 1500) ? 1024 : 512;
@@ -659,26 +660,28 @@ void ConvertFromFLT::visitColorPalette(osg::Group& , ColorPaletteRecord* rec)
if( colorLen > colors )
colorLen = colors;
for (int i = 0; i < colorLen ; i++){
osg::Vec4 color( pCol->Colors[i].get());
//
// Force alpha to one
//
color[3] = 1.0f;
pColorPool->addColor(i, color);
}
int i;
for (i = 0; i < colorLen ; i++)
{
osg::Vec4 color( pCol->Colors[i].get());
//
// Force alpha to one
//
// Fill any remainder of the palette with white
//
for (int i = colorLen; i < colors ; i++){
osg::Vec4 color( 1.0f, 1.0f, 1.0f, 1.0f );
pColorPool->addColor( i, color );
}
color[3] = 1.0f;
pColorPool->addColor(i, color);
}
//
// Fill any remainder of the palette with white
//
for (i = colorLen; i < colors ; i++)
{
osg::Vec4 color( 1.0f, 1.0f, 1.0f, 1.0f );
pColorPool->addColor( i, color );
}
} // ( flightVersion > 13 )
} // ( flightVersion > 13 )
else // version 11, 12 & 13
{