public GraphicsObject(GameObject host) { Host = host; }
/// <summary> /// Checks for a collision between this object and another. /// </summary> /// <param name="other"></param> /// <returns>Collision detected</returns> public bool CheckCollide(GameObject other) { if ((other.Position - Position).LengthSquared() > other.Sprite.RadiusSquared + Sprite.RadiusSquared) { return false; } GameObject small, large; if (Sprite.Dimensions.Width * Sprite.Dimensions.Height < other.Sprite.Dimensions.Width * other.Sprite.Dimensions.Height) { small = this; large = other; } else { large = this; small = other; } // Matrix to convert from small-space to large-space, the local space of the respective objects. Matrix s2l = small.Transform * Matrix.Invert(large.Transform); Color[] sColors = new Color[small.Sprite.Dimensions.Width * small.Sprite.Dimensions.Height]; Color[] lColors = new Color[large.Sprite.Dimensions.Width * large.Sprite.Dimensions.Height]; small.Sprite.GetColorData(ref sColors); large.Sprite.GetColorData(ref lColors); Vector3 sPos = new Vector3(0, 0, 1); Vector3 lPos; int sIndex = 0; int lIndex; for (sPos.Y = 0; sPos.Y < small.Sprite.Dimensions.Height; ++sPos.Y) for (sPos.X = 0; sPos.X < small.Sprite.Dimensions.Width; ++sPos.X, ++sIndex) { if (sColors[sIndex].A > 0) { Vector3.Transform(ref sPos, ref s2l, out lPos); lIndex = large.Sprite.Sheet.VectorToIndex(lPos); if (lIndex >= 0 && lColors[lIndex].A > 0) return true; } } return false; }