Пример #1
0
        public static void DrawDirectionalLight(Vector3 position, Quaternion rotation, Vector3 scale, Color color)
        {
            float sScale = RuntimeGraphics.GetScreenScale(position, Camera.current);

            Matrix4x4 zTranform  = Matrix4x4.TRS(Vector3.zero, rotation, Vector3.one);
            Matrix4x4 objToWorld = Matrix4x4.TRS(position, Quaternion.identity, scale * sScale);

            LinesMaterial.SetPass(0);
            GL.PushMatrix();
            GL.MultMatrix(objToWorld);

            GL.Begin(GL.LINES);
            GL.Color(color);

            float radius = 0.25f;
            float length = 1.25f;



            RuntimeGraphics.DrawCircleGL(zTranform, radius);
            RuntimeGraphics.DrawWireConeGL(zTranform, Vector3.zero, radius, length, 8);

            Vector3 point  = zTranform.MultiplyPoint(Vector3.zero);
            Vector3 point2 = zTranform.MultiplyPoint(Vector3.forward * length);

            GL.Vertex(point);
            GL.Vertex(point2);

            GL.End();
            GL.PopMatrix();
        }
Пример #2
0
        public static void DrawWireConeGL(float height, float radius, Vector3 position, Quaternion rotation, Vector3 scale, Color color)
        {
            Matrix4x4 circleTransform = Matrix4x4.TRS(height * Vector3.forward, Quaternion.identity, Vector3.one);

            Matrix4x4 objToWorld = Matrix4x4.TRS(position, rotation, scale);

            LinesMaterial.SetPass(0);
            GL.PushMatrix();
            GL.MultMatrix(objToWorld);

            GL.Begin(GL.LINES);
            GL.Color(color);
            RuntimeGraphics.DrawCircleGL(circleTransform, radius);

            GL.Vertex(Vector3.zero);
            GL.Vertex(Vector3.forward * height + new Vector3(1, 1, 0).normalized *radius);

            GL.Vertex(Vector3.zero);
            GL.Vertex(Vector3.forward * height + new Vector3(-1, 1, 0).normalized *radius);

            GL.Vertex(Vector3.zero);
            GL.Vertex(Vector3.forward * height + new Vector3(-1, -1, 0).normalized *radius);

            GL.Vertex(Vector3.zero);
            GL.Vertex(Vector3.forward * height + new Vector3(1, -1, 0).normalized *radius);

            GL.End();
            GL.PopMatrix();
        }
Пример #3
0
        public static void DrawWireCapsuleGL(int axis, float height, float radius, Vector3 position, Quaternion rotation, Vector3 scale, Color color)
        {
            Matrix4x4 topCircleTransform;
            Matrix4x4 bottomCircleTransform;
            Matrix4x4 capsule2DTransform;
            Matrix4x4 capsule2DTransform2;

            radius = Mathf.Abs(radius);

            if (Mathf.Abs(height) < 2 * radius)
            {
                height = 0;
            }
            else
            {
                height = Mathf.Abs(height) - 2 * radius;
            }

            if (axis == 1)
            {
                topCircleTransform    = Matrix4x4.TRS(Vector3.up * height / 2, Quaternion.AngleAxis(-90, Vector3.right), Vector3.one);
                bottomCircleTransform = Matrix4x4.TRS(Vector3.down * height / 2, Quaternion.AngleAxis(-90, Vector3.right), Vector3.one);
                capsule2DTransform    = Matrix4x4.identity;
                capsule2DTransform2   = Matrix4x4.TRS(Vector3.zero, Quaternion.AngleAxis(-90, Vector3.up), Vector3.one);
            }
            else if (axis == 0)
            {
                topCircleTransform    = Matrix4x4.TRS(Vector3.right * height / 2, Quaternion.AngleAxis(-90, Vector3.up), Vector3.one);
                bottomCircleTransform = Matrix4x4.TRS(Vector3.left * height / 2, Quaternion.AngleAxis(-90, Vector3.up), Vector3.one);
                capsule2DTransform    = Matrix4x4.TRS(Vector3.zero, Quaternion.AngleAxis(-90, Vector3.forward), Vector3.one);
                capsule2DTransform2   = Matrix4x4.TRS(Vector3.zero, Quaternion.AngleAxis(-90, Vector3.forward) * Quaternion.AngleAxis(-90, Vector3.up), Vector3.one);
            }
            else
            {
                topCircleTransform    = Matrix4x4.TRS(Vector3.forward * height / 2, Quaternion.identity, Vector3.one);
                bottomCircleTransform = Matrix4x4.TRS(Vector3.back * height / 2, Quaternion.identity, Vector3.one);
                capsule2DTransform    = Matrix4x4.TRS(Vector3.zero, Quaternion.AngleAxis(-90, Vector3.right), Vector3.one);
                capsule2DTransform2   = Matrix4x4.TRS(Vector3.zero, Quaternion.AngleAxis(-90, Vector3.right) * Quaternion.AngleAxis(-90, Vector3.up), Vector3.one);
            }


            Matrix4x4 objToWorld = Matrix4x4.TRS(position, rotation, scale);

            LinesMaterial.SetPass(0);
            GL.PushMatrix();
            GL.MultMatrix(objToWorld);

            GL.Begin(GL.LINES);
            GL.Color(color);
            RuntimeGraphics.DrawCircleGL(topCircleTransform, radius);
            RuntimeGraphics.DrawCircleGL(bottomCircleTransform, radius);

            RuntimeGraphics.DrawCapsule2DGL(capsule2DTransform, radius, height);
            RuntimeGraphics.DrawCapsule2DGL(capsule2DTransform2, radius, height);

            GL.End();
            GL.PopMatrix();
        }
Пример #4
0
        public static void DrawWireDisc(Vector3 position, Quaternion rotation, Vector3 scale, Color color)
        {
            Matrix4x4 zTranform  = Matrix4x4.TRS(Vector3.zero, rotation, Vector3.one);
            Matrix4x4 objToWorld = Matrix4x4.TRS(position, Quaternion.identity, scale);

            LinesMaterial.SetPass(0);
            GL.PushMatrix();
            GL.MultMatrix(objToWorld);

            GL.Begin(GL.LINES);
            GL.Color(color);
            RuntimeGraphics.DrawCircleGL(zTranform, 1);
            GL.End();
            GL.PopMatrix();
        }
Пример #5
0
        public static void DrawWireSphereGL(Vector3 position, Quaternion rotation, Vector3 scale, Color color)
        {
            Matrix4x4 xTranform  = Matrix4x4.TRS(Vector3.zero, rotation * Quaternion.AngleAxis(-90, Vector3.up), Vector3.one);
            Matrix4x4 yTranform  = Matrix4x4.TRS(Vector3.zero, rotation * Quaternion.AngleAxis(-90, Vector3.right), Vector3.one);
            Matrix4x4 zTranform  = Matrix4x4.TRS(Vector3.zero, rotation, Vector3.one);
            Matrix4x4 objToWorld = Matrix4x4.TRS(position, Quaternion.identity, scale);

            LinesMaterial.SetPass(0);
            GL.PushMatrix();
            GL.MultMatrix(objToWorld);

            GL.Begin(GL.LINES);
            GL.Color(color);
            RuntimeGraphics.DrawCircleGL(xTranform, 1);
            RuntimeGraphics.DrawCircleGL(yTranform, 1);
            RuntimeGraphics.DrawCircleGL(zTranform, 1);
            if (Camera.current.orthographic)
            {
                Matrix4x4 outTransform = Matrix4x4.TRS(Vector3.zero, Camera.current.transform.rotation, Vector3.one);
                RuntimeGraphics.DrawCircleGL(outTransform, 1);
            }
            else
            {
                Vector3 toCam     = Camera.current.transform.position - position;
                Vector3 toCamNorm = toCam.normalized;
                if (Vector3.Dot(toCamNorm, Camera.current.transform.forward) < 0)
                {
                    float     m            = toCam.magnitude;
                    Matrix4x4 outTransform = Matrix4x4.TRS(toCamNorm * 0.56f * scale.x / m, Quaternion.LookRotation(toCamNorm, Camera.current.transform.up), Vector3.one);
                    RuntimeGraphics.DrawCircleGL(outTransform, 1);
                }
            }

            GL.End();
            GL.PopMatrix();
        }
        public static void DoRotationHandle(Quaternion rotation, Vector3 position, RuntimeHandleAxis selectedAxis = RuntimeHandleAxis.None, LockObject lockObject = null)
        {
            float     screenScale = GetScreenScale(position, Camera.current);
            float     radius      = HandleScale;
            Vector3   scale       = new Vector3(screenScale, screenScale, screenScale);
            Matrix4x4 xTranform   = Matrix4x4.TRS(Vector3.zero, rotation * Quaternion.AngleAxis(-90, Vector3.up), Vector3.one);
            Matrix4x4 yTranform   = Matrix4x4.TRS(Vector3.zero, rotation * Quaternion.AngleAxis(-90, Vector3.right), Vector3.one);
            Matrix4x4 zTranform   = Matrix4x4.TRS(Vector3.zero, rotation, Vector3.one);
            Matrix4x4 objToWorld  = Matrix4x4.TRS(position, Quaternion.identity, scale);

            bool xLocked      = lockObject != null && lockObject.RotationX;
            bool yLocked      = lockObject != null && lockObject.RotationY;
            bool zLocked      = lockObject != null && lockObject.RotationZ;
            bool screenLocked = lockObject != null && lockObject.RotationScreen;

            LinesClipMaterial.SetPass(0);
            GL.PushMatrix();
            GL.MultMatrix(objToWorld);

            GL.Begin(GL.LINES);
            if (xLocked)
            {
                GL.Color(RTHColors.DisabledColor);
            }
            else
            {
                GL.Color(selectedAxis != RuntimeHandleAxis.X ? RTHColors.XColor : RTHColors.SelectionColor);
            }
            RuntimeGraphics.DrawCircleGL(xTranform, radius);

            if (yLocked)
            {
                GL.Color(RTHColors.DisabledColor);
            }
            else
            {
                GL.Color(selectedAxis != RuntimeHandleAxis.Y ? RTHColors.YColor : RTHColors.SelectionColor);
            }
            RuntimeGraphics.DrawCircleGL(yTranform, radius);

            if (zLocked)
            {
                GL.Color(RTHColors.DisabledColor);
            }
            else
            {
                GL.Color(selectedAxis != RuntimeHandleAxis.Z ? RTHColors.ZColor : RTHColors.SelectionColor);
            }
            RuntimeGraphics.DrawCircleGL(zTranform, radius);
            GL.End();

            GL.PopMatrix();

            LinesBillboardMaterial.SetPass(0);
            GL.PushMatrix();
            GL.MultMatrix(objToWorld);

            GL.Begin(GL.LINES);
            if (xLocked && yLocked && zLocked)
            {
                GL.Color(RTHColors.DisabledColor);
            }
            else
            {
                GL.Color(selectedAxis != RuntimeHandleAxis.Free ? RTHColors.AltColor : RTHColors.SelectionColor);
            }
            RuntimeGraphics.DrawCircleGL(Matrix4x4.identity, radius);

            if (screenLocked)
            {
                GL.Color(RTHColors.DisabledColor);
            }
            else
            {
                GL.Color(selectedAxis != RuntimeHandleAxis.Screen ? RTHColors.AltColor : RTHColors.SelectionColor);
            }
            RuntimeGraphics.DrawCircleGL(Matrix4x4.identity, radius * 1.1f);
            GL.End();

            GL.PopMatrix();
        }