Пример #1
0
        public void RenderScaleTool(Camera Camera, Ray Ray)
        {
            Matrix4 mat    = b.transform.ClearScale(); // Matrix4.CreateTranslation(b.transform.ExtractTranslation());
            Vector3 center = Vector3.TransformPosition(Vector3.Zero, mat);

            if (state == 0)
            {
                _hiX = false;
                _hiY = false;
                _hiZ = false;

                Vector3 close;
                if (Ray.CheckSphereHit(center, 0.5f, out close))
                {
                    _hiX = true;
                    _hiY = true;
                    _hiZ = true;
                }
                else
                if (Ray.CheckSphereHit(Vector3.TransformPosition(new Vector3(2, 0, 0), mat), 0.5f, out close))
                {
                    _hiX = true;
                }
                else
                if (Ray.CheckSphereHit(Vector3.TransformPosition(new Vector3(0, 2, 0), mat), 0.5f, out close))
                {
                    _hiY = true;
                }
                else
                if (Ray.CheckSphereHit(Vector3.TransformPosition(new Vector3(0, 0, 2), mat), 0.5f, out close))
                {
                    _hiZ = true;
                }

                hit = true;
                if (!_hiX && !_hiZ && !_hiY)
                {
                    hit = false;
                }
            }
            if (state == 1)
            {
                float sx = (Ray.mouse_x - PrevPoint.X) / 100;
                float sy = (Ray.mouse_y - PrevPoint.Y) / 100;
                float s  = sx + sy;
                b.sca = b.sca + new Vector3(_hiX ? s : 0, _hiY ? s : 0, _hiZ ? s : 0);
                b.vbnParent.update();
            }

            GL.PushMatrix();
            GL.MultMatrix(ref mat);
            GL.LineWidth(2f);
            GL.Begin(PrimitiveType.Lines);
            GL.Color3(_hiX ? Color.Yellow : Color.Red);
            GL.Vertex3(0, 0, 0);
            GL.Vertex3(2, 0, 0);
            GL.Color3(_hiY ? Color.Yellow : Color.Green);
            GL.Vertex3(0, 0, 0);
            GL.Vertex3(0, 2, 0);
            GL.Color3(_hiZ ? Color.Yellow : Color.Blue);
            GL.Vertex3(0, 0, 0);
            GL.Vertex3(0, 0, 2);
            GL.End();


            GL.Color3(_hiX ? Color.Yellow : Color.Red);
            RenderTools.DrawCube(new Vector3(2, 0, 0), 0.25f);
            GL.Color3(_hiY ? Color.Yellow : Color.Green);
            RenderTools.DrawCube(new Vector3(0, 2, 0), 0.25f);
            GL.Color3(_hiZ ? Color.Yellow : Color.Blue);
            RenderTools.DrawCube(new Vector3(0, 0, 2), 0.25f);
            GL.PopMatrix();
        }