Ejemplo n.º 1
0
        public override void Render(object opaqueContext, ViewControl vc)
        {
            Matrix4F normWorld = GetManipulatorMatrix();

            if (normWorld == null)
            {
                return;
            }

            var context = opaqueContext as GUILayer.SimpleRenderingContext;

            if (context == null)
            {
                return;
            }

            Vec3F pos = normWorld.Translation;
            float s   = Util.CalcAxisScale(vc.Camera, pos, AxisLength, vc.Height);

            Color xcolor          = (m_hitRegion == HitRegion.XAxis || m_hitRegion == HitRegion.CenterCube) ? Color.Gold : XAxisColor;
            Color ycolor          = (m_hitRegion == HitRegion.YAxis || m_hitRegion == HitRegion.CenterCube) ? Color.Gold : YAxisColor;
            Color zcolor          = (m_hitRegion == HitRegion.ZAxis || m_hitRegion == HitRegion.CenterCube) ? Color.Gold : ZAxisColor;
            Color centerCubeColor = (m_hitRegion == HitRegion.CenterCube) ? Color.Gold : Color.White;


            Vec3F sv      = new Vec3F(s, s, s);
            Vec3F axscale = new Vec3F(s * AxisThickness, s, s * AxisThickness);

            Matrix4F scale = new Matrix4F();

            axscale.Y = Math.Abs(s * m_scale.X);
            scale.Scale(axscale);
            Matrix4F rot = new Matrix4F();

            rot.RotZ(-MathHelper.PiOver2);
            Matrix4F xform = scale * rot * normWorld;

            Util3D.DrawCylinder(context, xform, xcolor);

            axscale.Y = Math.Abs(s * m_scale.Y);
            scale.Scale(axscale);
            xform = scale * normWorld;
            Util3D.DrawCylinder(context, xform, ycolor);
            rot.RotX(MathHelper.PiOver2);
            axscale.Y = Math.Abs(s * m_scale.Z);
            scale.Scale(axscale);
            xform = scale * rot * normWorld;
            Util3D.DrawCylinder(context, xform, zcolor);

            Vec3F centerCubeScale = sv * CenterCubeSize;

            scale.Scale(centerCubeScale);
            Matrix4F centerCubeXform = scale * normWorld;

            Util3D.DrawCube(context, centerCubeXform, centerCubeColor);


            Vec3F handleScale = new Vec3F(Math.Abs(s * m_scale.X), Math.Abs(s * m_scale.Y), Math.Abs(s * m_scale.Z));
            Vec3F handle      = sv * AxisHandle;
            float handleWidth = handle.X / 2;

            scale.Scale(handle);
            Matrix4F trans = new Matrix4F();

            trans.Translation = new Vec3F(handleScale.X - handleWidth, 0, 0);
            xform             = scale * trans * normWorld;

            Util3D.DrawCube(context, xform, xcolor);

            trans.Translation = new Vec3F(0, handleScale.Y - handleWidth, 0);
            xform             = scale * trans * normWorld;
            Util3D.DrawCube(context, xform, ycolor);

            trans.Translation = new Vec3F(0, 0, handleScale.Z - handleWidth);
            xform             = scale * trans * normWorld;
            Util3D.DrawCube(context, xform, zcolor);
        }
Ejemplo n.º 2
0
        public override void Render(object opaqueContext, ViewControl vc)
        {
            Matrix4F normWorld = GetManipulatorMatrix();

            if (normWorld == null)
            {
                return;
            }

            var context = opaqueContext as GUILayer.SimpleRenderingContext;

            if (context == null)
            {
                return;
            }

            int axis = (int)m_hitRegion;

            // axis colors
            Color saveColor = m_axisColor[axis];

            m_axisColor[axis] = m_highlightColor;
            Color xcolor  = m_axisColor[(int)HitRegion.XAxis];
            Color ycolor  = m_axisColor[(int)HitRegion.YAxis];
            Color zcolor  = m_axisColor[(int)HitRegion.ZAxis];
            Color nxcolor = m_axisColor[(int)HitRegion.NegXAxis];
            Color nycolor = m_axisColor[(int)HitRegion.NegYAxis];
            Color nzcolor = m_axisColor[(int)HitRegion.NegZAxis];

            m_axisColor[axis] = saveColor;


            if (m_hitRegion != HitRegion.None)
            {
                normWorld.Translation = HitMatrix.Translation;
            }

            Vec3F pos = normWorld.Translation;
            float s   = Util.CalcAxisScale(vc.Camera, pos, AxisLength, vc.Height);

            Vec3F sv           = new Vec3F(s, s, s);
            Vec3F axscale      = new Vec3F(s * AxisThickness, s, s * AxisThickness);
            bool  negativeAxis = m_hitRegion == HitRegion.NegXAxis || m_hitRegion == HitRegion.NegYAxis || m_hitRegion == HitRegion.NegZAxis;
            Vec3F dragScale    = new Vec3F(Math.Abs(m_scale.X),
                                           Math.Abs(m_scale.Y), Math.Abs(m_scale.Z));



            Matrix4F rot   = new Matrix4F();
            Matrix4F scale = new Matrix4F();

            axscale.Y = negativeAxis ? s : s * dragScale.X;
            scale.Scale(axscale);
            rot.RotZ(-MathHelper.PiOver2);
            Matrix4F xform = scale * rot * normWorld;

            Util3D.DrawCylinder(context, xform, xcolor);

            axscale.Y = negativeAxis ? s : s * dragScale.Y;
            scale.Scale(axscale);
            xform = scale * normWorld;
            Util3D.DrawCylinder(context, xform, ycolor);

            axscale.Y = negativeAxis ? s : s * dragScale.Z;
            scale.Scale(axscale);
            rot.RotX(MathHelper.PiOver2);
            xform = scale * rot * normWorld;
            Util3D.DrawCylinder(context, xform, zcolor);


            rot.RotZ(MathHelper.PiOver2);
            axscale.Y = negativeAxis ? s * dragScale.X : s;
            scale.Scale(axscale);
            xform = scale * rot * normWorld;
            Util3D.DrawCylinder(context, xform, nxcolor);

            rot.RotZ(MathHelper.Pi);
            axscale.Y = negativeAxis ? s * dragScale.Y : s;
            scale.Scale(axscale);
            xform = scale * rot * normWorld;
            Util3D.DrawCylinder(context, xform, nycolor);

            rot.RotX(-MathHelper.PiOver2);
            axscale.Y = negativeAxis ? s * dragScale.Z : s;
            scale.Scale(axscale);
            xform = scale * rot * normWorld;
            Util3D.DrawCylinder(context, xform, nzcolor);


            // draw center cube
            scale.Scale(s * (1.0f / 16.0f));
            xform = scale * normWorld;
            Util3D.DrawCube(context, xform, Color.White);

            Vec3F handle      = sv * AxisHandle;
            float handleWidth = handle.X / 2;

            scale.Scale(handle);
            Matrix4F trans = new Matrix4F();


            // X handle
            float drag = m_hitRegion == HitRegion.XAxis ? dragScale.X : 1.0f;

            trans.Translation = new Vec3F(drag * sv.X - handleWidth, 0, 0);
            xform             = scale * trans * normWorld;
            Util3D.DrawCube(context, xform, xcolor);

            // y handle
            drag = m_hitRegion == HitRegion.YAxis ? dragScale.Y : 1.0f;
            trans.Translation = new Vec3F(0, drag * sv.Y - handleWidth, 0);
            xform             = scale * trans * normWorld;
            Util3D.DrawCube(context, xform, ycolor);

            // z handle
            drag = m_hitRegion == HitRegion.ZAxis ? dragScale.Z : 1.0f;
            trans.Translation = new Vec3F(0, 0, drag * sv.Z - handleWidth);
            xform             = scale * trans * normWorld;
            Util3D.DrawCube(context, xform, zcolor);


            // -x handle
            drag = m_hitRegion == HitRegion.NegXAxis ? dragScale.X : 1.0f;
            trans.Translation = new Vec3F(-sv.X * drag + handleWidth, 0, 0);
            xform             = scale * trans * normWorld;
            Util3D.DrawCube(context, xform, nxcolor);

            // -y handle
            drag = m_hitRegion == HitRegion.NegYAxis ? dragScale.Y : 1.0f;
            trans.Translation = new Vec3F(0, -sv.Y * drag + handleWidth, 0);
            xform             = scale * trans * normWorld;
            Util3D.DrawCube(context, xform, nycolor);

            // -z handle
            drag = m_hitRegion == HitRegion.NegZAxis ? dragScale.Z : 1.0f;
            trans.Translation = new Vec3F(0, 0, -sv.Z * drag + handleWidth);
            xform             = scale * trans * normWorld;
            Util3D.DrawCube(context, xform, nzcolor);
        }
Ejemplo n.º 3
0
        public void Render(ViewControl vc, Matrix4F normWorld)
        {
            float s      = Util.CalcAxisScale(vc.Camera, normWorld.Translation, Manipulator.AxisLength, vc.Height);
            Color xcolor = (m_hitRegion == HitRegion.XAxis || m_hitRegion == HitRegion.XYSquare || m_hitRegion == HitRegion.XZSquare) ? Color.Gold : Manipulator.XAxisColor;
            Color ycolor = (m_hitRegion == HitRegion.YAxis || m_hitRegion == HitRegion.XYSquare || m_hitRegion == HitRegion.YZSquare) ? Color.Gold : Manipulator.YAxisColor;
            Color Zcolor = (m_hitRegion == HitRegion.ZAxis || m_hitRegion == HitRegion.XZSquare || m_hitRegion == HitRegion.YZSquare) ? Color.Gold : Manipulator.ZAxisColor;

            Color XYx = m_hitRegion == HitRegion.XYSquare ? Color.Gold : Manipulator.XAxisColor;
            Color XYy = m_hitRegion == HitRegion.XYSquare ? Color.Gold : Manipulator.YAxisColor;


            Color XZx = m_hitRegion == HitRegion.XZSquare ? Color.Gold : Manipulator.XAxisColor;
            Color XZz = m_hitRegion == HitRegion.XZSquare ? Color.Gold : Manipulator.ZAxisColor;


            Color YZy = m_hitRegion == HitRegion.YZSquare ? Color.Gold : Manipulator.YAxisColor;
            Color YZz = m_hitRegion == HitRegion.YZSquare ? Color.Gold : Manipulator.ZAxisColor;


            var axisScale = new Matrix4F();

            axisScale.Scale(new Vec3F(s * Manipulator.AxisThickness, s * (1 - ConeHeight), s * Manipulator.AxisThickness));
            var axisrot = new Matrix4F();


            // Draw X axis
            axisrot.RotZ(-MathHelper.PiOver2);
            Matrix4F scaleRot  = axisScale * axisrot;
            Matrix4F axisXform = scaleRot * normWorld;

            Util3D.DrawCylinder(axisXform, xcolor);

            // draw y
            axisXform = axisScale * normWorld;
            Util3D.DrawCylinder(axisXform, ycolor);

            // draw z
            axisrot.RotX(MathHelper.PiOver2);
            scaleRot  = axisScale * axisrot;
            axisXform = scaleRot * normWorld;
            Util3D.DrawCylinder(axisXform, Zcolor);

            // draw center cube.
            Matrix4F cubeScale = new Matrix4F();

            cubeScale.Scale(CenterCube * s);
            var cubexform = cubeScale * normWorld;

            Util3D.DrawCube(cubexform, Color.White);


            Matrix4F arrowHead = ComputeXhead(normWorld, s);

            Util3D.DrawCone(arrowHead, xcolor);

            arrowHead = ComputeYhead(normWorld, s);
            Util3D.DrawCone(arrowHead, ycolor);

            arrowHead = ComputeZhead(normWorld, s);
            Util3D.DrawCone(arrowHead, Zcolor);

            // draw xy rect.
            Matrix4F scale = new Matrix4F();

            scale.Scale(s * Manipulator.AxisThickness, s * SquareLength, s * Manipulator.AxisThickness);
            Matrix4F trans = new Matrix4F();

            trans.Translation = new Vec3F(0, s * SquareLength, 0);
            Matrix4F rot = new Matrix4F();

            rot.RotZ(-MathHelper.PiOver2);
            Matrix4F squareXform = scale * rot * trans * normWorld;


            Util3D.DrawCylinder(squareXform, XYy);

            trans.Translation = new Vec3F(s * SquareLength, 0, 0);
            squareXform       = scale * trans * normWorld;
            Util3D.DrawCylinder(squareXform, XYx);


            // draw xz rect.
            trans.Translation = new Vec3F(0, 0, s * SquareLength);
            rot.RotZ(-MathHelper.PiOver2);
            squareXform = scale * rot * trans * normWorld;
            Util3D.DrawCylinder(squareXform, XZz);

            trans.Translation = new Vec3F(s * SquareLength, 0, 0);
            rot.RotX(MathHelper.PiOver2);
            squareXform = scale * rot * trans * normWorld;
            Util3D.DrawCylinder(squareXform, XZx);

            // draw yz
            trans.Translation = new Vec3F(0, s * SquareLength, 0);
            rot.RotX(MathHelper.PiOver2);
            squareXform = scale * rot * trans * normWorld;
            Util3D.DrawCylinder(squareXform, YZy);

            trans.Translation = new Vec3F(0, 0, s * SquareLength);
            squareXform       = scale * trans * normWorld;
            Util3D.DrawCylinder(squareXform, YZz);
        }