示例#1
0
    void LateUpdate()
    {
        Vector2 pos2d = (Vector2)_parentTransform.position;

        pos2d.x *= -1f;
        Vector3 pos = ProjectionMath.ThreeDimCoordsOnPlane(pos2d, _plane) + _plane.Normal * 0.15f;

        Debug.DrawLine(pos, pos + Vector3.up);
        _transform.position = pos + offset;
    }
示例#2
0
    public void SetVerts(List <Vector2> vertices2D, Plane plane)
    {
        transform.rotation = Quaternion.identity;
        List <Vector2>    toTriangulate = new List <Vector2>();
        HashSet <Vector2> duplicates    = new HashSet <Vector2>();

        for (int i = vertices2D.Count - 1; i > 0; i--)
        {
            Vector3 toInsert = vertices2D[i];
            if (duplicates.Contains(toInsert))
            {
                continue;         // Don't allow dups
            }
            duplicates.Add(toInsert);
            toTriangulate.Add(toInsert);
        }

        // Use the triangulator to get indices for creating triangles
        Triangulator tr = new Triangulator(toTriangulate.ToArray());

        int[] indices = tr.Triangulate();

        // Create the Vector3 vertices
        if (_vertices == null || _vertices.Length != vertices2D.Count)
        {
            _vertices = new Vector3[vertices2D.Count];
            _normals  = new Vector3[vertices2D.Count];
            _uvs      = new Vector2[vertices2D.Count];
        }

        for (int i = 0; i < toTriangulate.Count; i++)
        {
            _normals[i]  = plane.Normal;
            _vertices[i] = ProjectionMath.ThreeDimCoordsOnPlane(new Vector2(-toTriangulate[i].x, toTriangulate[i].y), plane) + plane.Normal * 0.1f;
            _uvs[i]      = new Vector2(i / (toTriangulate.Count - 1.0f), 0);
            // TODO(Julian): set the uvs if we need shadow textures
        }
        Mesh mesh = _meshFilter.mesh;

        mesh.vertices  = _vertices;
        mesh.triangles = indices;
        mesh.normals   = _normals;
        mesh.uv        = _uvs;
        mesh.RecalculateBounds();
    }
示例#3
0
    public Vector3 WorldPosFromIntVec(IntVector2D vec, PlaneOrientation orientation)
    {
        float   tileSize = WorldManager.g.TileSize;
        Vector2 vector2  = vec.ToVector2();

        if (orientation == PlaneOrientation.XY)
        {
            vector2.x *= -1f;
            vector2.x -= 1f;
        }
        if (orientation == PlaneOrientation.XY)
        {
            return(ProjectionMath.ThreeDimCoordsOnPlane(vector2 * tileSize + Vector2.one * tileSize / 2f, _planeXY));
        }
        else
        {
            return(ProjectionMath.ThreeDimCoordsOnPlane(vector2 * tileSize + Vector2.one * tileSize / 2f, _planeZY));
        }
    }
示例#4
0
        Vector3 Vector3FromIntPoint(IntPoint ip, Plane plane, float precision)
        {
            Vector2 v = new Vector2(ip.X, ip.Y) / precision;

            return(ProjectionMath.ThreeDimCoordsOnPlane(v, plane));
        }