|
|
@@ -17,6 +17,7 @@ Actor::Actor(Game* game)
|
|
|
,mScale(1.0f)
|
|
|
,mRotation(0.0f)
|
|
|
,mGame(game)
|
|
|
+ ,mRecomputeWorldTransform(false)
|
|
|
{
|
|
|
mGame->AddActor(this);
|
|
|
}
|
|
|
@@ -36,8 +37,12 @@ void Actor::Update(float deltaTime)
|
|
|
{
|
|
|
if (mState == EActive)
|
|
|
{
|
|
|
+ ComputeWorldTransform();
|
|
|
+
|
|
|
UpdateComponents(deltaTime);
|
|
|
UpdateActor(deltaTime);
|
|
|
+
|
|
|
+ ComputeWorldTransform();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -73,9 +78,20 @@ void Actor::ActorInput(const uint8_t* keyState)
|
|
|
|
|
|
void Actor::ComputeWorldTransform()
|
|
|
{
|
|
|
- mWorldTransform = Matrix4::CreateScale(mScale);
|
|
|
- mWorldTransform *= Matrix4::CreateRotationZ(mRotation);
|
|
|
- mWorldTransform *= Matrix4::CreateTranslation(Vector3(mPosition.x, mPosition.y, 0.0f));
|
|
|
+ if (mRecomputeWorldTransform)
|
|
|
+ {
|
|
|
+ mRecomputeWorldTransform = false;
|
|
|
+ // Scale, then rotate, then translate
|
|
|
+ mWorldTransform = Matrix4::CreateScale(mScale);
|
|
|
+ mWorldTransform *= Matrix4::CreateRotationZ(mRotation);
|
|
|
+ mWorldTransform *= Matrix4::CreateTranslation(Vector3(mPosition.x, mPosition.y, 0.0f));
|
|
|
+
|
|
|
+ // Inform components world transform updated
|
|
|
+ for (auto comp : mComponents)
|
|
|
+ {
|
|
|
+ comp->OnUpdateWorldTransform();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void Actor::AddComponent(Component* component)
|