doLightRecalc() need improve for spot and direct light
Posted: Mon Feb 16, 2015 11:59 am
ref. https://gist.github.com/patriciogonzale ... a542aabc63
//outer code here
camera = smgr->addCameraSceneNodeFPS(0, 100.0f, .02f, 0, 0, 0, true, 1.0f);
camera->setPosition(core::vector3df(0,0,110));
camera->setTarget(core::vector3df(0,0,110.5));
.
.
.
scnode = smgr->addLightSceneNode(0, core::vector3df(0,5,120), video::SColorf(1.0f, 1.0f, 1.0f, 1.0f), 100.0f, -1);
scnode->setRotation(core::vector3df(0,0,5));
.
.
.
spotLightData = scnode->getLightData();
spotLightData.Type = video::ELT_SPOT;
spotLightData.Direction = core::vector3df(0,0.2,1);
spotLightData.Falloff = 60.0f;
spotLightData.OuterCone = 20;
scnode->setLightData(spotLightData);
.
.
.
node = smgr->addAnimatedMeshSceneNode( mesh );
node->setPosition(core::vector3df(0,0,140));
/////
///////inner code here
/////////////void CLightSceneNode::doLightRecalc()
if ((LightData.Type == video::ELT_SPOT) || (LightData.Type == video::ELT_DIRECTIONAL))
{
LightData.Direction = core::vector3df(.0f,.0f,1.0f);
getAbsoluteTransformation().rotateVect(LightData.Direction);
LightData.Direction.normalize();
}
/////////Spot light test
//if do the 3 code lines then spotLightData.Direction = core::vector3df(0,0.2,1); setting is non useful
// light direction non use
LightData.Direction = core::vector3df(.0f,.0f,1.0f);
getAbsoluteTransformation().rotateVect(LightData.Direction);
LightData.Direction.normalize();
////
//if mark this one line
//LightData.Direction = core::vector3df(.0f,.0f,1.0f);
getAbsoluteTransformation().rotateVect(LightData.Direction);
LightData.Direction.normalize(); //then spot light on the mesh node will turn and turn again, never stop
//scnode->setRotation(core::vector3df(0,0,z)); //the z bigger the turn more faster
////////
the correct spot light need mark, test in OGLES1 OGLES2 all the same result~
//LightData.Direction = core::vector3df(.0f,.0f,1.0f);
//getAbsoluteTransformation().rotateVect(LightData.Direction);
and need do once only
getAbsoluteTransformation().rotateVect(LightData.Direction);
//outer code here
camera = smgr->addCameraSceneNodeFPS(0, 100.0f, .02f, 0, 0, 0, true, 1.0f);
camera->setPosition(core::vector3df(0,0,110));
camera->setTarget(core::vector3df(0,0,110.5));
.
.
.
scnode = smgr->addLightSceneNode(0, core::vector3df(0,5,120), video::SColorf(1.0f, 1.0f, 1.0f, 1.0f), 100.0f, -1);
scnode->setRotation(core::vector3df(0,0,5));
.
.
.
spotLightData = scnode->getLightData();
spotLightData.Type = video::ELT_SPOT;
spotLightData.Direction = core::vector3df(0,0.2,1);
spotLightData.Falloff = 60.0f;
spotLightData.OuterCone = 20;
scnode->setLightData(spotLightData);
.
.
.
node = smgr->addAnimatedMeshSceneNode( mesh );
node->setPosition(core::vector3df(0,0,140));
/////
///////inner code here
/////////////void CLightSceneNode::doLightRecalc()
if ((LightData.Type == video::ELT_SPOT) || (LightData.Type == video::ELT_DIRECTIONAL))
{
LightData.Direction = core::vector3df(.0f,.0f,1.0f);
getAbsoluteTransformation().rotateVect(LightData.Direction);
LightData.Direction.normalize();
}
/////////Spot light test
//if do the 3 code lines then spotLightData.Direction = core::vector3df(0,0.2,1); setting is non useful
// light direction non use
LightData.Direction = core::vector3df(.0f,.0f,1.0f);
getAbsoluteTransformation().rotateVect(LightData.Direction);
LightData.Direction.normalize();
////
//if mark this one line
//LightData.Direction = core::vector3df(.0f,.0f,1.0f);
getAbsoluteTransformation().rotateVect(LightData.Direction);
LightData.Direction.normalize(); //then spot light on the mesh node will turn and turn again, never stop
//scnode->setRotation(core::vector3df(0,0,z)); //the z bigger the turn more faster
////////
the correct spot light need mark, test in OGLES1 OGLES2 all the same result~
//LightData.Direction = core::vector3df(.0f,.0f,1.0f);
//getAbsoluteTransformation().rotateVect(LightData.Direction);
and need do once only
getAbsoluteTransformation().rotateVect(LightData.Direction);