public void OnCircleButtonClick(CircleType circleType)
	{
		if (circleType != lastCircleTypeSpawned)
		{
			if (circleType.numberOfUses >= 0 )
			{
				circlePrefabToSpawn = circleType.circlePrefab;
				lastCircleTypeSpawned = circleType;
				circleType.numberOfUses--;

				if (circleType.numberOfUses <= 0)
				{
					circleType.button.GetComponent<Button>().interactable = false;
				}
			}

			UpdateButtonText(circleType);

			// Spawn the new circle if there is already a circle waiting to be flicked
			// If there isn't a circle waiting to be flicked, then the speacil circle type will be spawned when a new circle appears
			if (lastCircleAbsent == false)
			{
				SpawnCircle();
			}
		}
	}
Example #2
0
        public GameController(int firstMove, PlayerType p1, PlayerType p2)
        {
            state = new CircleType[HEIGHT][];
            for (int i = 0; i < HEIGHT; i++)
            {
                state[i] = new CircleType[WIDTH];
            }
            for (int i = 0; i < HEIGHT; i++)
            {
                for (int j = 0; j < WIDTH; j++)
                {
                    state[i][j] = CircleType.NONE;
                }
            }
            playerOnMove = firstMove;
            player1      = new Player(p1, CircleType.RED);
            player2      = new Player(p2, CircleType.YELLOW);
            circles      = new List <Circle> [WIDTH];
            for (int i = 0; i < WIDTH; i++)
            {
                circles[i] = new List <Circle>();
            }
            TimeSpan t = (DateTime.UtcNow - new DateTime(1970, 1, 1));

            lastTime = (long)t.TotalSeconds;
        }
	public void UpdateButtonText(CircleType circleType)
	{
		if (circleType.button != null)
		{
			// Gets the second text object on this button and updates the text
			circleType.button.transform.GetChild(0).GetChild(0).GetComponent<Text>().text = circleType.numberOfUses.ToString();
		}
	}
Example #4
0
 public Circle(CircleType type, Brush circlecolor)
 {
     this.X      = 0;
     this.Y      = 0;
     this.Type   = type;
     this.Color  = circlecolor;
     this.Points = 100;
 }
Example #5
0
 /// <summary>
 ///     Draw a circle directly without instancing a new circle, external drawing method.
 /// </summary>
 /// <param name="position">Circle Position and Radius</param>
 /// <param name="rotate">Circle Rotation</param>
 /// <param name="type">Circle Type</param>
 /// <param name="smooth">Smooth Circle</param>
 /// <param name="resolution">Ricle Resolution</param>
 /// <param name="color">Circle Color</param>
 public static void Draw(Vector3 position,
                         int rotate,
                         CircleType type,
                         bool smooth,
                         int resolution,
                         ColorBGRA color)
 {
     Draw(position.ToVector2(), position.Z, rotate, type, smooth, resolution, color);
 }
Example #6
0
 /// <summary>
 ///     Draw a circle directly without instancing a new circle, external drawing method.
 /// </summary>
 /// <param name="position">Position to draw the Circle</param>
 /// <param name="radius">Circle Radius</param>
 /// <param name="rotate">Circle Rotation</param>
 /// <param name="type">Circle Type</param>
 /// <param name="smooth">Smooth Circle</param>
 /// <param name="resolution">Circle Resolution</param>
 /// <param name="color">Circle Color</param>
 public static void Draw(Vector2 position,
                         float radius,
                         int rotate,
                         CircleType type,
                         bool smooth,
                         int resolution,
                         Color color)
 {
     Draw(position, radius, rotate, type, smooth, resolution, new ColorBGRA(color.R, color.G, color.B, color.A));
 }
        protected void BindData(int circleTypeID)
        {
            var list = circleTypeBLL.GetCircleType(circleType => circleType.CircleTypeID == circleTypeID);

            circleType              = list.First();
            circleType.Image        = ConfigurationManager.AppSettings["UploadUrl"] + circleType.Image;
            DetailsView1.DataSource = list;
            DetailsView1.DataBind();
            CurrentMode_Init();
        }
Example #8
0
 /// <summary>
 ///     Circle Constructor
 /// </summary>
 /// <param name="position">Circle Position</param>
 /// <param name="radius">Circle Radius</param>
 /// <param name="rotate">Circle Rotation</param>
 /// <param name="type">Circle Type</param>
 /// <param name="smooth">Smooth Circle</param>
 /// <param name="resolution">Circle Resolution</param>
 /// <param name="color">Circle Color</param>
 public Circle(Vector2 position,
               float radius,
               int rotate,
               CircleType type,
               bool smooth,
               int resolution,
               ColorBGRA color)
 {
     Base(position, radius, rotate, type, smooth, resolution, color);
 }
        //------------------------------------------------------------------------//
        // Convierte la entidad <Circle> de is2Graph a su tipo equivalente de NX.
        /// <summary>
        ///
        /// </summary>
        /// <param name="C"></param>
        /// <returns></returns>
        public static UFCurve.Arc ToNx(CircleType C)
        {
            UFCurve.Arc nxC = new UFCurve.Arc();

            nxC.start_angle = 0.0;
            nxC.end_angle   = 2 * Math.PI;
            nxC.arc_center  = ToNx(C.Center);
            nxC.radius      = C.Radius;

            return(nxC);
        }
Example #10
0
    public static bool IsPassable(this CircleType type)
    {
        switch (type)
        {
        case CircleType.Bullet:
            return(true);

        default:
            return(false);
        }
    }
Example #11
0
    public bool EqualCircleType(CircleType type)
    {
        bool result = false;

        if (circleType == type)
        {
            result = true;
        }

        return(result);
    }
        private int[] coords;//0=x 1=y
        //private Color Cl; //{ get; set; }


        public MyCircle(int[] clickCoords)
        {
            coords = new int[clickCoords.Length];
            for (int i = 0; i < clickCoords.Length; i++) // Length=2 (x,y)
            {
                coords[i] = clickCoords[i];              // 0= x , 1= y
            }

            IsSelected = false;
            typ        = CircleType.Usual;
        }
Example #13
0
    public static bool IsTarget(this CircleType type)
    {
        switch (type)
        {
        case CircleType.Hero:
        case CircleType.Gnome:
            return(true);

        default:
            return(false);
        }
    }
Example #14
0
 public Circle(CircleType t, int t_x, int t_y, int t_width, int t_height, System.Windows.Forms.Panel p)
 {
     type   = t;
     x      = t_x; y = t_y;
     parent = p;
     width  = t_width;
     height = t_height;
     if (parent == null)
     {
         int a = 3;
     }
 }
Example #15
0
    public static bool IsInteractive(this CircleType type)
    {
        switch (type)
        {
        case CircleType.Gnome:
        case CircleType.DrillCar:
        case CircleType.Resource:
            return(true);

        default:
            return(false);
        }
    }
        private bool MouseOver(CircleType type, ViewportEvent ev, MapViewport viewport)
        {
            var cache = _cachedLines.FirstOrDefault(x => x.Viewport == viewport.Viewport);

            if (cache == null)
            {
                return(false);
            }
            var lines = cache.Cache[type];
            var point = new Vector3(ev.X, ev.Y, 0);

            return(lines.Any(x => (x.ClosestPoint(point) - point).Length() <= 8));
        }
Example #17
0
        private bool MouseOver(CircleType type, ViewportEvent ev, Viewport3D viewport)
        {
            var cache = _cachedLines.FirstOrDefault(x => x.Viewport3D == viewport);

            if (cache == null)
            {
                return(false);
            }
            var lines = cache.Cache[type];
            var point = new Coordinate(ev.X, viewport.Height - ev.Y, 0);

            return(lines.Any(x => (x.ClosestPoint(point) - point).VectorMagnitude() <= 8));
        }
Example #18
0
 public JoinCircleForm(CircleType circleType)
 {
     this.circleType = circleType;
     InitializeComponent();
     if (circleType == CircleType.kademlia)
     {
         urlBox.Text = "#Test";
         if (!App.kademlia.ready)
         {
             joinButton.Enabled   = false;
             kadInitLabel.Visible = true;
         }
     }
 }
        private void DdsCircleUpdated(object sender, CircleType e)
        {
            CircleType circle = _subscribedCircles.FirstOrDefault(s => s.Color == e.Color && s.PublicationHandle == e.PublicationHandle);

            if (circle != null)
            {
                circle.X = e.X;
                circle.Y = e.Y;
            }
            else
            {
                _subscribedCircles.Add(e);
            }
        }
        private void PublishShape()
        {
            switch (_selectedPublisherShape)
            {
            case ShapeKind.Circle:
                CircleType circle = new CircleType
                {
                    Color       = _selectedColor.ToString().ToUpper(),
                    Size        = _selectedSize,
                    X           = (int)(_random.NextDouble() * 300),
                    Y           = (int)(_random.NextDouble() * 300),
                    IsPublished = true
                };

                _publishedCircles.Add(circle);
                _dds.Publish(circle, _rect, _selectedSpeed / 9);
                break;

            case ShapeKind.Square:
                SquareType square = new SquareType
                {
                    Color       = _selectedColor.ToString().ToUpper(),
                    Size        = _selectedSize,
                    X           = (int)(_random.NextDouble() * 300),
                    Y           = (int)(_random.NextDouble() * 300),
                    IsPublished = true
                };

                _publishedSquares.Add(square);

                _dds.Publish(square, _rect, _selectedSpeed / 9);
                break;

            case ShapeKind.Triangle:
                TriangleType triangle = new TriangleType
                {
                    Color       = _selectedColor.ToString().ToUpper(),
                    Size        = _selectedSize,
                    X           = (int)(_random.NextDouble() * 300),
                    Y           = (int)(_random.NextDouble() * 300),
                    IsPublished = true
                };

                _publishedTriangles.Add(triangle);

                _dds.Publish(triangle, _rect, _selectedSpeed / 9);
                break;
            }
        }
        /// <summary>
        /// Gets the circle colors.
        /// </summary>
        /// <returns>The circle colors.</returns>
        /// <param name="circleType">Circle type.</param>
        /// <param name="absolutePercent">Absolute percent.</param>
        /// <param name="relativePercent">Relative percent.</param>
        protected CircleColors GetCircleColors(CircleType circleType, float absolutePercent, float relativePercent)
        {
            CircleColors circleColors;

            //Determine what part of the circle we are drawing
            switch (circleType)
            {
            case CircleType.Main:            //Body of the circle
                circleColors.outerColor = GetOuterColor(absolutePercent, relativePercent);
                circleColors.innerColor = GetInnerColor(absolutePercent, relativePercent);
                break;

            case CircleType.GlowOuter:            //Outer glow of the circle
                if (useCircleColor)
                {
                    circleColors.innerColor = GetInnerColor(absolutePercent, relativePercent);
                }
                else
                {
                    circleColors.innerColor   = glowColor;
                    circleColors.innerColor.a = color.a * glowColor.a;
                }
                circleColors.outerColor   = circleColors.innerColor;
                circleColors.outerColor.a = 0;
                break;

            case CircleType.GlowInner:            //Inner glow of the circle
                if (useCircleColor)
                {
                    circleColors.outerColor = GetOuterColor(absolutePercent, relativePercent);
                }
                else
                {
                    circleColors.outerColor   = glowColor;
                    circleColors.outerColor.a = color.a * glowColor.a;
                }
                circleColors.innerColor   = circleColors.outerColor;
                circleColors.innerColor.a = 0;
                break;

            default:
                circleColors.outerColor = Color.white;
                circleColors.innerColor = Color.white;
                break;
            }
            return(circleColors);
        }
Example #22
0
        private void SetStartOrStopCircle(int[] clickCoords, CircleType typ)
        {
            MyCircle clickedCircle = circles.FirstOrDefault(c => c.IsNearClick(clickCoords));

            if (clickedCircle != null)
            {
                foreach (MyCircle c in circles)
                {
                    if (c.typ == typ)
                    {
                        c.typ = CircleType.Usual;
                    }
                }

                clickedCircle.typ = typ;
            }
        }
Example #23
0
 public void Ripe(CircleType type)
 {
     if(type==CircleType.Normal)
     {
         core.transform.renderer.material = (Material)Resources.Load("Material/Purple Core");
         edge.transform.renderer.material = (Material)Resources.Load("Material/Purple Edge");
         circle.transform.renderer.material = (Material)Resources.Load("Material/Purple Edge");
         return;
     }
     if(type==CircleType.Freedom)
     {
         core.transform.renderer.material = (Material)Resources.Load("Material/Purple Freedom Core");
         edge.transform.renderer.material = (Material)Resources.Load("Material/Purple Edge");
         circle.transform.renderer.material = (Material)Resources.Load("Material/Purple Edge");
         return;
     }
 }
        protected override void MouseDown(MapDocument document, MapViewport viewport, PerspectiveCamera camera, ViewportEvent e)
        {
            if (viewport != ActiveViewport)
            {
                return;
            }

            if (e.Button != MouseButtons.Left || _mouseOver == CircleType.None)
            {
                return;
            }
            _mouseDown      = _mouseOver;
            _mouseDownPoint = new Vector3(e.X, e.Y, 0);
            _mouseMovePoint = null;
            e.Handled       = true;
            viewport.AquireInputLock(this);
        }
        public CircleInstanceController(string name, List <Coordinate> coords, CircleType type, CircleRouteType routeType, ushort minLevel, ushort maxLevel, string groupName = null, bool isEvent = false)
        {
            Name         = name;
            Coordinates  = coords;
            Type         = type;
            RouteType    = routeType;
            MinimumLevel = minLevel;
            MaximumLevel = maxLevel;
            GroupName    = groupName;
            IsEvent      = isEvent;

            _logger = new Logger <CircleInstanceController>(LoggerFactory.Create(x => x.AddConsole()));

            _lastCompletedTime = DateTime.UtcNow;
            _lastUuid          = new Dictionary <string, DeviceIndex>();
            _lastIndex         = 0;
        }
        private void DrawPoints(List <Point> data, CircleType type)
        {
            var diameter = type == CircleType.Normal ? 10 : 6;
            var radius   = diameter / 2.0;
            var color    = type == CircleType.Normal ? Brushes.Black : Brushes.Red;

            foreach (var point in data)
            {
                var circle = new Ellipse()
                {
                    Width = diameter, Height = diameter, Fill = color
                };
                Canvas.SetLeft(circle, point.X * Scale - radius);
                Canvas.SetTop(circle, point.Y * Scale - radius);
                (type == CircleType.Normal ? _canvasPoints : _canvasResults).Children.Add(circle);
            }
        }
Example #27
0
        private void AddLine(CircleType type, Coordinate start, Coordinate end, Plane test, CachedLines cache)
        {
            var line = new Line(start, end);
            var cls  = line.ClassifyAgainstPlane(test);

            if (cls == PlaneClassification.Back)
            {
                return;
            }
            if (cls == PlaneClassification.Spanning)
            {
                var isect = test.GetIntersectionPoint(line, true);
                var first = test.OnPlane(line.Start) > 0 ? line.Start : line.End;
                line = new Line(first, isect);
            }
            cache.Cache[type].Add(new Line(cache.Viewport3D.WorldToScreen(line.Start), cache.Viewport3D.WorldToScreen(line.End)));
        }
        protected override void MouseMove(MapDocument document, MapViewport viewport, PerspectiveCamera camera, ViewportEvent e)
        {
            if (viewport != ActiveViewport)
            {
                return;
            }

            if (document.Selection.IsEmpty || !viewport.IsUnlocked(this))
            {
                return;
            }

            if (_mouseDown != CircleType.None)
            {
                _mouseMovePoint = new Vector3(e.X, e.Y, 0);
                e.Handled       = true;
                var tform = GetTransformationMatrix(viewport);
                OnTransforming(tform);
            }
            else
            {
                UpdateCache(viewport.Viewport, camera);

                if (MouseOver(CircleType.Z, e, viewport))
                {
                    _mouseOver = CircleType.Z;
                }
                else if (MouseOver(CircleType.Y, e, viewport))
                {
                    _mouseOver = CircleType.Y;
                }
                else if (MouseOver(CircleType.X, e, viewport))
                {
                    _mouseOver = CircleType.X;
                }
                else if (MouseOver(CircleType.Outer, e, viewport))
                {
                    _mouseOver = CircleType.Outer;
                }
                else
                {
                    _mouseOver = CircleType.None;
                }
            }
        }
        protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
        {
            try
            {
                var circleType = new CircleType();
                var file_url   = (HtmlInputHidden)DetailsView1.FindControl("file_url");
                if (!string.IsNullOrEmpty(file_url.Value))
                {
                    var img_url = (HtmlImage)DetailsView1.FindControl("img_url");
                    img_url.Src      = ConfigurationManager.AppSettings["UploadUrl"] + file_url.Value;
                    circleType.Image = file_url.Value;
                }
                else
                {
                    throw new Exception("图片不能为空");
                }
                if (e.Values["Title"] == null)
                {
                    throw new Exception("标题不能为空");
                }
                if (e.Values["SubTitle"] == null)
                {
                    throw new Exception("子标题不能为空");
                }

                if (e.Values["OrderBy"] != null)
                {
                    circleType.OrderBy = Convert.ToInt32(e.Values["OrderBy"].ToString());
                }
                circleType.Title    = e.Values["Title"].ToString();
                circleType.SubTitle = e.Values["SubTitle"].ToString();
                circleType.State    = Convert.ToInt32(((RadioButtonList)DetailsView1.FindControl("RadioButtonList_State")).SelectedValue);
                using (Entity entity = new Entity())
                {
                    entity.CircleType.Add(circleType);
                    entity.SaveChanges();
                }
                Response.Redirect("CircleTypeDetail.aspx?circleTypeID=" + circleType.CircleTypeID);
            }
            catch (Exception exception)
            {
                string error = exception.GetErrorMessage().Replace("'", "\\'").Replace("\"", "\\\"").Replace("\r\n", "\\r\\n");
                ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", string.Format("<script>alert('{0}')</script>", error));
            }
        }
Example #30
0
 public Player(PlayerType t, CircleType ct)
 {
     type         = t;
     myCircleType = ct;
     if (type == PlayerType.RANDOM)
     {
         randomLogic = new RandomPlayer();
     }
     else if (type == PlayerType.MINIMAX)
     {
         minimaxLogic = new MinimaxLogic(myCircleType);
     }
     else if (type == PlayerType.ABMINIMAX)
     {
         abMinimaxLogic = new ABminimaxLogic(ct);
     }
     numOfMoves = 0;
 }
        protected override void MouseUp(MapDocument document, MapViewport viewport, PerspectiveCamera camera, ViewportEvent e)
        {
            if (viewport != ActiveViewport)
            {
                return;
            }

            if (_mouseDown != CircleType.None && _mouseMovePoint != null)
            {
                e.Handled = true;
            }

            var transformation = GetTransformationMatrix(viewport);

            OnTransformed(transformation);
            _mouseDown      = CircleType.None;
            _mouseMovePoint = null;
            viewport.ReleaseInputLock(this);
        }
    void CreateCircle(Vector2 pos, float radius, float fadeOutTime, Color color, CircleType type, int sortOrder = 0, float speed = 1f)
    {
        int index = particleCount++;

        SpriteRenderer sr = renderers[index];

        sr.transform.position = pos;
        sr.sortingOrder       = 5 + sortOrder;
        sr.gameObject.SetActive(true);
        sr.transform.localScale = Vector2.one * radius / radiusScales[(int)type];

        particles[index] = new ParticleCircle(radiusTimes[(int)type], thicknessTimes[(int)type], fadeOutTime, speed);

        block.Clear();
        block.SetFloat(radiusID, radiusScales[(int)type]);
        block.SetFloat(radiusTimerID, 0);
        block.SetFloat(thicknessID, thicknessValues[(int)type]);
        block.SetFloat(thicknessTimerID, 0);
        block.SetFloat(fadeOutTimerID, 0);
        block.SetColor(colorID, color);
        sr.SetPropertyBlock(block);
    }
        private void UpdateFeedbackWithGeoCircle()
        {
            if (Point1 == null || Distance <= 0)
            {
                return;
            }

            var construct = new Polyline() as IConstructGeodetic;

            if (construct != null)
            {
                ClearTempGraphics();
                IDictionary <String, System.Object> circleAttributes = new Dictionary <String, System.Object>();
                if (HasPoint1)
                {
                    IDictionary <String, System.Object> ptAttributes = new Dictionary <String, System.Object>();
                    ptAttributes.Add("X", Point1.X);
                    ptAttributes.Add("Y", Point1.Y);
                    circleAttributes.Add("centerx", Point1.X);
                    circleAttributes.Add("centery", Point1.Y);
                    // Re-add the point as it was cleared by ClearTempGraphics() but we still want to see it
                    AddGraphicToMap(Point1, new RgbColor()
                    {
                        Green = 255
                    } as IColor, true, attributes: ptAttributes);


                    circleAttributes.Add("radius", Distance);
                    circleAttributes.Add("disttype", CircleType.ToString());

                    construct.ConstructGeodesicCircle(Point1, GetLinearUnit(), Distance, esriCurveDensifyMethod.esriCurveDensifyByAngle, 0.45);

                    Point2 = (construct as IPolyline).ToPoint;
                    var color = new RgbColorClass() as IColor;
                    this.AddGraphicToMap(construct as IGeometry, color, true, rasterOpCode: esriRasterOpCode.esriROPNotXOrPen, attributes: circleAttributes);
                }
            }
        }
Example #34
0
        public override void MouseDown(ViewportBase viewport, ViewportEvent ve)
        {
            if (viewport is Viewport2D)
            {
                var vp2 = (Viewport2D)viewport;
                if (ve.Button == MouseButtons.Left && MouseOverPivot(vp2, ve))
                {
                    _movingPivot = true;
                    ve.Handled = true;
                }
                return;
            }

            var vp = viewport as Viewport3D;
            if (vp == null || vp != _activeViewport) return;

            if (ve.Button != MouseButtons.Left || _mouseOver == CircleType.None) return;
            _mouseDown = _mouseOver;
            _mouseDownPoint = new Coordinate(ve.X, vp.Height - ve.Y, 0);
            _mouseMovePoint = null;
            ve.Handled = true;
            vp.AquireInputLock(this);
        }
Example #35
0
 public void TextureChange(CircleType type, bool ripe)
 {
     if(ripe)
     {
         Ripe(type);
     }
     else
     {
         if(type==CircleType.Freedom)
         {
             core.transform.renderer.material = (Material)Resources.Load("Material/Yellow Freedom Core");
             edge.transform.renderer.material = (Material)Resources.Load("Material/Yellow Edge");
             circle.transform.renderer.material = (Material)Resources.Load("Material/Yellow Edge");
             return;
         }
         if (type == CircleType.Normal)
         {
             core.transform.renderer.material = (Material)Resources.Load("Material/Yellow Core");
             edge.transform.renderer.material = (Material)Resources.Load("Material/Yellow Edge");
             circle.transform.renderer.material = (Material)Resources.Load("Material/Yellow Edge");
             return;
         }
     }
 }
	// Set lastCircleTypeSpawned to null so that the any special circle type can be spawned
	public void ClearLastCircleTypeSpawned()
	{
		lastCircleTypeSpawned = null;
	}
Example #37
0
        /// <summary>
        /// Draws a filled Circle
        /// </summary>
        /// <param name="x">Position X</param>
        /// <param name="y">Position Y</param>
        /// <param name="rad">Radius</param>
        /// <param name="rotate">Rotation 0 - 360</param>
        /// <param name="type">Circle Type</param>
        /// <param name="smoothing">Smooth Antialiasing</param>
        /// <param name="resolution">Real smooth value</param>
        /// <param name="color">Color</param>
        public static void DrawCircleFilled(float x, float y, float rad, float rotate, CircleType type, bool smoothing, int resolution, Color color)
        {
            VertexBuffer vertices = new VertexBuffer(
             Drawing.Direct3DDevice, Utilities.SizeOf<Vector4>() * 2 * (resolution + 4), Usage.WriteOnly, VertexFormat.Diffuse | VertexFormat.PositionRhw, Pool.Default);

            double angle = rotate * Math.PI / 180d;
            double pi = 0.0d;

            if (type == CircleType.Full) pi = Math.PI;        // Full circle
            if (type == CircleType.Half) pi = Math.PI / 2d;      // 1/2 circle
            if (type == CircleType.Quarter) pi = Math.PI / 4d;   // 1/4 circle

            List<Vector4> data = new List<Vector4>(new []
                                                        {
                                                            new Vector4(x, y, 0f, 1f), color.ToVector4() 
                                                        });

            for (int i = 1; i < resolution + 4; i++)
            {
                float x1 = (float)(x - rad * Math.Cos(pi * ((i - 1) / (resolution / 2.0f))));
                float y1 = (float)(y - rad * Math.Sin(pi * ((i - 1) / (resolution / 2.0f))));
                data.AddRange(new[]
                    {
                        new Vector4(x1, y1, 0f, 1.0f), color.ToVector4()
                    });
            }

            // Rotate matrix
            int res = 2 * resolution + 4;
            for (int i = 0; i < res; i = i + 2)
            {
                data[i] = new Vector4((float)(x + Math.Cos(angle) * (data[i].X - x) - Math.Sin(angle) * (data[i].Y - y)),
                    (float)(y + Math.Sin(angle) * (data[i].X - x) + Math.Cos(angle) * (data[i].Y - y)),
                    data[i].Z, data[i].W);
            }

            vertices.Lock(0, Utilities.SizeOf<Vector4>() * 2 * (resolution + 4), LockFlags.None).WriteRange(data.ToArray());
            vertices.Unlock();

            VertexElement[] vertexElements = {
                    new VertexElement(
                        0, 0, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Position, 0),
                    new VertexElement(
                        0, 16, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Color, 0),
                    VertexElement.VertexDeclarationEnd
            };

            VertexDeclaration vertexDeclaration = new VertexDeclaration(Drawing.Direct3DDevice, vertexElements);

            if (smoothing)
            {
                Drawing.Direct3DDevice.SetRenderState(RenderState.MultisampleAntialias, true);
                Drawing.Direct3DDevice.SetRenderState(RenderState.AntialiasedLineEnable, true);
            }
            else
            {
                Drawing.Direct3DDevice.SetRenderState(RenderState.MultisampleAntialias, false);
                Drawing.Direct3DDevice.SetRenderState(RenderState.AntialiasedLineEnable, false);
            }

            var olddec = Drawing.Direct3DDevice.VertexDeclaration;
            Drawing.Direct3DDevice.SetStreamSource(0, vertices, 0, Utilities.SizeOf<Vector4>() * 2);
            Drawing.Direct3DDevice.VertexDeclaration = vertexDeclaration;
            Drawing.Direct3DDevice.DrawPrimitives(PrimitiveType.TriangleFan, 0, resolution);
            Drawing.Direct3DDevice.VertexDeclaration = olddec;

            vertexDeclaration.Dispose();
            vertices.Dispose();
        }
Example #38
0
        /// <summary>
        ///     Draws a Circle (not filled)
        /// </summary>
        /// <param name="x">Position X</param>
        /// <param name="y">Position Y</param>
        /// <param name="radius">Radius</param>
        /// <param name="rotate">Rotation 0 - 360</param>
        /// <param name="type">Circle Type</param>
        /// <param name="smoothing">Smooth Antialiasing</param>
        /// <param name="resolution">Real smooth value</param>
        /// <param name="color">Color</param>
        public static void DrawCircle(
            float x,
            float y,
            float radius,
            int rotate,
            CircleType type,
            bool smoothing,
            int resolution,
            Color color)
        {
            var vertices = new VertexBuffer(
                Drawing.Direct3DDevice9,
                Utilities.SizeOf<Vector4>() * 2 * (resolution + 2),
                Usage.WriteOnly,
                VertexFormat.Diffuse | VertexFormat.PositionRhw,
                Pool.Default);

            var angle = rotate * (float)Math.PI / 180f;
            var pi = 0.0f;

            if (type == CircleType.Full)
            {
                pi = (float)Math.PI; // Full circle
            }

            if (type == CircleType.Half)
            {
                pi = (float)Math.PI / 2f; // 1/2 circle
            }

            if (type == CircleType.Quarter)
            {
                pi = (float)Math.PI / 4f; // 1/4 circle
            }

            var data = new List<Vector4>();

            for (var i = 0; i < resolution + 2; i++)
            {
                var x1 = x - (radius * (float)Math.Cos(i * (2f * pi / resolution)));
                var y1 = y - (radius * (float)Math.Sin(i * (2f * pi / resolution)));
                data.AddRange(new[] { new Vector4(x1, y1, 0f, 1.0f), color.ToVector4() });
            }

            // Rotate matrix
            var res = (2 * resolution) + 2;
            for (var i = 0; i < res; i = i + 2)
            {
                data[i] =
                    new Vector4(
                        (float)(x + (Math.Cos(angle) * (data[i].X - x)) - (Math.Sin(angle) * (data[i].Y - y))),
                        (float)(y + (Math.Sin(angle) * (data[i].X - x)) + (Math.Cos(angle) * (data[i].Y - y))),
                        data[i].Z,
                        data[i].W);
            }

            vertices.Lock(0, 0, LockFlags.None).WriteRange(data.ToArray());
            vertices.Unlock();

            VertexElement[] vertexElements =
                {
                    new VertexElement(
                        0,
                        0,
                        DeclarationType.Float4,
                        DeclarationMethod.Default,
                        DeclarationUsage.Position,
                        0),
                    new VertexElement(
                        0,
                        16,
                        DeclarationType.Float4,
                        DeclarationMethod.Default,
                        DeclarationUsage.Color,
                        0),
                    VertexElement.VertexDeclarationEnd
                };

            var vertexDeclaration = new VertexDeclaration(Drawing.Direct3DDevice9, vertexElements);

            if (smoothing)
            {
                Drawing.Direct3DDevice9.SetRenderState(RenderState.MultisampleAntialias, true);
                Drawing.Direct3DDevice9.SetRenderState(RenderState.AntialiasedLineEnable, true);
            }

            var olddec = Drawing.Direct3DDevice9.VertexDeclaration;
            Drawing.Direct3DDevice9.SetStreamSource(0, vertices, 0, Utilities.SizeOf<Vector4>() * 2);
            Drawing.Direct3DDevice9.VertexDeclaration = vertexDeclaration;
            Drawing.Direct3DDevice9.DrawPrimitives(PrimitiveType.LineStrip, 0, resolution);
            Drawing.Direct3DDevice9.VertexDeclaration = olddec;

            vertexDeclaration.Dispose();
            vertices.Dispose();
        }
Example #39
0
        public override void MouseUp(ViewportBase viewport, ViewportEvent ve)
        {
            if (viewport is Viewport2D)
            {
                // var vp2 = (Viewport2D) viewport;
                if (_movingPivot && ve.Button == MouseButtons.Left)
                {
                    _movingPivot = false;
                    ve.Handled = true;
                }
                return;
            }

            var vp = viewport as Viewport3D;
            if (vp == null || vp != _activeViewport) return;

            if (_mouseDown != CircleType.None && _mouseMovePoint != null) ve.Handled = true;

            var transformation = GetTransformationMatrix(vp);
            OnTransformed(transformation);
            _mouseDown = CircleType.None;
            _mouseMovePoint = null;
            vp.ReleaseInputLock(this);
        }
Example #40
0
        public override void MouseMove(ViewportBase viewport, ViewportEvent e)
        {
            if (viewport is Viewport2D)
            {
                var vp2 = (Viewport2D) viewport;
                if (_movingPivot)
                {
                    var pp = SnapToSelection(vp2.ScreenToWorld(e.X, vp2.Height - e.Y), vp2);
                    _pivotPoint = vp2.GetUnusedCoordinate(_pivotPoint) + vp2.Expand(pp);
                    _autoPivot = false;
                    e.Handled = true;
                }
                else if (MouseOverPivot(vp2, e))
                {
                    vp2.Cursor = Cursors.Cross;
                    e.Handled = true;
                }
                else
                {
                    vp2.Cursor = Cursors.Default;
                }
                return;
            }

            var vp = viewport as Viewport3D;
            if (vp == null || vp != _activeViewport) return;

            if (Document.Selection.IsEmpty() || !vp.IsUnlocked(this)) return;

            if (_mouseDown != CircleType.None)
            {
                _mouseMovePoint = new Coordinate(e.X, vp.Height - e.Y, 0);
                e.Handled = true;
                var tform = GetTransformationMatrix(vp);
                OnTransforming(tform);
            }
            else
            {
                UpdateCache(vp, Document);

                if (MouseOver(CircleType.Z, e, vp)) _mouseOver = CircleType.Z;
                else if (MouseOver(CircleType.Y, e, vp)) _mouseOver = CircleType.Y;
                else if (MouseOver(CircleType.X, e, vp)) _mouseOver = CircleType.X;
                else if (MouseOver(CircleType.Outer, e, vp)) _mouseOver = CircleType.Outer;
                else _mouseOver = CircleType.None;
            }
        }
Example #41
0
 private bool MouseOver(CircleType type, ViewportEvent ev, Viewport3D viewport)
 {
     var cache = _cachedLines.FirstOrDefault(x => x.Viewport3D == viewport);
     if (cache == null) return false;
     var lines = cache.Cache[type];
     var point = new Coordinate(ev.X, viewport.Height - ev.Y, 0);
     return lines.Any(x => (x.ClosestPoint(point) - point).VectorMagnitude() <= 8);
 }
Example #42
0
 private void AddLine(CircleType type, Coordinate start, Coordinate end, Plane test, CachedLines cache)
 {
     var line = new Line(start, end);
     var cls = line.ClassifyAgainstPlane(test);
     if (cls == PlaneClassification.Back) return;
     if (cls == PlaneClassification.Spanning)
     {
         var isect = test.GetIntersectionPoint(line, true);
         var first = test.OnPlane(line.Start) > 0 ? line.Start : line.End;
         line = new Line(first, isect);
     }
     cache.Cache[type].Add(new Line(cache.Viewport3D.WorldToScreen(line.Start), cache.Viewport3D.WorldToScreen(line.End)));
 }