Beispiel #1
0
    // Creates an array of rays centered at center and equally distributed between [-width/2;width/2] and [-110°;110°] depending of wPrecision and rPrecision
    rayElem[] listRays(Vector3 center, float radius, float width, int rPrecision, int wPrecision)
    {
        int   numberRays = rPrecision * wPrecision;
        int   cpt        = 0;
        float widthInc   = width / wPrecision;
        float rInc       = 220.0f / (float)rPrecision;
        bool  showRays   = false;

        rayElem[]  tabRays = new rayElem[numberRays];
        Quaternion rotate  = Quaternion.Euler(0, maxSteeringAngle * steering, 0);

        if (debugRay)
        {
            debugRay = false;
            showRays = true;
        }

        for (int w = 0; w < wPrecision; w++)
        {
            for (float a = 0.0f; a < 220.0f; a += rInc)
            {
                Vector3 translation = new Vector3((-width / 2) + w * widthInc, -suspensionTravel, 0);
                Vector3 direction   = new Vector3(0, -radius * Mathf.Sin(a * Mathf.PI / 180), radius * Mathf.Cos(a * Mathf.PI / 180));

                tabRays[cpt] = new rayElem(transform.TransformPoint(translation), transform.TransformDirection(rotate * direction), radius);
                if (showRays)
                {
                    Debug.DrawRay(tabRays[cpt].c(), tabRays[cpt].d(), Color.blue, 10.0f);
                }
                cpt++;
            }
        }
        return(tabRays);
    }
Beispiel #2
0
    // Creates an array of rays centered at center and equally distributed between [-width/2;width/2] and [-110°;110°] depending of wPrecision and rPrecision
    rayElem[] listRays(Vector3 center, float radius, float width, int rPrecision, int wPrecision)
    {
        int numberRays = rPrecision * wPrecision;
        int cpt = 0;
        float widthInc = width / wPrecision;
        float rInc = 220.0f / (float)rPrecision;
        bool showRays = false;
        rayElem[] tabRays = new rayElem[numberRays];
        Quaternion rotate = Quaternion.Euler(0, maxSteeringAngle * steering, 0);

        if (debugRay)
        {
            debugRay = false;
            showRays = true;
        }

        for (int w = 0; w < wPrecision; w++)
        {
            for (float a = 0.0f; a < 220.0f; a += rInc)
            {
                Vector3 translation = new Vector3((-width/2) + w*widthInc, -suspensionTravel, 0);
                Vector3 direction = new Vector3(0, -radius * Mathf.Sin(a * Mathf.PI / 180), radius * Mathf.Cos(a * Mathf.PI / 180));

                tabRays[cpt] = new rayElem(transform.TransformPoint( translation), transform.TransformDirection(rotate * direction), radius);
                if (showRays)
                {
                    Debug.DrawRay(tabRays[cpt].c(), tabRays[cpt].d(), Color.blue, 10.0f);
                }
                cpt++;
            }
        }
        return tabRays;
    }