public void Update(TimeSpan elapsed) { var x = m_location.Position.X; var y = m_location.Position.Y; var width = Math.Min(Bounds.Size.X, Bounds.Size.X); var height = Math.Min(Bounds.Size.Y, Bounds.Size.Y); if (x < Bounds.MinX) { x = Bounds.MinX; } else if (x > Bounds.MaxX - width) { x = Bounds.MaxX - width; } if (y < Bounds.MinY) { y = Bounds.MinY; } else if (y > Bounds.MaxY - height) { y = Bounds.MaxY - height; } Bounds = new Box2(x, y, width, height); }
public Sprite(SpriteSheet spriteSheet, string name, Vector2i size, Box2 coordinates) { SpriteSheet = spriteSheet; Name = name; Size = size; Coordinates = coordinates; }
private FormattedText(List<GlyphInstance> instances, Box2 bounds, string text, Font font, TextAlignment alignment, SizeConstraint constraint) { m_instances = instances; Bounds = bounds; Text = text; Font = font; Alignment = alignment; Constraint = constraint; }
public void Box2_Box2_4_Intersection() { var box1 = new Box2(0, 0, 100, 100); var box2 = new Box2(25, 25, 50, 50); var result = Granite.Collision.Collision.Intersect(box1, box2); Assert.IsTrue(result.Count == 4); }
public static bool Detection(Box2 b1, Box2 b2) { if ((b2.MinX >= b1.MaxX) // trop à droite || (b2.MaxX <= b1.MinX) // trop à gauche || (b2.MinY >= b1.MaxY) // trop en bas || (b2.MaxY <= b1.MinY)) // trop en haut return false; else return true; }
public void Box2_Segment_True() { var box1 = new Box2(0, 0, 100, 100); var box2 = new Box2(50, 0, 100, 100); Stopwatch w = new Stopwatch(); w.Start(); var result = Granite.Collision.Collision.Detection(box1, box2); w.Stop(); Console.WriteLine(string.Format("Box2_Segment_True : {0}", w.Elapsed)); Assert.IsTrue(result); }
public ColorMapHelper(WarpedDataSource2D<double> field, Box2 regionBox, double minT, double maxT) { this.minT = minT; this.maxT = maxT; warpedField = field; if (regionBox != null) { this.tileBox = new GeoRect( regionBox.MinCoordinate.X, regionBox.MinCoordinate.Y, regionBox.MaxCoordinate.X - regionBox.MinCoordinate.X, regionBox.MaxCoordinate.Y - regionBox.MinCoordinate.Y); this.regionBox = regionBox; } System.Windows.Point[,] grid = warpedField.Grid; Coordinate2D minCoordinate = new Coordinate2D(grid[0, 0].X, grid[0, 0].Y); Coordinate2D maxCoordinate = new Coordinate2D(grid[warpedField.Width - 1, warpedField.Height - 1].X, grid[warpedField.Width - 1, warpedField.Height - 1].Y); for (int j = 0; j < warpedField.Height; j++) { for (int i = 0; i < warpedField.Width; i++) { if (grid[i, j].X < minCoordinate.X) minCoordinate.X = grid[i, j].X; if (grid[i, j].X > maxCoordinate.X) maxCoordinate.X = grid[i, j].X; if (grid[i, j].Y < minCoordinate.Y) minCoordinate.Y = grid[i, j].Y; if (grid[i, j].Y > maxCoordinate.Y) maxCoordinate.Y = grid[i, j].Y; } } gridBox = new GeoRect( minCoordinate.X, minCoordinate.Y, maxCoordinate.X - minCoordinate.X, maxCoordinate.Y - minCoordinate.Y); palette = new LinearPalette(swm.Colors.Blue, swm.Colors.Green, swm.Colors.Red); workingTriangle = new RasterTriangle(); }
public static void Main() { // Declare a class instance "myBox": Box2 myBox = new Box2(30.0f, 20.0f); // Declare an instance of the English units interface: IEnglishDimensions eDimensions = (IEnglishDimensions)myBox; // Declare an instance of the metric units interface: IMetricDimensions mDimensions = (IMetricDimensions)myBox; // Print dimensions in English units: System.Console.WriteLine("Length(in): {0}", eDimensions.Length()); System.Console.WriteLine("Width (in): {0}", eDimensions.Width()); // Print dimensions in metric units: System.Console.WriteLine("Length(cm): {0}", mDimensions.Length()); System.Console.WriteLine("Width (cm): {0}", mDimensions.Width()); }
public ColorMapHelper(NonUniformDataSource2D<double> field, Box2 regionBox, double minT, double maxT) { this.minT = minT; this.maxT = maxT; this.gridBox = new GeoRect( Math.Min(field.X[0], field.X[field.Width - 1]), Math.Min(field.Y[0], field.Y[field.Height - 1]), Math.Abs(field.X[field.Width - 1] - field.X[0]), Math.Abs(field.Y[field.Height - 1] - field.Y[0])); if (regionBox != null) { this.tileBox = new GeoRect( regionBox.MinCoordinate.X, regionBox.MinCoordinate.Y, regionBox.MaxCoordinate.X - regionBox.MinCoordinate.X, regionBox.MaxCoordinate.Y - regionBox.MinCoordinate.Y); } palette = new LinearPalette(swm.Colors.Blue, swm.Colors.Green, swm.Colors.Red); this.field = field; }
public D3DGraphic(SystemConfiguration windowConfig) { this.windowConfig = windowConfig; ShaderName shaderName = ShaderName.Texture; IShape shape = new Box2(); ModelShader.Get(shaderName, shape); d3d = new D3D11(windowConfig); camera = new Camera(); model = new Bitmap(d3d.Device, ModelShader.GetShaderEffect, shaderName, this.windowConfig, new Vector2(256, 256)); //model = new D3DModel(d3d.Device, ModelShader.GetModelForRender, ModelShader.GetIndexes); shader = new D3DShader(d3d.Device, ModelShader.GetShaderEffect, shaderName); graph.Add(d3d); graph.Add(model); graph.Add(shader); //camera.Position = new Vector3(-2, 1, -3); camera.Position = new Vector3(0.0f, 0.0f, -10.0f); }
public GlyphInstance(Box2 rectangle, Sprite sprite) { Rectangle = rectangle; Sprite = sprite; }
public void Draw(Box2 rectangle, Texture2D texture, Vector2 textureCoordinates0, Vector2 textureCoordinates1, Color4ub color) { if (m_queueSize == m_queueCapacity) { Flush(); } m_queue[m_queueSize++] = new QuadData() { Transform = new Matrix3x2( m_transform.M00 * rectangle.Size.X, m_transform.M01 * rectangle.Size.X, m_transform.M10 * rectangle.Size.Y, m_transform.M11 * rectangle.Size.Y, m_transform.M00 * rectangle.Position.X + m_transform.M10 * rectangle.Position.Y + m_transform.M20, m_transform.M01 * rectangle.Position.X + m_transform.M11 * rectangle.Position.Y + m_transform.M21 ), Color = color, Texture = (sbyte)GetTextureIndex(texture), TextureCoordinates0 = textureCoordinates0, TextureCoordinates1 = textureCoordinates1 }; }
public void SetSize(Vector2 size) { var center = m_location.Position; m_box = new Box2(center - size / 2, size); }
public QuadNode(float x, float y, float width, float height) : this(Box2.FromDimensions(x, y, width, height)) { }
public void Draw(Box2 rectangle, Sprite sprite, Color4ub color) { Draw(rectangle, sprite.Texture, sprite.TextureCoordinates0, sprite.TextureCoordinates1, color); }
/// <inheritdoc /> public bool AnyEntitiesIntersecting(MapId mapId, Box2 box) => _entityTreesPerMap[mapId].Query(box).Any(ent => !ent.Deleted);
/// <inheritdoc /> public IEnumerable <IEntity> GetEntitiesInRange(MapId mapId, Vector2 point, float range) { var aabb = new Box2(point, point).Enlarged(range); return(GetEntitiesIntersecting(mapId, aabb)); }
public static void Draw(DrawContext drawContext, Camera camera, Box2 bounds, float opacity, Project project, OsbSprite sprite) { var time = project.DisplayTime * 1000; if (sprite.TexturePath == null || !sprite.IsActive(time)) { return; } var fade = sprite.OpacityAt(time); if (fade < 0.00001f) { return; } var scale = (Vector2)sprite.ScaleAt(time); if (scale.X == 0 || scale.Y == 0) { return; } if (sprite.FlipHAt(time)) { scale.X = -scale.X; } if (sprite.FlipVAt(time)) { scale.Y = -scale.Y; } var fullPath = Path.Combine(project.MapsetPath, sprite.GetTexturePathAt(time)); Texture2dRegion texture = null; try { texture = project.TextureContainer.Get(fullPath); } catch (IOException) { // Happens when another process is writing to the file, will try again later. return; } if (texture == null) { return; } var position = sprite.PositionAt(time); var rotation = sprite.RotationAt(time); var color = sprite.ColorAt(time); var finalColor = ((Color4)color).WithOpacity(opacity * fade); var additive = sprite.AdditiveAt(time); Vector2 origin; switch (sprite.Origin) { default: case OsbOrigin.TopLeft: origin = new Vector2(0, 0); break; case OsbOrigin.TopCentre: origin = new Vector2(texture.Width * 0.5f, 0); break; case OsbOrigin.TopRight: origin = new Vector2(texture.Width, 0); break; case OsbOrigin.CentreLeft: origin = new Vector2(0, texture.Height * 0.5f); break; case OsbOrigin.Centre: origin = new Vector2(texture.Width * 0.5f, texture.Height * 0.5f); break; case OsbOrigin.CentreRight: origin = new Vector2(texture.Width, texture.Height * 0.5f); break; case OsbOrigin.BottomLeft: origin = new Vector2(0, texture.Height); break; case OsbOrigin.BottomCentre: origin = new Vector2(texture.Width * 0.5f, texture.Height); break; case OsbOrigin.BottomRight: origin = new Vector2(texture.Width, texture.Height); break; } var boundsScaling = bounds.Height / 480; DrawState.Prepare(drawContext.Get <SpriteRenderer>(), camera, additive ? AdditiveStates : AlphaBlendStates) .Draw(texture, bounds.Left + bounds.Width * 0.5f + (position.X - 320) * boundsScaling, bounds.Top + position.Y * boundsScaling, origin.X, origin.Y, scale.X * boundsScaling, scale.Y * boundsScaling, rotation, finalColor); }
private bool CheckPeek(Coordinate2D peek, Box2 gridBox) { if (peek.X > gridBox.MinCoordinate.X && peek.X < gridBox.MaxCoordinate.X && peek.Y > gridBox.MinCoordinate.Y && peek.Y < gridBox.MaxCoordinate.Y) return true; else return false; }
/// <summary> /// Constructs a new state snapshot of a PhysicsComponent. /// </summary> /// <param name="aabb">Current AABB of the entity.</param> public BoundingBoxComponentState(Box2 aabb) : base(NetIDs.BOUNDING_BOX) { AABB = aabb; }
public void Draw(DrawContext drawContext, Camera camera, Box2 bounds, float opacity, Project project) => Draw(drawContext, camera, bounds, opacity, project, this);
public static void DrawSquare(this LineRenderer line, Box2 box, Color4 color) => line.DrawSquare(new Vector3(box.Left, box.Top, 0), new Vector3(box.Right, box.Bottom, 0), color);
/// <summary> /// Actually renders the scene. /// <param name="scene">The scene that should be rendered.</param> /// <param name="camera">The camera setting for the scene.</param> /// </summary> protected override void Render(Scene scene, Camera camera) { if (scene == null) { throw new ArgumentNullException("scene"); } if (camera == null) { throw new ArgumentNullException("camera"); } var renderTarget = FrameBuffer.Current; Viewport.Push(); Viewport.Area = new Box2i(0, 0, this.Width, this.Height); GL.Enable(EnableCap.TextureCubeMap); GL.Enable(EnableCap.TextureCubeMapSeamless); //RenderLightMaps(ref camera, ref projection, out shadowMatrix, args); RenderGeometry(camera); RenderLights(camera); RenderOpaque(camera); //RenderTranslucent(ref camera, ref projection, args); var sunView = camera.ViewMatrix; sunView.M41 = 0; sunView.M42 = 0; sunView.M43 = 0; Vector3 sunPosition = this.Sky.GetSunDirection() * 1000.0f; var projPos = Vector4.Transform(new Vector4(sunPosition, 1), sunView * camera.ProjectionMatrix); this.lightScatteringShader.LightPosition = new Vector2(0.5f, 0.5f) + 0.5f * (projPos.Xy * (1.0f / projPos.W)); //this.lightScattering.Enabled = false;// Math.Abs(this.lightScatteringShader.LightPosition.X) < 2.0f && Math.Abs(this.lightScatteringShader.LightPosition.Y) < 2.0f && projPos.Z > 0.0f; FrameBuffer.Current = renderTarget; Viewport.Pop(); GL.Disable(EnableCap.Blend); GL.Disable(EnableCap.DepthTest); GL.Enable(EnableCap.CullFace); var target = new Box2(0, 0, Game.Current.Width, Game.Current.Height); Texture2D result = this.sceneBuffer; result = this.preBloomStages.Render(result); // After prebloom, set shader variable this.bloomCombineShader.OriginalMap = result; result = this.bloomStages.Render(result); result = this.postBloomStages.Render(result); if (!Game.Current.Input.Keyboard[OpenTK.Input.Key.ShiftLeft]) { if (Game.Current.Input.Keyboard[OpenTK.Input.Key.Number1]) { result = this.NormalBuffer; } else if (Game.Current.Input.Keyboard[OpenTK.Input.Key.Number2]) { result = this.DiffuseLightBuffer; } else if (Game.Current.Input.Keyboard[OpenTK.Input.Key.Number3]) { result = this.SpecularLightBuffer; } else if (Game.Current.Input.Keyboard[OpenTK.Input.Key.Number4]) { result = this.PositionBuffer; } } else { if (Game.Current.Input.Keyboard[OpenTK.Input.Key.Number1]) { result = this.preBloomStages.FinalTexture; } else if (Game.Current.Input.Keyboard[OpenTK.Input.Key.Number2]) { result = this.bloomStages.FinalTexture; } else if (Game.Current.Input.Keyboard[OpenTK.Input.Key.Number3]) { result = this.postBloomStages.FinalTexture; } } Game.Current.Utilities.Draw(target, result, true); }
private Box2 Combine(Box2 first, Box2 second) { return(new Box2(Math.Min(first.Left, second.Left), Math.Max(first.Top, second.Top), Math.Max(first.Right, second.Right), Math.Min(first.Bottom, second.Bottom))); }
private void _drawGrids(Box2 worldBounds) { var mapId = _eyeManager.CurrentMap; if (!_mapManager.MapExists(mapId)) { // fall back to the default eye's map _eyeManager.CurrentEye = null; mapId = _eyeManager.CurrentMap; } var atlasTexture = _tileDefinitionManager.TileTextureAtlas; var loadedTex = _loadedTextures[((ClydeTexture)atlasTexture).TextureId]; GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, loadedTex.OpenGLObject.Handle); GL.ActiveTexture(TextureUnit.Texture1); if (_lightingReady) { var lightTexture = _loadedTextures[LightRenderTarget.Texture.TextureId].OpenGLObject; GL.BindTexture(TextureTarget.Texture2D, lightTexture.Handle); } else { var white = _loadedTextures[_stockTextureWhite.TextureId].OpenGLObject; GL.BindTexture(TextureTarget.Texture2D, white.Handle); } var instance = _shaderInstances[_defaultShader.Handle]; var gridProgram = _loadedShaders[instance.ShaderHandle].Program; gridProgram.Use(); gridProgram.SetUniformTextureMaybe(UniIMainTexture, TextureUnit.Texture0); gridProgram.SetUniformTextureMaybe(UniILightTexture, TextureUnit.Texture1); gridProgram.SetUniform(UniIModUV, new Vector4(0, 0, 1, 1)); gridProgram.SetUniform(UniIModulate, Color.White); foreach (var mapGrid in _mapManager.FindGridsIntersecting(mapId, worldBounds)) { var grid = (IMapGridInternal)mapGrid; if (!_mapChunkData.ContainsKey(grid.Index)) { continue; } var model = Matrix3.Identity; model.R0C2 = grid.WorldPosition.X; model.R1C2 = grid.WorldPosition.Y; gridProgram.SetUniform(UniIModelMatrix, model); foreach (var(_, chunk) in grid.GetMapChunks()) { // Calc world bounds for chunk. if (!chunk.CalcWorldBounds().Intersects(worldBounds)) { continue; } if (_isChunkDirty(grid, chunk)) { _updateChunkMesh(grid, chunk); } var datum = _mapChunkData[grid.Index][chunk.Indices]; if (datum.TileCount == 0) { continue; } GL.BindVertexArray(datum.VAO); datum.EBO.Use(); datum.VBO.Use(); _debugStats.LastGLDrawCalls += 1; GL.DrawElements(BeginMode.TriangleStrip, datum.TileCount * 5, DrawElementsType.UnsignedShort, 0); } } }
/// <summary> /// returns true if collider intersects a physBody under management. /// </summary> /// <param name="collider">Rectangle to check for collision</param> /// <param name="map">Map ID to filter</param> /// <returns></returns> public bool TryCollideRect(Box2 collider, MapId map) { var state = (collider, map, found : false); this[map].QueryAabb(ref state, (ref (Box2 collider, MapId map, bool found)state, in IPhysBody body) =>
public RasterPatch2 GetTilePatch(PointSet pointSet, Box2 regionBox, double iconSize) { GeoRect tileBox = new GeoRect( regionBox.MinCoordinate.X, regionBox.MinCoordinate.Y, regionBox.MaxCoordinate.X - regionBox.MinCoordinate.X, regionBox.MaxCoordinate.Y - regionBox.MinCoordinate.Y); int width = 256; int height = 256; Bitmap resultBitmap = new Bitmap(width, height); Graphics graphics = Graphics.FromImage(resultBitmap); double minT = 0, maxT = 0, k; if (!Double.IsNaN(pointSet.MaxValue)) { minT = pointSet.MinValue; maxT = pointSet.MaxValue; k = 1.0 / (maxT - minT); } else k = Double.NaN; ColorMatrix colorMatrix = new ColorMatrix(); ImageAttributes imageAttributes = new ImageAttributes(); for (int i = 0; i < pointSet.Data.Count; i++) { GeoRect workingRect = new GeoRect( pointSet.Data[i].Longitude - iconSize / 2.0, pointSet.Data[i].Latitude - iconSize / 2.0, iconSize, iconSize); if (GeoRect.IntersectionExist(workingRect, tileBox)) { int x0 = (int)(Math.Min(width, Math.Max(0, pointSet.Data[i].Longitude - iconSize / 2.0 - tileBox.Left) / tileBox.Width * width)); int y0 = (int)(Math.Min(height, Math.Max(0, tileBox.Top - pointSet.Data[i].Latitude - iconSize / 2.0) / tileBox.Height * height)); int x1 = (int)(Math.Min(width, Math.Max(0, pointSet.Data[i].Longitude + iconSize / 2.0 - tileBox.Left) / tileBox.Width * width)); int y1 = (int)(Math.Min(height, Math.Max(0, tileBox.Top - pointSet.Data[i].Latitude + iconSize / 2.0) / tileBox.Height * height)); double widthX = Math.Min(tileBox.Width, iconSize); double heightY = Math.Min(tileBox.Height, iconSize); lock (icon) { System.Windows.Media.Color tempColor = System.Windows.Media.Brushes.Red.Color; if (!Double.IsNaN(k)) { double hue = 270 * ((maxT - (double)pointSet.Data[i].Value) * k); tempColor = new HsbColor(hue, 1, 1, 0.8).ToArgb(); } colorMatrix.Matrix00 = (float)tempColor.R / 255f; colorMatrix.Matrix11 = (float)tempColor.G / 255f; colorMatrix.Matrix22 = (float)tempColor.B / 255f; imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); int x2 = 0; if (pointSet.Data[i].Longitude - iconSize / 2.0 < tileBox.Left) { x2 = icon.Width - (int)((double)(x1 - x0) * icon.Width / (widthX / tileBox.Width * width)); } int y2 = 0; if (tileBox.Top - pointSet.Data[i].Latitude - iconSize / 2.0 < 0) { y2 = icon.Height - (int)((double)(y1 - y0) * icon.Height / (heightY / tileBox.Height * height)); } graphics.DrawImage( icon, new Rectangle(x0, y0, x1 - x0, y1 - y0), x2, y2, (int)((double)(x1 - x0) * icon.Width / (widthX / tileBox.Width * width)), (int)((double)(y1 - y0) * icon.Height / (heightY / tileBox.Height * height)), GraphicsUnit.Pixel, imageAttributes); } } } return new RasterPatch2( regionBox, resultBitmap, Wgs84CoordinateReferenceSystem.Instance); }
private void PlaceNewTile(ushort tileType, MapId mapId, Vector2 position) { // tile can snap up to 0.75m away from grid var gridSearchBox = new Box2(-0.5f, -0.5f, 0.5f, 0.5f) .Scale(1.5f) .Translated(position); var gridsInArea = _mapManager.FindGridsIntersecting(mapId, gridSearchBox); IMapGrid closest = null; float distance = float.PositiveInfinity; Box2 intersect = new Box2(); foreach (var grid in gridsInArea) { // figure out closest intersect var gridIntersect = gridSearchBox.Intersect(grid.WorldBounds); var gridDist = (gridIntersect.Center - position).LengthSquared; if (gridDist >= distance) { continue; } distance = gridDist; closest = grid; intersect = gridIntersect; } if (closest != null) // stick to existing grid { // round to nearest cardinal dir var normal = new Angle(position - intersect.Center).GetCardinalDir().ToVec(); // round coords to center of tile var tileIndices = closest.WorldToTile(intersect.Center); var tileCenterWorld = closest.GridTileToWorldPos(tileIndices); // move mouse one tile out along normal var newTilePos = tileCenterWorld + normal * closest.TileSize; // you can always remove a tile if (Tile.Empty.TypeId != tileType) { var tileBounds = Box2.UnitCentered.Scale(closest.TileSize).Translated(newTilePos); var collideCount = _mapManager.FindGridsIntersecting(mapId, tileBounds).Count(); // prevent placing a tile if it overlaps more than one grid if (collideCount > 1) { return; } } var pos = closest.WorldToTile(position); closest.SetTile(pos, new Tile(tileType)); } else // create a new grid { var newGrid = _mapManager.CreateGrid(mapId); newGrid.WorldPosition = position + (newGrid.TileSize / 2f); // assume bottom left tile origin var tilePos = newGrid.WorldToTile(position); newGrid.SetTile(tilePos, new Tile(tileType)); } }
public void Draw(DrawContext drawContext, Camera camera, Box2 bounds, float opacity) { if (Texture == null) { return; } var width = bounds.Width + Outset.Horizontal; var height = bounds.Height + Outset.Vertical; var x0 = bounds.Left - Outset.Left; var y0 = bounds.Top - Outset.Top; var x1 = x0 + Borders.Left; var y1 = y0 + Borders.Top; var x2 = bounds.Right + Outset.Right - (Texture.Width - Borders.Right); var y2 = bounds.Bottom + Outset.Bottom - (Texture.Height - Borders.Bottom); var horizontalScale = (x2 - x1) / (Borders.Right - Borders.Left); var verticalScale = (y2 - y1) / (Borders.Bottom - Borders.Top); var color = Color.WithOpacity(opacity); var renderer = DrawState.Prepare(drawContext.Get <SpriteRenderer>(), camera, RenderStates); // Center if (!BordersOnly && horizontalScale > 0 && verticalScale > 0) { renderer.Draw(Texture, x1, y1, 0, 0, horizontalScale, verticalScale, 0, color, Borders.Left, Borders.Top, Borders.Right, Borders.Bottom); } // Sides if (verticalScale > 0) { renderer.Draw(Texture, x0, y1, 0, 0, 1, verticalScale, 0, color, 0, Borders.Top, Borders.Left, Borders.Bottom); renderer.Draw(Texture, x2, y1, 0, 0, 1, verticalScale, 0, color, Borders.Right, Borders.Top, Texture.Width, Borders.Bottom); } if (horizontalScale > 0) { renderer.Draw(Texture, x1, y0, 0, 0, horizontalScale, 1, 0, color, Borders.Left, 0, Borders.Right, Borders.Top); renderer.Draw(Texture, x1, y2, 0, 0, horizontalScale, 1, 0, color, Borders.Left, Borders.Bottom, Borders.Right, Texture.Height); } // Corners renderer.Draw(Texture, x0, y0, 0, 0, 1, 1, 0, color, 0, 0, Borders.Left, Borders.Top); renderer.Draw(Texture, x2, y0, 0, 0, 1, 1, 0, color, Borders.Right, 0, Texture.Width, Borders.Top); renderer.Draw(Texture, x0, y2, 0, 0, 1, 1, 0, color, 0, Borders.Bottom, Borders.Left, Texture.Height); renderer.Draw(Texture, x2, y2, 0, 0, 1, 1, 0, color, Borders.Right, Borders.Bottom, Texture.Width, Texture.Height); }
/// <inheritdoc /> public IEnumerable <IEntity> GetEntitiesInRange(MapId mapId, Box2 box, float range) { var aabb = box.Enlarged(range); return(GetEntitiesIntersecting(mapId, aabb)); }
private void _drawGrids(Box2 worldBounds) { var mapId = _eyeManager.CurrentMap; if (!_mapManager.MapExists(mapId)) { // fall back to the default eye's map _eyeManager.ClearCurrentEye(); mapId = _eyeManager.CurrentMap; } SetTexture(TextureUnit.Texture0, _tileDefinitionManager.TileTextureAtlas); SetTexture(TextureUnit.Texture1, _lightingReady ? _currentViewport !.LightRenderTarget.Texture : _stockTextureWhite); var(gridProgram, _) = ActivateShaderInstance(_defaultShader.Handle); gridProgram.SetUniformTextureMaybe(UniIMainTexture, TextureUnit.Texture0); gridProgram.SetUniformTextureMaybe(UniILightTexture, TextureUnit.Texture1); gridProgram.SetUniform(UniIModUV, new Vector4(0, 0, 1, 1)); gridProgram.SetUniform(UniIModulate, Color.White); var compMan = _entityManager.ComponentManager; foreach (var mapGrid in _mapManager.FindGridsIntersecting(mapId, worldBounds)) { var grid = (IMapGridInternal)mapGrid; if (!_mapChunkData.ContainsKey(grid.Index)) { continue; } var transform = compMan.GetComponent <ITransformComponent>(grid.GridEntityId); gridProgram.SetUniform(UniIModelMatrix, transform.WorldMatrix); foreach (var(_, chunk) in grid.GetMapChunks()) { // Calc world bounds for chunk. if (!chunk.CalcWorldBounds().Intersects(in worldBounds)) { continue; } if (_isChunkDirty(grid, chunk)) { _updateChunkMesh(grid, chunk); } var datum = _mapChunkData[grid.Index][chunk.Indices]; if (datum.TileCount == 0) { continue; } GL.BindVertexArray(datum.VAO); _debugStats.LastGLDrawCalls += 1; GL.DrawElements(BeginMode.TriangleStrip, datum.TileCount * 5, DrawElementsType.UnsignedShort, 0); } } }
public void Draw(DrawContext drawContext, Camera camera, Box2 bounds, float opacity) { effectUpdateQueue.Enabled = true; layerManager.Draw(drawContext, camera, bounds, opacity); }
public QuadNode(Box2 bounds) { Bounds = bounds; Nodes = new ReadOnlyCollection <QuadNode>(_nodes); Objects = new ReadOnlyCollection <T>(quadObjects); }
public IEnumerable <IEntity> GetEntitiesInRange(GridLocalCoordinates position, float Range) { var AABB = new Box2(position.Position - new Vector2(Range / 2, Range / 2), position.Position + new Vector2(Range / 2, Range / 2)); return(GetEntitiesIntersecting(position.MapID, AABB)); }
public void Draw(Box2 rectangle, Sprite sprite) { Draw(rectangle, sprite.Texture, sprite.TextureCoordinates0, sprite.TextureCoordinates1, new Color4ub(0xFF, 0xFF, 0xFF, 0xFF)); }
/// <inheritdoc /> public IEnumerable <IEntity> GetEntitiesInRange(GridCoordinates position, float range) { var aabb = new Box2(position.Position - new Vector2(range / 2, range / 2), position.Position + new Vector2(range / 2, range / 2)); return(GetEntitiesIntersecting(_mapManager.GetGrid(position.GridID).ParentMapId, aabb)); }
public void Draw(Box2 rectangle, Texture2D texture, Vector2 textureCoordinates0, Vector2 textureCoordinates1) { Draw(rectangle, texture, textureCoordinates0, textureCoordinates1, new Color4ub(0xFF, 0xFF, 0xFF, 0xFF)); }
public void Draw(Box2 rectangle, Color4ub color) { if (m_queueSize == m_queueCapacity) { Flush(); } m_queue[m_queueSize++] = new QuadData() { Transform = new Matrix3x2( m_transform.M00 * rectangle.Size.X, m_transform.M01 * rectangle.Size.X, m_transform.M10 * rectangle.Size.Y, m_transform.M11 * rectangle.Size.Y, m_transform.M00 * rectangle.Position.X + m_transform.M10 * rectangle.Position.Y + m_transform.M20, m_transform.M01 * rectangle.Position.X + m_transform.M11 * rectangle.Position.Y + m_transform.M21 ), Color = color, Texture = -1 }; }
public Texture2d(int textureId, int width, int height, string description) : base(null, Box2.FromTLRB(0, 0, width, height), description) { this.textureId = textureId; }
public bool Intersects(Box2 other) => Intersects(new OrientedBoundingBox(new Vector2(other.Left, other.Top), Vector2.Zero, other.Width, other.Height, 0));
public IList <IEntity> GetEntitiesUnderPosition(MapCoordinates coordinates) { // Find all the entities intersecting our click var entities = IoCManager.Resolve <IEntityLookup>().GetEntitiesIntersecting(coordinates.MapId, Box2.CenteredAround(coordinates.Position, (1, 1))); // Check the entities against whether or not we can click them var foundEntities = new List <(IEntity clicked, int drawDepth, uint renderOrder)>(); foreach (var entity in entities) { if (entity.TryGetComponent <ClickableComponent>(out var component) && entity.Transform.IsMapTransform && component.CheckClick(coordinates.Position, out var drawDepthClicked, out var renderOrder)) { foundEntities.Add((entity, drawDepthClicked, renderOrder)); } } if (foundEntities.Count == 0) { return(new List <IEntity>()); } foundEntities.Sort(new ClickableEntityComparer()); // 0 is the top element. foundEntities.Reverse(); return(foundEntities.Select(a => a.clicked).ToList()); }
public FixtureProxy(Box2 aabb, Fixture fixture, int childIndex) { AABB = aabb; Fixture = fixture; ChildIndex = childIndex; }
/// <summary> /// Converts a OpenTK Box2 to a SFML FloatRect. /// </summary> /// <param name="box">OpenTK Box2.</param> /// <returns>SFML FloatRect.</returns> public static FloatRect Convert(this Box2 box) { return(new FloatRect(box.Left, box.Top, box.Width, box.Height)); }
public RasterPatch2 GetTilePatch(IDataSource2D<double> field, Box2 regionBox, double iconSize) { System.Windows.Point[,] grid = field.Grid; Coordinate2D minCoordinate = new Coordinate2D(grid[0, 0].X, grid[0, 0].Y); Coordinate2D maxCoordinate = new Coordinate2D(grid[field.Width - 1, field.Height - 1].X, grid[field.Width - 1, field.Height - 1].Y); for (int j = 0; j < field.Height; j++) { for (int i = 0; i < field.Width; i++) { if (grid[i, j].X < minCoordinate.X) minCoordinate.X = grid[i, j].X; if (grid[i, j].X > maxCoordinate.X) maxCoordinate.X = grid[i, j].X; if (grid[i, j].Y < minCoordinate.Y) minCoordinate.Y = grid[i, j].Y; if (grid[i, j].Y > maxCoordinate.Y) maxCoordinate.Y = grid[i, j].Y; } } GeoRect gridBox = new GeoRect( minCoordinate.X, minCoordinate.Y, maxCoordinate.X - minCoordinate.X, maxCoordinate.Y - minCoordinate.Y); GeoRect tileBox = new GeoRect( regionBox.MinCoordinate.X, regionBox.MinCoordinate.Y, regionBox.MaxCoordinate.X - regionBox.MinCoordinate.X, regionBox.MaxCoordinate.Y - regionBox.MinCoordinate.Y); GeoRect intersectionRect = GeoRect.Intersect(gridBox, tileBox); if (intersectionRect != null) { int width = 256; int height = 256; Bitmap resultBitmap = new Bitmap(width, height); Graphics graphics = Graphics.FromImage(resultBitmap); for (int i = 0; i < field.Width; i++) { for (int j = 0; j < field.Height; j++) { GeoRect workingRect = new GeoRect( field.Grid[i, j].X - iconSize / 2.0, field.Grid[i, j].Y - iconSize / 2.0, iconSize, iconSize); if (GeoRect.IntersectionExist(workingRect, intersectionRect)) { int x0 = (int)(Math.Min(width, Math.Max(0, field.Grid[i, j].X - iconSize / 2.0 - tileBox.Left) / tileBox.Width * width)); int y0 = (int)(Math.Min(height, Math.Max(0, tileBox.Top - field.Grid[i, j].Y - iconSize / 2.0) / tileBox.Height * height)); int x1 = (int)(Math.Min(width, Math.Max(0, field.Grid[i, j].X + iconSize / 2.0 - tileBox.Left) / tileBox.Width * width)); int y1 = (int)(Math.Min(height, Math.Max(0, tileBox.Top - field.Grid[i, j].Y + iconSize / 2.0) / tileBox.Height * height)); double widthX = Math.Min(tileBox.Width, iconSize); double heightY = Math.Min(tileBox.Height, iconSize); lock (icon) { int x2 = 0; if (field.Grid[i, j].X - iconSize / 2.0 < tileBox.Left) { x2 = icon.Width - (int)((double)(x1 - x0) * icon.Width / (widthX / tileBox.Width * width)); } int y2 = 0; if (tileBox.Top - field.Grid[i, j].Y - iconSize / 2.0 < 0) { y2 = icon.Height - (int)((double)(y1 - y0) * icon.Height / (heightY / tileBox.Height * height)); } graphics.DrawImage( icon, new Rectangle(x0, y0, x1 - x0, y1 - y0), x2, y2, (int)((double)(x1 - x0) * icon.Width / (widthX / tileBox.Width * width)), (int)((double)(y1 - y0) * icon.Height / (heightY / tileBox.Height * height)), GraphicsUnit.Pixel); } } } } return new RasterPatch2( regionBox, resultBitmap, Wgs84CoordinateReferenceSystem.Instance); } else { return null; } }
public override bool Update(ScreenCoordinates mouseS) { if (mouseS.MapID == MapId.Nullspace) { return(false); } MouseScreen = mouseS; MouseCoords = CluwneLib.ScreenToCoordinates(MouseScreen); if (pManager.CurrentPermission.IsTile) { return(false); } CurrentTile = MouseCoords.Grid.GetTile(MouseCoords); if (!RangeCheck()) { return(false); } var manager = IoCManager.Resolve <IClientEntityManager>(); var snapToEntities = manager.GetEntitiesInRange(MouseCoords, SnapToRange) .Where(entity => entity.Prototype == pManager.CurrentPrototype && entity.GetComponent <ITransformComponent>().MapID == MouseCoords.MapID) .OrderBy(entity => (entity.GetComponent <ITransformComponent>().WorldPosition - MouseCoords.ToWorld().Position).LengthSquared) .ToList(); if (snapToEntities.Any()) { var closestEntity = snapToEntities.First(); if (closestEntity.TryGetComponent <ISpriteRenderableComponent>(out var component)) { var closestSprite = component.GetCurrentSprite(); var closestBounds = closestSprite.LocalBounds; var closestRect = Box2.FromDimensions( closestEntity.GetComponent <ITransformComponent>().WorldPosition.X - closestBounds.Width / 2f, closestEntity.GetComponent <ITransformComponent>().WorldPosition.Y - closestBounds.Height / 2f, closestBounds.Width, closestBounds.Height); var sides = new[] { new Vector2(closestRect.Left + closestRect.Width / 2f, closestRect.Top - closestBounds.Height / 2f), new Vector2(closestRect.Left + closestRect.Width / 2f, closestRect.Bottom + closestBounds.Height / 2f), new Vector2(closestRect.Left - closestBounds.Width / 2f, closestRect.Top + closestRect.Height / 2f), new Vector2(closestRect.Right + closestBounds.Width / 2f, closestRect.Top + closestRect.Height / 2f) }; var closestSide = (from Vector2 side in sides orderby(side - MouseCoords.Position).LengthSquared select side).First(); MouseCoords = new LocalCoordinates(closestSide, MouseCoords.Grid); MouseScreen = CluwneLib.WorldToScreen(MouseCoords); } } if (CheckCollision()) { return(false); } return(true); }
/// <inheritdoc /> public IEnumerable <IEntity> GetEntitiesInRange(MapId mapId, Box2 box, float range) { var aabb = new Box2(box.Left - range, box.Top - range, box.Right + range, box.Bottom + range); return(GetEntitiesIntersecting(mapId, aabb)); }
static Box2 ConstrainSize(View view, Box2 box) => Box2.FromCornerSize(box.TopLeft, ConstrainSize(view, box.Size));
public static List<Vector2> Intersect(Box2 b1, Box2 b2) { var intersections = new List<Vector2>(); return intersections; }
/// <summary> /// Removes padding from a supplied <see cref="Box2" /> and returns the <see cref="Box2" /> /// not including the padding. /// </summary> /// <param name="box">The <see cref="Box2" /> value to remove padding from.</param> /// <returns>The newly created <see cref="Box2" /> value that does not include padding. /// </returns> public Box2 Unpad(Box2 box) => new Box2( box.Min + new Vector2(Left, Top), box.Max - new Vector2(Right, Bottom) );
private void OnValidate() { LandBounds = new Box2(-LandSize / 2, LandSize / 2, LandSize / 2, -LandSize / 2); }
public static void GetFloatv(uint pname, out Box2 data) { m_GetFloatv_8(pname, out data); if(m_debug) CheckError("GetFloatv"); }