Only updateAbsolutePosition if transformation changed

This commit is contained in:
Benau 2022-06-25 11:54:06 +08:00
parent e599a7fff8
commit f63ce6917b

View File

@ -47,7 +47,8 @@ namespace scene
: RelativeTranslation(position), RelativeRotation(rotation), RelativeScale(scale), : RelativeTranslation(position), RelativeRotation(rotation), RelativeScale(scale),
Parent(0), SceneManager(mgr), TriangleSelector(0), ID(id), Parent(0), SceneManager(mgr), TriangleSelector(0), ID(id),
AutomaticCullingState(EAC_BOX), DebugDataVisible(EDS_OFF), AutomaticCullingState(EAC_BOX), DebugDataVisible(EDS_OFF),
IsVisible(true), IsDebugObject(false) IsVisible(true), IsDebugObject(false),
NeedsUpdateAbsTrans(true), UpdatedAbsTrans(false)
{ {
if (parent) if (parent)
parent->addChild(this); parent->addChild(this);
@ -473,7 +474,10 @@ namespace scene
/** \param scale New scale of the node, relative to its parent. */ /** \param scale New scale of the node, relative to its parent. */
virtual void setScale(const core::vector3df& scale) virtual void setScale(const core::vector3df& scale)
{ {
if (RelativeScale == scale)
return;
RelativeScale = scale; RelativeScale = scale;
NeedsUpdateAbsTrans = true;
} }
@ -493,7 +497,10 @@ namespace scene
\param rotation New rotation of the node in degrees. */ \param rotation New rotation of the node in degrees. */
virtual void setRotation(const core::vector3df& rotation) virtual void setRotation(const core::vector3df& rotation)
{ {
if (RelativeRotation == rotation)
return;
RelativeRotation = rotation; RelativeRotation = rotation;
NeedsUpdateAbsTrans = true;
} }
@ -512,7 +519,10 @@ namespace scene
\param newpos New relative position of the scene node. */ \param newpos New relative position of the scene node. */
virtual void setPosition(const core::vector3df& newpos) virtual void setPosition(const core::vector3df& newpos)
{ {
if (RelativeTranslation == newpos)
return;
RelativeTranslation = newpos; RelativeTranslation = newpos;
NeedsUpdateAbsTrans = true;
} }
@ -663,15 +673,27 @@ namespace scene
hierarchy you might want to update the parents first.*/ hierarchy you might want to update the parents first.*/
virtual void updateAbsolutePosition() virtual void updateAbsolutePosition()
{ {
bool updated_trans = false;
if (Parent) if (Parent)
{
if (Parent->UpdatedAbsTrans || NeedsUpdateAbsTrans)
{ {
AbsoluteTransformation = AbsoluteTransformation =
Parent->getAbsoluteTransformation() * getRelativeTransformation(); Parent->getAbsoluteTransformation() * getRelativeTransformation();
updated_trans = true;
}
} }
else else
{
if (NeedsUpdateAbsTrans)
{
AbsoluteTransformation = getRelativeTransformation(); AbsoluteTransformation = getRelativeTransformation();
updated_trans = true;
}
}
UpdatedAbsTrans = updated_trans;
NeedsUpdateAbsTrans = false;
} }
//! Returns the parent of this scene node //! Returns the parent of this scene node
/** \return A pointer to the parent. */ /** \return A pointer to the parent. */
@ -759,6 +781,12 @@ namespace scene
/** \return The node's scene manager. */ /** \return The node's scene manager. */
virtual ISceneManager* getSceneManager(void) const { return SceneManager; } virtual ISceneManager* getSceneManager(void) const { return SceneManager; }
//! STK addition to optimize updateAbsolutePosition, only do that if changed transformation.
bool getNeedsUpdateAbsTrans() const { return NeedsUpdateAbsTrans; }
bool getUpdatedAbsTrans() const { return UpdatedAbsTrans; }
void setNeedsUpdateAbsTrans(bool val) { NeedsUpdateAbsTrans = val; }
void setUpdatedAbsTrans(bool val) { UpdatedAbsTrans = val; }
protected: protected:
//! A clone function for the ISceneNode members. //! A clone function for the ISceneNode members.
@ -779,6 +807,8 @@ namespace scene
DebugDataVisible = toCopyFrom->DebugDataVisible; DebugDataVisible = toCopyFrom->DebugDataVisible;
IsVisible = toCopyFrom->IsVisible; IsVisible = toCopyFrom->IsVisible;
IsDebugObject = toCopyFrom->IsDebugObject; IsDebugObject = toCopyFrom->IsDebugObject;
NeedsUpdateAbsTrans = true;
UpdatedAbsTrans = false;
if (newManager) if (newManager)
SceneManager = newManager; SceneManager = newManager;
@ -858,6 +888,8 @@ namespace scene
//! Is debug object? //! Is debug object?
bool IsDebugObject; bool IsDebugObject;
bool NeedsUpdateAbsTrans, UpdatedAbsTrans;
}; };