|
栈溢出
模仿王锐老师编的《OSG三维渲染引擎设计与实践》第5章中的例子“跃动的线”想实现“构成曲线的点逐个显示”这个过程。更新回调类代码如下:
class DynamicCurveCallback:public osg:rawable::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, -50.0},{80.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) //当t=1时,更新回调结束
{
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 += a[k]*b[k][j];
ab[k] = 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+=ab[k]*c[k][j];
d[j]=temp;
}
osg::Vec3&pt=vertices->back();
pt.set(d[0][0], 0.0, d[0][1]);
vertices->dirty();
}
t += 1.0/40.0;
}
}
}
protected:
float t;
};
程序编译时没有错误,但是debug时,提示变量 ab“栈溢出” ,请问这是什么原因呢? |
|