Exemplo n.º 1
0
    private static CollisionInfo circleToLine(GeomBase geom1, GeomBase geom2)
    {
        GeomCircle circle = (GeomCircle)geom1;
        GeomLine   line   = (GeomLine)geom2;

        Vector2D v1 = circle.center.clone().subtract(line.point1);
        Vector2D v2 = line.vector2D;

        double len = v2.length;

        v2.normalize();
        double u = v1.dotProd(v2);

        Vector2D v0 = Vector2D.createVector();

        if (u <= 0)
        {
            v0.copy(line.point1);
        }
        else if (u >= len)
        {
            v0.copy(line.point2);
        }
        else
        {
            v0.copy(v2.multiply(u).add(line.point1));
        }
        help.isHit = v0.dist(circle.center) <= circle.radius;
        v0.clear();
        v1.clear();
        v2.clear();
        return(help);
    }
Exemplo n.º 2
0
    ///得到某个单位向指定方向移动,首个需要躲避的前方友军或障碍物
    public FightEntity getDodgeTarget(double aimAngle)
    {
        Vector2D aimDeltaV2d = Vector2D.createVector2(AIConstant.DODGE_BARRIER_RADIUS, aimAngle);

        new GeomCircle(null, int.MaxValue);
        GeomBase geom = new GeomCircle(null, int.MaxValue);

        geom.parseData(new object[] { this._aiPlayer.player.shape.radius + AIConstant.DODGE_BARRIER_RADIUS });
        geom.position.copy(aimDeltaV2d.add(_aiPlayer.player.position));
        geom.applyEntity = false;
//		Collision.createGeom(this._aiPlayer.player, ( new object[] { this._aiPlayer.player.shape.radius} ));
//		geom.position.copy (aimDeltaV2d.add(_aiPlayer.player.position));
        aimDeltaV2d.clear();

//		List<FightEntity> fightList = this.map.getFightEntitysByRange (geom,new List<int> { ConfigConstant.ENTITY_PLAYER},FightEntity.getPureAllyTeamFilter,-1);
        List <BarrierEntity> barrierList = this._map.getFightEntitysByRange(geom, new List <int> {
            ConfigConstant.ENTITY_BARRIER
        }, null, 0).ConvertAll <BarrierEntity>((e) => { return(e as BarrierEntity); });

        if (barrierList.Count > 0)
        {
            return(barrierList [0]);
        }
        else
        {
            return(null);
        }
    }
Exemplo n.º 3
0
        /// <summary>
        ///   Builds a circle with the parameters passed and extracts a point locted on the circle
        /// </summary>
        protected static gpPnt GetPointOnCircle(gpAx1 axis, double radius, gpTrsf trsf)
        {
            var centerCoord = new gpAx2();

            centerCoord.Axis = (axis);
            var circle = new GeomCircle(centerCoord, radius);

            // Get the first point on the circle's parametric curve
            return(circle.Value(circle.FirstParameter));//.Transformed(trsf);
        }
Exemplo n.º 4
0
    private static CollisionInfo circleToSector(GeomBase geom1, GeomBase geom2)
    {
        GeomCircle circle = (GeomCircle)geom1;
        GeomSector sector = (GeomSector)geom2;
        GeomLine   line1  = sector.line1;
        GeomLine   line2  = sector.line2;

        //这个因为有需求所以就这么直接写一下了。
        bool result = !(0 != sector.inRadius && sector.center.dist(circle.center) <= sector.inRadius /* + circle.radius*/) && //不能在内圆
                      ((line1.checkPoint(circle.center) >= 0 && line2.checkPoint(circle.center) <= 0) ||                      //在夹角内
                       circleToLine(circle, line1).isHit || circleToLine(circle, line2).isHit);                               //或者与线相交

        help.isHit = result;
        return(help);
    }
Exemplo n.º 5
0
    private static CollisionInfo circleToRect(GeomBase geom1, GeomBase geom2)
    {
        GeomCircle circle = (GeomCircle)geom1;
        GeomRect   rect   = (GeomRect)geom2;

        Vector2D unRotated = circle.center.clone().subtract(rect.center);

        unRotated.angle -= rect.angle;
        unRotated        = unRotated.add(rect.center);

        Vector2D closest = Vector2D.createVector();

        if (unRotated.x < rect.x)
        {
            closest.x = rect.x;
        }
        else if (unRotated.x > rect.right)
        {
            closest.x = rect.right;
        }
        else
        {
            closest.x = unRotated.x;
        }

        if (unRotated.y < rect.y)
        {
            closest.y = rect.y;
        }
        else if (unRotated.y > rect.bottom)
        {
            closest.y = rect.bottom;
        }
        else
        {
            closest.y = unRotated.y;
        }
        help.isHit = unRotated.dist(closest) < circle.radius;
        unRotated.clear();
        closest.clear();
        return(help);
    }
Exemplo n.º 6
0
        public static ComplexGeometry ExecuteStages(Point centerLocation)
        {
            var finalGeometry = new List <Geometry>();

            var pointsList = GeomPoint.CreatePoints();

            finalGeometry.Add(pointsList);
            var linesList = GeomLine.CreateLines(pointsList);

            finalGeometry.Add(linesList);
            var ellipse = GeomEllipse.CreateEllipse(linesList);

            finalGeometry.Add(ellipse);
            var circle = GeomCircle.CreateCircle(ellipse);

            finalGeometry.Add(circle);
            var boundingBox = GeomBoundingBox.CreateBoundingBox(ellipse);

            finalGeometry.Add(boundingBox);

            return(finalGeometry);
        }
Exemplo n.º 7
0
    public static GeomBase createGeom(FightEntity entity, object[] datas, object[] offset = null)
    {
        GeomBase result = null;

        switch (datas.Length)
        {
        case 1:
            result = new GeomCircle(entity.map);
            break;

        case 2:
            result = new GeomRect(entity.map);
            break;

        case 3:
        case 4:
            result = new GeomSector(entity.map);
            break;
        }
        result.entity = entity;
        result.parseData(datas, offset);
        return(result);
    }
Exemplo n.º 8
0
        private void circleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SelectedShapeQuery query = new SelectedShapeQuery();

            renderView.QuerySelection(query);
            var shape = query.GetSubGeometry();

            if (shape == null)
            {
                return;
            }

            GeomCurve curve = new GeomCurve();

            if (!curve.Initialize(shape))
            {
                return;
            }

            if (curve.GetCurveType() != EnumCurveType.CurveType_Circle)
            {
                var     xx  = curve.FirstParameter() + curve.LastParameter();
                Vector3 pt1 = curve.Value(curve.FirstParameter());
                Vector3 pt2 = curve.Value(xx * 0.3);
                Vector3 pt3 = curve.Value(xx * 0.6);

                var arc = GlobalInstance.BrepTools.MakeArc3Pts(pt1, pt3, pt2);
                if (arc != null)
                {
                    GeomCircle circle = new GeomCircle();
                    circle.Initialize(arc);
                    var center = circle.GetCenter();
                    MessageBox.Show(String.Format("Center: {0}, {1}, {2}", center.X, center.Y, center.Z));
                }
            }
        }