Forced LOD=0 when a kart finishes a race, this way end animations

are shown even when the end camera is far away from the kart.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@12078 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2012-11-25 22:24:54 +00:00
parent 0f6757be65
commit 604f61d1b4
5 changed files with 38 additions and 1 deletions

View File

@ -33,7 +33,7 @@
*/
LODNode::LODNode(std::string group_name, scene::ISceneNode* parent,
scene::ISceneManager* mgr, s32 id)
: ISceneNode(parent, mgr, id) //: IDummyTransformationSceneNode(parent, mgr, id)
: ISceneNode(parent, mgr, id)
{
assert(mgr != NULL);
assert(parent != NULL);
@ -47,6 +47,8 @@ LODNode::LODNode(std::string group_name, scene::ISceneNode* parent,
// so that only the reference from the parent is active, causing this
// node to be deleted when it is removed from the parent.
drop();
m_forced_lod = -1;
}
LODNode::~LODNode()
@ -63,6 +65,10 @@ void LODNode::render()
*/
int LODNode::getLevel()
{
// If a level is forced, use it
if(m_forced_lod>-1)
return m_forced_lod;
// TODO: optimize this, there is no need to check every frame
scene::ICameraSceneNode* curr_cam = irr_driver->getSceneManager()->getActiveCamera();
@ -78,7 +84,16 @@ int LODNode::getLevel()
return -1;
} // getLevel
// ---------------------------------------------------------------------------
/** Forces the level of detail to be n. If n>number of levels, the most
* detailed level is used. This is used to disable LOD when the end
* camera is activated, since it zooms in to the kart. */
void LODNode::forceLevelOfDetail(int n)
{
m_forced_lod = (n >=(int)m_detail.size()) ? m_detail.size()-1 : n;
} // forceLevelOfDetail
// ----------------------------------------------------------------------------
void LODNode::OnAnimate(u32 timeMs)
{
if (isVisible())

View File

@ -57,6 +57,10 @@ private:
std::string m_group_name;
/** The normal level of detail can be overwritten. If
* m_forced_lod is >=0, only this level is be used. */
int m_forced_lod;
int getLevel();
enum PreviousVisibility
@ -95,6 +99,8 @@ public:
*/
void add(int level, scene::ISceneNode* node, bool reparent);
void forceLevelOfDetail(int n);
/** Get the highest level of detail node */
scene::ISceneNode* getFirstNode()
{
@ -139,6 +145,7 @@ public:
m_nodes[n]->setScale(scale);
}
}
};
#endif

View File

@ -769,6 +769,7 @@ void Kart::finishedRace(float time)
m_finished_race = true;
m_finish_time = time;
m_controller->finishedRace(time);
m_kart_model->finishedRace();
race_manager->kartFinishedRace(this, time);
if (race_manager->getMinorMode() == RaceManager::MINOR_MODE_NORMAL_RACE ||

View File

@ -417,8 +417,21 @@ void KartModel::reset()
// Stop any animations currently being played.
setAnimation(KartModel::AF_DEFAULT);
// Don't force any LOD
((LODNode*)m_kart->getNode())->forceLevelOfDetail(-1);
} // reset
// ----------------------------------------------------------------------------
/** Called when the kart finished the race. It will force the highest LOD
* for the kart, since otherwise the end camera can be far away (due to
* zooming) and show non-animated karts.
*/
void KartModel::finishedRace()
{
// Force the animated model, independent of actual camera distance.
((LODNode*)m_kart->getNode())->forceLevelOfDetail(0);
} // finishedRace
// ----------------------------------------------------------------------------
/** Enables- or disables the end animation.
* \param type The type of animation to play.

View File

@ -148,6 +148,7 @@ public:
const float suspension[4]);
void setDefaultPhysicsPosition(const Vec3 &center_shift,
float wheel_radius);
void finishedRace();
scene::ISceneNode*
attachModel(bool animatedModels);
// ------------------------------------------------------------------------