[osg-users] hello,I have a problem.

2008-03-18 Thread Niuheming

Hi,   I want to write a class from osg::Drawable::UpdateCallback to update a 
Geometry call named geom,but there is no update happen.I dot't know what's 
wrong.Does someone knows?Thanks in advance!NiuHeming
 
class niuhm : public osg::Drawable::UpdateCallback{public:
niuhm(const osg::Vec3& v11,const osg::Vec3& v22,const osg::Vec3& v33)   
 {v1=v11;v2=v22;   v2=v33;  
bs.radius()*=1.5f;
bs=osg::BoundingSphere(osg::Vec3(0.0f,0.0f,0.0f),4.0f); 
bb.expandBy(bs);}virtual void update(osg::NodeVisitor* nv, 
osg::Drawable* node){osg::Geometry* geom = 
dynamic_cast(node);const osg::FrameStamp* 
frameStamp = nv->getFrameStamp();if (geom && frameStamp)
{
  osg::PositionAttitudeTransform* mt = new 
osg::PositionAttitudeTransform();  { // set 
up the animation path   osg::AnimationPath* animationPath = 
new osg::AnimationPath;  
animationPath->insert(0.0,osg::AnimationPath::ControlPoint(bb.corner(0)));  

animationPath->insert(1.0,osg::AnimationPath::ControlPoint(bb.corner(1)));  
 
animationPath->insert(2.0,osg::AnimationPath::ControlPoint(bb.corner(2)));  
 
animationPath->insert(3.0,osg::AnimationPath::ControlPoint(bb.corner(3)));  
   
animationPath->insert(4.0,osg::AnimationPath::ControlPoint(bb.corner(0)));  
 animationPath->setLoopMode(osg::AnimationPath::SWING); 
  mt->setUpdateCallback(new 
osg::AnimationPathCallback(animationPath));  }  
// create marker for point light.
   osg::Vec3 vertices = mt->getPosition();
 
  unsigned int noXSteps = 100;  
unsigned int noYSteps = 100;  osg::Vec3Array* coords = 
new osg::Vec3Array;  coords->reserve(noXSteps*noYSteps);
  osg::Vec3 dx = (v2-v1)/((float)noXSteps-1.0f);
  osg::Vec3 dy = (v3-v1)/((float)noYSteps-1.0f);
 unsigned int rowvertices;   
unsigned int colvertices;rowvertices=(unsigned 
int)((vertices._v[0])/(dx._v[0])); 
colvertices=(unsigned int)((vertices._v[1])/(dy._v[1]));
unsigned int row;   osg::Vec3 vRowStart = v1;   
 for(row=0;rowpush_back(v+osg::Vec3(0.0f,0.0f,-1.0f));
else  coords->push_back(v);
v += dx; }  
 vRowStart+=dy;}
 geom->setVertexArray(coords); } }  
 osg::Vec3 v1;   osg::Vec3 v2;   osg::Vec3 v3;  
  osg::BoundingSphere bs;osg::BoundingBox bb;
};
_
MSN圣诞礼物火热登场,免费发放中,快来领取吧!
http://im.live.cn/emoticons/?ID=18___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] hello,I have a problem.

2008-03-19 Thread Wu Xiaodong
Hello. Niu:


You need to set the " class niuhm : public
osg::Drawable::UpdateCallback" object to your node to update; by:
   geom->setDataVariance( );   geom->setUpdateCallback(  );

You can refer to the osgcallback in the osgExamples.

xiaodong





2008/3/19 Niuheming <[EMAIL PROTECTED]>:

>
> Hi,
>I want to write a class from osg::Drawable::UpdateCallback to update a
> Geometry call named geom,but there is no update happen.I dot't know what's
> wrong.Does someone knows?
> Thanks in advance!
> NiuHeming
>
> class niuhm : public osg::Drawable::UpdateCallback
> {
> public:
> niuhm(const osg::Vec3& v11,const osg::Vec3& v22,const osg::Vec3&
> v33)
> {
> v1=v11;
> v2=v22;
>v2=v33;
>
>bs.radius()*=1.5f;
> bs=osg::BoundingSphere(osg::Vec3(0.0f,0.0f,0.0f),4.0f);
>  bb.expandBy(bs);
> }
>
>  ;virtual void update(osg::NodeVisitor* nv, osg::Drawable*
> node)
> {
> osg::Geometry* geom = dynamic_cast(node);
> const osg::FrameStamp* frameStamp = nv->getFrameStamp();
> if (geom && frameStamp)
> {
>   osg::PositionAttitudeTransform* mt = new
> osg::PositionAttitudeTransform();
>   {
>  // set up the animation path
>   osg::AnimationPath* animationPath = new
> osg::AnimationPath;
>   animationPath->insert(0.0
> ,osg::AnimationPath::ControlPoint(bb.corner(0)));
>   animationPath->inse rt(1.0
> ,osg::AnimationPath::ControlPoint(bb.corner(1)));
>animationPath->insert(2.0
> ,osg::AnimationPath::ControlPoint(bb.corner(2)));
>animationPath->insert(3.0
> ,osg::AnimationPath::ControlPoint(bb.corner(3)));
>  animationPath->insert(4.0
> ,osg::AnimationPath::ControlPoint(bb.corner(0)));
>
> animationPath->setLoopMode(osg::AnimationPath::SWING);
>  &nbs p; mt->setUpdateCallback(new
> osg::AnimationPathCallback(animationPath));
>   }
>
>   // create marker for point light.
>   osg::Vec3 vertices = mt->getPosition();
>
>   unsigned int noXSteps = 100;
>   unsigned int noYSteps = 100;
>
>   osg::Vec3Array* coords = new osg::Vec3Array;
>   coords->reserve(noXSteps*noYSteps);
>
>
>   osg::Vec3 dx = (v2-v1)/((float)noXSteps-1.0f);
>  &nbs p;osg::Vec3 dy = (v3-v1)/((float)noYSteps-1.0f);
>  unsigned int rowvertices;
>unsigned int colvertices;
> rowvertices=(unsigned
> int)((vertices._v[0])/(dx._v[0]));
>  colvertices=(unsigned
> int)((vertices._v[1])/(dy._v[1]));
>
> unsigned int row;
>& nbsp;   osg::Vec3 vRowStart = v1;
> for(row=0;row osg::Vec3 v = vRowStart;
> for(unsigned int col=0;colif ((row==rowvertices)&&(col==colvertices))
>   coords->push_back(v+osg::Vec3(0.0f,0.0f
> ,-1.0f));
> else
>   coords->push_back(v);
> v += dx;
>  }
>vRowStart+=dy;
> }
>
>  geom->setVertexArray(coords);
>   }
>
>  }
>osg::Vec3 v1;
>osg::Vec3 v2;
>osg::Vec3 v3;
> osg::BoundingSphere bs;
> osg::BoundingBox bb;
> };
>
> --
> "七件武器,七种完美" 立刻体验! 
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>


-- 
吴晓东
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] hello,I have a problem.

2008-03-19 Thread Robert Osfield
Hi NiuHeming,

Most likely problem is that your geometry has display lists enabled
and it hasn't been told that its now out of date so isn't updated.

If you are dynamically updating a geometry then its best to turn of
display lists via geometry->setUseDisplayLists(false);  Or if you
update very occassionally then on after each batch of changes you need
a geometry->dirtyDisplayList();

Robert.

2008/3/19 Niuheming <[EMAIL PROTECTED]>:
>
>
> Hi,
>I want to write a class from osg::Drawable::UpdateCallback to update a
> Geometry call named geom,but there is no update happen.I dot't know what's
> wrong.Does someone knows?
> Thanks in advance!
> NiuHeming
>
>  class niuhm : public osg::Drawable::UpdateCallback
> {
> public:
>  niuhm(const osg::Vec3& v11,const osg::Vec3& v22,const osg::Vec3&
> v33)
> {
> v1=v11;
> v2=v22;
>v2=v33;
>
>bs.radius()*=1.5f;
> bs=osg::BoundingSphere(osg::Vec3(0.0f,0.0f,0.0f),4.0f);
>  bb.expandBy(bs);
> }
>
>  ;virtual void update(osg::NodeVisitor* nv, osg::Drawable* node)
> {
> osg::Geometry* geom = dynamic_cast(node);
> const osg::FrameStamp* frameStamp = nv->getFrameStamp();
> if (geom && frameStamp)
> {
>osg::PositionAttitudeTransform* mt = new
> osg::PositionAttitudeTransform();
>   {
>  // set up the animation path
>   osg::AnimationPath* animationPath = new
> osg::AnimationPath;
>
> animationPath->insert(0.0,osg::AnimationPath::ControlPoint(bb.corner(0)));
>   animationPath->inse
> rt(1.0,osg::AnimationPath::ControlPoint(bb.corner(1)));
>
> animationPath->insert(2.0,osg::AnimationPath::ControlPoint(bb.corner(2)));
>
> animationPath->insert(3.0,osg::AnimationPath::ControlPoint(bb.corner(3)));
>
> animationPath->insert(4.0,osg::AnimationPath::ControlPoint(bb.corner(0)));
>
> animationPath->setLoopMode(osg::AnimationPath::SWING);
>  &nbs p; mt->setUpdateCallback(new
> osg::AnimationPathCallback(animationPath));
>   }
>
>   // create marker for point light.
>   osg::Vec3 vertices = mt->getPosition();
>
>unsigned int noXSteps = 100;
>   unsigned int noYSteps = 100;
>
>   osg::Vec3Array* coords = new osg::Vec3Array;
>   coords->reserve(noXSteps*noYSteps);
>
>
>   osg::Vec3 dx = (v2-v1)/((float)noXSteps-1.0f);
>  &nbs p;osg::Vec3 dy = (v3-v1)/((float)noYSteps-1.0f);
>   unsigned int rowvertices;
>unsigned int colvertices;
> rowvertices=(unsigned
> int)((vertices._v[0])/(dx._v[0]));
>  colvertices=(unsigned
> int)((vertices._v[1])/(dy._v[1]));
>
> unsigned int row;
>& nbsp;   osg::Vec3 vRowStart = v1;
> for(row=0;row osg::Vec3 v = vRowStart;
> for(unsigned int col=0;colif ((row==rowvertices)&&(col==colvertices))
>
> coords->push_back(v+osg::Vec3(0.0f,0.0f,-1.0f));
> else
>   coords->push_back(v);
>  v += dx;
>  }
>vRowStart+=dy;
> }
>
>  geom->setVertexArray(coords);
>   }
>
>  }
>osg::Vec3 v1;
>osg::Vec3 v2;
>osg::Vec3 v3;
> osg::BoundingSphere bs;
> osg::BoundingBox bb;
>  };
>
> 
> "七件武器,七种完美" 立刻体验!
> ___
>  osg-users mailing list
>  osg-users@lists.openscenegraph.org
>  http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org