/// <summary> /// Make a collider. /// </summary> /// <param name="x" >Collider x value</param> /// <param name="y" >Collider y value</param> /// <param name="collider" >Reference to the current collider component</param> /// <param name="data" >Reference to the output collider data</param> private void MakeCollider(float x, float y, ref Collider collider, ref ColliderData data) { data.X = x; data.Y = y; data.Width = collider.Width; data.Height = collider.Height; }
private void GetBox(ref ColliderData circle) { this.CircleBox.X = circle.X - circle.Width; this.CircleBox.Y = circle.Y - circle.Width; this.CircleBox.Width = circle.Height; this.CircleBox.Height = circle.Height; }
/** * Based on OpenClassroom "Theorie des collisions" **/ #region TEMPORARY COLLISION FUNCTIONS private bool PointRectangle(ref ColliderData point, ref ColliderData rectangle) { if ( point.X > rectangle.X && point.X < rectangle.X + rectangle.Width && point.Y > rectangle.Y && point.Y < rectangle.Y + rectangle.Height ) { this.Offset.X = rectangle.X - point.X; this.Offset.Y = rectangle.Y - point.Y; return(true); } return(false); }
private bool PointCircle(ref ColliderData point, ref ColliderData circle) { var dist = (point.X - circle.X) * (point.X - circle.X) + (point.Y - circle.Y) * (point.Y - circle.Y); if (dist > circle.Height) { return(false); } else { this.Offset.X = 0f; this.Offset.Y = 0f; return(true); } }
private bool PointCircle(float x, float y, ref ColliderData circle) { var dist = (x - circle.X) * (x - circle.X) + (y - circle.Y) * (y - circle.Y); if (dist > circle.Height) { return(false); } else { this.Offset.X = 0f; this.Offset.Y = 0f; return(true); } }
private bool CircleCircle(ref ColliderData cir_one, ref ColliderData cir_two) { var dist = (cir_one.X - cir_two.X) * (cir_one.X - cir_two.X) + (cir_one.Y - cir_two.Y) * (cir_one.Y - cir_two.Y); var dist_two = (cir_one.Height + cir_two.Height) * (cir_one.Height + cir_two.Height); if (dist > dist_two) { return(false); } else { this.Offset.X = 0f; this.Offset.Y = 0f; return(true); } }
private bool RectangleRectangle(ref ColliderData rect_one, ref ColliderData rect_two) { if ( (rect_two.X > rect_one.X + rect_one.Width) || // trop a droite (rect_two.X + rect_two.Width < rect_one.X) || // trop a gauche (rect_two.Y > rect_one.Y + rect_one.Height) || // trop en base (rect_two.Y + rect_two.Height < rect_one.Y) // trop en haut ) { return(false); } else { this.Offset.X = rect_two.X - rect_one.X; this.Offset.Y = rect_two.Y - rect_one.Y; return(true); } }
private bool RectangleCircle(ref ColliderData rectangle, ref ColliderData circle) { this.GetBox(ref circle); if (this.RectangleRectangle(ref rectangle, ref this.CircleBox)) { return(false); } if ( PointCircle(rectangle.X, rectangle.Y, ref circle) || PointCircle(rectangle.X, rectangle.Y + rectangle.Height, ref circle) || PointCircle(rectangle.X + rectangle.Width, rectangle.Y, ref circle) || PointCircle(rectangle.X + rectangle.Width, rectangle.Y + rectangle.Height, ref circle) ) { this.Offset.X = 0f; this.Offset.Y = 0f; return(true); } if (PointRectangle(ref circle, ref rectangle)) { this.Offset.X = 0f; this.Offset.Y = 0f; return(true); } var proj_vert = ProjectionSegment(circle.X, circle.Y, rectangle.X, rectangle.Y, rectangle.X, rectangle.Y + rectangle.Height); var proj_hori = ProjectionSegment(circle.X, circle.Y, rectangle.X, rectangle.Y, rectangle.X + rectangle.Width, rectangle.Y); if (proj_vert || proj_hori) { this.Offset.X = 0f; this.Offset.Y = 0f; return(true); } return(false); }