First of all you should separate the ISceneManager::drawAll() function in two:
1) ISceneManager::update( float fDeltaTime );
2) ISceneManager::drawAll();
as below:
Code: Select all
void CSceneManager::update()
{
// reset attributes
Parameters.setAttribute ( "culled", 0 );
Parameters.setAttribute ( "calls", 0 );
Parameters.setAttribute ( "drawn", 0 );
// reset all transforms
video::IVideoDriver* driver = getVideoDriver();
if ( driver )
{
core::matrix4 identity;
driver->setTransform ( video::ETS_PROJECTION, identity );
driver->setTransform ( video::ETS_VIEW, identity );
driver->setTransform ( video::ETS_WORLD, identity );
driver->setTransform ( video::ETS_TEXTURE_0, identity );
driver->setTransform ( video::ETS_TEXTURE_1, identity );
driver->setTransform ( video::ETS_TEXTURE_2, identity );
driver->setTransform ( video::ETS_TEXTURE_3, identity );
}
u32 currentTime = os::Timer::getTime();
/*
char string[1024];
sprintf( string, "current time: %d\n", currentTime );
appendToDebugLog( DS_IRRLICHT_DEBUG_CHANNEL, string );
//*/
// do animations and other stuff.
OnAnimate( currentTime );
/*!
First Scene Node for prerendering should be the active camera
consistent Camera is needed for culling
*/
camWorldPos.set(0,0,0);
if ( ActiveCamera )
{
ActiveCamera->OnRegisterSceneNode();
camWorldPos = ActiveCamera->getAbsolutePosition();
}
// let all nodes register themselves
OnRegisterSceneNode();
u32 i; // new ISO for scoping problem in some compilers
//render camera scenes
{
CurrentRendertime = ESNRP_CAMERA;
for (i=0; i<CameraList.size(); ++i)
CameraList[i]->render();
CameraList.set_used(0);
}
}
Code: Select all
void CSceneManager::drawAll()
{
if (!Driver)
return;
u32 i; // new ISO for scoping problem in some compilers
//render lights scenes
{
CurrentRendertime = ESNRP_LIGHT;
Driver->deleteAllDynamicLights();
Driver->setAmbientLight(AmbientLight);
LightList.sort (); // on distance to camera
u32 maxLights = core::min_ ( Driver->getMaximalDynamicLightAmount (), LightList.size () );
for (i=0; i< maxLights; ++i)
LightList[i].node->render();
LightList.set_used(0);
}
// render skyboxes
{
CurrentRendertime = ESNRP_SKY_BOX;
for (i=0; i<SkyBoxList.size(); ++i)
SkyBoxList[i]->render();
SkyBoxList.set_used(0);
}
// render default objects
{
CurrentRendertime = ESNRP_SOLID;
SolidNodeList.sort(); // sort by textures
for (i=0; i<SolidNodeList.size(); ++i)
SolidNodeList[i].node->render();
Parameters.setAttribute ( "drawn", (s32) SolidNodeList.size () );
SolidNodeList.set_used(0);
}
// render shadows
{
CurrentRendertime = ESNRP_SHADOW;
for (i=0; i<ShadowNodeList.size(); ++i)
ShadowNodeList[i]->render();
if (!ShadowNodeList.empty())
Driver->drawStencilShadow(true,ShadowColor, ShadowColor,
ShadowColor, ShadowColor);
ShadowNodeList.set_used(0);
}
// render transparent objects.
{
CurrentRendertime = ESNRP_TRANSPARENT;
TransparentNodeList.sort(); // sort by distance from camera
for (i=0; i<TransparentNodeList.size(); ++i)
TransparentNodeList[i].node->render();
TransparentNodeList.set_used(0);
}
// render shader objects.
{
for ( u32 g = 0; g!= ESNRP_SHADER_10 - ESNRP_SHADER_0 + 1; ++g )
{
CurrentRendertime = (scene::E_SCENE_NODE_RENDER_PASS) (ESNRP_SHADER_0 + g);
const u32 size = ShaderNodeList[g].size ();
if ( 0 == size )
continue;
ShaderNodeList[g].sort(); // sort by textures
for (i=0; i< size; ++i)
ShaderNodeList[g][i].node->render();
ShaderNodeList[g].set_used(0);
}
}
clearDeletionList();
CurrentRendertime = ESNRP_COUNT;
}
if you make a
Code: Select all
bool m_bPaused;
Code: Select all
inline void setPause( bool bPause ){ m_bPaused = bPause; }
Code: Select all
m_bPaused = false;
Code: Select all
if( m_bPaused ) return;
About fDeltaTime ... it is the difference between 2 frames. It will also help with lerp motion. For example if I want to move a scene node from point a to point b but using smooth motion, I can use the function
Code: Select all
vector3df LerpValue( vector3df& current_point, vector3df& target_point, float fFactor )
{
if( factor >= 1.0f )
return target_point;
return current_point * ( 1.0f - fFactor ) + target_point * fFactor );
}
Code: Select all
void move( vector3df to_pos ){ m_targetPos = to_pos;}
Code: Select all
m_pos = LerpValue( m_pos, m_targetPos, fDeltaTime * fSpeed );
SetPosition( m_pos );/* m_pos is the current position*/
That's all for now If you think that my ideeas are good I will continue.