private void deleteSelection() { if (selection.Count > 0) { WorldAction action = new WorldAction(ActionType.Delete, selection, selectionIndices); add(action); for (int i = 0; i < World.Lines.Count; i++) { LineGraph line = World.Lines[i]; for (int j = 0; j < selection.Count; j++) { WorldPoint point = selection[j]; if (line.Remove(point)) { selection.RemoveAt(j--); } } if (line.Count <= 1) { World.Lines.RemoveAt(i--); } Invalidate(); } } }
SoundSource(WorldPoint position, IReadOnlyList <SoundInstance> instances) { Assert.Ref(instances); Position = position; SoundInstances = instances; }
/// <summary> /// Constructs a new <see cref="RectDrawable"/>. /// </summary> /// <param name="rect">The <see cref="heng.Rect"/> to draw.</param> /// <param name="position">The world-space position of the <see cref="heng.Rect"/>.</param> /// <param name="fill">Whether to fill the rect.</param> /// <param name="color">The color of the rect.</param> public RectDrawable(Rect rect, WorldPoint position, bool fill, Color color) { Rect = rect; Position = position; Fill = fill; Color = color; }
/// <summary> /// Constructs a new <see cref="AudioState"/>. /// </summary> /// <param name="sources">All <see cref="SoundSource"/>s available to the new state.</param> /// <param name="listener">The world-space position from which <see cref="SoundSource"/>s are heard.</param> public AudioState(IEnumerable <SoundSource> sources, WorldPoint listener) { ListenerPosition = listener; SoundSources = AddSources(sources); Core.Audio.PushSound(); }
/// <summary> /// Returns a pixel-space vector between this <see cref="WorldPoint"/> and another. /// </summary> /// <param name="other">The other <see cref="WorldPoint"/>.</param> /// <returns>The pixel-space vector between the two <see cref="WorldPoint"/>s.</returns> public Vector2 PixelDistance(WorldPoint other) { float x = this.X.PixelDistance(other.X); float y = this.Y.PixelDistance(other.Y); return(new Vector2(x, y)); }
/// <summary> /// Clamps this <see cref="WorldPoint"/> between two other <see cref="WorldPoint"/> values. /// </summary> /// <param name="lower">The lower bound to clamp between.</param> /// <param name="upper">The upper bound to clamp between.</param> /// <returns>A new <see cref="WorldPoint"/>, clamped within the given bounds.</returns> public WorldPoint Clamp(WorldPoint lower, WorldPoint upper) { WorldCoordinate x = this.X.Clamp(lower.X, upper.X); WorldCoordinate y = this.Y.Clamp(lower.Y, upper.Y); return(new WorldPoint(x, y)); }
/// <summary> /// Constructs a new <see cref="WorldPoint"/> at the given pixel-space position. /// </summary> /// <param name="pixelPos">The new <see cref="WorldPoint"/>'s pixel-space position.</param> public WorldPoint(Vector2 pixelPos) { WorldPoint point = WorldPoint.Zero.PixelTranslate(pixelPos); X = point.X; Y = point.Y; }
List <WorldPoint> GetNeighbors(WorldPoint point) { int x = (int)point.position.x; int y = (int)point.position.z; List <WorldPoint> neighbors = new List <WorldPoint>(); if (y < height - 1) { WorldPoint up = map[x, y + 1]; neighbors.Add(up); } if (x < width - 1) { WorldPoint right = map[x + 1, y]; neighbors.Add(right); } if (y > 0) { WorldPoint down = map[x, y - 1]; neighbors.Add(down); } if (x > 0) { WorldPoint left = map[x - 1, y]; neighbors.Add(left); } return(neighbors); }
public void Undo() { if (actionIndex > 0) { WorldAction action = actionList[actionIndex - 1]; switch (action.Type) { case ActionType.FreeDraw: case ActionType.PointDraw: World.Lines.Remove(action.Line); break; case ActionType.Delete: for (int i = 0; i < action.Points.Count; i++) { WorldPoint point = action.Points[i]; point.Parent.Insert(point, action.PointIndices[i]); } break; case ActionType.MoveSelection: foreach (WorldPoint point in action.Points) { point.X -= action.Dx; point.Y -= action.Dy; } break; } actionIndex--; } Invalidate(); }
public void Redo() { if (actionIndex < actionList.Count) { WorldAction action = actionList[actionIndex]; switch (action.Type) { case ActionType.FreeDraw: case ActionType.PointDraw: World.Lines.Add(action.Line); break; case ActionType.Delete: for (int i = action.Points.Count - 1; i >= 0; i--) { WorldPoint point = action.Points[i]; point.Parent.RemoveAt(action.PointIndices[i]); } break; case ActionType.MoveSelection: foreach (WorldPoint point in action.Points) { point.X += action.Dx; point.Y += action.Dy; } break; } actionIndex++; } Invalidate(); }
PlayerUnit(Gamestate oldState, GamestateBuilder newState) { Assert.Ref(oldState, newState); PlayerUnit oldUnit = oldState.PlayerUnit; texture = oldUnit.texture; InputDevice device = oldState.Input.Devices[oldUnit.inputDevice]; RigidBody body = (RigidBody)(oldState.Physics.PhysicsBodies[oldUnit.rigidBody]); Sprite spr = (Sprite)(oldState.Video.Drawables[oldUnit.sprite]); float x = device.GetAxisFrac("Horizontal"); float y = device.GetAxisFrac("Vertical"); Vector2 move = new Vector2(x, y).ClampMagnitude(0, 1) * accel; body = body.AddImpulse(move); inputDevice = newState.Input.AddDevice(device); rigidBody = newState.Physics.AddPhysicsObject(body); sprite = newState.Video.AddDrawable(spr.Reposition(body.Position)); newState.Audio.SetListenerPosition(body.Position); Window window = oldState.Video.Windows[0]; Vector2 centerOffset = new Vector2(window.Rect.W / 2, window.Rect.H / 2); WorldPoint cameraPos = body.Position.PixelTranslate(-centerOffset + new Vector2(16, 16)); newState.Video.SetCamera(new Camera(cameraPos)); }
void Start() { /// If World Points List is empty, create a few examples if (worldPointsList.Count == 0) { WorldPoint a = new WorldPoint(); a.name = "Example 1"; a.color = Color.red; a.x = 0; a.y = 20; WorldPoint b = new WorldPoint(); b.name = "Example 2"; b.color = Color.green; b.x = 50; b.y = -20; WorldPoint c = new WorldPoint(); c.name = "Example 3"; c.color = Color.blue; c.x = -20; c.y = -10; worldPointsList.Add(a); worldPointsList.Add(b); worldPointsList.Add(c); } /// Loop through the list of world points for (int i = 0; i < worldPointsList.Count; i++) { /// Create the world point for the according element in the loop. CreateWorldPoint(worldPointsList[i]); /// Create the debug buttons for the according element in the loop. CreateDebugWorldPointButton(worldPointsList[i]); } /// Look at the first world point (If the list count is bigger than 0). if (worldPointsList.Count > 0) { LookAtWorldPoint(worldPointsList[0]); } }
/// ------------------------------------------------ DEBUG STUFF ------------------------------------------------------ /// void CreateDebugWorldPointButton(WorldPoint wp) { GameObject button = new GameObject(); GameObject text = new GameObject(); button.transform.SetParent(_ButtonUiHolder); button.transform.localScale = Vector3.one; button.transform.localPosition = Vector3.zero; button.AddComponent <Image>(); button.AddComponent <Outline>(); Button b = button.AddComponent <Button>(); b.onClick.AddListener(ButtonClick); text.transform.SetParent(button.transform); text.transform.localScale = Vector3.one; text.transform.localPosition = Vector3.zero; Text txt = text.AddComponent <Text>(); Font ArialFont = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf"); txt.font = ArialFont; txt.material = ArialFont.material; txt.color = Color.black; txt.alignment = TextAnchor.MiddleCenter; txt.text = (wp.name == string.Empty) ? "No Name " + button.transform.GetSiblingIndex() : wp.name; }
public static void TrimLineSegment(WorldPoint p1, WorldPoint p2, WorldRectangle viewBounds) { double dx = p2.X - p1.X; double dy = p2.Y - p1.Y; //Trim off Left if (p1.X < viewBounds.Left && p2.X > viewBounds.Left) { double trimPercent = (viewBounds.Left - p1.X) / dx; p1.X = viewBounds.Left; if (dy != 0) { p1.Y = p1.Y + dy * trimPercent; } } else if (p1.X > viewBounds.Left && p2.X < viewBounds.Left) { double trimPercent = (viewBounds.Left - p2.X) / dx; p2.X = viewBounds.Left; if (dy != 0) { p2.Y = p2.Y + dy * trimPercent; } } //TRIM THE REST // AND MAKE SURE THE RECTANGLES ARE ALSO TRIMMED CORRECTLY }
/// <summary> /// Linearly interpolates between two <see cref="WorldPoint"/>s. /// </summary> /// <param name="a">The interpolation start point.</param> /// <param name="b">The interpolation end point.</param> /// <param name="t">A 0-1 fraction, indicating which value between the two points to return.</param> /// <returns>A <see cref="WorldPoint"/> value between the start and end point.</returns> public static WorldPoint Lerp(WorldPoint a, WorldPoint b, float t) { WorldCoordinate x = WorldCoordinate.Lerp(a.X, b.X, t); WorldCoordinate y = WorldCoordinate.Lerp(a.Y, b.Y, t); return(new WorldPoint(x, y)); }
private void selectActionMouseDown(MouseEventArgs e) { currentAction = ActionType.Select; double selectionWorldDistance = selectionPixelDistance / (zoomPercent / 100); double pointDistance = selectionWorldDistance; LineGraph closestPointsLine = null; WorldPoint closestPoint = null; double lineDistance = selectionWorldDistance; LineGraph closestLine = null; foreach (LineGraph line in World.Lines) { bool isLine; double distance; int index = line.Grab(mouseDownWorldX, mouseDownWorldY, selectionWorldDistance, out distance, out isLine); if (index != -1) { if (isLine) { if (distance < lineDistance) { lineDistance = distance; closestLine = line; } } else { if (distance < pointDistance) { pointDistance = distance; closestPoint = line[index]; closestPointsLine = line; } } } } if (closestPoint != null) { if (!selection.Contains(closestPoint)) { selection.Clear(); selectionIndices.Clear(); selection.Add(closestPoint); selectionIndices.Add(closestPoint.getIndex()); } currentAction = ActionType.MoveSelection; } else if (closestLine != null) { selection.Clear(); selectionIndices.Clear(); for (int i = 0; i < closestLine.Count; i++) { selection.Add(closestLine[i]); selectionIndices.Add(i); } currentAction = ActionType.MoveSelection; } }
internal void ReSetCenter(WorldPoint world, SimulationPoint sim) { _center.Lat = Globe.DegreesToRadians(world.Lat); _center.Lon = Globe.DegreesToRadians(world.Lon); _offset.X = sim.X; _offset.Y = sim.Y; _projection = new AzimuthalEquidistant(_center.Lat, _center.Lon); }
float CalculateWaterWeight(WorldPoint point) { float weight = point.height + point.water / 4; weight += point.isDug ? 0 : dugWaterOffset; return(weight); }
public MainForm() { InitializeComponent(); // Create a new scene Group scene = new(); // Create some meshes WorldPoint origin = WorldPoint.ZeroOrigin; scene.Add(origin); Group axes = Arrow.Axes; scene.Add(axes); Cube cube = new( origin : new Vector3D(10, 10, 10), directionForward : Vector3D.UnitZ, directionUp : Vector3D.UnitY, sideLength : 30 ); Cone cone = new( origin : new Vector3D(70, 10, 10), directionForward : Vector3D.UnitZ, directionUp : Vector3D.UnitY, height : 30, radius : 20, resolution : 50 ); scene.Add(cube, cone); // Create a light DistantLight light = new( origin : new Vector3D(0, 100, 0), pointedAt : scene.Meshes[0], directionUp : Vector3D.UnitZ ); scene.Add(light); // Create a camera OrthogonalCamera renderCamera = new( origin : new Vector3D(500, 0, 100), pointedAt : scene.SceneObjects[0], directionUp : Vector3D.UnitY, viewWidth : pictureBox.Width / 10f, viewHeight : pictureBox.Height / 10f, zNear : 50, zFar : 750, renderWidth : pictureBox.Width, renderHeight : pictureBox.Height ); // Render the scene and display the output in the picture box pictureBox.Image = renderCamera.Render(scene); }
/*private void OnDrawGizmos() * { * for (int x = 0; x < width; x++) * { * for (int y = 0; y < height; y++) * { * Gizmos.color = new Color(map[x, y].light, map[x, y].light, map[x, y].light, 1f); * Gizmos.DrawCube(map[x, y].position, Vector3.one); * } * } * }*/ void SimulateTiles() { List <WorldPoint> points = new List <WorldPoint>(); float[,] waterChange = new float[width, height]; //first pass for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { WorldPoint point = map[x, y]; points.Add(point); //water point.waterWeight = CalculateWaterWeight(map[x, y]); } } //light WorldPoint[] pointsByTreeHeight = points.Where(q => q.plant != null).OrderBy(q => q.plant.size).ToArray(); foreach (WorldPoint point in pointsByTreeHeight) { int x = (int)point.position.x; int y = (int)point.position.z; //set light to sun level point.light = Game.control.cycle.intensityMultiplier; //block neighbor tiles for (int neighborX = x - point.plant.numTilesBlocked; neighborX < x + point.plant.numTilesBlocked; neighborX++) { for (int neighborY = y - point.plant.numTilesBlocked; neighborY < y + point.plant.numTilesBlocked; neighborY++) { Game.control.world.map[neighborX, neighborY].light *= 0.2f; } } } //second pass for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { SimulateWaterTile(x, y, ref waterChange); } } //third pass for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { map[x, y].AddWater(waterChange[x, y]); } } }
public void WriteTest() => File.OpenRead(FileName).Using(stream => { Helpers.AssertStream(stream, x => { var outStream = new MemoryStream(); WorldPoint.Write(outStream, WorldPoint.Read(x)); return(outStream); }); });
public SimulationPoint Convert(WorldPoint input) { var p = _projection.ToPlane(input.Lat, input.Lon); return(new SimulationPoint { X = _offset.X + p.X, Y = _offset.Y + p.Y, }); }
/// <inheritdoc /> public void Draw(Window window, Camera camera) { ScreenPoint[] points = new ScreenPoint[Polygon.Points.Count]; for (int i = 0; i < points.Length; i++) { WorldPoint pointPos = Position.PixelTranslate(Polygon.Points[i]); points[i] = camera.WorldToViewportPosition(pointPos); } window.DrawPolygon(points, Color); }
/// <summary> /// Constructs a new <see cref="Sprite"/>. /// </summary> /// <param name="texture">The new <see cref="Sprite"/>'s <see cref="Video.Texture"/>.</param> /// <param name="position">The new <see cref="Sprite"/>'s world-space position.</param> /// <param name="rotation">The new <see cref="Sprite"/>'s rotation, in degrees.</param> public Sprite(Texture texture, WorldPoint position, float rotation) { Texture = texture; Position = position; Rotation = rotation; if (texture == null) { Log.Warning("constructed Sprite with null texture"); } }
/// <summary> /// Constructs a new <see cref="StaticBody"/>. /// </summary> /// <param name="position">The world-space position of the new <see cref="StaticBody"/>.</param> /// <param name="collider">The collidable representation of the new <see cref="StaticBody"/>.</param> /// <param name="material">The <see cref="PhysicsMaterial"/> representing the new <see cref="StaticBody"/>.</param> public StaticBody(WorldPoint position, ICollider collider, PhysicsMaterial material) { if (collider == null) { Log.Warning("constructed a StaticBody with no collider"); } Position = position; Collider = collider; Material = material; }
IPhysicsBody IPhysicsBody.CollisionPass(IEnumerable <CollisionData> collisions) { WorldPoint newPosition = Position; Vector2 newVelocity = Velocity; foreach (CollisionData collision in collisions) { newPosition = newPosition.PixelTranslate(collision.MTV); newVelocity = GetMomentumChange(this, collision) + GetFriction(this, collision); } return(new RigidBody(this, position: newPosition, velocity: newVelocity)); }
private void DrawLine(Graphics g, Pen pen, WorldPoint p1, WorldPoint p2) { double dx = p2.X - p1.X; double dy = p2.Y - p1.Y; WorldRectangle.TrimLineSegment(p1, p2, viewBounds); int screenX1 = worldToScreenX(p1.X); int screenY1 = worldToScreenY(p1.Y); int screenX2 = worldToScreenX(p2.X); int screenY2 = worldToScreenY(p2.Y); g.DrawLine(pen, screenX1, screenY1, screenX2, screenY2); }
bool TestPair(IPhysicsBody a, IPhysicsBody b, out Vector2 mtv) { Assert.Ref(a, b); // collisions will be tested in a localized space, originating at the least common sector of both colliders // (i think? this is easier than setting the origin at the collider vertex closest to 0,0) WorldPoint origin = WorldPoint.LeastCommonSector(a.Position, b.Position); Vector2 posA = a.Position.PixelDistance(origin); Vector2 posB = b.Position.PixelDistance(origin); // we're also returning the minimum translation vector float minOverlap = float.MaxValue; mtv = Vector2.Zero; // test seperating axes foreach (Vector2 axis in GetAllSeperatingAxes(a.Collider, b.Collider)) { // project colliders on this seperating axis ColliderProjection projA = a.Collider.Project(posA, axis); ColliderProjection projB = b.Collider.Project(posB, axis); // find the overlap. if there is none, we're not colliding and can get out now float overlap = ColliderProjection.GetOverlap(projA, projB); if (overlap > 0) { // otherwise, update the mtv if it's a smaller overlap than before if (overlap < minOverlap) { minOverlap = overlap; mtv = axis; } } else { return(false); } } // make sure mtv isn't negative Vector2 diff = posA - posB; if (diff.Dot(mtv) < 0) { mtv = -mtv; } // scale mtv by the smallest overlap, and we're done mtv *= minOverlap; return(true); }
IPhysicsBody IPhysicsBody.ImpulsePass(Vector2 gravity, float deltaT) { WorldPoint secOrigin = new WorldPoint(Position.Sector, Vector2.Zero); Vector2 f = Forces + gravity; Vector2 a = GetAccel(f, Mass); Vector2 p = Position.PixelDistance(secOrigin); Vector2 newP = GetNewPosition(p, a, Velocity, deltaT); Vector2 newVelocity = GetNewVelocity(a, Velocity, deltaT); WorldPoint newPosition = secOrigin.PixelTranslate(newP); return(new RigidBody(this, position: newPosition, velocity: newVelocity, forces: Vector2.Zero)); }
/// <summary> /// Function that creates the visual representation of a World Point class. /// </summary> /// <param name="wp">Reference to the World Point to be created.</param> void CreateWorldPoint(WorldPoint wp) { /// Instantiate the World Point point prefab as a child of the world sphere (As new GameObject) GameObject pivot = Instantiate(worldPointPrefab, worldSphere.transform); /// Use the World Point coordinates to rotate the New GameObject in euler angles. pivot.transform.eulerAngles = new Vector3(wp.y, -wp.x, 0); /// Name the New GameObject pivot.name = wp.name; /// Set the target transform of the reference World Point. wp.SetTarget(pivot.transform.GetChild(0)); /// Change the color of the new Game Object's renderer. pivot.GetComponentInChildren <Renderer>().material.color = wp.color; }
/// <summary> /// Erzeugt einen neuen Trupp /// </summary> /// <param name="ID">ID</param> /// <param name="data">GameData</param> /// <returns></returns> public static Troop create(int ID, GameData data) { MySqlDataReader Reader = data.Query("SELECT * FROM `PX_mom-troops` WHERE `ID` = '" + ID + "'"); Reader.Read(); int type = (int)Reader["Class"]; string name = (string)Reader["Name"]; User UID = data.getUser((int)Reader["UID"]); int power = (int)Reader["Power"]; int health = (int)Reader["health"]; int team = (int)Reader["team"]; WorldPoint position = new WorldPoint((string)(Reader["worldpos"])); string states = (string)Reader["states"]; int power2 = (int)Reader["Power2"]; int power3 = (int)Reader["Power3"]; int power4 = (int)Reader["Power4"]; int resistend1 = (int)Reader["Resistend1"]; int resistend2 = (int)Reader["Resistend2"]; int resistend3 = (int)Reader["Resistend3"]; int resistend4 = (int)Reader["Resistend4"]; int hide = (int)Reader["hide"]; string verhalten = (string)Reader["verhalten"]; TroopClass typeClass = data.getTroopType(type); Troop troop = new Troop(ID, typeClass, UID, name, team, states); troop.position = position; troop.health = health; troop.power = power; troop.power2 = power2; troop.power3 = power3; troop.power4 = power4; troop.resistend1 = resistend1; troop.resistend2 = resistend2; troop.resistend3 = resistend3; troop.resistend4 = resistend4; troop.hide = hide; troop.verhalten = verhalten; troop.fighterTyp = FighterType.TROOP; Reader.Close(); return troop; }