Ejemplo n.º 1
0
        private void RenderSystemAxis()
        {
            float nz = Camera.Frustum.NearZ;

            float    x   = 0.05f * Width;
            Vec3F    pos = new Vec3F(x, Height - x, 0.0f);
            Matrix4F vp  = Camera.ViewMatrix * Camera.ProjectionMatrix;

            pos = this.Unproject(pos, vp);
            if (Camera.Frustum.IsOrtho)
            {
                pos = pos + Camera.LookAt;
            }
            else
            {
                pos = pos + Camera.LookAt * (Camera.NearZ * 0.1f);
            }

            float s;

            Util.CalcAxisLengths(Camera, pos, out s);
            Matrix4F scale = new Matrix4F();

            scale.Scale(s * 0.3f);
            Matrix4F trans = new Matrix4F(pos);
            Matrix4F xform = scale * trans;

            Util3D.RenderFlag = BasicRendererFlags.WireFrame | BasicRendererFlags.DisableDepthTest;
            Util3D.DrawX(xform, Color.Red);
            Util3D.DrawY(xform, Color.Green);
            Util3D.DrawZ(xform, Color.Blue);

            Matrix4F wvp = xform * vp;

            if (ViewType != ViewTypes.Left && ViewType != ViewTypes.Right)
            {
                Vec3F xaxis = new Vec3F(1, 0, 0);
                Point scPt  = Project(wvp, xaxis);
                GameEngine.DrawText2D("X", Util3D.CaptionFont, scPt.X, scPt.Y, Color.Red);
            }

            if (ViewType != ViewTypes.Top && ViewType != ViewTypes.Bottom)
            {
                Vec3F yaxis = new Vec3F(0, 1.6f, 0);
                Point scPt  = Project(wvp, yaxis);
                GameEngine.DrawText2D("Y", Util3D.CaptionFont, scPt.X, scPt.Y, Color.Green);
            }

            if (ViewType != ViewTypes.Front && ViewType != ViewTypes.Back)
            {
                Vec3F zaxis = new Vec3F(0, 0, 1);
                Point scPt  = Project(wvp, zaxis);
                GameEngine.DrawText2D("Z", Util3D.CaptionFont, scPt.X, scPt.Y, Color.Blue);
            }
        }
Ejemplo n.º 2
0
        public void Render(Matrix4F normWorld, float s)
        {
            BasicRendererFlags solid = BasicRendererFlags.Solid | BasicRendererFlags.DisableDepthTest;
            BasicRendererFlags wire  = BasicRendererFlags.WireFrame | BasicRendererFlags.DisableDepthTest;

            Color xcolor = (m_hitRegion == HitRegion.XAxis || m_hitRegion == HitRegion.XYSquare || m_hitRegion == HitRegion.XZSquare) ? Color.Gold : Color.Red;
            Color ycolor = (m_hitRegion == HitRegion.YAxis || m_hitRegion == HitRegion.XYSquare || m_hitRegion == HitRegion.YZSquare) ? Color.Gold : Color.Green;
            Color Zcolor = (m_hitRegion == HitRegion.ZAxis || m_hitRegion == HitRegion.XZSquare || m_hitRegion == HitRegion.YZSquare) ? Color.Gold : Color.Blue;

            Color XYx = m_hitRegion == HitRegion.XYSquare ? Color.Gold : Color.Red;
            Color XYy = m_hitRegion == HitRegion.XYSquare ? Color.Gold : Color.Green;


            Color XZx = m_hitRegion == HitRegion.XZSquare ? Color.Gold : Color.Red;
            Color XZz = m_hitRegion == HitRegion.XZSquare ? Color.Gold : Color.Blue;


            Color YZy = m_hitRegion == HitRegion.YZSquare ? Color.Gold : Color.Green;
            Color YZz = m_hitRegion == HitRegion.YZSquare ? Color.Gold : Color.Blue;

            Vec3F    axScale   = new Vec3F(s, s, s);
            Matrix4F axisXform = ComputeAxis(normWorld, axScale);

            Util3D.RenderFlag = wire;
            Util3D.DrawX(axisXform, xcolor);
            Util3D.DrawY(axisXform, ycolor);
            Util3D.DrawZ(axisXform, Zcolor);

            Matrix4F arrowHead = ComputeXhead(normWorld, s);

            Util3D.RenderFlag = solid;

            Util3D.DrawCone(arrowHead, xcolor);

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

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

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

            scale.Scale(axScale * SquareLength);
            Matrix4F trans = new Matrix4F();

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

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

            // draw xz rect.
            trans.Translation = new Vec3F(0, 0, s * SquareLength);
            squareXform       = scale * trans * normWorld;
            Util3D.DrawX(squareXform, XZz);

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

            // draw yz
            trans.Translation = new Vec3F(0, s * SquareLength, 0);
            squareXform       = scale * trans * normWorld;
            Util3D.DrawZ(squareXform, YZy);

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