Пример #1
0
    static public bool overlap(SceneShapeLine shape1, SceneShapeRound shape2)
    {
        LineSegf line = new LineSegf(new Vector2f(shape1.mVertex1.x, shape1.mVertex1.y), new Vector2f(shape1.mVertex2.x, shape1.mVertex2.y));

        Vector2f tarPos = Geometryalgorithm2d.point_line_intersect(new Vector2f(shape2.mCenter.x, shape2.mCenter.y), line);

        return((tarPos.Subtract(new Vector2f(shape2.mCenter.x, shape2.mCenter.y))).length() <= shape2.mRadius);
    }
Пример #2
0
    static public bool circle_intersect_triangle(Vector2f center, float radius, Trianglef triangle)
    {
        if (Geometryalgorithm2d.point_in_triangle(center, triangle))
        {
            return(true);
        }

        for (uint i = 0; i < 3; i++)
        {
            LineSegf line = triangle.side(i);

            Vector2f pt = Geometryalgorithm2d.point_line_intersect(center, line);

            float distance = pt.Subtract(center).length();
            if (distance < radius)
            {
                return(true);
            }
        }

        return(false);
    }
Пример #3
0
    private UpdateRetCode UpdateMovePos(uint elapsed)
    {
        if (mPathNodes == null)
        {
            return(UpdateRetCode.Aborted);
        }

        float movDist = elapsed * mOwner.GetSpeed() / 1000f;

        if (movDist < 0.001f)
        {
            return(UpdateRetCode.Continue);
        }

        Vector3f toPos  = mOwner.GetPosition3f();
        Vector3f curPos = mOwner.GetPosition3f();

        while (movDist > 0 && mCurrentIndex < mPathNodes.Count)
        {
            Vector3f nodePos = mPathNodes[mCurrentIndex];
            Vector3f len3d   = nodePos.Subtract(curPos);
            len3d.y = 0;

            float distToNode = len3d.Length();
            if (movDist >= distToNode)
            {
                movDist -= distToNode;
                toPos    = nodePos;

                ++mCurrentIndex;

                if (mCurrentIndex < mPathNodes.Count)
                {
                    Vector3f nodePosNext = mPathNodes[mCurrentIndex];
                    Vector3f posOwner    = mOwner.GetPosition3f();
                    if (Math.Abs(posOwner.x - nodePosNext.x) > 0.01f ||
                        Math.Abs(posOwner.z - nodePosNext.z) > 0.01f)
                    {
                        float dir = Utility.Angle2D(new UnityEngine.Vector3(nodePosNext.x, nodePosNext.y, nodePosNext.z), new UnityEngine.Vector3(posOwner.x, posOwner.y, posOwner.z)) * UnityEngine.Mathf.Deg2Rad;
                        mOwner.SetDirection(dir);
                        mOwner.SetMoveDirection(dir);
                    }
                }
                else
                {
                    movDist = 0;
                }
            }
            else
            {
                if (mCurrentIndex > 0)
                {
                    Vector3f dir = mPathNodes[mCurrentIndex].Subtract(mPathNodes[mCurrentIndex - 1]);
                    dir.y = 0;

                    dir.Normalize();
                    dir.MultiplyBy(movDist);
                    toPos = curPos.Add(dir);

                    LineSegf line = new LineSegf(new Vector2f(mPathNodes[mCurrentIndex - 1].x, mPathNodes[mCurrentIndex - 1].z),
                                                 new Vector2f(mPathNodes[mCurrentIndex].x, mPathNodes[mCurrentIndex].z));
                    Vector2f tarPos = Geometryalgorithm2d.point_line_intersect(new Vector2f(toPos.x, toPos.z), line);
                    toPos.x = tarPos.x;
                    toPos.z = tarPos.y;
                    movDist = 0;
                }
                else
                {
                    len3d.y = 0;
                    len3d.Normalize();
                    toPos   = curPos.Add(len3d.MultiplyBy(movDist));
                    movDist = 0;
                }
            }
        }

        if (!mOwner.Scene.IsInWalkableRegion(toPos.x, toPos.z))
        {
            return(UpdateRetCode.Finished);
        }

        //if (mOwner.Scene.IsBarrierRegion(mOwner, toPos.x, toPos.z))
        //{
        //    return UpdateRetCode.Finished;
        //}

        toPos.y = mOwner.Scene.GetHeight(toPos.x, toPos.z);

        mOwner.SetPosition3f(toPos);

        return(mCurrentIndex >= mPathNodes.Count ? UpdateRetCode.Finished : UpdateRetCode.Continue);
    }