|
|
@@ -53,14 +53,8 @@ void TileMapLayer2D::RegisterObject(Context* context)
|
|
|
context->RegisterFactory<TileMapLayer2D>();
|
|
|
}
|
|
|
|
|
|
-// Transform vector from tiled isometric space to Urho3d node-local space
|
|
|
-static Vector2 TransformIsometricVector(Vector2 vec)
|
|
|
-{
|
|
|
- return Vector2(vec.x_ - vec.y_, - (vec.x_ + vec.y_) / 2);
|
|
|
-}
|
|
|
-
|
|
|
// Transform vector from node-local space to global space
|
|
|
-Vector2 TransformNode2D(Matrix3x4 transform, Vector2 local)
|
|
|
+static Vector2 TransformNode2D(Matrix3x4 transform, Vector2 local)
|
|
|
{
|
|
|
Vector3 transformed = transform * Vector4(local.x_, local.y_, 0.f, 1.f);
|
|
|
return Vector2(transformed.x_, transformed.y_);
|
|
|
@@ -78,80 +72,77 @@ void TileMapLayer2D::DrawDebugGeometry(DebugRenderer* debug, bool depthTest)
|
|
|
{
|
|
|
TileMapObject2D* object = objectGroup_->GetObject(i);
|
|
|
const Color& color = Color::YELLOW;
|
|
|
+ const Vector2& size = object->GetSize();
|
|
|
+ const TileMapInfo2D& info = tileMap_->GetInfo();
|
|
|
+
|
|
|
|
|
|
switch (object->GetObjectType())
|
|
|
{
|
|
|
case OT_RECTANGLE:
|
|
|
{
|
|
|
- switch (GetTileMap()->GetInfo().orientation_)
|
|
|
+ Vector<Vector2> points;
|
|
|
+
|
|
|
+ switch (info.orientation_)
|
|
|
{
|
|
|
case O_ORTHOGONAL:
|
|
|
case O_HEXAGONAL:
|
|
|
case O_STAGGERED:
|
|
|
{
|
|
|
- const Vector2& lb = object->GetPosition();
|
|
|
- const Vector2& rt = lb + object->GetSize();
|
|
|
- debug->AddLine(TransformNode2D(transform, Vector2(lb.x_, lb.y_)), TransformNode2D(transform, Vector2(rt.x_, lb.y_)), color, depthTest);
|
|
|
- debug->AddLine(TransformNode2D(transform, Vector2(rt.x_, lb.y_)), TransformNode2D(transform, Vector2(rt.x_, rt.y_)), color, depthTest);
|
|
|
- debug->AddLine(TransformNode2D(transform, Vector2(rt.x_, rt.y_)), TransformNode2D(transform, Vector2(lb.x_, rt.y_)), color, depthTest);
|
|
|
- debug->AddLine(TransformNode2D(transform, Vector2(lb.x_, rt.y_)), TransformNode2D(transform, Vector2(lb.x_, lb.y_)), color, depthTest);
|
|
|
+ points.Push(Vector2::ZERO);
|
|
|
+ points.Push(Vector2(size.x_, 0.0f));
|
|
|
+ points.Push(Vector2(size.x_, -size.y_));
|
|
|
+ points.Push(Vector2(0.0f, -size.y_));
|
|
|
break;
|
|
|
}
|
|
|
case O_ISOMETRIC:
|
|
|
{
|
|
|
- const Vector2& size = object->GetSize();
|
|
|
- const Vector2 lt = object->GetPosition();
|
|
|
- const Vector2 lb = lt - TransformIsometricVector(Vector2(0, size.y_));
|
|
|
- const Vector2 rb = lb + TransformIsometricVector(Vector2(size.x_, 0));
|
|
|
- const Vector2 rt = lb + TransformIsometricVector(Vector2(size.x_, size.y_));
|
|
|
- debug->AddLine(TransformNode2D(transform, lt), TransformNode2D(transform, lb), color, depthTest);
|
|
|
- debug->AddLine(TransformNode2D(transform, lb), TransformNode2D(transform, rb), color, depthTest);
|
|
|
- debug->AddLine(TransformNode2D(transform, rb), TransformNode2D(transform, rt), color, depthTest);
|
|
|
- debug->AddLine(TransformNode2D(transform, rt), TransformNode2D(transform, lt), color, depthTest);
|
|
|
+ float ratio = (info.tileWidth_ / info.tileHeight_) * 0.5f;
|
|
|
+ points.Push(Vector2::ZERO);
|
|
|
+ points.Push(Vector2(size.y_ * ratio, size.y_ * 0.5f));
|
|
|
+ points.Push(Vector2((size.x_ + size.y_) * ratio, (-size.x_ + size.y_) * 0.5f));
|
|
|
+ points.Push(Vector2(size.x_ * ratio, -size.x_ * 0.5f));
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ for (unsigned j = 0; j < points.Size(); ++j)
|
|
|
+ debug->AddLine(TransformNode2D(transform, points[j] + object->GetPosition()),
|
|
|
+ TransformNode2D(transform, points[(j + 1) % points.Size()] + object->GetPosition()), color, depthTest);
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case OT_ELLIPSE:
|
|
|
{
|
|
|
- switch (GetTileMap()->GetInfo().orientation_)
|
|
|
+ const Vector2 halfSize = object->GetSize() * 0.5f;
|
|
|
+ float ratio = (info.tileWidth_ / info.tileHeight_) * 0.5f; // For isometric only
|
|
|
+
|
|
|
+ Vector2 pivot = object->GetPosition();
|
|
|
+ if (info.orientation_ == O_ISOMETRIC)
|
|
|
{
|
|
|
- case O_ORTHOGONAL:
|
|
|
- case O_HEXAGONAL:
|
|
|
- case O_STAGGERED:
|
|
|
- {
|
|
|
- const Vector2 halfSize = object->GetSize() * 0.5f;
|
|
|
- const Vector2 center = object->GetPosition() + halfSize;
|
|
|
- for (unsigned i = 0; i < 360; i += 30)
|
|
|
- {
|
|
|
- unsigned j = i + 30;
|
|
|
- float x1 = halfSize.x_ * Cos((float)i);
|
|
|
- float y1 = halfSize.y_ * Sin((float)i);
|
|
|
- float x2 = halfSize.x_ * Cos((float)j);
|
|
|
- float y2 = halfSize.y_ * Sin((float)j);
|
|
|
- debug->AddLine(TransformNode2D(transform, center + Vector2(x1, y1)),
|
|
|
- TransformNode2D(transform, center + Vector2(x2, y2)), color, depthTest);
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- case O_ISOMETRIC:
|
|
|
+ pivot += Vector2((halfSize.x_ + halfSize.y_) * ratio, (-halfSize.x_ + halfSize.y_) * 0.5f);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ pivot += halfSize;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (unsigned i = 0; i < 360; i += 30)
|
|
|
+ {
|
|
|
+ unsigned j = i + 30;
|
|
|
+ float x1 = halfSize.x_ * Cos((float)i);
|
|
|
+ float y1 = halfSize.y_ * Sin((float)i);
|
|
|
+ float x2 = halfSize.x_ * Cos((float)j);
|
|
|
+ float y2 = halfSize.y_ * Sin((float)j);
|
|
|
+ Vector2 point1 = Vector2(x1, - y1);
|
|
|
+ Vector2 point2 = Vector2(x2, - y2);
|
|
|
+
|
|
|
+ if (info.orientation_ == O_ISOMETRIC)
|
|
|
{
|
|
|
- const Vector2 halfSize = object->GetSize() * 0.5f;
|
|
|
- const Vector2 center = object->GetPosition() + TransformIsometricVector(Vector2(halfSize.x_, -halfSize.y_));
|
|
|
- for (unsigned i = 0; i < 360; i += 30)
|
|
|
- {
|
|
|
- unsigned j = i + 30;
|
|
|
- float x1 = halfSize.x_ * Cos((float)i);
|
|
|
- float y1 = halfSize.y_ * Sin((float)i);
|
|
|
- float x2 = halfSize.x_ * Cos((float)j);
|
|
|
- float y2 = halfSize.y_ * Sin((float)j);
|
|
|
- debug->AddLine(TransformNode2D(transform, center + TransformIsometricVector(Vector2(x1, y1))),
|
|
|
- TransformNode2D(transform, center + TransformIsometricVector(Vector2(x2, y2))), color, depthTest);
|
|
|
- }
|
|
|
- break;
|
|
|
+ point1 = Vector2((point1.x_ + point1.y_) * ratio, (point1.y_ - point1.x_) * 0.5f);
|
|
|
+ point2 = Vector2((point2.x_ + point2.y_) * ratio, (point2.y_ - point2.x_) * 0.5f);
|
|
|
}
|
|
|
+
|
|
|
+ debug->AddLine(TransformNode2D(transform, pivot + point1), TransformNode2D(transform, pivot + point2), color, depthTest);
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
@@ -166,6 +157,9 @@ void TileMapLayer2D::DrawDebugGeometry(DebugRenderer* debug, bool depthTest)
|
|
|
if (object->GetObjectType() == OT_POLYGON)
|
|
|
debug->AddLine(TransformNode2D(transform, object->GetPoint(0)),
|
|
|
TransformNode2D(transform, object->GetPoint(object->GetNumPoints() - 1)), color, depthTest);
|
|
|
+ // Also draw a circle at origin to indicate direction
|
|
|
+ else
|
|
|
+ debug->AddCircle(TransformNode2D(transform, object->GetPoint(0)), Vector3::FORWARD, 0.05f, color, 64, depthTest);
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
@@ -337,10 +331,7 @@ Node* TileMapLayer2D::GetObjectNode(unsigned index) const
|
|
|
|
|
|
Node* TileMapLayer2D::GetImageNode() const
|
|
|
{
|
|
|
- if (!imageLayer_)
|
|
|
- return 0;
|
|
|
-
|
|
|
- if (nodes_.Empty())
|
|
|
+ if (!imageLayer_ || nodes_.Empty())
|
|
|
return 0;
|
|
|
|
|
|
return nodes_[0];
|