[osg-users] Using Light without LightSource in OSG 3.4.0
chenyanlin at fulongtech.cn
chenyanlin at fulongtech.cn
Tue Aug 21 20:27:46 PDT 2018
Hi,
I want to add light to my scene and I want the different light which have same Number can be used at the same time.Thus , I use light as a Attribute to set it to stateset. There is no problem when the model is not rotate.But when model is rotated, the light seemed rotated by the matrix.There is my source code:
int main()
{
osg::ref_ptr<osg::Group> root = new osg::Group;
osg::ref_ptr<osg::Light> light = new osg::Light;
light->setLightNum(0);
light->setPosition(osg::Vec4(0, 0, 1, 0));
light->setAmbient(osg::Vec4(0,0, 0, 1));
light->setDiffuse(osg::Vec4(0, 1, 0, 1));
light->setSpecular(osg::Vec4(1, 0, 0, 1));
auto stateSet = root->getOrCreateStateSet();
stateSet->setAttributeAndModes(light);
osg::ref_ptr<osg::TessellationHints> hints = new osg::TessellationHints;
hints->setDetailRatio(0.1);
osg::ref_ptr<osg::Geode> geode1 = new osg::Geode;
osg::ref_ptr<osg::ShapeDrawable> shape1 = new osg::ShapeDrawable(new osg::Box(osg::Vec3(0, 0, 0), 10, 10,10), hints.get());
geode1->addDrawable(shape1);
osg::ref_ptr<osg::Geode> geode2 = new osg::Geode;
osg::ref_ptr<osg::ShapeDrawable> shape2 = new osg::ShapeDrawable(new osg::Box(osg::Vec3(20, 20, 20), 10, 10, 10), hints.get());
geode2->addDrawable(shape2);
osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform;
osg::Matrix mat;
mat = mat.rotate(180, osg::Vec3(0, 1, 0));
mt->setMatrix(mat);
mt->addChild(geode2);
root->addChild(mt);
root->addChild(geode1);
osgViewer::Viewer myViewer;
myViewer.setSceneData(root);
myViewer.run();
return 0;
}
So,is it the light can be used without LightSource?
Thank you!
Chenyanlin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20180822/a941e238/attachment-0001.html>
More information about the osg-users
mailing list