Additions since the CVS back up was made.

This commit is contained in:
Robert Osfield
2003-06-24 21:57:13 +00:00
parent 15f88f35b2
commit d70ab592ed
53 changed files with 2630 additions and 124 deletions

View File

@@ -83,7 +83,6 @@ CXXFILES =\
Texture3D.cpp\
TextureCubeMap.cpp\
TextureRectangle.cpp\
TransformAttributeFunctor.cpp\
Timer.cpp\
Transform.cpp\
UnitTestFramework.cpp\

View File

@@ -2184,3 +2184,38 @@ void Geometry::Extensions::glVertexAttrib4Nubv(unsigned int index, const GLubyte
notify(WARN)<<"Error: glVertexAttrib4Nubv not supported by OpenGL driver"<<std::endl;
}
}
Geometry* osg::createTexturedQuadGeometry(const osg::Vec3& corner,const osg::Vec3& widthVec,const osg::Vec3& heightVec)
{
Geometry* geom = new Geometry;
Vec3Array* coords = new Vec3Array(4);
(*coords)[0] = corner+heightVec;
(*coords)[1] = corner;
(*coords)[2] = corner+widthVec;
(*coords)[3] = corner+widthVec+heightVec;
geom->setVertexArray(coords);
Vec2Array* tcoords = new Vec2Array(4);
(*tcoords)[0].set(0.0f,1.0f);
(*tcoords)[1].set(0.0f,0.0f);
(*tcoords)[2].set(1.0f,0.0f);
(*tcoords)[3].set(1.0f,1.0f);
geom->setTexCoordArray(0,tcoords);
osg::Vec4Array* colours = new osg::Vec4Array(1);
(*colours)[0].set(1.0f,1.0f,1.0,1.0f);
geom->setColorArray(colours);
geom->setColorBinding(Geometry::BIND_OVERALL);
osg::Vec3Array* normals = new osg::Vec3Array(1);
(*normals)[0] = widthVec^heightVec;
(*normals)[0].normalize();
geom->setNormalArray(normals);
geom->setNormalBinding(Geometry::BIND_OVERALL);
geom->addPrimitiveSet(new DrawArrays(PrimitiveSet::QUADS,0,4));
return geom;
}

View File

@@ -160,7 +160,7 @@ unsigned int Image::computeNumComponents(GLenum format)
case(GL_LUMINANCE_ALPHA): return 2;
default:
{
std::cout<<"error format = "<<std::hex<<format<<std::endl;
notify(WARN)<<"error format = "<<std::hex<<format<<std::endl;
return 0;
}
}
@@ -208,7 +208,7 @@ unsigned int Image::computePixelSizeInBits(GLenum format,GLenum type)
case(GL_UNSIGNED_INT_2_10_10_10_REV): return 32;
default:
{
std::cout<<"error type = "<<type<<std::endl;
notify(WARN)<<"error type = "<<type<<std::endl;
return 0;
}
}
@@ -220,7 +220,7 @@ unsigned int Image::computeRowWidthInBytes(int width,GLenum format,GLenum type,i
unsigned int pixelSize = computePixelSizeInBits(format,type);
int widthInBits = width*pixelSize;
int packingInBits = packing*8;
std::cout << "width="<<width<<" pixelSize="<<pixelSize<<" width in bit="<<widthInBits<<" packingInBits="<<packingInBits<<" widthInBits%packingInBits="<<widthInBits%packingInBits<<std::endl;
//notify(INFO) << "width="<<width<<" pixelSize="<<pixelSize<<" width in bit="<<widthInBits<<" packingInBits="<<packingInBits<<" widthInBits%packingInBits="<<widthInBits%packingInBits<<std::endl;
return (widthInBits/packingInBits + ((widthInBits%packingInBits)?1:0))*packing;
}
@@ -267,7 +267,7 @@ unsigned int Image::getTotalSizeInBytesIncludingMipmaps() const
unsigned int sizeOfLastMipMap = computeRowWidthInBytes(s,_pixelFormat,_dataType,_packing)*
r*t;
// std::cout<<"sizeOfLastMipMap="<<sizeOfLastMipMap<<"\ts="<<s<<"\tt="<<t<<"\tr"<<r<<std::endl;
// notify(INFO)<<"sizeOfLastMipMap="<<sizeOfLastMipMap<<"\ts="<<s<<"\tt="<<t<<"\tr"<<r<<std::endl;
return maxValue+sizeOfLastMipMap;
}
@@ -491,7 +491,7 @@ void Image::copySubImage(int s_offset,int t_offset,int r_offset,osg::Image* sour
if (!_data)
{
cout<<"allocating image"<<endl;
notify(INFO)<<"allocating image"<<endl;
allocateImage(s_offset+source->r(),t_offset+source->t(),r_offset+source->t(),
source->getPixelFormat(),source->getDataType(),
source->getPacking());

View File

@@ -16,6 +16,11 @@
using namespace osg;
// arbitrary minima for rows & segments
const unsigned int MIN_NUM_ROWS = 3;
const unsigned int MIN_NUM_SEGMENTS = 5;
///////////////////////////////////////////////////////////////////////////////
//
// draw shape
@@ -29,11 +34,12 @@ class DrawShapeVisitor : public ConstShapeVisitor
_state(state),
_hints(hints)
{
#if 0
if (hints)
{
notify(NOTICE)<<"Warning: TessellationHints ignored in present osg::ShapeDrawable implementation."<<std::endl;
}
#endif
}
virtual void apply(const Sphere&);
@@ -59,9 +65,17 @@ void DrawShapeVisitor::apply(const Sphere& sphere)
glTranslatef(sphere.getCenter().x(),sphere.getCenter().y(),sphere.getCenter().z());
unsigned int numSegments = 40;
unsigned int numRows = 20;
if (_hints && _hints->getDetailRatio() != 1.0f) {
float ratio = _hints->getDetailRatio();
numRows = (unsigned int) (numRows * ratio);
if (numRows < MIN_NUM_ROWS)
numRows = MIN_NUM_ROWS;
numSegments = (unsigned int) (numSegments * ratio);
if (numSegments < MIN_NUM_SEGMENTS)
numSegments = MIN_NUM_SEGMENTS;
}
float lDelta = osg::PI/(float)numRows;
float vDelta = 1.0f/(float)numRows;
@@ -76,9 +90,7 @@ void DrawShapeVisitor::apply(const Sphere& sphere)
float nzBase=-1.0f;
float nRatioBase=0.0f;
for(unsigned int rowi=0;
rowi<numRows;
++rowi)
for(unsigned int rowi=0; rowi<numRows; ++rowi)
{
float lTop = lBase+lDelta;
@@ -93,8 +105,7 @@ void DrawShapeVisitor::apply(const Sphere& sphere)
float angle = 0.0f;
float texCoord = 0.0f;
for(unsigned int topi=0;
topi<numSegments;
for(unsigned int topi=0; topi<numSegments;
++topi,angle+=angleDelta,texCoord+=texCoordHorzDelta)
{
@@ -135,14 +146,16 @@ void DrawShapeVisitor::apply(const Sphere& sphere)
nRatioBase=nRatioTop;
}
glPopMatrix();
}
void DrawShapeVisitor::apply(const Box& box)
{
// evaluate hints
bool createBody = (_hints ? _hints->getCreateBody() : true);
bool createTop = (_hints ? _hints->getCreateTop() : true);
bool createBottom = (_hints ? _hints->getCreateBottom() : true);
float dx = box.getHalfLengths().x();
float dy = box.getHalfLengths().y();
@@ -160,6 +173,7 @@ void DrawShapeVisitor::apply(const Box& box)
glBegin(GL_QUADS);
if (createBody) {
// -ve y plane
glNormal3f(0.0f,-1.0f,0.0f);
@@ -219,7 +233,9 @@ void DrawShapeVisitor::apply(const Box& box)
glTexCoord2f(1.0f,1.0f);
glVertex3f(-dx,-dy,dz);
}
if (createTop) {
// +ve z plane
glNormal3f(0.0f,0.0f,1.0f);
@@ -234,7 +250,9 @@ void DrawShapeVisitor::apply(const Box& box)
glTexCoord2f(1.0f,1.0f);
glVertex3f(dx,dy,dz);
}
if (createBottom) {
// -ve z plane
glNormal3f(0.0f,0.0f,-1.0f);
@@ -249,6 +267,7 @@ void DrawShapeVisitor::apply(const Box& box)
glTexCoord2f(1.0f,1.0f);
glVertex3f(-dx,dy,-dz);
}
glEnd();
@@ -268,9 +287,21 @@ void DrawShapeVisitor::apply(const Cone& cone)
glMultMatrixf(rotation.ptr());
}
// evaluate hints
bool createBody = (_hints ? _hints->getCreateBody() : true);
bool createBottom = (_hints ? _hints->getCreateBottom() : true);
unsigned int numSegments = 40;
unsigned int numRows = 10;
if (_hints && _hints->getDetailRatio() != 1.0f) {
float ratio = _hints->getDetailRatio();
numRows = (unsigned int) (numRows * ratio);
if (numRows < MIN_NUM_ROWS)
numRows = MIN_NUM_ROWS;
numSegments = (unsigned int) (numSegments * ratio);
if (numSegments < MIN_NUM_SEGMENTS)
numSegments = MIN_NUM_SEGMENTS;
}
float r = cone.getRadius();
float h = cone.getHeight();
@@ -294,79 +325,71 @@ void DrawShapeVisitor::apply(const Cone& cone)
float angle;
float texCoord;
for(unsigned int rowi=0;
rowi<numRows;
++rowi,topz=basez, basez-=hDelta, topr=baser, baser+=rDelta, topv=basev, basev-=texCoordRowDelta)
{
// we can't use a fan for the cone top
// since we need different normals at the top
// for each face..
glBegin(GL_QUAD_STRIP);
if (createBody) {
for(unsigned int rowi=0; rowi<numRows;
++rowi,topz=basez, basez-=hDelta, topr=baser, baser+=rDelta, topv=basev, basev-=texCoordRowDelta) {
// we can't use a fan for the cone top
// since we need different normals at the top
// for each face..
glBegin(GL_QUAD_STRIP);
angle = 0.0f;
texCoord = 0.0f;
for(unsigned int topi=0;
topi<numSegments;
++topi,angle+=angleDelta,texCoord+=texCoordHorzDelta)
{
angle = 0.0f;
texCoord = 0.0f;
for(unsigned int topi=0; topi<numSegments;
++topi,angle+=angleDelta,texCoord+=texCoordHorzDelta) {
float c = cosf(angle);
float s = sinf(angle);
float c = cosf(angle);
float s = sinf(angle);
glNormal3f(c*normalRatio,s*normalRatio,normalz);
glNormal3f(c*normalRatio,s*normalRatio,normalz);
glTexCoord2f(texCoord,topv);
glVertex3f(c*topr,s*topr,topz);
glTexCoord2f(texCoord,topv);
glVertex3f(c*topr,s*topr,topz);
glTexCoord2f(texCoord,basev);
glVertex3f(c*baser,s*baser,basez);
glTexCoord2f(texCoord,basev);
glVertex3f(c*baser,s*baser,basez);
}
}
// do last point by hand to ensure no round off errors.
glNormal3f(normalRatio,0.0f,normalz);
// do last point by hand to ensure no round off errors.
glNormal3f(normalRatio,0.0f,normalz);
glTexCoord2f(1.0f,topv);
glVertex3f(topr,0.0f,topz);
glTexCoord2f(1.0f,topv);
glVertex3f(topr,0.0f,topz);
glTexCoord2f(1.0f,basev);
glVertex3f(baser,0.0f,basez);
glTexCoord2f(1.0f,basev);
glVertex3f(baser,0.0f,basez);
glEnd();
}
}
glEnd();
}
// we can't use a fan for the cone top
// since we need different normals at the top
// for each face..
glBegin(GL_TRIANGLE_FAN);
if (createBottom) {
glBegin(GL_TRIANGLE_FAN);
angle = osg::PI*2.0f;
texCoord = 1.0f;
basez = cone.getBaseOffset();
angle = osg::PI*2.0f;
texCoord = 1.0f;
basez = cone.getBaseOffset();
glNormal3f(0.0f,0.0f,-1.0f);
glTexCoord2f(0.5f,0.5f);
glVertex3f(0.0f,0.0f,basez);
glNormal3f(0.0f,0.0f,-1.0f);
glTexCoord2f(0.5f,0.5f);
glVertex3f(0.0f,0.0f,basez);
for(unsigned int bottomi=0;
bottomi<numSegments;
++bottomi,angle-=angleDelta,texCoord-=texCoordHorzDelta)
{
for(unsigned int bottomi=0; bottomi<numSegments;
++bottomi,angle-=angleDelta,texCoord-=texCoordHorzDelta) {
float c = cosf(angle);
float s = sinf(angle);
float c = cosf(angle);
float s = sinf(angle);
glTexCoord2f(c*0.5f+0.5f,s*0.5f+0.5f);
glVertex3f(c*r,s*r,basez);
glTexCoord2f(c*0.5f+0.5f,s*0.5f+0.5f);
glVertex3f(c*r,s*r,basez);
}
}
glTexCoord2f(1.0f,0.0f);
glVertex3f(r,0.0f,basez);
glTexCoord2f(1.0f,0.0f);
glVertex3f(r,0.0f,basez);
glEnd();
}
glEnd();
glPopMatrix();
}
@@ -382,12 +405,21 @@ void DrawShapeVisitor::apply(const Cylinder& cylinder)
glMultMatrixf(rotation.ptr());
}
// evaluate hints
bool createBody = (_hints ? _hints->getCreateBody() : true);
bool createTop = (_hints ? _hints->getCreateTop() : true);
bool createBottom = (_hints ? _hints->getCreateBottom() : true);
unsigned int numSegments = 40;
if (_hints && _hints->getDetailRatio() != 1.0f) {
float ratio = _hints->getDetailRatio();
numSegments = (unsigned int) (numSegments * ratio);
if (numSegments < MIN_NUM_SEGMENTS)
numSegments = MIN_NUM_SEGMENTS;
}
float angleDelta = 2.0f*osg::PI/(float)numSegments;
float texCoordDelta = 1.0/(float)numSegments;
float texCoordDelta = 1.0f/(float)numSegments;
float r = cylinder.getRadius();
float h = cylinder.getHeight();
@@ -395,16 +427,17 @@ void DrawShapeVisitor::apply(const Cylinder& cylinder)
float basez = -h*0.5f;
float topz = h*0.5f;
float angle = 0.0f;
float texCoord = 0.0f;
// cylinder body
glBegin(GL_QUAD_STRIP);
if (createBody) {
glBegin(GL_QUAD_STRIP);
float angle = 0.0f;
float texCoord = 0.0f;
for(unsigned int bodyi=0;
bodyi<numSegments;
++bodyi,angle+=angleDelta,texCoord+=texCoordDelta)
{
float c = cosf(angle);
float s = sinf(angle);
@@ -415,7 +448,6 @@ void DrawShapeVisitor::apply(const Cylinder& cylinder)
glTexCoord2f(texCoord,0.0f);
glVertex3f(c*r,s*r,basez);
}
// do last point by hand to ensure no round off errors.
@@ -427,12 +459,12 @@ void DrawShapeVisitor::apply(const Cylinder& cylinder)
glTexCoord2f(1.0f,0.0f);
glVertex3f(r,0.0f,basez);
glEnd();
glEnd();
}
// cylinder top
glBegin(GL_TRIANGLE_FAN);
// cylinder top
if (createTop) {
glBegin(GL_TRIANGLE_FAN);
glNormal3f(0.0f,0.0f,1.0f);
glTexCoord2f(0.5f,0.5f);
@@ -444,22 +476,22 @@ void DrawShapeVisitor::apply(const Cylinder& cylinder)
topi<numSegments;
++topi,angle+=angleDelta,texCoord+=texCoordDelta)
{
float c = cosf(angle);
float s = sinf(angle);
glTexCoord2f(c*0.5f+0.5f,s*0.5f+0.5f);
glVertex3f(c*r,s*r,topz);
}
glTexCoord2f(1.0f,0.0f);
glVertex3f(r,0.0f,topz);
glEnd();
glEnd();
}
// cylinder bottom
glBegin(GL_TRIANGLE_FAN);
if (createBottom) {
glBegin(GL_TRIANGLE_FAN);
glNormal3f(0.0f,0.0f,-1.0f);
glTexCoord2f(0.5f,0.5f);
@@ -471,19 +503,18 @@ void DrawShapeVisitor::apply(const Cylinder& cylinder)
bottomi<numSegments;
++bottomi,angle-=angleDelta,texCoord-=texCoordDelta)
{
float c = cosf(angle);
float s = sinf(angle);
glTexCoord2f(c*0.5f+0.5f,s*0.5f+0.5f);
glVertex3f(c*r,s*r,basez);
}
glTexCoord2f(0.0f,0.0f);
glVertex3f(r,0.0f,basez);
glEnd();
glEnd();
}
glPopMatrix();
}
@@ -519,8 +550,6 @@ void DrawShapeVisitor::apply(const TriangleMesh& mesh)
glEnd();
}
}
void DrawShapeVisitor::apply(const ConvexHull& hull)
@@ -1262,8 +1291,9 @@ ShapeDrawable::ShapeDrawable():
{
}
ShapeDrawable::ShapeDrawable(Shape* shape):
_color(1.0f,1.0f,1.0f,1.0f)
ShapeDrawable::ShapeDrawable(Shape* shape,TessellationHints* hints):
_color(1.0f,1.0f,1.0f,1.0f),
_tessellationHints(hints)
{
setShape(shape);
}

View File

@@ -28,6 +28,15 @@ Texture2D::Texture2D():
setUseHardwareMipMapGeneration(true);
}
Texture2D::Texture2D(osg::Image* image):
_textureWidth(0),
_textureHeight(0),
_numMipmapLevels(0)
{
setUseHardwareMipMapGeneration(true);
setImage(image);
}
Texture2D::Texture2D(const Texture2D& text,const CopyOp& copyop):
Texture(text,copyop),
_image(copyop(text._image.get())),

View File

@@ -0,0 +1,82 @@
/**********************************************************************
*
* FILE: ConvexPlanarOccluder.cpp
*
* DESCRIPTION: Read/Write osg::ConvexPlanarOccluder in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 23.4.2003
*
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
#include "Object.h"
#include "ConvexPlanarOccluder.h"
#include "ConvexPlanarPolygon.h"
using namespace ive;
void ConvexPlanarOccluder::write(DataOutputStream* out){
// Write ConvexPlanarOccluder's identification.
out->writeInt(IVECONVEXPLANAROCCLUDER);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("ConvexPlanarOccluder::write(): Could not cast this osg::ConvexPlanarOccluder to an osg::Object.");
// Write ConvexPlanarOccluder's properties.
// Write planar polygon occluder.
out->writeInt((int)&getOccluder());
if(&getOccluder())
((ive::ConvexPlanarPolygon*)(&getOccluder()))->write(out);
// Write hole list.
HoleList holeList = getHoleList();
int size = holeList.size();
out->writeInt(size);
for(int i=0; i<size; i++){
((ive::ConvexPlanarPolygon*)(&holeList[i]))->write(out);
}
}
void ConvexPlanarOccluder::read(DataInputStream* in){
// Peek on ConvexPlanarOccluder's identification.
int id = in->peekInt();
if(id == IVECONVEXPLANAROCCLUDER){
// Read ConvexPlanarOccluder's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("ConvexPlanarOccluder::read(): Could not cast this osg::ConvexPlanarOccluder to an osg::Object.");
// Read ConvexPlanarOccluder's properties
// Read planar polygon occluder.
if(in->readInt()){
osg::ConvexPlanarPolygon* cpp = new osg::ConvexPlanarPolygon();
((ive::ConvexPlanarPolygon*)(cpp))->read(in);
setOccluder(*cpp);
}
// Read hole list.
int size = in->readInt();
for(int i=0; i<size; i++){
osg::ConvexPlanarPolygon* cpp = new osg::ConvexPlanarPolygon();
((ive::ConvexPlanarPolygon*)(cpp))->read(in);
addHole(*cpp);
}
}
else{
throw Exception("ConvexPlanarOccluder::read(): Expected ConvexPlanarOccluder identification.");
}
}

View File

@@ -0,0 +1,15 @@
#ifndef IVE_CONVEXPLANAROCCLUDER
#define IVE_CONVEXPLANAROCCLUDER 1
#include <osg/ConvexPlanarOccluder>
#include "ReadWrite.h"
namespace ive{
class ConvexPlanarOccluder : public osg::ConvexPlanarOccluder, public ReadWrite {
public:
void write(DataOutputStream* out);
void read(DataInputStream* in);
};
}
#endif

View File

@@ -0,0 +1,67 @@
/**********************************************************************
*
* FILE: ConvexPlanarPolygon.cpp
*
* DESCRIPTION: Read/Write osg::ConvexPlanarPolygon in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 23.4.2003
*
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
#include "ConvexPlanarPolygon.h"
using namespace ive;
void ConvexPlanarPolygon::write(DataOutputStream* out){
// Write ConvexPlanarPolygon's identification.
out->writeInt(IVECONVEXPLANARPOLYGON);
// If the osg class is inherited by any other class we should also write this to file.
//osg::Object* obj = dynamic_cast<osg::Object*>(this);
//if(obj){
// ((ive::Object*)(obj))->write(out);
//}
//else
// throw Exception("ConvexPlanarPolygon::write(): Could not cast this osg::ConvexPlanarPolygon to an osg::Object.");
// Write ConvexPlanarPolygon's properties.
// Write Vertex list
VertexList vertexList = getVertexList();
int size = vertexList.size();
out->writeInt(size);
for(int i=0; i<size; i++){
out->writeVec3(vertexList[i]);
}
}
void ConvexPlanarPolygon::read(DataInputStream* in){
// Peek on ConvexPlanarPolygon's identification.
int id = in->peekInt();
if(id == IVECONVEXPLANARPOLYGON){
// Read ConvexPlanarPolygon's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
//osg::Object* obj = dynamic_cast<osg::Object*>(this);
//if(obj){
// ((ive::Object*)(obj))->read(in);
//}
//else
// throw Exception("ConvexPlanarPolygon::read(): Could not cast this osg::ConvexPlanarPolygon to an osg::Object.");
// Read ConvexPlanarPolygon's properties
// Read Vertex list
int size = in->readInt();
for(int i=0; i<size; i++){
add(in->readVec3());
}
}
else{
throw Exception("ConvexPlanarPolygon::read(): Expected ConvexPlanarPolygon identification.");
}
}

View File

@@ -0,0 +1,17 @@
#ifndef IVE_CONVEXPLANARPOLYGON
#define IVE_CONVEXPLANARPOLYGON 1
#include <osg/ConvexPlanarPolygon>
#include "ReadWrite.h"
namespace ive{
class ConvexPlanarPolygon : public osg::ConvexPlanarPolygon, public ReadWrite {
public:
void write(DataOutputStream* out);
void read(DataInputStream* in);
virtual ~ConvexPlanarPolygon() {}
};
}
#endif

View File

@@ -0,0 +1,64 @@
/**********************************************************************
*
* FILE: DrawElementsUInt.cpp
*
* DESCRIPTION: Read/Write osg::DrawElementsUInt in binary format to disk.
*
* CREATED BY: Copied from DrawElementsUShort.cpp by Marco Jez
*
*
* HISTORY: Created 20.3.2003
*
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
#include "DrawElementsUInt.h"
#include "PrimitiveSet.h"
using namespace ive;
void DrawElementsUInt::write(DataOutputStream* out){
// Write DrawElementsUInt's identification.
out->writeInt(IVEDRAWELEMENTSUINT);
// If the osg class is inherited by any other class we should also write this to file.
osg::PrimitiveSet* prim = dynamic_cast<osg::PrimitiveSet*>(this);
if(prim){
((ive::PrimitiveSet*)(prim))->write(out);
}
else
throw Exception("DrawElementsUInt::write(): Could not cast this osg::DrawElementsUInt to an osg::PrimitiveSet.");
// Write DrawElementsUInt's properties.
// Write array length and its elements.
out->writeInt(size());
for(unsigned int i=0; i<size(); i++){
out->writeUInt(((osg::VectorUInt)(*this))[i]);
}
}
void DrawElementsUInt::read(DataInputStream* in){
// Read DrawElementsUInt's identification.
int id = in->peekInt();
if(id == IVEDRAWELEMENTSUINT){
// Code to read DrawElementsUInt's properties.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::PrimitiveSet* prim = dynamic_cast<osg::PrimitiveSet*>(this);
if(prim){
((ive::PrimitiveSet*)(prim))->read(in);
}
else
throw Exception("DrawElementsUInt::read(): Could not cast this osg::DrawElementsUInt to an osg::PrimtiveSet.");
// Read array length and its elements.
int size = in->readInt();
for(int i=0; i<size; i++){
push_back(in->readUInt());
}
}
else{
throw Exception("DrawElementsUInt::read(): Expected DrawElementsUInt identification.");
}
}

View File

@@ -0,0 +1,15 @@
#ifndef IVE_DRAWELEMENTSUINT
#define IVE_DRAWELEMENTSUINT 1
#include <osg/PrimitiveSet>
#include "ReadWrite.h"
namespace ive{
class DrawElementsUInt : public osg::DrawElementsUInt, public ReadWrite {
public:
void write(DataOutputStream* out);
void read(DataInputStream* in);
};
}
#endif

View File

@@ -0,0 +1,54 @@
/**********************************************************************
*
* FILE: Impostor.cpp
*
* DESCRIPTION: Read/Write osg::Impostor in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 16.4.2003
*
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
#include "Impostor.h"
#include "LOD.h"
using namespace ive;
void Impostor::write(DataOutputStream* out){
// Write Impostor's identification.
out->writeInt(IVEIMPOSTOR);
// If the osg class is inherited by any other class we should also write this to file.
osg::LOD* lod = dynamic_cast<osg::LOD*>(this);
if(lod){
((ive::LOD*)(lod))->write(out);
}
else
throw Exception("Impostor::write(): Could not cast this osg::Impostor to an osg::LOD.");
// Write Impostor's properties.
out->writeFloat(getImpostorThreshold());
}
void Impostor::read(DataInputStream* in){
// Peek on Impostor's identification.
int id = in->peekInt();
if(id == IVEIMPOSTOR){
// Read Impostor's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::LOD* lod = dynamic_cast<osg::LOD*>(this);
if(lod){
((ive::LOD*)(lod))->read(in);
}
else
throw Exception("Impostor::read(): Could not cast this osg::Impostor to an osg::LOD.");
// Read Impostor's properties
setImpostorThreshold(in->readFloat());
}
else{
throw Exception("Impostor::read(): Expected Impostor identification.");
}
}

View File

@@ -0,0 +1,15 @@
#ifndef IVE_IMPOSTOR
#define IVE_IMPOSTOR 1
#include <osg/Impostor>
#include "ReadWrite.h"
namespace ive{
class Impostor : public osg::Impostor, public ReadWrite {
public:
void write(DataOutputStream* out);
void read(DataInputStream* in);
};
}
#endif

View File

@@ -0,0 +1,61 @@
/**********************************************************************
*
* FILE: OccluderNode.cpp
*
* DESCRIPTION: Read/Write osg::OccluderNode in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 16.4.2003
*
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
#include "OccluderNode.h"
#include "Group.h"
#include "ConvexPlanarOccluder.h"
using namespace ive;
void OccluderNode::write(DataOutputStream* out){
// Write OccluderNode's identification.
out->writeInt(IVEOCCLUDERNODE);
// If the osg class is inherited by any other class we should also write this to file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->write(out);
}
else
throw Exception("OccluderNode::write(): Could not cast this osg::OccluderNode to an osg::Group.");
// Write OccluderNode's properties.
out->writeInt((int)getOccluder());
if(getOccluder())
((ive::ConvexPlanarOccluder*)(getOccluder()))->write(out);
}
void OccluderNode::read(DataInputStream* in){
// Peek on OccluderNode's identification.
int id = in->peekInt();
if(id == IVEOCCLUDERNODE){
// Read OccluderNode's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->read(in);
}
else
throw Exception("OccluderNode::read(): Could not cast this osg::OccluderNode to an osg::Group.");
// Read OccluderNode's properties
if(in->readInt()){
osg::ConvexPlanarOccluder* cpo = new osg::ConvexPlanarOccluder();
((ive::ConvexPlanarOccluder*)(cpo))->read(in);
setOccluder(cpo);
}
}
else{
throw Exception("OccluderNode::read(): Expected OccluderNode identification.");
}
}

View File

@@ -0,0 +1,16 @@
#ifndef IVE_OCCLUDERNODE
#define IVE_OCCLUDERNODE 1
#include <osg/OccluderNode>
#include "ReadWrite.h"
namespace ive{
class OccluderNode : public osg::OccluderNode, public ReadWrite {
public:
void write(DataOutputStream* out);
void read(DataInputStream* in);
};
}
#endif

View File

@@ -0,0 +1,62 @@
/**********************************************************************
*
* FILE: Point.cpp
*
* DESCRIPTION: Read/Write osg::Point in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 27.3.2003
*
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
#include "Point.h"
#include "Object.h"
using namespace ive;
void Point::write(DataOutputStream* out){
// Write CullFace's identification.
out->writeInt(IVEPOINT);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("Point::write(): Could not cast this osg::Point to an osg::Object.");
// Write Point's properties.
out->writeFloat(getSize());
out->writeFloat(getFadeThresholdSize());
out->writeVec3(getDistanceAttenuation());
out->writeFloat(getMinSize());
out->writeFloat(getMaxSize());
}
void Point::read(DataInputStream* in){
// Peek on Point's identification.
int id = in->peekInt();
if(id == IVEPOINT){
// Read Point's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("Point::read(): Could not cast this osg::Point to an osg::Object.");
// Read Point's properties
setSize(in->readFloat());
setFadeThresholdSize(in->readFloat());
setDistanceAttenuation(in->readVec3());
setMinSize(in->readFloat());
setMaxSize(in->readFloat());
}
else{
throw Exception("Point::read(): Expected Point identification.");
}
}

View File

@@ -0,0 +1,15 @@
#ifndef IVE_POINT
#define IVE_POINT 1
#include <osg/Point>
#include "ReadWrite.h"
namespace ive{
class Point : public osg::Point, public ReadWrite {
public:
void write(DataOutputStream* out);
void read(DataInputStream* in);
};
}
#endif

View File

@@ -0,0 +1,56 @@
/**********************************************************************
*
* FILE: PolygonOffset.cpp
*
* DESCRIPTION: Read/Write osg::PolygonOffset in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 27.3.2003
*
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
#include "PolygonOffset.h"
#include "Object.h"
using namespace ive;
void PolygonOffset::write(DataOutputStream* out){
// Write CullFace's identification.
out->writeInt(IVEPOLYGONOFFSET);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("PolygonOffset::write(): Could not cast this osg::PolygonOffset to an osg::Object.");
// Write PolygonOffset's properties.
out->writeFloat(getFactor());
out->writeFloat(getUnits());
}
void PolygonOffset::read(DataInputStream* in){
// Peek on PolygonOffset's identification.
int id = in->peekInt();
if(id == IVEPOLYGONOFFSET){
// Read PolygonOffset's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("PolygonOffset::read(): Could not cast this osg::PolygonOffset to an osg::Object.");
// Read PolygonOffset's properties
setFactor(in->readFloat());
setUnits(in->readFloat());
}
else{
throw Exception("PolygonOffset::read(): Expected PolygonOffset identification.");
}
}

View File

@@ -0,0 +1,15 @@
#ifndef IVE_POLYGONOFFSET
#define IVE_POLYGONOFFSET 1
#include <osg/PolygonOffset>
#include "ReadWrite.h"
namespace ive{
class PolygonOffset : public osg::PolygonOffset, public ReadWrite {
public:
void write(DataOutputStream* out);
void read(DataInputStream* in);
};
}
#endif

View File

@@ -0,0 +1,54 @@
/**********************************************************************
*
* FILE: ShadeModel.cpp
*
* DESCRIPTION: Read/Write osg::ShadeModel in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 27.3.2003
*
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
#include "ShadeModel.h"
#include "Object.h"
using namespace ive;
void ShadeModel::write(DataOutputStream* out){
// Write CullFace's identification.
out->writeInt(IVESHADEMODEL);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("ShadeModel::write(): Could not cast this osg::ShadeModel to an osg::Object.");
// Write ShadeModel's properties.
out->writeInt(getMode());
}
void ShadeModel::read(DataInputStream* in){
// Peek on ShadeModel's identification.
int id = in->peekInt();
if(id == IVESHADEMODEL){
// Read ShadeModel's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("ShadeModel::read(): Could not cast this osg::ShadeModel to an osg::Object.");
// Read ShadeModel's properties
setMode((Mode)in->readInt());
}
else{
throw Exception("ShadeModel::read(): Expected ShadeModel identification.");
}
}

View File

@@ -0,0 +1,15 @@
#ifndef IVE_SHADEMODEL
#define IVE_SHADEMODEL 1
#include <osg/ShadeModel>
#include "ReadWrite.h"
namespace ive{
class ShadeModel : public osg::ShadeModel, public ReadWrite {
public:
void write(DataOutputStream* out);
void read(DataInputStream* in);
};
}
#endif

View File

@@ -0,0 +1,62 @@
/**********************************************************************
*
* FILE: Switch.cpp
*
* DESCRIPTION: Read/Write osg::Switch in binary format to disk.
*
* CREATED BY: Auto generated by iveGenerator
* and later modified by Rune Schmidt Jensen.
*
* HISTORY: Created 9.4.2003
*
* Copyright 2003 VR-C
**********************************************************************/
#include "Exception.h"
#include "Switch.h"
#include "Group.h"
using namespace ive;
void Switch::write(DataOutputStream* out){
// Write Switch's identification.
out->writeInt(IVESWITCH);
// If the osg class is inherited by any other class we should also write this to file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->write(out);
}
else
throw Exception("Switch::write(): Could not cast this osg::Switch to an osg::Group.");
// Write Switch's properties.
// Write childrens value.
for(unsigned int i=0; i<getNumChildren();i++)
out->writeBool(getValue(i));
}
void Switch::read(DataInputStream* in){
// Peek on Switch's identification.
int id = in->peekInt();
if(id == IVESWITCH){
// Read Switch's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){
((ive::Group*)(group))->read(in);
}
else
throw Exception("Switch::read(): Could not cast this osg::Switch to an osg::Group.");
// Read Switch's properties
// Read childrens value.
for(unsigned int i=0; i<getNumChildren();i++)
setValue(i, in->readBool());
}
else{
throw Exception("Switch::read(): Expected Switch identification.");
}
}

View File

@@ -0,0 +1,15 @@
#ifndef IVE_SWITCH
#define IVE_SWITCH 1
#include <osg/Switch>
#include "ReadWrite.h"
namespace ive{
class Switch : public osg::Switch, public ReadWrite {
public:
void write(DataOutputStream* out);
void read(DataInputStream* in);
};
}
#endif

View File

@@ -47,6 +47,7 @@ CXXFILES =\
Sequence.cpp\
Stencil.cpp\
Switch.cpp\
TessellationHints.cpp\
TexEnv.cpp\
TexEnvCombine.cpp\
TexGen.cpp\

View File

@@ -1,4 +1,5 @@
#include <osg/ShapeDrawable>
#include <osg/Notify>
#include <osgDB/Registry>
#include <osgDB/Input>
@@ -11,17 +12,6 @@ using namespace osgDB;
bool ShapeDrawable_readLocalData(Object& obj, Input& fr);
bool ShapeDrawable_writeLocalData(const Object& obj, Output& fw);
// //register the read and write functions with the osgDB::Registry.
// RegisterDotOsgWrapperProxy g_ShapeDrawableFuncProxy
// (
// new osg::ShapeDrawable,
// "ShapeDrawable",
// "Object Drawable ShapeDrawable",
// 0,
// 0,
// DotOsgWrapper::READ_AND_WRITE
// );
RegisterDotOsgWrapperProxy g_ShapeDrawableFuncProxy
(
new osg::ShapeDrawable,
@@ -52,6 +42,16 @@ bool ShapeDrawable_readLocalData(Object& obj, Input& fr)
iteratorAdvanced = true;
}
ref_ptr<Object> readObject = fr.readObject();
if (readObject.valid()) {
TessellationHints* hints = dynamic_cast<TessellationHints*>(readObject.get());
if (hints)
geom.setTessellationHints(hints);
else
notify(WARN) << "Warning: " << readObject->className() << " loaded but cannot be attached to ShapeDrawable.\n";
iteratorAdvanced = true;
}
return iteratorAdvanced;
}
@@ -61,5 +61,9 @@ bool ShapeDrawable_writeLocalData(const Object& obj, Output& fw)
fw.indent() << "color " << geom.getColor() << std::endl;
const TessellationHints* hints = geom.getTessellationHints();
if (hints)
fw.writeObject(*hints);
return true;
}

View File

@@ -9,7 +9,7 @@ CXXFILES = \
LightPointNode.cpp\
Sector.cpp\
Version.cpp\
# SphereSegment.cpp\
DEF += -DOSGSIM_LIBRARY

View File

@@ -21,6 +21,7 @@ CXXFILES = \
SmoothingVisitor.cpp\
Tesselator.cpp\
TransformCallback.cpp\
TransformAttributeFunctor.cpp\
TriStripVisitor.cpp\
TriStrip_tri_stripper.cpp\
CubeMapGenerator.cpp\

View File

@@ -13,7 +13,6 @@
#include <osgUtil/Optimizer>
#include <osg/Transform>
#include <osg/TransformAttributeFunctor>
#include <osg/MatrixTransform>
#include <osg/PositionAttitudeTransform>
#include <osg/LOD>
@@ -25,6 +24,8 @@
#include <osg/Sequence>
#include <osg/Switch>
#include <osgUtil/TransformAttributeFunctor>
#include <typeinfo>
#include <algorithm>
#include <numeric>
@@ -497,7 +498,7 @@ void CollectLowestTransformsVisitor::doTransform(osg::Object* obj,osg::Matrix& m
osg::Drawable* drawable = dynamic_cast<osg::Drawable*>(obj);
if (drawable)
{
osg::TransformAttributeFunctor tf(matrix);
osgUtil::TransformAttributeFunctor tf(matrix);
drawable->accept(tf);
drawable->dirtyBound();
return;
@@ -532,7 +533,7 @@ void CollectLowestTransformsVisitor::doTransform(osg::Object* obj,osg::Matrix& m
osg::Matrix matrix_no_trans = matrix;
matrix_no_trans.setTrans(0.0f,0.0f,0.0f);
osg::TransformAttributeFunctor tf(matrix_no_trans);
osgUtil::TransformAttributeFunctor tf(matrix_no_trans);
osg::Vec3 axis = osg::Matrix::transform3x3(tf._im,billboard->getAxis());
axis.normalize();

View File

@@ -0,0 +1,48 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#include <osgUtil/TransformAttributeFunctor>
using namespace osgUtil;
TransformAttributeFunctor::TransformAttributeFunctor(const osg::Matrix& m)
{
_m = m;
_im.invert(_m);
}
TransformAttributeFunctor::~TransformAttributeFunctor()
{
}
void TransformAttributeFunctor::apply(osg::Drawable::AttributeType type,unsigned int count,osg::Vec3* begin)
{
if (type == osg::Drawable::VERTICES)
{
osg::Vec3* end = begin+count;
for (osg::Vec3* itr=begin;itr<end;++itr)
{
(*itr) = (*itr)*_m;
}
}
else if (type == osg::Drawable::NORMALS)
{
osg::Vec3* end = begin+count;
for (osg::Vec3* itr=begin;itr<end;++itr)
{
// note post mult by inverse for normals.
(*itr) = osg::Matrix::transform3x3(_im,(*itr));
(*itr).normalize();
}
}
}