public void Center(Button button) { if (editorCamera != null && ParentScene.SelectedGameObjects.Count > 0) { editorCamera.Position.set(Basic2DObject.GetAveragePosition(ParentScene.SelectedGameObjects)); } }
public Basic2DObject CheckCollision(Basic2DObject Tester) { Vector2 MinPosition = (Tester.getUpperLeftCorner() - Min) / CellSize; Vector2 MaxPosition = (Tester.getLowerRightCorner() - Min) / CellSize; int MinCellX = (int)MathHelper.Clamp(MinPosition.X, 0, CellsX); int MinCellY = (int)MathHelper.Clamp(MinPosition.Y, 0, CellsY); int MaxCellX = (int)MathHelper.Clamp(MaxPosition.X, 0, CellsX) + 1; int MaxCellY = (int)MathHelper.Clamp(MaxPosition.Y, 0, CellsY) + 1; for (int x = MinCellX; x < MaxCellX; x++) { for (int y = MinCellY; y < MaxCellY; y++) { Basic2DObject g = null; g = Children[x, y].CheckCollision(Tester); if (g != null) { return(g); } } } return(null); }
public void ApplySnap(bool ApplyToChildren) { if (ParentScene != null && ParentScene.GetType().IsSubclassOf(typeof(Basic2DScene))) { Basic2DScene s = (Basic2DScene)ParentScene; if (s.GridSize != null) { Vector2 GridSize = s.GridSize.get(); Vector2 Pos = Position.get(); Position.set(new Vector2((float)Math.Round(Position.get().X / s.GridSize.get().X), (float)Math.Round(Position.get().Y / s.GridSize.get().Y)) * s.GridSize.get()); } } if (ApplyToChildren) { foreach (GameObject g in HierarchyChildren) #if EDITOR && WINDOWS { if (!ParentLevel.LevelForEditing || !g.EditorSelected) #endif { if (g.GetType().IsSubclassOf(typeof(Basic2DObject))) { Basic2DObject b = (Basic2DObject)g; b.ApplySnap(true); } } } }
public override bool RayCast(GameTime gameTime) { foreach (GameObject o in Children) { if (o.RayCast(gameTime)) { return(true); } } if (!KeyboardManager.AltPressed()) { return(objectControls.RayCast(gameTime)); } else { if (MouseManager.MouseClicked && CreatorBasic.LastCreator != null) { GameObject o = CreatorBasic.LastCreator.ReturnObject(); ParentLevel.AddObject(o); if (o.GetType().IsSubclassOf(typeof(Basic2DObject))) { Basic2DObject b = (Basic2DObject)o; b.Position.set(Vector2.Transform(WorldViewer.self.RelativeMousePosition, Matrix.Invert(DrawCamera.ViewMatrix))); ClearSelected(); AddSelected(b); if (UseGrid.get()) { SnapSelected(); } } } return(true); } }
public Basic2DObject CheckCollision(Basic2DObject Tester) { foreach (Basic2DObject g in Children) { if (g.CheckCollision(Tester)) { return(g); } } return(null); }
public void MoveSelected(Vector2 Force) { foreach (GameObject g in SelectedGameObjects) { if (g.GetType().IsSubclassOf(typeof(Basic2DObject))) { Basic2DObject b = (Basic2DObject)g; b.ApplyMove(Force, false); } } }
public void RotateSelected(float Force, Vector2 Origin) { foreach (GameObject g in SelectedGameObjects) { if (g.GetType().IsSubclassOf(typeof(Basic2DObject))) { Basic2DObject b = (Basic2DObject)g; b.ApplyRotate(Force, Basic2DObject.GetAveragePosition(SelectedGameObjects), false); } } }
public void DrawControls() { if (ParentScene.DrawCamera != null && ParentScene.SelectedGameObjects.Count > 0) { Vector2 Avg = Basic2DObject.GetAveragePosition(ParentScene.SelectedGameObjects); Texture2D tex = controlMode == ControlMode.Move ? MoveControl : controlMode == ControlMode.Rotate ? RotateControl : ScaleControl; Render.DrawSprite(tex, Avg, new Vector2(128) / ParentScene.DrawCamera.getZoom(), 0); } base.Draw(); }
public void SnapSelected() { foreach (GameObject g in SelectedGameObjects) { if (g.GetType().IsSubclassOf(typeof(Basic2DObject))) { Basic2DObject b = (Basic2DObject)g; b.ApplySnap(false); } } }
public void Add(Basic2DObject g) { if (ChildCount >= ArraySize - 1) { ArraySize = ArraySize * 2; Basic2DObject[] NewChildren = new Basic2DObject[ArraySize]; for (int i = 0; i < ChildCount; i++) { NewChildren[i] = Children[i]; } Children = NewChildren; } Children[ChildCount++] = g; }
public static Basic2DObject Nearest(LinkedList <Basic2DObject> Items, Vector2 Position) { float BestDistance = 1000000; Basic2DObject BestObject = null; foreach (Basic2DObject o in Items) { float d = Vector2.Distance(o.getPosition(), Position); if (d < BestDistance) { BestDistance = d; BestObject = o; } } return(BestObject); }
public static Vector2 GetAveragePosition(LinkedList <GameObject> SelectObjects) { Vector2 val = Vector2.Zero; int Count = 0; foreach (GameObject g in SelectObjects) { if (g.GetType().IsSubclassOf(typeof(Basic2DObject))) { Basic2DObject b = (Basic2DObject)g; val += b.getPosition(); Count++; } } return(val / Count); }
private void commitWorldBlocker(Basic2DObject w) { Vector2 UpperLeftCorner = (w.getUpperLeftCorner() - Parent2DScene.MinBoundary.get()) / Divisor + new Vector2(0.5f); Vector2 LowerRightCorner = (w.getLowerRightCorner() - Parent2DScene.MinBoundary.get()) / Divisor + new Vector2(0.5f); Vector2 Center = (w.getLowerRightCorner() - Parent2DScene.MinBoundary.get()) / Divisor; int MinX = (int)UpperLeftCorner.X; int MinY = (int)UpperLeftCorner.Y; int MaxX = (int)LowerRightCorner.X; int MaxY = (int)LowerRightCorner.Y; for (int x = MinX; x < MaxX + 1; x++) { for (int y = MinY; y < MaxY + 1; y++) { CellGrid[x, y] = DeadCell; } } if (w.GetType().Equals(typeof(WallNode))) { WallNode s = (WallNode)w; if (s.wallConnector != null) { UpperLeftCorner = Logic.Min(UpperLeftCorner, (s.wallConnector.PositionNext - s.Size.get() / 2 - Parent2DScene.MinBoundary.get()) / Divisor + new Vector2(0.5f)); LowerRightCorner = Logic.Max(LowerRightCorner, (s.wallConnector.PositionNext + s.Size.get() / 2 - Parent2DScene.MinBoundary.get()) / Divisor + new Vector2(0.5f)); MinX = (int)UpperLeftCorner.X; MinY = (int)UpperLeftCorner.Y; MaxX = (int)LowerRightCorner.X; MaxY = (int)LowerRightCorner.Y; for (int x = MinX; x < MaxX + 1; x++) { for (int y = MinY; y < MaxY + 1; y++) { if (Logic.DistanceLineSegmentToPoint(s.Position.get(), s.wallConnector.PositionNext, (new Vector2(x, y) - new Vector2(0.5f)) * Divisor + Parent2DScene.MinBoundary.get()) < w.Size.X()) { CellGrid[x, y] = DeadCell; } } } } } }
public void ApplyScale(Vector2 Force, Vector2 Origin, bool ApplyToChildren) { Size.mult(Force); Position.set(Origin + (Position.get() - Origin) * Force); if (ApplyToChildren) { foreach (GameObject g in HierarchyChildren) #if EDITOR && WINDOWS if (!ParentLevel.LevelForEditing || !g.EditorSelected) #endif if (g.GetType().IsSubclassOf(typeof(Basic2DObject))) { Basic2DObject b = (Basic2DObject)g; b.ApplyScale(Force, Origin, true); } } }
public void ApplyMove(Vector2 Force, bool ApplyToChildren) { Position.add(Force); if (ApplyToChildren) { foreach (GameObject g in HierarchyChildren) #if EDITOR && WINDOWS { if (!ParentLevel.LevelForEditing || !g.EditorSelected) #endif { if (g.GetType().IsSubclassOf(typeof(Basic2DObject))) { Basic2DObject b = (Basic2DObject)g; b.ApplyMove(Force, true); } } } }
public void SetObjects(LinkedList <GameObject> Objects) { for (int x = 0; x < CellsX; x++) { for (int y = 0; y < CellsY; y++) { if (Children[x, y].ChildCount > Children[x, y].ArraySize / 2) { Children[x, y].ArraySize = Children[x, y].ArraySize * 2; Children[x, y].Children = new Basic2DObject[Children[x, y].ArraySize]; } Children[x, y].ChildCount = 0; } } foreach (Basic2DObject g in Objects) { for (int x = g.QuadGridXMin; x <= g.QuadGridXMax; x++) { for (int y = g.QuadGridYMin; y <= g.QuadGridYMax; y++) { if (Children[x, y].ChildCount >= Children[x, y].ArraySize - 1) { Children[x, y].ArraySize = Children[x, y].ArraySize * 2; Basic2DObject[] NewChildren = new Basic2DObject[Children[x, y].ArraySize]; for (int i = 0; i < Children[x, y].ChildCount; i++) { NewChildren[i] = Children[x, y].Children[i]; } Children[x, y].Children = NewChildren; } Children[x, y].Children[Children[x, y].ChildCount++] = g; } } } }
public override void Update(GameTime gameTime, Window Updater) { if (CurrentMode != LockMode.None) { if (MouseManager.mouseState.LeftButton == ButtonState.Pressed) { Vector2 AMT = MouseManager.MousePosition - MouseLockPosition; switch (controlMode) { case ControlMode.Move: ParentScene.MoveSelected(AMT); break; case ControlMode.Rotate: ParentScene.RotateSelected(AMT.X + AMT.Y, Basic2DObject.GetAveragePosition(ParentScene.SelectedGameObjects)); break; case ControlMode.Scale: ParentScene.ScaleSelected(Vector2.One + AMT / 300, Basic2DObject.GetAveragePosition(ParentScene.SelectedGameObjects)); break; } } else { if (controlMode == ControlMode.Move && ParentScene.UseGrid.get()) { ParentScene.SnapSelected(); } Game1.self.IsMouseVisible = true; CurrentMode = LockMode.None; } Mouse.SetPosition((int)MouseLockPosition.X, (int)MouseLockPosition.Y); } base.Update(gameTime, Updater); }
public bool CheckCircle(Basic2DObject g) { return(Logic.DistanceLineSegmentToPoint(getPosition(), PreviousPosition, g.getPosition()) < (g.Size.get().X + Size.get().X) / 2); }
public override bool CheckCollision(Basic2DObject Tester) { return(Vector2.Distance(getPosition(), Tester.getPosition()) < Tester.getSize().X + getSize().X); }