Ejemplo n.º 1
0
    void Update()
    {
        if (data.Count > 0)
        {
            LaserSliceData lastSlice     = data[data.Count - 1];
            float          lastTimeStamp = lastSlice.Timestamp;

            float deltaTime = (Time.time - lastTimeStamp);

            int sampleCount = Mathf.FloorToInt(SampleFrequency * deltaTime);

            int currIdx = data.Count - 1;
            for (int i = 1; i <= sampleCount; i++)
            {
                LaserSliceData temp;
                RenderSlice(Mathf.LerpUnclamped(0, 360, (currIdx + i) / (float)CloudWidth), out temp);
                data.Add(temp);
            }
        }
        else
        {
            LaserSliceData temp;
            RenderSlice(0, out temp);
            data.Add(temp);
        }

        //TryComposeTexture();
    }
Ejemplo n.º 2
0
    void RenderSlice(float horizontalAngle, out LaserSliceData outSlice)
    {
        int   Channels            = 64;
        float MaximalVerticalFOV  = +0.2f;
        float MinimalVerticalFOV  = -24.9f;
        float MeasurementRange    = 120f;
        float MeasurementAccuracy = 0.02f;

        LaserData[] lasers = new LaserData[Channels];

        for (int i = 0; i < Channels; i++)
        {
            RaycastHit hit;

            float dist;
            float verticalAngel = -Mathf.Lerp(MaximalVerticalFOV, MinimalVerticalFOV, (i / (float)(NUM_OF_LASERS - 1)));
            //Debug.LogFormat("verticalAngel : {0}, Vector: {1}", verticalAngel, Quaternion.Euler(verticalAngel, 0, 0) * Vector3.forward);

            Vector3 fwd = transform.TransformDirection(Quaternion.Euler(verticalAngel, horizontalAngle, 0) * Vector3.forward);
            if (Physics.Raycast(transform.position, fwd, out hit, MeasurementRange))
            {
                dist = hit.distance + UnityEngine.Random.Range(-MeasurementAccuracy, MeasurementAccuracy);
                dist = Mathf.Clamp(dist, 0, MeasurementRange);

                Debug.DrawLine(transform.position, hit.point, Color.green);
                Debug.DrawLine(hit.point - Vector3.up * 0.3f, hit.point + Vector3.up * 0.3f, Color.red, 0, false);
                Debug.DrawLine(hit.point - Vector3.left * 0.3f, hit.point + Vector3.left * 0.3f, Color.red, 0, false);
                Debug.DrawLine(hit.point - Vector3.forward * 0.3f, hit.point + Vector3.forward * 0.3f, Color.red, 0, false);
            }
            else
            {
                dist = MeasurementRange;
                Debug.DrawRay(transform.position, fwd, Color.gray);
            }

            //Debug.LogFormat(dist.ToString());

            lasers[i] = new LaserData()
            {
                distance = dist,
            };
        }

        LaserSliceData laserSliceData = new LaserSliceData()
        {
            RotationalPosition = horizontalAngle,
            Timestamp          = Time.time,
            Lasers             = lasers,
        };

        outSlice = laserSliceData;
    }
    void RenderSlice(float horizontalAngle, out LaserSliceData outSlice)
    {
        LaserData[] lasers = new LaserData[Channels];

        for (int i = 0; i < Channels; i++)
        {
            float verticalAngel = -Mathf.Lerp(MinimalVerticalFOV, MaximalVerticalFOV, (i / (float)(Channels - 1)));

            RaycastHit hit;

            float dist;

            Vector3 fwd = transform.TransformDirection(Quaternion.Euler(verticalAngel, horizontalAngle, 0) * Vector3.forward);
            if (Physics.Raycast(transform.position, fwd, out hit, MeasurementRange))
            {
                dist = hit.distance + Random.Range(-MeasurementAccuracy, MeasurementAccuracy);
                dist = Mathf.Clamp(dist, 0, MeasurementRange);

                Debug.DrawLine(transform.position, hit.point, Color.green);
                Debug.DrawLine(hit.point - Vector3.up * 0.3f, hit.point + Vector3.up * 0.3f, Color.red, 0, false);
                Debug.DrawLine(hit.point - Vector3.left * 0.3f, hit.point + Vector3.left * 0.3f, Color.red, 0, false);
                Debug.DrawLine(hit.point - Vector3.forward * 0.3f, hit.point + Vector3.forward * 0.3f, Color.red, 0, false);
            }
            else
            {
                dist = MeasurementRange;
            }

            lasers[i] = new LaserData()
            {
                distance = dist,
            };
        }

        LaserSliceData laserSliceData = new LaserSliceData()
        {
            RotationalPosition = horizontalAngle,
            Timestamp          = Time.time,
            Lasers             = lasers,
        };

        outSlice = laserSliceData;
    }