IntersectsWith() public method

public IntersectsWith ( RectangleD other ) : bool
other RectangleD
return bool
Example #1
0
        public void RenderGdi(Graphics graphics, RectangleD cameraBounds)
        {
            // Update position and rotation given the parent's motion
            double currentRotation = (_parent.Pitch - _initialRotation) + _rotationOffset;

            DVector2 rotationNormal = DVector2.FromAngle(currentRotation);

            Position = _parent.Position + rotationNormal * _initialDistance;

            var bounds = new RectangleD(Position.X - Width * 0.5, Position.Y - Height * 0.5, Width, Height);

            // Not in range easy return
            if (!cameraBounds.IntersectsWith(bounds))
            {
                return;
            }

            RectangleF screenBounds = RenderUtils.ComputeBoundingBox(Position, cameraBounds, Width, Height);

            // Saftey
            if (screenBounds.Width > RenderUtils.ScreenWidth * 500) return;

            double drawingRotation = currentRotation + Math.PI * 0.5;

            var offset = new PointF(screenBounds.X + screenBounds.Width * 0.5f,
                                    screenBounds.Y + screenBounds.Height * 0.5f);

            graphics.TranslateTransform(offset.X, offset.Y);

            graphics.RotateTransform((float)(drawingRotation * 180 / Math.PI));

            graphics.TranslateTransform(-offset.X, -offset.Y);

            graphics.DrawImage(_texture, screenBounds.X, screenBounds.Y, screenBounds.Width, screenBounds.Height);

            graphics.ResetTransform();

            double visibility = Visibility(cameraBounds);

            if (visibility < 1)
            {
                PointF iconPoint = RenderUtils.WorldToScreen(Position, cameraBounds);

                var iconBounds = new RectangleF(iconPoint.X - 5, iconPoint.Y - 5, 10, 10);

                var iconColor = Color.FromArgb((int)((1 - visibility) * 255), IconColor.R, IconColor.G, IconColor.B);

                graphics.FillEllipse(new SolidBrush(iconColor), iconBounds);
            }
        }
Example #2
0
        public void RenderGdiFallback(Graphics graphics, RectangleD cameraBounds, IPhysicsBody sun)
        {
            RectangleD bounds = ComputeBoundingBox();

            // Not in range easy return
            if (!cameraBounds.IntersectsWith(bounds))
            {
                return;
            }

            if (AtmosphereHeight > 0)
            {
                RectangleF atmosphereBounds = RenderUtils.ComputeEllipseSize(Position, cameraBounds, BoundingRadius);

                // Saftey
                if (atmosphereBounds.Width > RenderUtils.ScreenWidth * 5000) return;

                graphics.FillEllipse(new SolidBrush(IconAtmopshereColor), atmosphereBounds);
            }

            RectangleF surfaceBounds = RenderUtils.ComputeEllipseSize(Position, cameraBounds, SurfaceRadius);

            // Saftey
            if (surfaceBounds.Width > RenderUtils.ScreenWidth * 5000) return;

            graphics.FillEllipse(new SolidBrush(IconColor), surfaceBounds);
        }
Example #3
0
        /// <summary>
        /// Renders the space craft at it's correct scale and rotation according to the camera.
        /// The engines are rendered first and then the space craft body.
        /// </summary>
        public override void RenderGdi(Graphics graphics, RectangleD cameraBounds)
        {
            // Only draws the ship if it's visible
            if (Visibility(cameraBounds) > 0)
            {
                RectangleD bounds = ComputeBoundingBox();

                // In range for render
                if (cameraBounds.IntersectsWith(bounds))
                {
                    RectangleF screenBounds = RenderUtils.ComputeBoundingBox(Position, cameraBounds, Width, Height);

                    // Saftey
                    if (screenBounds.Width > RenderUtils.ScreenWidth * 500) return;

                    RenderBelow(graphics, cameraBounds);

                    RenderShip(graphics, cameraBounds, screenBounds);

                    RenderAbove(graphics, cameraBounds);
                }
            }

            // Only draw orbit traces and launch trails for detatched ships
            if (Parent == null)
            {
                if (cameraBounds.Width > 1000)
                {
                    _launchTrail.Draw(graphics, cameraBounds, GravitationalParent);
                }

                // Don't draw orbit traces on the ground
                base.RenderGdi(graphics, cameraBounds);
            }
        }
Example #4
0
        public void RenderCl(OpenCLProxy clProxy, RectangleD cameraBounds, IPhysicsBody sun)
        {
            RectangleD bounds = ComputeBoundingBox();

            // Not in range easy return
            if (!cameraBounds.IntersectsWith(bounds))
            {
                return;
            }

            DVector2 sunNormal = DVector2.Zero;

            if (sun != null)
            {
                sunNormal = sun.Position - Position;

                sunNormal.Normalize();
            }

            var normalizedPosition = new DVector2(cameraBounds.X - Position.X, cameraBounds.Y - Position.Y);

            if (clProxy.HardwareAccelerationEnabled)
            {
                clProxy.UpdateDoubleArgument("cameraLeft", normalizedPosition.X);
                clProxy.UpdateDoubleArgument("cameraTop", normalizedPosition.Y);

                clProxy.UpdateDoubleArgument("cameraWidth", cameraBounds.Width);
                clProxy.UpdateDoubleArgument("cameraHeight", cameraBounds.Height);

                clProxy.UpdateDoubleArgument("sunNormalX", sunNormal.X);
                clProxy.UpdateDoubleArgument("sunNormalY", sunNormal.Y);

                clProxy.UpdateDoubleArgument("rotation", Rotation);

                clProxy.RunKernel(_computeKernel, RenderUtils.ScreenArea);
            }
            else
            {
                int totalSize = RenderUtils.ScreenArea;

                for (int i = 0; i < totalSize; i++)
                {
                    Kernel.Run(clProxy.ReadIntBuffer("image", totalSize), RenderUtils.ScreenWidth, RenderUtils.ScreenHeight,
                                                    normalizedPosition.X, normalizedPosition.Y, cameraBounds.Width, cameraBounds.Height,
                                                    sunNormal.X, sunNormal.Y, Rotation);
                }

                Kernel.Finish();
            }
        }