public Armor New( Ship ship ) { Armor armor = new Armor(ship, ship.template.component_armor_size, this); return armor; }
public HitboxArmorMarker(HitboxPolygon hitbox, Armor arg_armor, float displacement, float segment_separation) { // we need to construct the lines to represent our armor segments. // We have to project the armors angular system onto the hitbox. armor = arg_armor; nodes = new List<Vector2>[armor.segment_count]; int count = hitbox.count; Vector2[] corners = new Vector2[count]; Vector2[] displacements = new Vector2[count]; Vector2 last = hitbox.corners.Last(); for (int i = 0; i < count; i++) { Vector2 p = hitbox.corners[i]; Vector2 delta = last - p; delta.Normalize(); displacements[i] = Utility.RotateNeg(delta) * displacement / 2.0f; corners[i] = p; last = p; } for (int i = 0; i < count; i++) { int k = (i == count - 1) ? 0 : i + 1; corners[i] += displacements[i]; corners[i] += displacements[k]; } Vector2 p1 = corners[0]; int first_segment = armor.GetSegmentLocal(p1); int segment = first_segment; nodes[segment] = new List<Vector2>(); List<Vector2> popped = null; for (int j = 0; j < count; j++) { // iterate through all hitbox segments int i = j + 1; if (i == count) { i = 0; } Vector2 p2 = corners[i]; // if this line has crossed an armor intersection int new_segment = armor.GetSegmentLocal(p2); if (new_segment != segment) { // We find the midpoint of the the line where it croses the armor angle Vector2 cossin = Utility.CosSin(-armor.GetSegmentStartAngle(segment)); float p1ry = p1.X * cossin.Y + p1.Y * cossin.X; float p2ry = p2.X * cossin.Y + p2.Y * cossin.X; float alpha = p1ry / (p1ry - p2ry); Vector2 mid = ((p2 - p1) * alpha) + p1; if (new_segment == first_segment) { // this segment already has data in it. // we will add this back in later. popped = nodes[new_segment]; } // the new segment starts at the midpoint nodes[new_segment] = new List<Vector2>(); nodes[new_segment].Add(mid); nodes[new_segment].Add(p2); // the previous segment ends at the midpoint nodes[segment].Add(mid); segment = new_segment; } else { nodes[segment].Add(p2); } p1 = p2; } if (popped != null) { // We popped some of the data from the first segment, time to get it back foreach (Vector2 pt in popped) { nodes[first_segment].Add(pt); } } float sep = segment_separation / 2.0f; foreach (List<Vector2> node in nodes) { trim(node, 1, sep); trim(node, -1, sep); } }
public virtual void Draw(Camera camera, Armor armor, float width, Vector2 pos_override, float angle_override) { }