|
楼主 |
发表于 2008-4-8 19:59:45
|
显示全部楼层
原帖由 array 于 2008-4-8 18:32 发表
呵呵,用LightSource的做法肯定是正确地,至于为什么不能setPosition~~能否再提供一些代码参考呢?
添加光源的代码是: lightnum=0;
osg::ref_ptr<osg:ight> light=new osg::Light;
light->setLightNum(lightnum);
light->setPosition(osg::Vec4(0.f,0.f,0.f,1.f));
light->setDirection(osg::Vec3(1.f,0.f,0.f));
light->setSpotCutoff(25.f);
osg::ref_ptr<osg::LightSource> ls=new osg::LightSource;
ls->setDataVariance(osg::Object:YNAMIC);
ls->setUpdateCallback(new lightCB);
ls->setLight(light.get());
mRoot->addChild(ls.get());
lightnum++;
更新回调:
void lightCB:perator()(osg::Node* node,osg::NodeVisitor* nv)
{
CMainFrame *pFrame = (CMainFrame *)AfxGetApp()->m_pMainWnd;
osg::LightSource * ls=dynamic_cast<osg::LightSource *>(node);
osg::Light * lt=ls->getLight();
lt->setAmbient(osg::Vec4((float)GetRValue(ambient)/255.0f,(float)GetGValue(ambient)/255.0f,(float)GetBValue(ambient)/255.0f,0.f));
lt->setSpecular(osg::Vec4((float)GetRValue(specular)/255.0f,(float)GetGValue(specular)/255.0f,(float)GetBValue(specular)/255.0f,0.f));
lt->setDiffuse(osg::Vec4((float)GetRValue(diffuse)/255.0f,(float)GetGValue(diffuse)/255.0f,(float)GetBValue(diffuse)/255.0f,0.f));
lt->setPosition(osg::Vec4(m_lpxing,m_lpying,m_lpzing,1.f));
lt->setDirection(osg::Vec3(m_ldxing,m_ldying,m_ldzing));
lt->setSpotCutoff(m_raing);
lt->setSpotExponent(m_dring) ;
//外部传入的参数 问题是外部参数发生改变了,但是光源的属性没有发生变化
ambient=pFrame->ambientm;
specular=pFrame->specularm;
diffuse=pFrame->diffusem;
m_ldaxing=pFrame->m_ldaxingm;
m_ldaying=pFrame->m_ldayingm;
m_ldazing=pFrame->m_ldazingm;
m_ldxing=pFrame->m_ldxingm;
m_ldying=pFrame->m_ldyingm;
m_ldzing=pFrame->m_ldzingm;
m_raing=pFrame->m_raingm;
m_dring=pFrame->m_dringm;
m_lpxing=pFrame->m_lpxingm; //位置x
m_lpying=pFrame->m_lpyingm; //位置y
m_lpzing=pFrame->m_lpzingm; //位置z
traverse(node,nv);
} |
|