Copy() публичный Метод

public Copy ( ) : Vector2D,
Результат Vector2D,
Пример #1
0
        Pair2D GetPair(Vector2 pA, Vector2 pB)
        {
            Vector2D posA = new Vector2D(pA);

            double rot = Vector2D.Atan2(pA, pB);

            Vector2D posA0 = posA.Copy();
            Vector2D posA1 = posA.Copy();

            posA0.Push(rot - Mathf.PI / 2, width);
            posA1.Push(rot + Mathf.PI / 2, width);

            return(new Pair2D(posA0, posA1));
        }
Пример #2
0
    static public List <Vector2D> GetLinearVertices(Pair2D pair, float minVertexDistance)
    {
        Vector2D startPoint = pair.A.Copy();
        Vector2D endPoint   = pair.B.Copy();

        List <Vector2D> linearPoints = new List <Vector2D>();
        int             loopCount    = 0;

        while ((Vector2D.Distance(startPoint, endPoint) > minVertexDistance))
        {
            linearPoints.Add(startPoint.Copy());
            float direction = (float)Vector2D.Atan2(endPoint, startPoint);
            startPoint.Push(direction, minVertexDistance);

            loopCount++;
            if (loopCount > 150)
            {
                break;
            }
        }

        linearPoints.Add(endPoint.Copy());

        return(linearPoints);
    }
Пример #3
0
    static void DrawSoftShadowTileBlur(Vector2D offset, float z, float height)
    {
        float sunDirection = LightingManager2D.GetSunDirection();

        Polygon2D poly = Polygon2DList.CreateFromRect(new Vector2(1, 1) / 2);

        offset += new Vector2D(0.5f, 0.5f);

        Polygon2D convexHull = Polygon2D.GenerateShadow(new Polygon2D(poly.pointsList), sunDirection, height);

        foreach (DoublePair2D p in DoublePair2D.GetList(convexHull.pointsList))
        {
            Vector2D zA = new Vector2D(p.A + offset);
            Vector2D zB = new Vector2D(p.B + offset);
            Vector2D zC = zB.Copy();

            Vector2D pA = zA.Copy();
            Vector2D pB = zB.Copy();

            zA.Push(Vector2D.Atan2(p.A, p.B) + pi2, .5f);
            zB.Push(Vector2D.Atan2(p.A, p.B) + pi2, .5f);
            zC.Push(Vector2D.Atan2(p.B, p.C) + pi2, .5f);

            GL.TexCoord2(uv0, uv0);
            Max2D.Vertex3(pB, z);
            GL.TexCoord2(0.5f - uv0, uv0);
            Max2D.Vertex3(pA, z);
            GL.TexCoord2(0.5f - uv0, uv1);
            Max2D.Vertex3(zA, z);

            GL.TexCoord2(uv0, uv1);
            Max2D.Vertex3(zA, z);
            GL.TexCoord2(0.5f - uv0, uv1);
            Max2D.Vertex3(zB, z);
            GL.TexCoord2(0.5f - uv0, uv0);
            Max2D.Vertex3(pB, z);

            GL.TexCoord2(uv0, uv1);
            Max2D.Vertex3(zB, z);
            GL.TexCoord2(0.5f - uv0, uv0);
            Max2D.Vertex3(pB, z);
            GL.TexCoord2(0.5f - uv0, uv1);
            Max2D.Vertex3(zC, z);
        }
    }
Пример #4
0
    private void UpdateLinear(Vector2D pos)
    {
        if (Input.GetMouseButtonDown(0))
        {
            linearPair   = new Pair2D(pos.Copy(), pos.Copy());
            mouseDown    = true;
            startedSlice = false;
        }

        if (startSliceIfPossible)
        {
            if (startedSlice == true)
            {
                if (InSlicerComponents(pos.Copy()) == false)
                {
                    startedSlice = false;
                }
            }
            else if (startedSlice == false)
            {
                if (InSlicerComponents(pos.Copy()))
                {
                    startedSlice = true;
                }
                else
                {
                    linearPair.A.Set(pos.Copy());
                }
            }
        }

        if (mouseDown && Input.GetMouseButton(0))
        {
            linearPair.B.Set(pos);

            if (endSliceIfPossible)
            {
                if (LinearSlice(linearPair))
                {
                    mouseDown = false;
                    linearPair.A.Set(pos);

                    if (startSliceIfPossible)
                    {
                        mouseDown    = true;
                        linearPair   = new Pair2D(pos.Copy(), pos.Copy());
                        startedSlice = false;
                    }
                }
            }
        }

        if (mouseDown == true && Input.GetMouseButton(0) == false)
        {
            mouseDown = false;

            LinearSlice(linearPair);
        }
    }
Пример #5
0
    public void Update(Vector2D pos)
    {
        float scroll     = Input.GetAxis("Mouse ScrollWheel");
        float newCutSize = cutSize + scroll;

        if (newCutSize > 0.05f)
        {
            cutSize = newCutSize;
        }

        if (input.GetInputClicked())
        {
            pointsList.Clear();
            pointsList.Add(pos);
        }

        if (pointsList.Count < 1)
        {
            return;
        }

        if (input.GetInputHolding())
        {
            Vector2D posMove   = pointsList.Last().Copy();
            int      loopCount = 0;
            while ((Vector2D.Distance(posMove, pos) > minVertexDistance * visuals.visualScale))
            {
                float direction = (float)Vector2D.Atan2(pos, posMove);
                posMove.Push(direction, minVertexDistance * visuals.visualScale);

                pointsList.Add(posMove.Copy());

                loopCount++;
                if (loopCount > 150)
                {
                    break;
                }
            }
        }

        if (input.GetInputReleased())
        {
            ComplexCut complexCutLine = ComplexCut.Create(GetList(), cutSize * visuals.visualScale);
            Slicer2D.ComplexCutSliceAll(complexCutLine, sliceLayer);

            pointsList.Clear();
        }
    }
Пример #6
0
    private void UpdateComplexCut(Vector2D pos)
    {
        if (Input.GetMouseButtonDown(0))
        {
            pointsList.Clear();
            pointsList.Add(pos);
            mouseDown = true;
        }

        if (pointsList.Count < 1)
        {
            return;
        }

        if (Input.GetMouseButton(0))
        {
            Vector2D posMove   = pointsList.Last().Copy();
            int      loopCount = 0;
            while ((Vector2D.Distance(posMove, pos) > minVertexDistance * visualScale))
            {
                float direction = (float)Vector2D.Atan2(pos, posMove);
                posMove.Push(direction, minVertexDistance * visualScale);

                pointsList.Add(posMove.Copy());

                loopCount++;
                if (loopCount > 150)
                {
                    break;
                }
            }
        }

        if (mouseDown == true && Input.GetMouseButton(0) == false)
        {
            ComplexCut complexCutLine = ComplexCut.Create(pointsList, cutSize * visualScale);
            Slicer2D.ComplexCutSliceAll(complexCutLine, sliceLayer);

            pointsList.Clear();
            mouseDown = false;
        }
    }
Пример #7
0
    public void Update(Vector2D pos)
    {
        if (input.GetInputClicked())
        {
            pointsList.Clear();
            complexTracker.trackerList.Clear();
            pointsList.Add(pos);
        }

        if (input.GetInputPressed() && pointsList.Count > 0)
        {
            Vector2D posMove = pointsList.Last().Copy();

            int loopCount = 0;
            while ((Vector2D.Distance(posMove, pos) > minVertexDistance))
            {
                float direction = (float)Vector2D.Atan2(pos, posMove);
                posMove.Push(direction, minVertexDistance);
                Slicer2D.complexSliceType = complexSliceType;
                pointsList.Add(posMove.Copy());
                complexTracker.Update(posMove.ToVector2(), 0);

                loopCount++;
                if (loopCount > 150)
                {
                    break;
                }
            }

            complexTracker.Update(posMove.ToVector2(), minVertexDistance);
        }

        if (input.GetInputReleased())
        {
            pointsList.Clear();

            complexTracker.trackerList.Clear();
        }
    }
Пример #8
0
    private void UpdateComplexTracked(Vector2D pos)
    {
        if (Input.GetMouseButtonDown(0))
        {
            pointsList.Clear();
            complexTracker.trackerList.Clear();
            pointsList.Add(pos);
        }

        if (Input.GetMouseButton(0) && pointsList.Count > 0)
        {
            Vector2D posMove = pointsList.Last().Copy();

            int loopCount = 0;
            while ((Vector2D.Distance(posMove, pos) > minVertexDistance))
            {
                float direction = (float)Vector2D.Atan2(pos, posMove);
                posMove.Push(direction, minVertexDistance);
                Slicer2D.complexSliceType = complexSliceType;
                pointsList.Add(posMove.Copy());
                complexTracker.Update(posMove.ToVector2(), 0);

                loopCount++;
                if (loopCount > 150)
                {
                    break;
                }
            }

            mouseDown = true;

            complexTracker.Update(posMove.ToVector2(), minVertexDistance);
        }
        else
        {
            mouseDown = false;
        }
    }
Пример #9
0
        public Collision(Polygon2D polygon, List <Vector2D> slice)
        {
            bool enterCollision = false;

            Pair2D pair = Pair2D.Zero();

            // Generate correct intersected slice

            List <Vector2D> intersections;

            for (int i = 0; i < slice.Count - 1; i++)
            {
                pair.A = slice[i];
                pair.B = slice[i + 1];

                intersections = polygon.GetListLineIntersectPoly(pair);

                switch (intersections.Count)
                {
                case 1:
                    collisionCount += 1;

                    collisionSlice.Add(new Point(intersections[0], Point.Type.Intersection));

                    enterCollision = !enterCollision;
                    break;

                case 2:
                    collisionCount += 2;

                    if (Vector2D.Distance(intersections[0], pair.A) < Vector2D.Distance(intersections[1], pair.A))
                    {
                        collisionSlice.Add(new Point(intersections[0], Point.Type.Intersection));
                        collisionSlice.Add(new Point(intersections[1], Point.Type.Intersection));
                    }
                    else
                    {
                        collisionSlice.Add(new Point(intersections[1], Point.Type.Intersection));
                        collisionSlice.Add(new Point(intersections[0], Point.Type.Intersection));
                    }

                    intersection.A = intersections[0];
                    intersection.B = intersections[1];

                    break;

                case 0:
                    break;

                default:
                    error = true;

                    break;
                }

                if (enterCollision == true)
                {
                    collisionSlice.Add(new Point(pair.B, Point.Type.Inside));
                }
            }

            List <Vector2D> insidePoints = GetPointsInside();

            // Complex Points Generating
            if (insidePoints.Count > 0)
            {
                ///// Intersection Points
                intersection.A = First();
                intersection.B = Last();

                ///// Outside Points
                Vector2D first = insidePoints.First().Copy();
                Vector2D last  = insidePoints.Last().Copy();

                Vector2D firstOutside = First().Copy();
                Vector2D lastOutside  = Last().Copy();

                outside.A = firstOutside.Copy();
                outside.B = lastOutside.Copy();

                outside.A.Push(Vector2D.Atan2(firstOutside, first), precision);
                outside.B.Push(Vector2D.Atan2(lastOutside, last), precision);

                // Linear Points Generating
            }
            else
            {
                ///// Intersection Points
                intersections = GetIntersections();

                if (intersections.Count == 2)
                {
                    intersection.A = intersections.First();
                    intersection.B = intersections.Last();
                }
                else
                {
                    // How does this work with weird precision offset?
                    intersection.A = slice.First();
                    intersection.B = slice.Last();
                }

                // Outside Point
                Vector2D first = slice.Last().Copy();
                Vector2D last  = slice.First().Copy();

                Vector2D firstOutside = slice.First().Copy();
                Vector2D lastOutside  = slice.Last().Copy();

                outside.A = firstOutside.Copy();
                outside.B = lastOutside.Copy();

                outside.A.Push(Vector2D.Atan2(firstOutside, first), precision);
                outside.B.Push(Vector2D.Atan2(lastOutside, last), precision);
            }

            ///// Pairs Collided
            List <Vector2D> slicePoints = GetSlicePoints();

            pair.A = polygon.pointsList.Last();

            foreach (Vector2D p in polygon.pointsList)
            {
                pair.B = p;

                if (Math2D.LineIntersectSlice(pair, slicePoints) == true)
                {
                    polygonCollisionPairs.Add(pair);
                }

                pair.A = pair.B;
            }

            foreach (Polygon2D hole in polygon.holesList)
            {
                pair.A = hole.pointsList.Last();

                foreach (Vector2D p in hole.pointsList)
                {
                    pair.B = p;

                    if (Math2D.LineIntersectSlice(pair, slicePoints) == true)
                    {
                        polygonCollisionPairs.Add(pair);
                    }

                    pair.A = pair.B;
                }
            }
        }
    void DrawSoftShadows(Vector2D offset, float z)
    {
        float sunDirection = LightingManager2D.GetSunDirection();

        // Day Soft Shadows
        foreach (LightingCollider2D id in LightingCollider2D.GetList())
        {
            if (id.dayHeight && id.height > 0)
            {
                Polygon2D poly = id.GetPolygon();
                poly = poly.ToWorldSpace(id.gameObject.transform);

                GL.PushMatrix();
                Max2D.defaultMaterial.SetPass(0);
                GL.Begin(GL.TRIANGLES);
                GL.Color(Color.black);

                foreach (Pair2D p in Pair2D.GetList(poly.pointsList))
                {
                    Vector2D vA = p.A.Copy();
                    Vector2D vB = p.B.Copy();

                    vA.Push(sunDirection, id.height);
                    vB.Push(sunDirection, id.height);

                    Max2DMatrix.DrawTriangle(p.A, p.B, vA, offset, z);
                    Max2DMatrix.DrawTriangle(vA, vB, p.B, offset, z);
                }
                GL.End();
                GL.PopMatrix();

                Polygon2D convexHull = id.GenerateShadow(new Polygon2D(poly.pointsList), sunDirection);

                Max2D.SetColor(Color.white);

                GL.PushMatrix();
                LightingManager2D.Get().shadowBlurMaterial.SetPass(0);
                GL.Begin(GL.TRIANGLES);

                foreach (DoublePair2D p in DoublePair2D.GetList(convexHull.pointsList))
                {
                    Vector2D zA = new Vector2D(p.A + offset);
                    Vector2D zB = new Vector2D(p.B + offset);
                    Vector2D zC = new Vector2D(p.B + offset);

                    Vector2D pA = zA.Copy();
                    Vector2D pB = zB.Copy();

                    zA.Push(Vector2D.Atan2(p.A, p.B) + pi2, .5f);
                    zB.Push(Vector2D.Atan2(p.A, p.B) + pi2, .5f);
                    zC.Push(Vector2D.Atan2(p.B, p.C) + pi2, .5f);

                    GL.TexCoord2(uv0, uv0);
                    Max2D.Vertex3(pB, z);
                    GL.TexCoord2(0.5f - uv0, uv0);
                    Max2D.Vertex3(pA, z);
                    GL.TexCoord2(0.5f - uv0, uv1);
                    Max2D.Vertex3(zA, z);

                    GL.TexCoord2(uv0, uv1);
                    Max2D.Vertex3(zA, z);
                    GL.TexCoord2(0.5f - uv0, uv1);
                    Max2D.Vertex3(zB, z);
                    GL.TexCoord2(0.5f - uv0, uv0);
                    Max2D.Vertex3(pB, z);

                    GL.TexCoord2(uv0, uv1);
                    Max2D.Vertex3(zB, z);
                    GL.TexCoord2(0.5f - uv0, uv0);
                    Max2D.Vertex3(pB, z);
                    GL.TexCoord2(0.5f - uv0, uv1);
                    Max2D.Vertex3(zC, z);
                }

                GL.End();
                GL.PopMatrix();
            }
        }

        foreach (LightingCollider2D id in LightingCollider2D.GetList())
        {
            Max2D.SetColor(Color.white);
            Max2D.iDrawMesh(id.GetMesh(), id.transform, offset, z);
        }

        Vector2 size = new Vector2(bufferCamera.orthographicSize * ((float)Screen.width / Screen.height), bufferCamera.orthographicSize);
        Vector3 pos  = Camera.main.transform.position;

        Max2D.iDrawImage(LightingManager2D.Get().additiveMaterial, new Vector2D(pos), new Vector2D(size), pos.z);
    }
Пример #11
0
    private void UpdateComplex(Vector2D pos)
    {
        if (Input.GetMouseButtonDown(0))
        {
            pointsList.Clear();
            pointsList.Add(pos);
            mouseDown    = true;
            startedSlice = false;
        }

        if (pointsList.Count < 1)
        {
            return;
        }

        if (Input.GetMouseButton(0))
        {
            Vector2D posMove   = pointsList.Last().Copy();
            bool     added     = false;
            int      loopCount = 0;
            while ((Vector2D.Distance(posMove, pos) > minVertexDistance * visualScale))
            {
                float direction = (float)Vector2D.Atan2(pos, posMove);
                posMove.Push(direction, minVertexDistance * visualScale);

                if (startSliceIfPossible == true && startedSlice == false)
                {
                    if (InSlicerComponents(posMove.Copy()))
                    {
                        while (pointsList.Count > 2)
                        {
                            pointsList.RemoveAt(0);
                        }

                        startedSlice = true;
                    }
                }

                pointsList.Add(posMove.Copy());

                added = true;

                loopCount++;
                if (loopCount > 150)
                {
                    break;
                }
            }

            if (endSliceIfPossible == true && added)
            {
                if (ComplexSlice(pointsList) == true)
                {
                    mouseDown = false;
                    pointsList.Clear();

                    if (startSliceIfPossible)
                    {
                        pointsList.Add(pos);
                        mouseDown    = true;
                        startedSlice = false;
                    }
                }
            }
        }

        if (mouseDown == true && Input.GetMouseButton(0) == false)
        {
            mouseDown    = false;
            startedSlice = false;
            Slicer2D.complexSliceType = complexSliceType;
            ComplexSlice(pointsList);
            pointsList.Clear();
        }
    }
    public void Update()
    {
        for (int id = 0; id < 10; id++)
        {
            Vector2D pos = new Vector2D(input.GetInputPosition(id));

            if (input.GetInputClicked(id))
            {
                pointsList[id].Clear();
                pointsList[id].Add(pos);
                startedSlice = false;
            }

            if (pointsList[id].Count < 1)
            {
                return;
            }

            if (input.GetInputHolding(id))
            {
                Vector2D posMove   = pointsList[id].Last().Copy();
                bool     added     = false;
                int      loopCount = 0;

                while ((Vector2D.Distance(posMove, pos) > minVertexDistance * visuals.visualScale))
                {
                    float direction = (float)Vector2D.Atan2(pos, posMove);
                    posMove.Push(direction, minVertexDistance * visuals.visualScale);

                    if (startSliceIfPossible == true && startedSlice == false)
                    {
                        if (Slicer2D.PointInSlicerComponent(posMove.Copy()) != null)
                        {
                            while (pointsList[id].Count > 2)
                            {
                                pointsList[id].RemoveAt(0);
                            }

                            startedSlice = true;
                        }
                    }

                    pointsList[id].Add(posMove.Copy());

                    added = true;

                    loopCount++;
                    if (loopCount > 150)
                    {
                        break;
                    }
                }

                if (endSliceIfPossible == true && added)
                {
                    if (ComplexSlice(GetPoints(id)) == true)
                    {
                        pointsList[id].Clear();

                        if (startSliceIfPossible)
                        {
                            pointsList[id].Add(pos);
                            startedSlice = false;
                        }
                    }
                }
            }

            if (input.GetInputReleased(id))
            {
                startedSlice = false;
                Slicer2D.complexSliceType = complexSliceType;
                ComplexSlice(GetPoints(id));
                pointsList[id].Clear();
            }
        }
    }
Пример #13
0
    public static void Draw(Vector2D offset, float z)
    {
        float sunDirection = LightingManager2D.GetSunDirection();

        // Day Soft Shadows
        GL.PushMatrix();
        Max2D.defaultMaterial.SetPass(0);
        GL.Begin(GL.TRIANGLES);
        GL.Color(Color.black);

        foreach (LightingCollider2D id in LightingCollider2D.GetList())
        {
            if (id.dayHeight == false || id.height <= 0)
            {
                continue;
            }
            List <Polygon2D> polygons = id.GetPolygons();

            foreach (Polygon2D polygon in polygons)
            {
                Polygon2D poly = polygon;
                poly = poly.ToWorldSpace(id.gameObject.transform);

                foreach (Pair2D p in Pair2D.GetList(poly.pointsList))
                {
                    Vector2D vA = p.A.Copy();
                    Vector2D vB = p.B.Copy();

                    vA.Push(sunDirection, id.height);
                    vB.Push(sunDirection, id.height);

                    Max2DMatrix.DrawTriangle(p.A, p.B, vA, offset, z);
                    Max2DMatrix.DrawTriangle(vA, vB, p.B, offset, z);
                }
            }
        }

        GL.End();
        GL.PopMatrix();

        GL.PushMatrix();
        LightingManager2D.Get().shadowBlurMaterial.SetPass(0);
        GL.Begin(GL.TRIANGLES);
        Max2D.SetColor(Color.white);

        foreach (LightingCollider2D id in LightingCollider2D.GetList())
        {
            if (id.dayHeight == false || id.height <= 0)
            {
                continue;
            }
            List <Polygon2D> polygons = id.GetPolygons();

            foreach (Polygon2D polygon in polygons)
            {
                Polygon2D poly = polygon;
                poly = poly.ToWorldSpace(id.gameObject.transform);

                Polygon2D convexHull = Polygon2D.GenerateShadow(new Polygon2D(poly.pointsList), sunDirection, id.height);

                foreach (DoublePair2D p in DoublePair2D.GetList(convexHull.pointsList))
                {
                    Vector2D zA = new Vector2D(p.A + offset);
                    Vector2D zB = new Vector2D(p.B + offset);
                    Vector2D zC = zB.Copy();

                    Vector2D pA = zA.Copy();
                    Vector2D pB = zB.Copy();

                    zA.Push(Vector2D.Atan2(p.A, p.B) + pi2, .5f);
                    zB.Push(Vector2D.Atan2(p.A, p.B) + pi2, .5f);
                    zC.Push(Vector2D.Atan2(p.B, p.C) + pi2, .5f);

                    GL.TexCoord2(uv0, uv0);
                    Max2D.Vertex3(pB, z);
                    GL.TexCoord2(0.5f - uv0, uv0);
                    Max2D.Vertex3(pA, z);
                    GL.TexCoord2(0.5f - uv0, uv1);
                    Max2D.Vertex3(zA, z);

                    GL.TexCoord2(uv0, uv1);
                    Max2D.Vertex3(zA, z);
                    GL.TexCoord2(0.5f - uv0, uv1);
                    Max2D.Vertex3(zB, z);
                    GL.TexCoord2(0.5f - uv0, uv0);
                    Max2D.Vertex3(pB, z);

                    GL.TexCoord2(uv0, uv1);
                    Max2D.Vertex3(zB, z);
                    GL.TexCoord2(0.5f - uv0, uv0);
                    Max2D.Vertex3(pB, z);
                    GL.TexCoord2(0.5f - uv0, uv1);
                    Max2D.Vertex3(zC, z);
                }
            }
        }

        GL.End();
        GL.PopMatrix();

        GL.PushMatrix();
        Max2D.defaultMaterial.SetPass(0);
        GL.Begin(GL.TRIANGLES);
        GL.Color(Color.black);


        GL.End();
        GL.PopMatrix();

        GL.PushMatrix();
        LightingManager2D.Get().shadowBlurMaterial.SetPass(0);
        GL.Begin(GL.TRIANGLES);
        Max2D.SetColor(Color.white);


        GL.End();
        GL.PopMatrix();

        Material material = LightingManager2D.Get().whiteSpriteMaterial;

        foreach (LightingSprite2D id in LightingSprite2D.GetList())
        {
            if (id.GetSpriteRenderer() == null)
            {
                continue;
            }
            material.mainTexture = id.GetSpriteRenderer().sprite.texture;             //Debug.Log(sprite.pivot);

            Vector2 p     = id.transform.position;
            Vector2 scale = id.transform.lossyScale;

            if (id.GetSpriteRenderer().flipX)
            {
                scale.x = -scale.x;
            }

            if (id.GetSpriteRenderer().flipY)
            {
                scale.y = -scale.y;
            }

            Max2D.DrawImage(material, offset.ToVector2() + p, scale, id.transform.rotation.eulerAngles.z, z);
        }

        material = LightingManager2D.Get().additiveMaterial;
        foreach (LightingSpriteRenderer2D id in LightingSpriteRenderer2D.GetList())
        {
            if (id.sprite == null)
            {
                continue;
            }
            material.mainTexture = id.sprite.texture;             //Debug.Log(sprite.pivot);

            Vector2 position = id.transform.position;
            Vector2 scale    = id.transform.lossyScale;

            float scaleX = (float)id.sprite.texture.width / (id.sprite.pixelsPerUnit * 2);
            float scaleY = (float)id.sprite.texture.width / (id.sprite.pixelsPerUnit * 2);
            //Debug.Log(scaleX + " " + scaleY);

            scale.x *= scaleX;
            scale.y *= scaleY;

            scale.x *= id.scale.x;
            scale.y *= id.scale.y;

            if (id.flipX)
            {
                scale.x = -scale.x;
            }

            if (id.flipY)
            {
                scale.y = -scale.y;
            }

            //material.color = id.color;
            Color color = id.color;
            color.a = id.alpha;

            material.SetColor("_TintColor", color);
            Max2D.DrawImage(material, offset.ToVector2() + position + id.offset, scale, id.transform.rotation.eulerAngles.z, z);
        }

        material.mainTexture = null;

        float   ratio        = (float)Screen.width / Screen.height;
        Camera  bufferCamera = LightingMainBuffer2D.Get().bufferCamera;
        Vector2 size         = new Vector2(bufferCamera.orthographicSize * ratio, bufferCamera.orthographicSize);
        Vector3 pos          = Camera.main.transform.position;

        Max2D.iDrawImage(LightingManager2D.Get().additiveMaterial, new Vector2D(pos), new Vector2D(size), pos.z);
    }
Пример #14
0
    public static void Draw(Vector2D offset, float z)
    {
        // Collider Ambient Occlusion
        GL.PushMatrix();
        LightingManager2D.Get().occlusionBlurMaterial.SetPass(0);
        GL.Begin(GL.QUADS);
        GL.Color(Color.white);

        foreach (LightingCollider2D id in LightingCollider2D.GetList())
        {
            if (id.ambientOcclusion == false || id.smoothOcclusionEdges == true)
            {
                continue;
            }

            // Do not call Create From Collider
            List <Polygon2D> polygons = id.GetPolygons();

            foreach (Polygon2D polygon in polygons)
            {
                Polygon2D poly = polygon;
                poly = poly.ToWorldSpace(id.gameObject.transform);

                poly.Normalize();

                Vector2D first = null;

                List <Pair2D> iterate1 = Pair2D.GetList(poly.pointsList);
                List <Pair2D> iterate2 = Pair2D.GetList(PreparePolygon(poly, id.occlusionSize).pointsList);

                int i = 0;
                foreach (Pair2D pA in iterate1)
                {
                    if (id.edgeCollider2D == true && first == null)
                    {
                        first = pA.A;
                        continue;
                    }

                    Pair2D pB = iterate2[i];

                    GL.TexCoord2(uv0, uv0);
                    Max2D.Vertex3(pA.A + offset, z);
                    GL.TexCoord2(uv1, uv0);
                    Max2D.Vertex3(pA.B + offset, z);
                    GL.TexCoord2(uv1, uv1);
                    Max2D.Vertex3(pB.B + offset, z);
                    GL.TexCoord2(uv0, uv1);
                    Max2D.Vertex3(pB.A + offset, z);

                    i++;
                }
            }
        }
        GL.End();
        GL.PopMatrix();

        GL.PushMatrix();
        LightingManager2D.Get().occlusionEdgeMaterial.SetPass(0);
        GL.Begin(GL.TRIANGLES);

        foreach (LightingCollider2D id in LightingCollider2D.GetList())
        {
            if (id.ambientOcclusion == false || id.smoothOcclusionEdges == false)
            {
                continue;
            }

            // Do not call Create From Collider
            List <Polygon2D> polygons = id.GetPolygons();

            foreach (Polygon2D polygon in polygons)
            {
                Polygon2D poly = polygon;
                poly = poly.ToWorldSpace(id.gameObject.transform);

                poly.Normalize();

                foreach (DoublePair2D p in DoublePair2D.GetList(poly.pointsList))
                {
                    Vector2D vA = p.A + offset;
                    Vector2D vB = p.B + offset;
                    Vector2D vC = p.B + offset;

                    Vector2D pA = p.A + offset;
                    Vector2D pB = p.B + offset;

                    vA.Push(Vector2D.Atan2(p.A, p.B) - Mathf.PI / 2, id.occlusionSize);
                    vB.Push(Vector2D.Atan2(p.A, p.B) - Mathf.PI / 2, id.occlusionSize);
                    vC.Push(Vector2D.Atan2(p.B, p.C) - Mathf.PI / 2, id.occlusionSize);

                    GL.TexCoord2(uv0, uv0);
                    Max2D.Vertex3(pB, z);
                    GL.TexCoord2(0.5f - uv0, uv0);
                    Max2D.Vertex3(pA, z);
                    GL.TexCoord2(0.5f - uv0, uv1);
                    Max2D.Vertex3(vA, z);

                    GL.TexCoord2(uv0, uv1);
                    Max2D.Vertex3(vA, z);
                    GL.TexCoord2(0.5f - uv0, uv1);
                    Max2D.Vertex3(vB, z);
                    GL.TexCoord2(0.5f - uv0, uv0);
                    Max2D.Vertex3(pB, z);

                    GL.TexCoord2(uv1, uv0);
                    Max2D.Vertex3(vB, z);
                    GL.TexCoord2(0.5f - uv0, uv0);
                    Max2D.Vertex3(pB, z);
                    GL.TexCoord2(0.5f - uv0, uv1);
                    Max2D.Vertex3(vC, z);
                }
            }
        }
        GL.End();
        GL.PopMatrix();

        GL.PushMatrix();
        LightingManager2D.Get().occlusionEdgeMaterial.SetPass(0);
        GL.Begin(GL.TRIANGLES);

        foreach (LightingTilemapCollider2D id in LightingTilemapCollider2D.GetList())
        {
            if (id.map == null)
            {
                continue;
            }
            if (id.ambientOcclusion == false)
            {
                continue;
            }
            for (int x = 0; x < id.area.size.x; x++)
            {
                for (int y = 0; y < id.area.size.y; y++)
                {
                    if (id.map[x, y] == false)
                    {
                        continue;
                    }

                    Vector2D offs = offset.Copy();
                    offs += new Vector2D(0.5f, 0.5f);
                    offs += new Vector2D(id.area.position.x, id.area.position.y);
                    offs += new Vector2D(-id.area.size.x / 2, -id.area.size.y / 2);

                    DrawTileOcclussion(offs + new Vector2D(x, y), z, id);
                }
            }
        }
        GL.End();
        GL.PopMatrix();
    }
Пример #15
0
    static public Mesh2DTriangle CreateLineNew(Pair2D pair, Transform transform, float lineWidth, float z = 0f)
    {
        if (lineType == LineType.Legacy)
        {
            return(CreateLine(pair, lineWidth, z));
        }

        Mesh2DTriangle result = new Mesh2DTriangle();

        float xuv0 = 0;         //1f / 128;
        float xuv1 = 1f - xuv0;
        float yuv0 = 0;         //1f / 192;
        float yuv1 = 1f - xuv0;

        float size = lineWidth / 6;
        float rot  = (float)Vector2D.Atan2(pair.A, pair.B);

        Vector2D A1 = new Vector2D(pair.A);
        Vector2D A2 = new Vector2D(pair.A);
        Vector2D B1 = new Vector2D(pair.B);
        Vector2D B2 = new Vector2D(pair.B);

        Vector2 scale = new Vector2(1f / transform.localScale.x, 1f / transform.localScale.y);

        A1.Push(rot + pi2, size, scale);
        A2.Push(rot - pi2, size, scale);
        B1.Push(rot + pi2, size, scale);
        B2.Push(rot - pi2, size, scale);

        result.uv.Add(new Vector2(xuv1 / 3, yuv1));
        result.vertices.Add(new Vector3((float)B1.x, (float)B1.y, z));
        result.uv.Add(new Vector2(1 - xuv1 / 3, yuv1));
        result.vertices.Add(new Vector3((float)A1.x, (float)A1.y, z));
        result.uv.Add(new Vector2(1 - xuv1 / 3, yuv0));
        result.vertices.Add(new Vector3((float)A2.x, (float)A2.y, z));

        result.uv.Add(new Vector2(1 - xuv1 / 3, yuv0));
        result.vertices.Add(new Vector3((float)A2.x, (float)A2.y, z));
        result.uv.Add(new Vector2(yuv1 / 3, xuv0));
        result.vertices.Add(new Vector3((float)B2.x, (float)B2.y, z));
        result.uv.Add(new Vector2(xuv1 / 3, yuv1));
        result.vertices.Add(new Vector3((float)B1.x, (float)B1.y, z));

        Vector2D A3 = A1.Copy();
        Vector2D A4 = A1.Copy();

        A3.Push(rot - pi2, size, scale);

        A3 = A1.Copy();
        A4 = A2.Copy();

        A1.Push(rot, size, scale);
        A2.Push(rot, size, scale);

        result.uv.Add(new Vector2(xuv1 / 3, yuv1));
        result.vertices.Add(new Vector3((float)A3.x, (float)A3.y, z));
        result.uv.Add(new Vector2(xuv0, yuv1));
        result.vertices.Add(new Vector3((float)A1.x, (float)A1.y, z));
        result.uv.Add(new Vector2(xuv0, yuv0));
        result.vertices.Add(new Vector3((float)A2.x, (float)A2.y, z));

        result.uv.Add(new Vector2(xuv0, yuv0));
        result.vertices.Add(new Vector3((float)A2.x, (float)A2.y, z));
        result.uv.Add(new Vector2(yuv1 / 3, xuv0));
        result.vertices.Add(new Vector3((float)A4.x, (float)A4.y, z));
        result.uv.Add(new Vector2(xuv1 / 3, yuv1));
        result.vertices.Add(new Vector3((float)A3.x, (float)A3.y, z));

        A1 = B1.Copy();
        A2 = B2.Copy();

        B1.Push(rot - Mathf.PI, size, scale);
        B2.Push(rot - Mathf.PI, size, scale);

        result.uv.Add(new Vector2(xuv0, yuv1));
        result.vertices.Add(new Vector3((float)B1.x, (float)B1.y, z));
        result.uv.Add(new Vector2(xuv1 / 3, yuv1));
        result.vertices.Add(new Vector3((float)A1.x, (float)A1.y, z));
        result.uv.Add(new Vector2(xuv1 / 3, yuv0));
        result.vertices.Add(new Vector3((float)A2.x, (float)A2.y, z));

        result.uv.Add(new Vector2(xuv1 / 3, yuv0));
        result.vertices.Add(new Vector3((float)A2.x, (float)A2.y, z));
        result.uv.Add(new Vector2(yuv0, xuv0));
        result.vertices.Add(new Vector3((float)B2.x, (float)B2.y, z));
        result.uv.Add(new Vector2(xuv0, yuv1));
        result.vertices.Add(new Vector3((float)B1.x, (float)B1.y, z));

        return(result);
    }
Пример #16
0
    public void Update()
    {
        for (int id = 0; id < 10; id++)
        {
            Vector2D pos = new Vector2D(input.GetInputPosition(id));

            if (input.GetInputClicked(id))
            {
                linearPair[id] = new Pair2D(pos.Copy(), pos.Copy());
                startedSlice   = false;
            }

            // Start Slice If Possible
            if (startSliceIfPossible)
            {
                if (startedSlice == true)
                {
                    if (Slicer2D.PointInSlicerComponent(pos.Copy()) == null)
                    {
                        startedSlice = false;
                    }
                }
                else if (startedSlice == false)
                {
                    if (Slicer2D.PointInSlicerComponent(pos.Copy()) != null)
                    {
                        startedSlice = true;
                    }
                    else
                    {
                        linearPair[id].A.Set(pos.Copy());
                    }
                }
            }

            // End Slice If Possible
            if (input.GetInputHolding(id))
            {
                linearPair[id].B.Set(pos);

                if (endSliceIfPossible)
                {
                    if (input.GetSlicingEnabled(id))
                    {
                        if (LinearSlice(GetPair(id)))
                        {
                            linearPair[id].A.Set(pos);

                            if (startSliceIfPossible)
                            {
                                linearPair[id] = new Pair2D(pos.Copy(), pos.Copy());
                                startedSlice   = false;
                            }
                        }
                    }
                }
            }

            if (input.GetInputReleased(id))
            {
                if (input.GetSlicingEnabled(id))
                {
                    LinearSlice(GetPair(id));
                }
            }
        }
    }
Пример #17
0
    static public void DrawTilemaps(Vector2D offset, float z)
    {
                #if UNITY_2018_1_OR_NEWER
        LightingManager2D manager = LightingManager2D.Get();

        GL.PushMatrix();

        Max2D.defaultMaterial.SetPass(0);

        GL.Begin(GL.TRIANGLES);
        GL.Color(Color.black);

        // Day Soft Shadows
        foreach (LightingTilemapCollider2D id in LightingTilemapCollider2D.GetList())
        {
            if (id.map == null)
            {
                continue;
            }

            if (id.dayHeight == false)
            {
                continue;
            }

            Vector2D tilesetOffset = new Vector2D(offset);
            tilesetOffset += new Vector2D(id.area.position.x, id.area.position.y);

            for (int x = 0; x < id.area.size.x; x++)
            {
                for (int y = 0; y < id.area.size.y; y++)
                {
                    if (id.map[x, y] == null)
                    {
                        continue;
                    }

                    Vector2D tileOffset = tilesetOffset.Copy();
                    tileOffset += new Vector2D(x, y);

                    DrawSoftShadowTile(tileOffset, z, id.height);
                }
            }
        }

        GL.End();
        GL.PopMatrix();

        GL.PushMatrix();

        manager.materials.GetShadowBlur().SetPass(0);

        GL.Begin(GL.TRIANGLES);
        Max2D.SetColor(Color.white);

        // Day Soft Shadows Penumbra
        foreach (LightingTilemapCollider2D id in LightingTilemapCollider2D.GetList())
        {
            if (id.map == null)
            {
                continue;
            }

            if (id.dayHeight == false)
            {
                continue;
            }

            Vector2D tilesetOffset = new Vector2D(offset);
            tilesetOffset += new Vector2D(id.area.position.x, id.area.position.y);

            for (int x = 0; x < id.area.size.x; x++)
            {
                for (int y = 0; y < id.area.size.y; y++)
                {
                    if (id.map[x, y] == null)
                    {
                        continue;
                    }

                    Vector2D tileOffset = tilesetOffset.Copy();
                    tileOffset += new Vector2D(x, y);

                    DrawSoftShadowTileBlur(tileOffset, z, id.height);
                }
            }
        }

        GL.End();
        GL.PopMatrix();

        Material materialWhite = manager.materials.GetWhiteSprite();

        // Tilemap Daylighting Masks
        foreach (LightingTilemapCollider2D id in LightingTilemapCollider2D.GetList())
        {
            if (id.map == null)
            {
                continue;
            }

            if (id.dayHeight == false)
            {
                continue;
            }

            Vector3 rot = Math2D.GetPitchYawRollRad(id.transform.rotation);

            float rotationYScale = Mathf.Sin(rot.x + Mathf.PI / 2);
            float rotationXScale = Mathf.Sin(rot.y + Mathf.PI / 2);

            float scaleX = id.transform.lossyScale.x * rotationXScale * id.cellSize.x;
            float scaleY = id.transform.lossyScale.y * rotationYScale * id.cellSize.y;

            Vector2D tilesetOffset = new Vector2D(offset);
            tilesetOffset += new Vector2D(id.area.position.x, id.area.position.y);
            tilesetOffset += new Vector2D(id.cellAnchor.x, id.cellAnchor.y);

            //GL.PushMatrix ();

            for (int x = 0; x < id.area.size.x; x++)
            {
                for (int y = 0; y < id.area.size.y; y++)
                {
                    LightingTile tile = id.map[x, y];
                    if (tile == null)
                    {
                        continue;
                    }

                    if (tile.GetOriginalSprite() == null)
                    {
                        continue;
                    }

                    VirtualSpriteRenderer spriteRenderer = new VirtualSpriteRenderer();
                    spriteRenderer.sprite = tile.GetOriginalSprite();

                    materialWhite.mainTexture = tile.GetOriginalSprite().texture;

                    Vector2D tileOffset = tilesetOffset.Copy();
                    tileOffset += new Vector2D(x, y);


                    //Max2D.DrawSprite(materialWhite, spriteRenderer, tileOffset.ToVector2(), new Vector2(scaleX / id.cellSize.x, scaleY / id.cellSize.y), 0, z);

                    materialWhite.mainTexture = null;
                }
            }
        }

        //GL.PopMatrix ();
                #endif
    }
Пример #18
0
    public ComplexCollision(Polygon2D polygon, List <Vector2D> slice)
    {
        bool enterCollision = false;

        Pair2D pair = Pair2D.Zero();

        // Generate correct intersected slice

        List <Vector2D> intersections;

        for (int i = 0; i < slice.Count - 1; i++)
        {
            pair.A = slice[i];;
            pair.B = slice[i + 1];

            intersections = polygon.GetListLineIntersectPoly(pair);

            if (intersections.Count == 1)
            {
                //intersectionType = IntersectionType.DifferentPairs;
                collisionCount += 1;

                collisionSlice.Add(new Point(intersections[0], Point.Type.Intersection));

                enterCollision = !enterCollision;
            }
            else if (intersections.Count == 2)
            {
                //intersectionType = IntersectionType.SamePair;
                collisionCount += intersections.Count;                 // Check if it's okay

                if (Vector2D.Distance(intersections[0], pair.A) < Vector2D.Distance(intersections[1], pair.A))
                {
                    collisionSlice.Add(new Point(intersections[0], Point.Type.Intersection));
                    collisionSlice.Add(new Point(intersections[1], Point.Type.Intersection));
                }
                else
                {
                    collisionSlice.Add(new Point(intersections[1], Point.Type.Intersection));
                    collisionSlice.Add(new Point(intersections[0], Point.Type.Intersection));
                }
            }
            else if (intersections.Count > 2)
            {
                error = true;
            }

            if (enterCollision == true)
            {
                collisionSlice.Add(new Point(pair.B, Point.Type.Inside));
            }
        }

        List <Vector2D> insidePoints = GetPointsInside();

        // Complex Points Generating
        if (insidePoints.Count > 0)
        {
            ///// Outside Points
            Vector2D first = insidePoints.First();
            Vector2D last  = insidePoints.Last();

            Vector2D firstOutside = First();
            Vector2D lastOutside  = Last();

            outside.A = firstOutside.Copy();
            outside.B = lastOutside.Copy();

            outside.A.Push(Vector2D.Atan2(firstOutside, first), 0.001f);
            outside.B.Push(Vector2D.Atan2(lastOutside, last), 0.001f);

            ///// Inside Points

            Vector2D firstInside = First();
            Vector2D lastInside  = Last();

            inside.A = firstInside.Copy();
            inside.B = lastInside.Copy();

            inside.A.Push(Vector2D.Atan2(first, firstInside), 0.001f);
            inside.B.Push(Vector2D.Atan2(last, lastInside), 0.001f);

            // Linear Points Generating
        }
        else
        {
            Vector2D first = slice.Last();
            Vector2D last  = slice.First();

            Vector2D firstOutside = slice.First();
            Vector2D lastOutside  = slice.Last();

            outside.A = firstOutside.Copy();
            outside.B = lastOutside.Copy();

            outside.A.Push(Vector2D.Atan2(firstOutside, first), 0.001f);
            outside.B.Push(Vector2D.Atan2(lastOutside, last), 0.001f);

            ///// Inside Points
            Vector2D firstInside = slice.First();
            Vector2D lastInside  = slice.Last();

            inside.A = firstInside.Copy();
            inside.B = lastInside.Copy();

            inside.A.Push(Vector2D.Atan2(first, firstInside), 0.001f);
            inside.B.Push(Vector2D.Atan2(last, lastInside), 0.001f);
        }

        ///// Pairs Collided
        List <Vector2D> slicePoints = GetSlicePoints();

        pair.A = polygon.pointsList.Last();

        foreach (Vector2D p in polygon.pointsList)
        {
            pair.B = p;

            if (Math2D.LineIntersectSlice(pair, slicePoints) == true)
            {
                polygonCollisionPairs.Add(pair);
            }

            pair.A = pair.B;
        }

        foreach (Polygon2D hole in polygon.holesList)
        {
            pair.A = hole.pointsList.Last();

            foreach (Vector2D p in hole.pointsList)
            {
                pair.B = p;

                if (Math2D.LineIntersectSlice(pair, slicePoints) == true)
                {
                    polygonCollisionPairs.Add(pair);
                }

                pair.A = pair.B;
            }
        }
    }
Пример #19
0
    public static void Draw(Vector2D offset, float z)
    {
        float sunDirection = LightingManager2D.GetSunDirection();

        // Day Soft Shadows
        GL.PushMatrix();
        Max2D.defaultMaterial.SetPass(0);
        GL.Begin(GL.TRIANGLES);
        GL.Color(Color.black);

        foreach (LightingCollider2D id in LightingCollider2D.GetList())
        {
            if (id.dayHeight == false || id.height <= 0)
            {
                continue;
            }

            if (id.colliderType == LightingCollider2D.ColliderType.Mesh)
            {
                continue;
            }

            List <Polygon2D> polygons = null;
            switch (id.colliderType)
            {
            case LightingCollider2D.ColliderType.Collider:
                polygons = id.GetColliderPolygons();
                break;

            case LightingCollider2D.ColliderType.SpriteCustomPhysicsShape:
                polygons = id.GetShapePolygons();
                break;
            }

            Polygon2D poly;
            Vector3   vecA;
            Vector3   vecB;
            Vector3   vecC;

            foreach (Polygon2D polygon in polygons)
            {
                poly = polygon.ToWorldSpace(id.gameObject.transform);
                Polygon2D convexHull = Polygon2D.GenerateShadow(new Polygon2D(poly.pointsList), sunDirection, id.height);

                Mesh mesh = convexHull.CreateMesh(Vector2.zero, Vector2.zero);

                for (int i = 0; i < mesh.triangles.GetLength(0); i = i + 3)
                {
                    vecA = mesh.vertices [mesh.triangles [i]];
                    vecB = mesh.vertices [mesh.triangles [i + 1]];
                    vecC = mesh.vertices [mesh.triangles [i + 2]];
                    Max2DMatrix.DrawTriangle(vecA.x, vecA.y, vecB.x, vecB.y, vecC.x, vecC.y, offset, z);
                }
            }
        }

        GL.End();
        GL.PopMatrix();

        GL.PushMatrix();
        // Null Check?
        LightingManager2D.Get().shadowBlurMaterial.SetPass(0);
        GL.Begin(GL.TRIANGLES);
        Max2D.SetColor(Color.white);

        foreach (LightingCollider2D id in LightingCollider2D.GetList())
        {
            if (id.dayHeight == false || id.height <= 0)
            {
                continue;
            }

            if (id.colliderType == LightingCollider2D.ColliderType.Mesh)
            {
                continue;
            }

            List <Polygon2D> polygons = null;
            switch (id.colliderType)
            {
            case LightingCollider2D.ColliderType.Collider:
                polygons = id.GetColliderPolygons();
                break;

            case LightingCollider2D.ColliderType.SpriteCustomPhysicsShape:
                polygons = id.GetShapePolygons();
                break;
            }

            foreach (Polygon2D polygon in polygons)
            {
                Polygon2D poly       = polygon.ToWorldSpace(id.gameObject.transform);
                Polygon2D convexHull = Polygon2D.GenerateShadow(new Polygon2D(poly.pointsList), sunDirection, id.height);

                foreach (DoublePair2D p in DoublePair2D.GetList(convexHull.pointsList))
                {
                    Vector2D zA = new Vector2D(p.A + offset);
                    Vector2D zB = new Vector2D(p.B + offset);
                    Vector2D zC = zB.Copy();

                    Vector2D pA = zA.Copy();
                    Vector2D pB = zB.Copy();

                    zA.Push(Vector2D.Atan2(p.A, p.B) + pi2, .5f);
                    zB.Push(Vector2D.Atan2(p.A, p.B) + pi2, .5f);
                    zC.Push(Vector2D.Atan2(p.B, p.C) + pi2, .5f);

                    GL.TexCoord2(uv0, uv0);
                    Max2D.Vertex3(pB, z);
                    GL.TexCoord2(0.5f - uv0, uv0);
                    Max2D.Vertex3(pA, z);
                    GL.TexCoord2(0.5f - uv0, uv1);
                    Max2D.Vertex3(zA, z);

                    GL.TexCoord2(uv0, uv1);
                    Max2D.Vertex3(zA, z);
                    GL.TexCoord2(0.5f - uv0, uv1);
                    Max2D.Vertex3(zB, z);
                    GL.TexCoord2(0.5f - uv0, uv0);
                    Max2D.Vertex3(pB, z);

                    GL.TexCoord2(uv0, uv1);
                    Max2D.Vertex3(zB, z);
                    GL.TexCoord2(0.5f - uv0, uv0);
                    Max2D.Vertex3(pB, z);
                    GL.TexCoord2(0.5f - uv0, uv1);
                    Max2D.Vertex3(zC, z);
                }
            }
        }

        GL.End();
        GL.PopMatrix();

                #if UNITY_2018_1_OR_NEWER
        GL.PushMatrix();
        Max2D.defaultMaterial.SetPass(0);
        GL.Begin(GL.TRIANGLES);
        GL.Color(Color.black);



        // Day Soft Shadows
        foreach (LightingTilemapCollider2D id in LightingTilemapCollider2D.GetList())
        {
            if (id.map == null)
            {
                continue;
            }
            if (id.dayHeight == false)
            {
                continue;
            }
            for (int x = 0; x < id.area.size.x; x++)
            {
                for (int y = 0; y < id.area.size.y; y++)
                {
                    if (id.map[x, y] == null)
                    {
                        DrawSoftShadowTile(offset + new Vector2D(x, y), z, id.height);
                    }
                }
            }
        }

        GL.End();
        GL.PopMatrix();



        GL.PushMatrix();
        LightingManager2D.Get().shadowBlurMaterial.SetPass(0);
        GL.Begin(GL.TRIANGLES);
        Max2D.SetColor(Color.white);



        // Day Soft Shadows
        foreach (LightingTilemapCollider2D id in LightingTilemapCollider2D.GetList())
        {
            if (id.map == null)
            {
                continue;
            }
            if (id.dayHeight == false)
            {
                continue;
            }
            for (int x = 0; x < id.area.size.x; x++)
            {
                for (int y = 0; y < id.area.size.y; y++)
                {
                    if (id.map[x, y] == null)
                    {
                        DrawSoftShadowTileBlur(offset + new Vector2D(x, y), z, id.height);
                    }
                }
            }
        }

        GL.End();
        GL.PopMatrix();
                #endif

        /*
         *
         * Material material = LightingManager2D.Get().whiteSpriteMaterial;
         * foreach (LightingSprite2D id in LightingSprite2D.GetList()) {
         *      if (id.GetSpriteRenderer() == null) {
         *              continue;
         *      }
         *      material.mainTexture = id.GetSpriteRenderer().sprite.texture; //Debug.Log(sprite.pivot);
         *
         *      Vector2 p = id.transform.position;
         *      Vector2 scale = id.transform.lossyScale;
         *
         *      if (id.GetSpriteRenderer().flipX) {
         *              scale.x = -scale.x;
         *      }
         *
         *      if (id.GetSpriteRenderer().flipY) {
         *              scale.y = -scale.y;
         *      }
         *
         *      Max2D.DrawImage(material, offset.ToVector2() + p, scale, id.transform.rotation.eulerAngles.z, z);
         * } */

        float   ratio        = (float)Screen.width / Screen.height;
        Camera  bufferCamera = LightingMainBuffer2D.Get().bufferCamera;
        Vector2 size         = new Vector2(bufferCamera.orthographicSize * ratio, bufferCamera.orthographicSize);
        Vector3 pos          = Camera.main.transform.position;

        Max2D.DrawImage(LightingManager2D.Get().additiveMaterial, new Vector2D(pos), new Vector2D(size), pos.z);

        // Day Lighting Masking
        foreach (LightingCollider2D id in LightingCollider2D.GetList())
        {
            if (id.generateDayMask == false)
            {
                continue;
            }

            switch (id.maskType)
            {
            case LightingCollider2D.MaskType.SpriteCustomPhysicsShape:
                Max2D.SetColor(Color.white);
                Max2D.DrawMesh(Max2D.defaultMaterial, id.GetShapeMesh(), id.transform, offset, z);

                break;

            case LightingCollider2D.MaskType.Collider:
                Max2D.SetColor(Color.white);
                Max2D.DrawMesh(Max2D.defaultMaterial, id.GetColliderMesh(), id.transform, offset, z);

                break;

            case LightingCollider2D.MaskType.Sprite:
                if (id.spriteRenderer == null || id.spriteRenderer.sprite == null)
                {
                    break;
                }

                Material material = LightingManager2D.Get().whiteSpriteMaterial;
                material.mainTexture = id.spriteRenderer.sprite.texture;

                Max2D.DrawSprite(material, id.spriteRenderer, new Vector2(id.transform.position.x, id.transform.position.y) + offset.ToVector2(), new Vector2(1, 1), id.transform.rotation.eulerAngles.z, z);

                break;
            }
        }
    }
Пример #20
0
    static public Mesh2DTriangle CreateLineNew(Pair2D pair, float lineWidth, float z = 0f)
    {
        Mesh2DTriangle result = new Mesh2DTriangle();

        float xuv0 = 0;
        float xuv1 = 1f;

        float yuv0 = 0;
        float yuv1 = 1f;

        float size = lineWidth / 6;
        float rot  = (float)Vector2D.Atan2(pair.A, pair.B);

        Vector2D A1 = pair.A.Copy();
        Vector2D A2 = pair.A.Copy();
        Vector2D B1 = pair.B.Copy();
        Vector2D B2 = pair.B.Copy();

        A1.Push(rot + pi2, size);
        A2.Push(rot - pi2, size);
        B1.Push(rot + pi2, size);
        B2.Push(rot - pi2, size);

        result.uv.Add(new Vector2(xuv1 / 3, yuv1));
        result.vertices.Add(new Vector3((float)B1.x, (float)B1.y, z));
        result.uv.Add(new Vector2(1 - xuv1 / 3, yuv1));
        result.vertices.Add(new Vector3((float)A1.x, (float)A1.y, z));
        result.uv.Add(new Vector2(1 - xuv1 / 3, yuv0));
        result.vertices.Add(new Vector3((float)A2.x, (float)A2.y, z));

        result.uv.Add(new Vector2(1 - xuv1 / 3, yuv0));
        result.vertices.Add(new Vector3((float)A2.x, (float)A2.y, z));
        result.uv.Add(new Vector2(yuv1 / 3, xuv0));
        result.vertices.Add(new Vector3((float)B2.x, (float)B2.y, z));
        result.uv.Add(new Vector2(xuv1 / 3, yuv1));
        result.vertices.Add(new Vector3((float)B1.x, (float)B1.y, z));

        Vector2D A3 = A1.Copy();
        Vector2D A4 = A1.Copy();

        A3.Push(rot - pi2, size);

        A3 = A1.Copy();
        A4 = A2.Copy();

        A1.Push(rot, size);
        A2.Push(rot, size);

        result.uv.Add(new Vector2(xuv1 / 3, yuv1));
        result.vertices.Add(new Vector3((float)A3.x, (float)A3.y, z));
        result.uv.Add(new Vector2(xuv0, yuv1));
        result.vertices.Add(new Vector3((float)A1.x, (float)A1.y, z));
        result.uv.Add(new Vector2(xuv0, yuv0));
        result.vertices.Add(new Vector3((float)A2.x, (float)A2.y, z));

        result.uv.Add(new Vector2(xuv0, yuv0));
        result.vertices.Add(new Vector3((float)A2.x, (float)A2.y, z));
        result.uv.Add(new Vector2(yuv1 / 3, xuv0));
        result.vertices.Add(new Vector3((float)A4.x, (float)A4.y, z));
        result.uv.Add(new Vector2(xuv1 / 3, yuv1));
        result.vertices.Add(new Vector3((float)A3.x, (float)A3.y, z));

        A1 = B1.Copy();
        A2 = B2.Copy();

        B1.Push(rot - Mathf.PI, size);
        B2.Push(rot - Mathf.PI, size);

        result.uv.Add(new Vector2(xuv0, yuv1));
        result.vertices.Add(new Vector3((float)B1.x, (float)B1.y, z));
        result.uv.Add(new Vector2(xuv1 / 3, yuv1));
        result.vertices.Add(new Vector3((float)A1.x, (float)A1.y, z));
        result.uv.Add(new Vector2(xuv1 / 3, yuv0));
        result.vertices.Add(new Vector3((float)A2.x, (float)A2.y, z));

        result.uv.Add(new Vector2(xuv1 / 3, yuv0));
        result.vertices.Add(new Vector3((float)A2.x, (float)A2.y, z));
        result.uv.Add(new Vector2(yuv0, xuv0));
        result.vertices.Add(new Vector3((float)B2.x, (float)B2.y, z));
        result.uv.Add(new Vector2(xuv0, yuv1));
        result.vertices.Add(new Vector3((float)B1.x, (float)B1.y, z));

        return(result);
    }