public static bool CircleAABBOverlap(Vector2f centre, float radius, cAABB rect) { return(IsPointInsideBox(centre, rect) || isPointInsideCircle(centre, radius, rect.topLeft) || isPointInsideCircle(centre, radius, rect.rightBottom) || isPointInsideCircle(centre, radius, new Vector2f(rect.rightBottom.X, rect.topLeft.Y)) || isPointInsideCircle(centre, radius, new Vector2f(rect.topLeft.X, rect.rightBottom.Y))); }
public static bool testLineVsAABB(Vector2f line_start, Vector2f line_end, cAABB box, ref Vector2f intersection) { Vector2f topLeft = box.topLeft; Vector2f topRight = new Vector2f(box.rightBottom.X, box.topLeft.Y); Vector2f rightBottom = box.rightBottom; Vector2f leftBottom = new Vector2f(box.topLeft.X, box.rightBottom.Y); // LineVsLine return(lineVsLineCollision(line_start, line_end, topLeft, topRight, ref intersection) || lineVsLineCollision(line_start, line_end, topRight, rightBottom, ref intersection) || lineVsLineCollision(line_start, line_end, rightBottom, leftBottom, ref intersection) || lineVsLineCollision(line_start, line_end, leftBottom, topLeft, ref intersection)); }
public static cGameObject MakeWall(cAABB box) { cGameObject go = new cGameObject(); go.Position = box.center; go.LastPosition = go.Position; go.Velocity = new Vector2f(0.0f, 0.0f); go.ViewPosition = go.Position; //box.SetDims(new Vector2f(Constants.TILE_SIZE, Constants.TILE_SIZE)); go.Bounds = box; go.HitCollisionRect = box; go.MovAble = false; // important! go.Mass = 0.0f; return(go); }
public cGameObject(cGameScene scene, Vector2f pos) : base() { pscene = scene; position = pos; lastPosition = pos; viewPosition = pos; velocity = new Vector2f(0.0f, 0.0f); acceleration = new Vector2f(0.0f, 0.0f); force = new Vector2f(0.0f, 0.0f); orientation = 0.0; mass = 1.0f; movAble = true; hitCollisionRect = new cAABB(); m_ID = GetNextValidID(); }
public static Vector2f getNormalOfClosestSide(Vector2f point, cAABB box) { /*if (IsPointInsideBox(point, box)) * return Side.INSIDE;*/ Vector2f topLeft = box.topLeft; Vector2f topRight = new Vector2f(box.rightBottom.X, box.topLeft.Y); Vector2f rightBottom = box.rightBottom; Vector2f leftBottom = new Vector2f(box.topLeft.X, box.rightBottom.Y); Vector2f ntop = cAppMath.Vec2Perp(topRight - topLeft); Vector2f nright = cAppMath.Vec2Perp(rightBottom - topRight); Vector2f nbottom = cAppMath.Vec2Perp(leftBottom - rightBottom); Vector2f nleft = cAppMath.Vec2Perp(topLeft - rightBottom); return(ntop); }
public cGameObject() : base() { pscene = null; position = new Vector2f(0.0f, 0.0f);; lastPosition = new Vector2f(0.0f, 0.0f);; viewPosition = new Vector2f(0.0f, 0.0f);; velocity = new Vector2f(0.0f, 0.0f); acceleration = new Vector2f(0.0f, 0.0f); force = new Vector2f(0.0f, 0.0f); MaxSpeed = 0.0f; SlowDown = 1.0f; orientation = 0.0; mass = 1.0f; movAble = true; hitCollisionRect = new cAABB(); m_ID = GetNextValidID(); }
public static bool IsPointInsideBox(Vector2f point, cAABB box) { if (point.X <= box.topLeft.X) { return(false); } if (point.X >= box.rightBottom.X) { return(false); } if (point.Y <= box.topLeft.Y) { return(false); } if (point.Y >= box.rightBottom.Y) { return(false); } return(true); }
public static bool testBulletVsEntity(Vector2f bulPos, Vector2f bulLastPos, cAABB entityBounds, ref Vector2f intersection) { int x0 = (int)bulLastPos.X; int y0 = (int)bulLastPos.Y; int x1 = (int)bulPos.X; int y1 = (int)bulPos.Y; bool collision = false; Vector2f temp = new Vector2f(0.0f, 0.0f); cAppMath.Raytrace(x0, y0, x1, y1, new VisitMethod( (int x, int y) => { collision = IsPointInsideBox(new Vector2f(x, y), entityBounds); temp.X = x; temp.Y = y; return(collision); } ) ); intersection = temp; return(collision); }
public static bool OverlapAABB(cAABB A, cAABB B) { if (A.rightBottom.Y <= B.topLeft.Y) { return(false); } if (A.topLeft.Y >= B.rightBottom.Y) { return(false); } if (A.rightBottom.X <= B.topLeft.X) { return(false); } if (A.topLeft.X >= B.rightBottom.X) { return(false); } return(true); }
protected virtual void init() { bounds = new cAABB(0, 0, 1, 1); bounds.SetDims(new Vector2f(Constants.CHAR_COLLISON_RECT.Width, Constants.CHAR_COLLISON_RECT.Height)); bounds.SetPosByTopLeft(position); this.hitCollisionRect.SetDims(new Vector2f(32.0f, 32.0f)); this.hitCollisionRect.SetPosByTopLeft(position); shape = new RectangleShape(); shape.FillColor = Color.Green; shape.Size = new Vector2f(bounds.dims.X, bounds.dims.Y); isJumpActive = false; isOnGround = false; isOnOnewWayPlatform = false; horizontalFacing = HorizontalFacing.FACING_RIGHT; //must call, else not working spriteControl.ChangeState(this.GetSpriteState()); this.health = 1; }