Explorar o código

Apply world transform to vertices.

aster2013 %!s(int64=11) %!d(string=hai) anos
pai
achega
1d3329c4aa

+ 9 - 2
Source/Engine/Urho2D/Drawable2D.cpp

@@ -90,7 +90,7 @@ void Drawable2D::UpdateBatches(const FrameInfo& frame)
     distance_ = frame.camera_->GetDistance(GetWorldBoundingBox().Center());
 
     batches_[0].distance_ = distance_;
-    batches_[0].worldTransform_ = &worldTransform;
+    batches_[0].worldTransform_ = &Matrix3x4::IDENTITY;
 }
 
 void Drawable2D::UpdateGeometry(const FrameInfo& frame)
@@ -290,6 +290,13 @@ void Drawable2D::OnNodeSet(Node* node)
     }
 }
 
+void Drawable2D::OnMarkedDirty(Node* node)
+{
+    Drawable::OnMarkedDirty(node);
+
+    verticesDirty_ = true;
+}
+
 void Drawable2D::OnWorldBoundingBoxUpdate()
 {
     if (verticesDirty_)
@@ -301,7 +308,7 @@ void Drawable2D::OnWorldBoundingBoxUpdate()
             boundingBox_.Merge(vertices_[i].position_);
     }
 
-    worldBoundingBox_ = boundingBox_.Transformed(node_->GetWorldTransform());
+    worldBoundingBox_ = boundingBox_;
 }
 
 void Drawable2D::UpdateMaterial()

+ 2 - 0
Source/Engine/Urho2D/Drawable2D.h

@@ -102,6 +102,8 @@ public:
 protected:
     /// Handle node being assigned.
     virtual void OnNodeSet(Node* node);
+    /// Handle node transform being dirtied.
+    virtual void OnMarkedDirty(Node* node);
     /// Recalculate the world-space bounding box.
     virtual void OnWorldBoundingBoxUpdate();
     /// Update vertices.

+ 7 - 4
Source/Engine/Urho2D/StaticSprite2D.cpp

@@ -128,10 +128,13 @@ void StaticSprite2D::UpdateVertices()
     float rightX = width * (1.0f - hotSpotX);
     float bottomY = -height * hotSpotY;
     float topY = height * (1.0f - hotSpotY);
-    vertex0.position_ = Vector3(leftX, bottomY, 0.0f);
-    vertex1.position_ = Vector3(leftX, topY, 0.0f);
-    vertex2.position_ = Vector3(rightX, topY, 0.0f);
-    vertex3.position_ = Vector3(rightX, bottomY, 0.0f);
+
+    const Matrix3x4& worldTransform = node_->GetWorldTransform();
+
+    vertex0.position_ = worldTransform * Vector3(leftX, bottomY, 0.0f);
+    vertex1.position_ = worldTransform * Vector3(leftX, topY, 0.0f);
+    vertex2.position_ = worldTransform * Vector3(rightX, topY, 0.0f);
+    vertex3.position_ = worldTransform * Vector3(rightX, bottomY, 0.0f);
 
     float invTexW = 1.0f / (float)texture->GetWidth();
     float invTexH = 1.0f / (float)texture->GetHeight();