|
使用更新回调函数,绘制下一帧时,上一帧的内容就被擦除了。现在想实现的功能是:绘制下一帧时,上一帧仍然保留,就好像在纸上作画一样,画下一笔,上一笔画的仍然在纸上保留着。
更新回调类代码如下:- class DynamicCurveCallback:public osg::Drawable::UpdateCallback
- {
- public:
- DynamicCurveCallback():t(0.0){} //构造函数初始化
- virtual void update(osg::NodeVisitor *nv, osg::Drawable *drawable)
- {
- osg::Geometry *geom = dynamic_cast<osg::Geometry*>(drawable);
- if(!geom) return;
- osg::Vec3Array *vertices = dynamic_cast<osg::Vec3Array*>(geom->getVertexArray());
- float a[1][3]={{0.0}};
- float b[3][3]={{2.0, -4.0, 2.0},{-3.0, 4.0, -1.0},{1.0, 0.0, 0.0}};
- float c[3][2]={{450.0, 10.0},{280.0, 60.0},{200.0, 110.0}}; // 三点定义一条抛物线
- float ab[1][3]={{0.0}};
- float d[1][2]={{0.0}};
- int i;
- int j;
- int k;
- float temp;
- if(vertices)
- {
- for (osg::Vec3Array::iterator itr = vertices->begin(); itr != vertices->end()-1; ++itr)
- itr->set((*(itr+1)));
- if (t<=1.01)
- {
- a[0][0] = t*t;
- a[0][1] = t;
- a[0][2] = 1;
- //矩阵a与矩阵b相乘运算得到矩阵ab
- for (i = 0; i < 1; i++)
- {
- for (j = 0; j < 3; j++)
- {
- temp=0.0;
- for (k = 0; k < 3; k++)
- {
- temp = temp+a[i][k]*b[k][j];
- }
- ab[i][j] = temp;
- }
- } //矩阵a与矩阵b运算结束
- //矩阵ab与矩阵c相乘得到矩阵d
- for(i = 0; i < 1; i++)
- {
- for (j=0; j<2; j++)
- {
- temp = 0.0;
- for(k=0; k<3; k++)
- {
- temp = temp + ab[i][j]*c[k][j];
- }
- d[i][j]=temp;
- }
- osg::Vec3&pt=vertices->back();
- pt.set(d[0][0], 0.0, d[0][1]);
- vertices->dirty();
- //vertices->push_back();
- }
- t += 1.0/40.0;
- }
- Sleep(100);
- }
- }
- protected:
- float t;
- };
复制代码
求教各位大侠,具体如何修改这个代码从而实现“绘制下一帧时,上一帧仍然保留”的效果呢呢? |
|