Hi Jean,
> Are you sure your light source is not just a directional light?
> Directional lights change lighting (and shadows) when their direction
> changes (i.e. rotation) but not when their position changes. It's
> probably not even related to platform.
>
yes i'm sure, also i have to say, I use binaries
(openscenegraph-all-2.8.2-win32-x86-vc80sp1-Release.zip) and visual studio
2008, i don't know if it causes some problems.
how my project is big, i did a simple fast code to show my problem in my
project,
i tested that on linux, the shadow works very well
i tested that on windows xp, the shadow doesn't work
please help me!!, i need that it works on windows
i hope someone tests my code on windows and tell me if works
or tell me if i have to change my code
Thank you!
Cheers,
mauricio
Code:
#include <osg/Node>
#include <osg/Group>
#include <osg/MatrixTransform>
#include <osg/Light>
#include <osgShadow/ShadowedScene>
#include <osgShadow/ShadowMap>
#include <osgShadow/ShadowTexture>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osgGA/TrackballManipulator>
#include <iostream>
#include <cmath>
#include <osg/PositionAttitudeTransform>
#include <string>
#include <osg/Geode>
#include <osg/Image>
#include <osg/StateSet>
#include <osg/MatrixTransform>
#include <osg/PositionAttitudeTransform>
#include <osg/Vec3>
#include <osg/Material>
#include <osg/Shape>
#include <osg/ShapeDrawable>
#include <osg/LightModel>
using namespace std;
osg::MatrixTransform* mt2 ;
void update(double time) {
osg::Matrix mt ;
switch((int)time%4){
case 1:
mt.makeTranslate(1.0, 0.0,3.0);
break;
case 2:
mt.makeTranslate(0.0, 0.0,3.0);
break;
case 3:
mt.makeTranslate(-1.0, 0.0,3.0);
break;
case 4:
mt.makeTranslate(1.0, 1.0,3.0);
break;
default:
mt.makeTranslate(1.0, 1.0,3.0);
break;
}
mt2->setMatrix(mt );
}
int main()
{
osg::ref_ptr<osg::Box> plano(new osg::Box(osg::Vec3(0, 0, 0), 4, 4,.1));
osg::ref_ptr<osg::ShapeDrawable> dibujable(new osg::ShapeDrawable());
dibujable->setShape(plano.get());
osg::ref_ptr<osg::Geode> geonodo1 = new osg::Geode;
geonodo1->addDrawable(dibujable.get());
osg::ref_ptr<osg::Sphere> planos(new osg::Sphere(osg::Vec3(0, 0, 0), .1));
osg::ref_ptr<osg::ShapeDrawable> dibujables(new osg::ShapeDrawable());
dibujables->setShape(planos.get());
osg::ref_ptr<osg::Geode> geonodo2 = new osg::Geode;
geonodo2->addDrawable(dibujables.get());
osg::ref_ptr<osg::Box> planob(new osg::Box(osg::Vec3(0, 0, .5), .5, .5,.5));
osg::ref_ptr<osg::ShapeDrawable> dibujableb(new osg::ShapeDrawable());
dibujableb->setShape(planob.get());
osg::ref_ptr<osg::Geode> geonodo3 = new osg::Geode;
geonodo3->addDrawable(dibujableb.get());
osg::ref_ptr<osg::MatrixTransform> rotacion = new osg::MatrixTransform;
rotacion->addChild(geonodo1.get());
osg::ref_ptr<osg::PositionAttitudeTransform> t_posicion = new
osg::PositionAttitudeTransform;
t_posicion->setPosition(osg::Vec3(0.0, 0.0, 0.0));
t_posicion->addChild(rotacion.get());
osg::Matrix mt ;
mt.makeTranslate(0.0, 0.0,3.0);
mt2 = new osg::MatrixTransform;
mt2->setMatrix(mt );
// Luz
osg::LightSource* fuente_luz = new osg::LightSource;
fuente_luz->addChild(geonodo2.get());
osg::Light* luz = fuente_luz->getLight();
luz->setPosition(osg::Vec4(0, 0, 0, 1)); // 0 -> infinito
luz->setDiffuse(osg::Vec4(1, 1, 1, 1));
luz->setSpecular(osg::Vec4(1, 1, 1, 1));
osg::LightModel* lightModel = new osg::LightModel;
fuente_luz->getOrCreateStateSet()->setAttribute(lightModel);
mt2->addChild(fuente_luz);
// Tecnica para sombrear
//osgShadow::ShadowTexture* tecnica_sombreado = new
osgShadow::ShadowTexture;
osgShadow::ShadowMap* tecnica_sombreado = new osgShadow::ShadowMap;
// Subgrafo de escena para manejar sombras
osgShadow::ShadowedScene* escena_con_sombras = new
osgShadow::ShadowedScene;
escena_con_sombras->setShadowTechnique(tecnica_sombreado);
//escena_con_sombras->addChild(mt);
escena_con_sombras->addChild(t_posicion.get());
escena_con_sombras->addChild(geonodo3.get());
t_posicion->setNodeMask(0x1);
escena_con_sombras->setReceivesShadowTraversalMask(0x1);
geonodo3->setNodeMask(0x2);
escena_con_sombras->setCastsShadowTraversalMask(0x2);
// Grafo de escena
osg::Group* raiz = new osg::Group;
raiz->addChild(mt2);
raiz->addChild(escena_con_sombras);
osgViewer::Viewer visor;
visor.setSceneData(raiz);
visor.setCameraManipulator(new osgGA::TrackballManipulator());
visor.realize();
while (!visor.done()) {
visor.frame();
update(visor.elapsedTime());
}
return visor.run();
}
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=20835#20835
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org