示例#1
0
        void ResizeSurface()
        {
            Math.Rectangle newBounds = surface.Bounds;
            SurfaceSize   = newBounds.Size;
            SurfaceBounds = newBounds;

            deviceContext.OutputMerger.ResetTargets();
            swapChain.ResizeBuffers(0, (int)newBounds.Width, (int)newBounds.Height, DXGI.Format.R8G8B8A8_UNorm, DXGI.SwapChainFlags.None);
            deviceContext.Rasterizer.SetViewport(0, 0, newBounds.Width, newBounds.Height);

            viewMatrix  = Matrix.Transpose(Matrix.Scaling(2f / newBounds.Width, -2f / newBounds.Height, 1));
            viewMatrix *= Matrix.Transpose(Matrix.Translation(-newBounds.Width / 2f, -newBounds.Height / 2f, 0));
            UpdateMatrixBuffer();

            depthStencilView?.Dispose();
            depthStencilBuffer?.Dispose();
            surfaceTarget?.Dispose();
            surfaceView?.Dispose();
            surfaceTexture?.Dispose();

            depthStencilBuffer = device.CreateDepthStencilBuffer((int)newBounds.Width, (int)newBounds.Height, sampleDescription, out depthStencilView);
            surfaceTexture     = device.CreateSurface((int)newBounds.Width, (int)newBounds.Height, sampleDescription, out surfaceTarget);
            deviceContext.OutputMerger.SetTargets(depthStencilView, surfaceTarget);
            surfaceView = new D3D11.ShaderResourceView(device, surfaceTexture);
        }
示例#2
0
 /// <summary>
 /// Populates a list of all the objects within a certain range of a position.
 /// </summary>
 /// <param name="rect">A collision rectangle to check against.</param>
 /// <param name="candidates">A list of all possible candidates source might be colliding with.</param>
 /// <param name="refObjects">A preallocated list of objects.  This is to avoid GC.</param>
 private void GetGameObjectsInRange(Math.Rectangle rect, List <GameObject> candidates, ref List <GameObject> refObjects)
 {
     for (int i = 0; i < mGameObjects.Count; i++)
     {
         if (rect.Intersects(mGameObjects[i].pCollisionRect))
         {
             refObjects.Add(mGameObjects[i]);
         }
     }
 }
        public void AddAABB(Math.Rectangle box, Color color, Boolean isSolid = true)
        {
            Vector2[] verts = new Vector2[8];
            verts[0] = new Vector2(box.pLeft, box.pBottom);
            verts[1] = new Vector2(box.pLeft, box.pTop);
            verts[2] = new Vector2(box.pRight, box.pTop);
            verts[3] = new Vector2(box.pRight, box.pBottom);

            if (isSolid)
            {
                AddSolidPolygon(verts, 4, color);
            }
            else
            {
                AddPolygon(verts, 4, color);
            }
        }
示例#4
0
        /// <summary>
        /// Populates a list of all the objects within a certain range of a position.
        /// </summary>
        /// <param name="rect">A collision rectangle to check against.</param>
        /// <param name="refObjects">A preallocated list of objects.  This is to avoid GC.</param>
        public void GetGameObjectsInRange(Math.Rectangle rect, ref List <GameObject> refObjects)
        {
            // Calculate which cell the source object is in. We only need to test collision
            // against objects in that cell.
            // TODO: The should likely include surrounding cells.
            Vector2 index = CellIndexFromPosition(rect.pCenterPoint);

            // Loop through the cell we are in and the surround cells for safety.
            for (Int32 y = (Int32)index.Y - 1; y <= (Int32)index.Y + 1; y++)
            {
                for (Int32 x = (Int32)index.X - 1; x <= (Int32)index.X + 1; x++)
                {
                    // It is possible this object is outside of the world.
                    if (IsValidCellIndex(x, y))
                    {
                        GetGameObjectsInRange(rect, mStaticGameObjects[x, y], ref refObjects);
                    }
                }
            }

            GetGameObjectsInRange(rect, mDynamicGameObjects, ref refObjects);
        }
 public static System.Drawing.Rectangle ToSystemRectangle(this Math.Rectangle rectangle)
 {
     return(new System.Drawing.Rectangle(rectangle.MinPoint.ToSystemPoint(), rectangle.Size.ToSystemSize()));
 }
 public RectangleView(Math.Rectangle rectangle, Color color)
 {
     Rectangle = rectangle;
     Color     = color;
 }
示例#7
0
 /// <summary>
 /// Converts the Rectangle.
 /// </summary>
 /// <param name="rectangle">The Rectangle.</param>
 /// <returns>Rectangle.</returns>
 internal static Rectangle ConvertRectangle(Math.Rectangle rectangle)
 {
     return(new Rectangle((int)rectangle.X, (int)rectangle.Y, (int)rectangle.Width, (int)rectangle.Height));
 }
示例#8
0
 /// <summary>
 /// Converts the Rectangle.
 /// </summary>
 /// <param name="rectangle">The Rectangle.</param>
 /// <returns>Rectangle.</returns>
 internal static RectangleF ConvertRectangleF(Math.Rectangle rectangle)
 {
     return(new RectangleF(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height));
 }
示例#9
0
 /// <summary>
 /// Converts a Rectangle into a WinRectangle.
 /// </summary>
 /// <param name="rectangle">The Rectangle.</param>
 /// <returns>Rectangle.</returns>
 public static Rectangle ConvertToWinRectangle(Math.Rectangle rectangle)
 {
     return(new Rectangle((int)rectangle.X, (int)rectangle.Y, (int)rectangle.Width,
                          (int)rectangle.Height));
 }