Exemple #1
0
    private static void RenderBeam(Plane[] frustum, Camera camera, LaserBeam beam, ref LaserBeam.FrameData frame)
    {
        Vector3 upwards = world2Cam.MultiplyPoint(frame.origin);
        Vector3 vector2 = world2Cam.MultiplyPoint(frame.point);
        Vector3 forward = vector2 - upwards;

        forward.Normalize();
        float      num        = 1f - ((1f - Mathf.Abs(forward.z)) * beam.beamOutput);
        Quaternion quaternion = Quaternion.LookRotation(forward, vector2);
        Vector3    vector4    = (Vector3)(Quaternion.LookRotation(forward, upwards) * new Vector3(frame.originWidth, 0f, 0f));
        Vector3    vector5    = (Vector3)(quaternion * new Vector3(frame.pointWidth, 0f, 0f));

        frame.beamVertices.m0  = cam2World.MultiplyPoint(((Vector3)(vector4 * 0.5f)) + upwards);
        frame.beamVertices.m2  = cam2World.MultiplyPoint(((Vector3)(vector5 * 0.5f)) + vector2);
        frame.beamVertices.m1  = cam2World.MultiplyPoint(((Vector3)(vector4 * -0.5f)) + upwards);
        frame.beamVertices.m3  = cam2World.MultiplyPoint(((Vector3)(vector5 * -0.5f)) + vector2);
        frame.beamNormals.m0.x = frame.originWidth;
        frame.beamNormals.m2.x = frame.pointWidth;
        frame.beamNormals.m1.x = -frame.originWidth;
        frame.beamNormals.m3.x = -frame.pointWidth;
        frame.beamNormals.m0.y = -frame.distance;
        frame.beamNormals.m1.y = -frame.distance;
        frame.beamNormals.m2.y = -frame.distance;
        frame.beamNormals.m3.y = -frame.distance;
        frame.beamNormals.m0.z = frame.beamNormals.m1.z = 0f;
        frame.beamNormals.m2.z = frame.beamNormals.m3.z = frame.distanceFraction;
        frame.beamColor.m0     = frame.beamColor.m1 = frame.beamColor.m2 = frame.beamColor.m3 = RangeBeamColor((Color)(beam.beamColor * num));
        frame.beamUVs.m0       = uv[0];
        frame.beamUVs.m0.x    *= frame.distanceFraction;
        frame.beamUVs.m1       = uv[1];
        frame.beamUVs.m1.x    *= frame.distanceFraction;
        frame.beamUVs.m2       = uv[2];
        frame.beamUVs.m2.x    *= frame.distanceFraction;
        frame.beamUVs.m3       = uv[3];
        frame.beamUVs.m3.x    *= frame.distanceFraction;
        frame.bufBeam          = MeshBuffer.ForBeamMaterial(beam.beamMaterial);
        if (Computation.beams.Add(frame.bufBeam))
        {
            frame.bufBeam.measureSize = 1;
        }
        else
        {
            frame.bufBeam.measureSize++;
        }
        frame.bufBeam.beams.Add(beam);
        if (frame.didHit)
        {
            Vector3 vector6 = world2Cam.MultiplyVector(-frame.hitNormal);
            if (vector6.z < 0f)
            {
                Vector3 start = cam2World.MultiplyPoint(Vector3.zero);
                if (!Physics.Linecast(start, Vector3.Lerp(start, frame.point, 0.95f), (int)beam.cullLayers))
                {
                    Vector3    vector8     = world2Cam.MultiplyPoint(frame.point);
                    Quaternion quaternion3 = Quaternion.LookRotation(vector8, Vector3.up);
                    frame.dotVertices1.m0 = cam2World.MultiplyPoint(vector8 + (quaternion3 * new Vector3(frame.dotRadius, -frame.dotRadius, 0f)));
                    frame.dotVertices1.m1 = cam2World.MultiplyPoint(vector8 + (quaternion3 * new Vector3(frame.dotRadius, frame.dotRadius, 0f)));
                    frame.dotVertices1.m2 = cam2World.MultiplyPoint(vector8 + (quaternion3 * new Vector3(-frame.dotRadius, -frame.dotRadius, 0f)));
                    frame.dotVertices1.m3 = cam2World.MultiplyPoint(vector8 + (quaternion3 * new Vector3(-frame.dotRadius, frame.dotRadius, 0f)));
                    quaternion3           = Quaternion.LookRotation(vector6, Vector3.up);
                    frame.dotVertices2.m0 = cam2World.MultiplyPoint(vector8 + (quaternion3 * new Vector3(frame.dotRadius, -frame.dotRadius, -0.01f)));
                    frame.dotVertices2.m1 = cam2World.MultiplyPoint(vector8 + (quaternion3 * new Vector3(frame.dotRadius, frame.dotRadius, -0.01f)));
                    frame.dotVertices2.m2 = cam2World.MultiplyPoint(vector8 + (quaternion3 * new Vector3(-frame.dotRadius, -frame.dotRadius, -0.01f)));
                    frame.dotVertices2.m3 = cam2World.MultiplyPoint(vector8 + (quaternion3 * new Vector3(-frame.dotRadius, frame.dotRadius, -0.01f)));
                    frame.dotColor1.m0    = frame.dotColor1.m1 = frame.dotColor1.m2 = frame.dotColor1.m3 = frame.dotColor2.m0 = frame.dotColor2.m1 = frame.dotColor2.m2 = frame.dotColor2.m3 = RangeDotColor(beam.dotColor);
                    frame.bufDot          = MeshBuffer.ForDotMaterial(beam.dotMaterial);
                    if (Computation.dots.Add(frame.bufDot))
                    {
                        frame.bufDot.measureSize = 2;
                    }
                    else
                    {
                        frame.bufDot.measureSize += 2;
                    }
                    frame.bufDot.beams.Add(beam);
                    frame.drawDot = true;
                }
                else
                {
                    frame.bufDot  = null;
                    frame.drawDot = false;
                }
            }
            else
            {
                frame.bufDot  = null;
                frame.drawDot = false;
            }
        }
        else
        {
            frame.bufDot  = null;
            frame.drawDot = false;
        }
    }