Esempio n. 1
0
    // retourne un nouveau polygone correspondant a un contour du polygone polygon
    // calcule a partir de quantity
    public static Polygon GetOutlinedPolygon(Polygon polygon, float quantity)
    {
        Point2Data [] pointsData = new Point2Data[polygon.GetPoints ().Count];
        polygon.CopyPoint2DataTo (pointsData);

        for (int pIndex = 0; pIndex < pointsData.Length; ++pIndex)
        {
            Point2 pt2 = polygon.GetPoints ()[pIndex];

            Vector2 position = pointsData[pIndex].position;
            position = position + pt2.GetCalculatedNormal () * quantity;

            pointsData[pIndex].position = position;
        }

        return new Polygon (pointsData);
    }
Esempio n. 2
0
    public Polygon(Point2Data [] pointsData)
    {
        _pointsData = new Point2Data[pointsData.Length];

        List<int> curvedIndices = new List<int> ();

        for (int pIndex = 0; pIndex < pointsData.Length; ++pIndex)
        {
            Point2Data newPointData 	= new Point2Data();
            newPointData.position.x 	= pointsData[pIndex].position.x;
            newPointData.position.y	 	= pointsData[pIndex].position.y;
            newPointData.radius 		= pointsData[pIndex].radius;
            newPointData.junctionType 	= pointsData[pIndex].junctionType;
            newPointData.bstairway  	= pointsData[pIndex].bstairway;
            _pointsData[pIndex] = newPointData;

            AddPoint (new Point2 (pointsData[pIndex].position));

            if (pointsData[pIndex].junctionType == JunctionType.Curved)
            {
                curvedIndices.Add (pIndex);
            }
        }

        if (pointsData.Length > 2)
        {
            Close ();
        }

        foreach (int curvedIndex in curvedIndices)
        {
            SetJunctionType (curvedIndex, JunctionType.Curved);

            ArchedPoint2 aPoint = _points[curvedIndex] as ArchedPoint2;
            Point2Data pData = pointsData[curvedIndex];

            aPoint.SetRadius (pData.radius);
        }
    }
    public void save(BinaryWriter buf)
    {
        int pointCount = _polygon.GetPoints ().Count;
        buf.Write (pointCount);

        Point2Data [] savedPolygon = new Point2Data[pointCount];
        _polygon.CopyPoint2DataTo (savedPolygon);

        foreach (Point2Data pData in savedPolygon)
        {
            buf.Write ((double)pData.position.x);
            buf.Write ((double)pData.position.y);
            buf.Write ((int)pData.junctionType);
            buf.Write ((double)pData.radius);
            buf.Write ((bool)pData.bstairway);
        }

        buf.Write ((double)fcurrentMagnitudeRail);
        buf.Write ((double)fcurrentTemp);
        buf.Write ((double)fscale);

        buf.Write ((bool)bstairway);
        buf.Write ((bool)broman);
        buf.Write ((double)fsizeStairway);
        buf.Write ((double)fradiusStairway);

        //buf.Write ((string) goBloc.name);
        buf.Write ((bool)goBloc.GetComponent<Renderer>().enabled);
        buf.Write ((double)goBloc.transform.position.x);
        buf.Write ((double)goBloc.transform.position.y);
        buf.Write ((double)goBloc.transform.position.z);
        buf.Write ((double)goBloc.transform.localRotation.eulerAngles.x);
        buf.Write ((double)goBloc.transform.localRotation.eulerAngles.y);
        buf.Write ((double)goBloc.transform.localRotation.eulerAngles.z);
    }
    public void reinitRail(Point2Data[] _pointsData)
    {
        listDoubleV3.Clear();

        fmagnitudeRail = 0.0f;

        float fminSize = 2.5f;

        for(int l = 1; l < _pointsData.Length || l < go3DPosition.Count; l++)
        {
            tryToAddDoubleVector3(_pointsData, l - 1, l);
        }

        tryToAddDoubleVector3(_pointsData, pointsData.Length - 1, 0);
    }
    public IEnumerator addStairway(Point2Data[] _p2d, bool _bgenerate, int _isens, float _fsize = 276.0f, float _fradius = 84.0f)
    {
        gameObject.GetComponent<DesignerDesjoyaux>().blockStairway = true;

        fsizeStairway = _fsize;
        fradiusStairway = _fradius;

        List<Point2Data> listPointsData = new List<Point2Data>();

        if(savedPointsData != null && savedPointsData.Length > 0)
        {
            foreach(Point2Data p2d in savedPointsData)
            {
                listPointsData.Add(p2d);
            }
        }
        else
        {
            foreach(Point2Data p2d in pointsData)
            {
                listPointsData.Add(p2d);
            }

            savedPointsData = new Point2Data[listPointsData.Count];
            for(int j = 0; j < listPointsData.Count; j++)
            {
                savedPointsData[j] = listPointsData[j];
            }
        }

        int iidNextPoint = icurrentPointStairway + 1 >= listPointsData.Count ? 0 : icurrentPointStairway + 1;
        float fmagnitude = (listPointsData[iidNextPoint].position - listPointsData[icurrentPointStairway].position).magnitude;
        Vector2 v2tempEnd = listPointsData[iidNextPoint].position;
        Vector2 v2tempFirst = listPointsData[icurrentPointStairway].position;
        Vector2 v = (listPointsData[iidNextPoint].position - listPointsData[icurrentPointStairway].position);
        v.Normalize();
        Vector2 v2perpendicularDirection = new Vector2(-v.y, v.x) / Mathf.Sqrt((v.x * v.x) + (v.y * v.y));

        int i = icurrentPointStairway + 1;

        Vector2 v2first = Vector2.zero;
        Vector2 v2end = Vector2.zero;

        if(!bcenter)
        {
            float fspeed = 600.0f;

            if(bnewStairwayId)
            {
                fspeed = 1.0f;
                bnewStairwayId = false;
            }

            fcurrentTemp += Time.deltaTime * _isens * fspeed;

            float ftps = 10.0f;
            fcurrentTemp = Mathf.Clamp(fcurrentTemp, ftps, fmagnitude - fsizeStairway - ftps);
        }
        else
        {
            checkIfAlwaysCenter(pointsData, fsizeStairway);
            fcurrentTemp = (fmagnitude * 0.5f) - (_fsize * 0.5f);
            bcenter = false;
        }

        if(!broman)
        {
            Point2Data newp2d = new Point2Data();
            newp2d.junctionType = JunctionType.Broken;
            newp2d.position = listPointsData[icurrentPointStairway].position + (v * fcurrentTemp);
            newp2d.radius = 0.0f;
            listPointsData.Insert(i++, newp2d);

            v2first = newp2d.position;

            newp2d = new Point2Data();
            newp2d.bstairway = true;
            newp2d.junctionType = JunctionType.Broken;
            newp2d.position = listPointsData[i - 1].position + (-v2perpendicularDirection * -165.0f);
            newp2d.radius = 0.0f;
            listPointsData.Insert(i++, newp2d);

            newp2d = new Point2Data();
            newp2d.bstairway = true;
            newp2d.junctionType = JunctionType.Broken;
            newp2d.position = listPointsData[i - 1].position + (v * _fsize);
            newp2d.radius = 0.0f;
            listPointsData.Insert(i++, newp2d);

            newp2d = new Point2Data();
            newp2d.junctionType = JunctionType.Broken;
            newp2d.position = listPointsData[i - 1].position + (v2perpendicularDirection * -165.0f);
            newp2d.radius = 0.0f;
            listPointsData.Insert(i++, newp2d);

            v2end = newp2d.position;
        }
        else
        {
            Point2Data newp2d = new Point2Data();
            newp2d.junctionType = JunctionType.Broken;
            newp2d.position = listPointsData[icurrentPointStairway].position + (v * fcurrentTemp);
            newp2d.radius = 0.0f;
            listPointsData.Insert(i++, newp2d);

            v2first = newp2d.position;

            newp2d = new Point2Data();
            newp2d.bstairway = true;
            newp2d.junctionType = JunctionType.Broken;
            newp2d.position = listPointsData[i - 1].position + (v2perpendicularDirection * 10.0f);
            newp2d.radius = 0.0f;
            listPointsData.Insert(i++, newp2d);

            newp2d = new Point2Data();
            newp2d.bstairway = true;
            newp2d.junctionType = JunctionType.Curved;
            newp2d.position = listPointsData[i - 1].position + (v * (_fsize * 0.5f)) - (v2perpendicularDirection * -1000.0f);
            newp2d.radius = _fradius;
            listPointsData.Insert(i++, newp2d);

            newp2d = new Point2Data();
            newp2d.bstairway = true;
            newp2d.junctionType = JunctionType.Broken;
            newp2d.position = listPointsData[i - 1].position + (v * (_fsize * 0.5f)) + (v2perpendicularDirection * -1000.0f);
            newp2d.radius = 0.0f;
            listPointsData.Insert(i++, newp2d);

            newp2d = new Point2Data();
            newp2d.junctionType = JunctionType.Broken;
            newp2d.position = listPointsData[i - 1].position + (-v2perpendicularDirection * 10.0f);
            newp2d.radius = 0.0f;
            listPointsData.Insert(i++, newp2d);

            v2end = newp2d.position;
        }

        float foffset = 25.0f;
        float fnewMagnitude = (v2tempFirst - v2tempEnd).magnitude - foffset;

        if((_isens == 1 && fnewMagnitude < ((v2tempFirst - v2end).magnitude)) || balwaysCenter)
        {
            nextCurrentStairwayID(savedPointsData);
            fcurrentTemp = foffset;
        }
        else if(_isens == -1 && fnewMagnitude < ((v2tempEnd - v2first).magnitude))
        {
            previousCurrentStairwayID(savedPointsData);
            iidNextPoint = icurrentPointStairway + 1 >= savedPointsData.Length ? 0 : icurrentPointStairway + 1;
            fcurrentTemp = Mathf.Abs((savedPointsData[icurrentPointStairway].position - savedPointsData[iidNextPoint].position).magnitude) - _fsize - foffset;
        }

        Point2Data[] p2ds = new Point2Data[listPointsData.Count];

        for(int j = 0; j < listPointsData.Count; j++)
        {
            p2ds[j] = listPointsData[j];
        }

        _polygon = new Polygon(p2ds);

        if(_bgenerate)
        {
            StartCoroutine (Generate (_polygon));

            yield return new WaitForEndOfFrame();

            init3DPoints();

            if(listDoubleV3.Count > 0)
            {
                idDoubleV3 = 0;
                v3positionBloc = listDoubleV3[0].v3start;
                goBloc.transform.localPosition = v3positionBloc;

                fgoBlocPosition = 5.0f;
                fcurrentMagnitudeRail = 0.0f;
            }
        }

        bstairway = true;
    }
    public void previousCurrentStairwayID(Point2Data[] _pointsData)
    {
        bool bcheck = false;
        do
        {
            icurrentPointStairway--;

            if(icurrentPointStairway < 0)
            {
                icurrentPointStairway = _pointsData.Length - 1;
            }

            if(icurrentPointStairway + 1 >= _pointsData.Length)
            {
                if(_pointsData[0].junctionType == JunctionType.Broken &&
                   _pointsData[icurrentPointStairway].junctionType == JunctionType.Broken)
                {
                    bnewStairwayId = true;
                    bcheck = true;

                    if((_pointsData[icurrentPointStairway].position - _pointsData[0].position).magnitude < fsizeStairway + _flimitSize)
                    {
                        bcenter = true;
                    }
                }
            }
            else if(_pointsData[icurrentPointStairway + 1].junctionType == JunctionType.Broken &&
                    _pointsData[icurrentPointStairway].junctionType == JunctionType.Broken)
            {
                bnewStairwayId = true;
                bcheck = true;

                if((_pointsData[icurrentPointStairway].position - _pointsData[icurrentPointStairway + 1].position).magnitude < fsizeStairway + _flimitSize)
                {
                    bcenter = true;
                }
            }

        }while(!bcheck);
    }
    public void load(BinaryReader buf)
    {
        int pointCount = buf.ReadInt32 ();
        pointsData = new Point2Data[pointCount];
        _pointsDataBackup = new Point2Data[pointCount];

        for (int pIndex = 0; pIndex < pointCount; ++pIndex)
        {
            Point2Data pData = new Point2Data ();
            pData.position = new Vector2 ((float)buf.ReadDouble (), (float)buf.ReadDouble ());
            pData.junctionType = (JunctionType)buf.ReadInt32 ();
            pData.radius = (float)buf.ReadDouble ();
            pData.bstairway = (bool)buf.ReadBoolean ();

            pointsData[pIndex] = pData;
            _pointsDataBackup[pIndex] = pData;
        }

        fcurrentMagnitudeRail = (float)buf.ReadDouble();
        fcurrentTemp = (float)buf.ReadDouble();
        fscale = (float)buf.ReadDouble();
        bstairway = (bool)buf.ReadBoolean();
        broman = (bool)buf.ReadBoolean();
        fsizeStairway = (float)buf.ReadDouble();
        fradiusStairway = (float)buf.ReadDouble();

        //goBloc = GameObject.Instantiate(Resources.Load((string)buf.ReadString ())) as GameObject;
        bool bblocRenderer = (bool)buf.ReadBoolean ();

        goBloc.GetComponent<Renderer>().enabled = bblocRenderer;

        foreach(Transform child in goBloc.transform)
        {
            child.GetComponent<Renderer>().enabled = bblocRenderer;
            child.gameObject.layer = 14;  // underwater
        }

        goBloc.transform.position = new Vector3((float)buf.ReadDouble(), (float)buf.ReadDouble(), (float)buf.ReadDouble());
        goBloc.transform.localRotation = Quaternion.Euler((float)buf.ReadDouble(), (float)buf.ReadDouble(), (float)buf.ReadDouble());

        _polygon = new Polygon (pointsData);
        _isLoading = true;
        _IsGenerated = true;
        StartCoroutine (Generate (_polygon));

        scalePool(0);

        //init3DPoints();

        //moveBloc();
    }
    public void checkIfAlwaysCenter(Point2Data[] _p2d, float _fsize = 276.0f)
    {
        List<Point2Data> listPointsData = new List<Point2Data>();

        int iid = 0;

        balwaysCenter = true;

        if(savedPointsData != null && savedPointsData.Length > 0)
        {
            foreach(Point2Data p2d in savedPointsData)
            {
                listPointsData.Add(p2d);
            }
        }
        else
        {
            foreach(Point2Data p2d in pointsData)
            {
                listPointsData.Add(p2d);
            }
        }

        foreach(Point2Data p2d in listPointsData)
        {
            int iidNextPoint = iid + 1 >= listPointsData.Count ? 0 : iid + 1;

            if(listPointsData[iidNextPoint].junctionType == JunctionType.Broken &&
               listPointsData[iid].junctionType == JunctionType.Broken)
            {
                float fmagnitude = (listPointsData[iidNextPoint].position - listPointsData[iid].position).magnitude;

                if(fmagnitude > (_fsize + _flimitSize))
                {
                    balwaysCenter = false;
                    return;
                }
            }

            iid++;
        }
    }
    public bool canAddStairway(Point2Data[] _p2d, float _fsize = 276.0f)
    {
        List<Point2Data> listPointsData = new List<Point2Data>();

        int iid = 0;

        bool bcheck = false;

        if(savedPointsData != null && savedPointsData.Length > 0)
        {
            foreach(Point2Data p2d in savedPointsData)
            {
                listPointsData.Add(p2d);
            }
        }
        else
        {
            foreach(Point2Data p2d in pointsData)
            {
                listPointsData.Add(p2d);
            }
        }

        foreach(Point2Data p2d in listPointsData)
        {
            int iidNextPoint = iid + 1 >= listPointsData.Count ? 0 : iid + 1;

            if(listPointsData[iidNextPoint].junctionType == JunctionType.Broken &&
               listPointsData[iid].junctionType == JunctionType.Broken)
               {
                    float fmagnitude = (listPointsData[iidNextPoint].position - listPointsData[iid].position).magnitude;

                    if(fmagnitude > _fsize)
                    {
                        bcheck = true;
                    }
                }

            iid++;
        }

        return bcheck;
    }
    /**
     * Fait une opération de mirroire selon l'axe X de la liste des points (X(n) = -x(n))
     */
    private Point2Data[] MirrorX(Point2Data[] previousPoints)
    {
        Point2Data[] newPointsData;
        newPointsData = new Point2Data[previousPoints.Length];
        for (int i=0;i<previousPoints.Length;i++)
        {
            Point2Data pData = new Point2Data ();
            //Point2Data pDataOrigine =previousPoints[previousPoints.Length-1-i];
            Point2Data pDataOrigine =previousPoints[i];
            pData.junctionType = pDataOrigine.junctionType;

            /*if (pData.junctionType == JunctionType.Curved)
            {
                ArchedPoint2 aPoint = pDataOrigine as ArchedPoint2;
                pData.radius = aPoint.GetMeasuredRadius ();
            }*/
            pData.radius = pDataOrigine.radius;
            pData.position.Set(
                pDataOrigine.position.x,
                pDataOrigine.position.y);
            newPointsData[i] = pData;
        }

        return newPointsData;
    }
    public void tryToAddDoubleVector3(Point2Data[] _pointsData, int _istart, int _iend)
    {
        float fminSize = 2.5f;

        if(_istart >= 0 && !_pointsData[_istart].bstairway && !_pointsData[_iend].bstairway &&
           _pointsData[_istart].junctionType == JunctionType.Broken &&
           _pointsData[_iend].junctionType == JunctionType.Broken)
        {
            DoubleVector3 dv3 = new DoubleVector3();

            dv3.v3start = go3DPosition[_istart].transform.localPosition;
            dv3.v3end = go3DPosition[_iend].transform.localPosition;

            float ffirstmagnitude = (dv3.v3start - dv3.v3end).magnitude;

            if(ffirstmagnitude > fminSize)
            {
                Vector3 v3direction = dv3.v3end - dv3.v3start;
                v3direction.Normalize();

                dv3.v3start += v3direction * 5.0f;
                dv3.v3end -= v3direction * 5.0f;

                Vector3 v3direction2 = dv3.v3end - dv3.v3start;
                v3direction2.Normalize();
                if(Vector3.Dot(v3direction2, v3direction) == 1.0f)
                {
                    fmagnitudeRail += (dv3.v3end - dv3.v3start).magnitude;

                    listDoubleV3.Add(dv3);
                }
            }
        }
    }
Esempio n. 12
0
    public void save(BinaryWriter buf)
    {
        int pointCount = _polygon.GetPoints ().Count;
        buf.Write (pointCount);

        Point2Data [] savedPolygon = new Point2Data[pointCount];
        _polygon.CopyPoint2DataTo (savedPolygon);

        foreach (Point2Data pData in savedPolygon)
        {
            buf.Write ((double)pData.position.x);
            buf.Write ((double)pData.position.y);
            buf.Write ((int)pData.junctionType);
            buf.Write ((double)pData.radius);
        }
    }
Esempio n. 13
0
    public void load(BinaryReader buf)
    {
        int pointCount = buf.ReadInt32 ();
        pointsData = new Point2Data[pointCount];
        _pointsDataBackup = new Point2Data[pointCount];

        for (int pIndex = 0; pIndex < pointCount; ++pIndex)
        {
            Point2Data pData = new Point2Data ();
            pData.position = new Vector2 ((float)buf.ReadDouble (), (float)buf.ReadDouble ());
            pData.junctionType = (JunctionType)buf.ReadInt32 ();
            pData.radius = (float)buf.ReadDouble ();

            pointsData[pIndex] = pData;
            _pointsDataBackup[pIndex] = pData;
        }

        _polygon = new Polygon (pointsData);
        _isLoading = true;
        _IsGenerated = true;
        StartCoroutine (Generate (_polygon));
    }
Esempio n. 14
0
    public Polygon GetMirrorX()
    {
        Polygon newPolygon = new Polygon();
        Point2Data[] newPointsData = new Point2Data[_points.Count];
        CopyPoint2DataToInverse(newPointsData);
        newPolygon = new Polygon(newPointsData);

        // ensemble de points et segments lié entre eux et ordonnés dans le sens antihoraire
        //	protected LoopedList <Point2> _points = new LoopedList<Point2> ();
        //	protected LoopedList <Edge2> _edges = new LoopedList<Edge2> ();
        return newPolygon;
    }
Esempio n. 15
0
    // Copy le polygon sous forme d'un ensemble de points uniquement avec les données de points
    // (arc de cercle geres sous forme de donnees et pas de points)
    // mais en inversant en mode miroire X
    public void CopyPoint2DataToInverse(Point2Data[] pointArray)
    {
        Point2Data[] pointArrayTemp = new Point2Data[_points.Count];
        for (int pIndex = 0;  pIndex < _points.Count; pIndex++)
        {
            Point2 currentPoint = _points[pIndex];
            Point2Data pData = new Point2Data ();

            pData.position = currentPoint;
            pData.position.y = 2*this.bounds.center.x - currentPoint.GetY();
            pData.junctionType = currentPoint.GetJunction ();

            if (pData.junctionType == JunctionType.Curved)
            {
                ArchedPoint2 aPoint = currentPoint as ArchedPoint2;
                pData.radius = aPoint.GetMeasuredRadius ();
            }
            pointArrayTemp[pIndex] = pData;
        //	pointArray[pIndex] = pData;
        }

        /*for (int pIndex = 0;  pIndex < pointArrayTemp.Length; pIndex++)
        {
            if (pIndex>0)
            {
                pointArray[pIndex].junctionType = pointArrayTemp[pIndex-1].junctionType;
                pointArray[pIndex].radius = pointArrayTemp[pIndex-1].radius;
            }
            else
            {
                pointArray[pIndex].junctionType = pointArrayTemp[pointArray.Length-1].junctionType;
                pointArray[pIndex].radius = pointArrayTemp[pointArray.Length-1].radius;
            }
        }*/
        for (int pIndex = 0;  pIndex < pointArrayTemp.Length; pIndex++)
        {
            pointArray[pIndex] = pointArrayTemp[pointArrayTemp.Length - pIndex -1];
        }
    }
Esempio n. 16
0
    // Copy le polygon sous forme d'un ensemble de points uniquement avec les données de points
    // (arc de cercle geres sous forme de donnees et pas de points)
    public void CopyPoint2DataTo(Point2Data[] pointArray)
    {
        for (int pIndex = 0;  pIndex < _points.Count; pIndex++)
        {
            Point2 currentPoint = _points[pIndex];
            Point2Data pData = new Point2Data ();

            pData.position = currentPoint;
            pData.junctionType = currentPoint.GetJunction ();

            if (pData.junctionType == JunctionType.Curved)
            {
                ArchedPoint2 aPoint = currentPoint as ArchedPoint2;
                pData.radius = aPoint.GetMeasuredRadius ();
            }

            pointArray[pIndex] = pData;
        }
    }