HI Ivan,
I'm afriad reviewing and debugging user code goes a bit beyond what I
can do, there are over 1500 developers on osg-users now.
As a general note having pointers to nodes higher in the hierachy
isn't good practice. Why not just move the clipnode transform around
relative to the current view matrix by using a cull callback or custom
Transform that computes the require matrix on the fly.
Robert.
On 11/10/06, Ivan Bolčina <[EMAIL PROTECTED]> wrote:
Can you see something fundamental wrong in my code, because thats seems to
happen. Maybe it is a problem with Delta3D, which uses OSG. I asked there
but if anyone sees a potential problem in following code, it would be great.
thanks,
ivan
/////////////////////////
///header
class SpaceField : public dtCore::DeltaDrawable
{
public:
SpaceField();
virtual ~SpaceField();
void Init();
void UpdatePosition(osg::Vec3 position,osg::Vec3 speed);
virtual osg::Node * GetOSGNode ();
virtual const osg::Node * GetOSGNode () const ;
protected:
osg::MatrixTransform * mTransformShip;
osg::MatrixTransform * mTransformField;
osg::Group * mLocalRoot;
osg::Group * mNode;
int NumberOfVertex;
int NumberOfVertexInBox;
int Radius;
int Frontier;
osg::Vec3 Camera;
osg::Vec3 Center;
};
////////////////////////////////////////////////
///here I build hierearhy
//////////////////////////////////////////////////
void SpaceField::Init()
{
//group that holds field
osg::Group* group = new osg::Group();
//base vertices
osg::Vec3Array* base_vertices = new
osg::Vec3Array(NumberOfVertexInBox);
for (int i=0;i<NumberOfVertexInBox;i++)
{
float x1=random(0,1)*Frontier;
float x2=random(0,1)*Frontier;
float x3=random(0,1)*Frontier;
(*base_vertices)[i].set(x1,x2,x3);
}
for (int i=0;i<3;i++)
for (int j=0;j<3;j++)
for (int k=0;k<3;k++)
{
osg::Geometry* geometry = new osg::Geometry;
// set up vertices
osg::Vec3Array* vertices = new
osg::Vec3Array(NumberOfVertexInBox);
geometry->setVertexArray(vertices);
float xo=Frontier*i-1.5*Frontier;
float yo=Frontier*j-1.5*Frontier;
float zo=Frontier*k-1.5*Frontier;
for (int idx=0;idx<NumberOfVertexInBox;idx++)
{
(*vertices)[idx].set((*base_vertices)[idx].x()+xo,
(*base_vertices)[idx].y()+yo,
(*base_vertices)[idx].z()+zo);
}
osg::Vec4Array* colours = new
osg::Vec4Array(NumberOfVertexInBox);
geometry->setColorArray(colours);
geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
for (int i=0;i<NumberOfVertexInBox;i++)
{
double shade=random(0.7,1);
(*colours)[i].set(shade,shade,shade,shade);
}
osg::DrawElementsUShort* points = new
osg::DrawElementsUShort(GL_POINTS,NumberOfVertex);
geometry->addPrimitiveSet(points);
for(int i=0;i<NumberOfVertexInBox;++i)
{
(*points)[i] = i;
}
geometry->setUseDisplayList(false);
osg::Geode* geode = new osg::Geode;
geode->addDrawable(geometry);
geode->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
geode->setCullingActive(true);
group->addChild(geode);
}
// set up colours
// set up the points for the stars.
mNode=group;
mLocalRoot=new osg::Group();
mTransformShip=new osg::MatrixTransform();
mLocalRoot->addChild(mTransformShip);
mTransformField=new osg::MatrixTransform();
osg::ClipNode *cn=new osg::ClipNode();
cn->createClipBox(osg::BoundingBox(-Frontier,-Frontier,-Frontier,
Frontier,Frontier,Frontier));
mTransformShip->addChild(cn);
cn->addChild(mTransformField);
mTransformField->addChild(mNode);
}
//////////////////////////////////////////////////////////////////////////
//here I apply frame-to-frame transformations
//////////////////////////////////////////////////////////////////////////
void SpaceField::UpdatePosition(osg::Vec3
position,osg::Vec3 speed)
{
osg::Vec3 star=position;
star*=10.;
double x=star.x();
double y=star.y();
double z=star.z();
x=MathUtil::MUmod(x,Frontier);
y=MathUtil::MUmod(y,Frontier);
z=MathUtil::MUmod(z,Frontier);
star=osg::Vec3(x,y,z);
star*=-1.;
osg::Matrix matrix=mTransformShip->getMatrix();
matrix.setTrans ( position.x(), position.y(),position.z());
mTransformShip->setMatrix(matrix);
osg::Matrix matrix2=mTransformField->getMatrix();
matrix2.setTrans ( star.x(), star.y(),star.z());
mTransformField->setMatrix(matrix2);
}
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/