game calc collisionsarea


SUBMITTED BY: Thor2607

DATE: Sept. 28, 2016, 9:06 p.m.

FORMAT: C#

SIZE: 1.2 kB

HITS: 1028

  1. [override]protected void recalcM(){
  2. m = Matrix.CreateTranslation(new Vector3(-_org.X, -_org.Y, 0))* Matrix.CreateRotationZ((float)_deg)* Matrix.CreateScale((float)_scale)
  3. * Matrix.CreateTranslation(_pos.X, _pos.Y, 0);
  4. Vector2 p1 = Vector2.Transform(pos, m), p2 = Vector2.Transform(new Vector2(size.X, 0) + pos, m), p3 = Vector2.Transform(new Vector2(size.X, size.Y) + pos, m), p4 = Vector2.Transform(new Vector2(0, size.Y) + pos, m);
  5. int minx, miny, maxx, maxy;
  6. { // min|max suche
  7. minx = Math.Min(Math.Min((int)p1.X, (int)p2.X), Math.Min((int)p3.X, (int)p4.X));
  8. maxx = Math.Max(Math.Max((int)p1.X, (int)p2.X), Math.Max((int)p3.X, (int)p4.X));
  9. miny = Math.Min(Math.Min((int)p1.Y, (int)p2.Y), Math.Min((int)p3.Y, (int)p4.Y));
  10. maxy = Math.Max(Math.Max((int)p1.Y, (int)p2.Y), Math.Max((int)p3.Y, (int)p4.Y));
  11. }
  12. rec = new Rectangle(minx, miny, maxx - minx, maxy - miny); //Cbox
  13. if (!rself) colr = Math.Max(Math.Max(Vector2.Distance(org, p1), Vector2.Distance(org, p2)), Math.Max(Vector2.Distance(org, p3), Vector2.Distance(org, p4))); //Collisionskreis berechnen
  14. }

comments powered by Disqus