Exemplo n.º 1
0
        private void RenderExtras(GUILayer.SimpleRenderingContext context, DesignView designView)
        {
            bool renderSelected = RenderState.DisplayBound == DisplayFlagModes.Selection ||
                                  RenderState.DisplayCaption == DisplayFlagModes.Selection ||
                                  RenderState.DisplayPivot == DisplayFlagModes.Selection;

            if (renderSelected)
            {
                var selection = DesignView.Context.As <ISelectionContext>().Selection;
                IEnumerable <DomNode> rootDomNodes = DomNode.GetRoots(selection.AsIEnumerable <DomNode>());
                RenderProperties(context, rootDomNodes,
                                 RenderState.DisplayCaption == DisplayFlagModes.Selection,
                                 RenderState.DisplayBound == DisplayFlagModes.Selection,
                                 RenderState.DisplayPivot == DisplayFlagModes.Selection);
            }

            if (RenderState.GridMode == RenderState.GridModes.Enabled)
            {
                var          game       = designView.Context.As <IGame>();
                GridRenderer gridRender = game.Grid.Cast <GridRenderer>();
                gridRender.Render(context, Camera);
            }

            RenderProperties(context, Items,
                             RenderState.DisplayCaption == DisplayFlagModes.Always,
                             RenderState.DisplayBound == DisplayFlagModes.Always,
                             RenderState.DisplayPivot == DisplayFlagModes.Always);

            GameEngine.DrawText2D(m_pendingCaption, Util3D.CaptionFont, 1, 1, Color.White);
        }
Exemplo n.º 2
0
 private static void NativeDrawPrimitive(
     GUILayer.SimpleRenderingContext context,
     PrimitiveType pt,
     ulong vb, uint StartVertex, uint vertexCount,
     float *color, float *xform)
 {
     context.DrawPrimitive((uint)pt, vb, StartVertex, vertexCount, color, xform);
 }
Exemplo n.º 3
0
 public static void DrawRect(GUILayer.SimpleRenderingContext context, Matrix4F xform, Color color)
 {
     GameEngine.DrawPrimitive(context, PrimitiveType.LineList,
                              s_linesVertId,
                              s_rectStartVertex,
                              s_rectVertexCount,
                              color,
                              xform);
 }
Exemplo n.º 4
0
 public static void DrawCircle(GUILayer.SimpleRenderingContext context, Matrix4F xform, Color color)
 {
     GameEngine.DrawPrimitive(context, PrimitiveType.LineStrip,
                              s_circleVerts,
                              0,
                              s_circleVertexCount,
                              color,
                              xform);
 }
Exemplo n.º 5
0
 private static void NativeDrawIndexedPrimitive(
     GUILayer.SimpleRenderingContext context,
     PrimitiveType pt,
     ulong vb, ulong ib,
     uint startIndex, uint indexCount, uint startVertex,
     float *color, float *xform)
 {
     context.DrawIndexedPrimitive((uint)pt, vb, ib, startIndex, indexCount, startVertex, color, xform);
 }
Exemplo n.º 6
0
 public static void DrawPivot(GUILayer.SimpleRenderingContext context, Matrix4F xform, Color c)
 {
     GameEngine.DrawPrimitive(context, PrimitiveType.LineStrip,
                              s_pivotVerts,
                              0,
                              s_pivotVertexCount,
                              c,
                              xform);
 }
Exemplo n.º 7
0
 public static void DrawZ(GUILayer.SimpleRenderingContext context, Matrix4F xform, Color color)
 {
     GameEngine.DrawPrimitive(context, PrimitiveType.LineList,
                              s_linesVertId,
                              s_axisStartVertex + 4,
                              2,
                              color,
                              xform);
 }
Exemplo n.º 8
0
        public static void DrawSphere(GUILayer.SimpleRenderingContext context, Sphere3F sphere, Color c)
        {
            // create matrix from AABB
            T1.Set(sphere.Center);
            float scale = 2 * sphere.Radius;

            T1.M11 = scale;
            T1.M22 = scale;
            T1.M33 = scale;
            DrawSphere(context, T1, c);
        }
Exemplo n.º 9
0
 public static void DrawArrowCap(GUILayer.SimpleRenderingContext context, Matrix4F xform, Color color)
 {
     GameEngine.DrawIndexedPrimitive(context, PrimitiveType.TriangleList,
                                     s_arrowCapVertId,
                                     s_arrowCapIndexId,
                                     0,
                                     s_arrowCapIndexCount,
                                     0,
                                     color,
                                     xform);
 }
Exemplo n.º 10
0
 public static void DrawSphere(GUILayer.SimpleRenderingContext context, Matrix4F xform, System.Drawing.Color color)
 {
     GameEngine.DrawIndexedPrimitive(context, PrimitiveType.TriangleList,
                                     s_sphereVertId,
                                     s_sphereIndexId,
                                     0,
                                     s_sphereIndexCount,
                                     0,
                                     color,
                                     xform);
 }
Exemplo n.º 11
0
        //Draw primitive with the given parameters.
        public static void DrawPrimitive(
            GUILayer.SimpleRenderingContext context,
            PrimitiveType pt,
            ulong vb, uint StartVertex, uint vertexCount,
            Color color, Matrix4F xform)
        {
            Vec4F vc;

            vc.X = color.R / 255.0f;
            vc.Y = color.G / 255.0f;
            vc.Z = color.B / 255.0f;
            vc.W = color.A / 255.0f;
            fixed(float *mtrx = &xform.M11)
            {
                NativeDrawPrimitive(context, pt, vb, StartVertex, vertexCount, &vc.X, mtrx);
            }
        }
Exemplo n.º 12
0
        public static void DrawAABB(GUILayer.SimpleRenderingContext context, AABB bound)
        {
            // create matrix from AABB
            Vec3F trans = bound.Center;
            Vec3F diag  = bound.Max - bound.Min;

            T1.Set(trans);
            T1.M11 = diag.X;
            T1.M22 = diag.Y;
            T1.M33 = diag.Z;

            GameEngine.DrawIndexedPrimitive(context, PrimitiveType.LineList,
                                            s_boxVertsId,
                                            s_boxIndicesId,
                                            0,
                                            s_boxIndicesCount,
                                            0,
                                            Color.White,
                                            T1);
        }
Exemplo n.º 13
0
        private void RenderManipulators(GUILayer.SimpleRenderingContext context, DesignView designView)
        {
            var mani = designView.Manipulator;

            if (mani == null)
            {
                return;
            }

            var extra           = mani as IManipulatorExtra;
            var clearBeforeDraw = (extra != null) ? extra.ClearBeforeDraw() : true;

            if (clearBeforeDraw)
            {
                // disable depth write and depth read
                context.InitState(false, false);
            }

            mani.Render(context, this);
        }
Exemplo n.º 14
0
        private void RenderProperties(GUILayer.SimpleRenderingContext context, IEnumerable <object> objects, bool renderCaption, bool renderBound, bool renderPivot)
        {
            if (renderCaption || renderBound)
            {
                Util3D.SetRenderFlag(context, BasicRendererFlags.WireFrame);
                Matrix4F vp = Camera.ViewMatrix * Camera.ProjectionMatrix;
                foreach (object obj in objects)
                {
                    IBoundable bnode = obj.As <IBoundable>();
                    if (bnode == null || bnode.BoundingBox.IsEmpty || obj.Is <IGameObjectFolder>())
                    {
                        continue;
                    }

                    INameable      nnode = obj.As <INameable>();
                    ITransformable trans = obj.As <ITransformable>();

                    if (renderBound)
                    {
                        Util3D.DrawAABB(context, bnode.BoundingBox);
                    }
                    if (renderCaption && nnode != null)
                    {
                        Vec3F topCenter = bnode.BoundingBox.Center;
                        topCenter.Y = bnode.BoundingBox.Max.Y;
                        Point pt = Project(vp, topCenter);
                        GameEngine.DrawText2D(nnode.Name, Util3D.CaptionFont, pt.X, pt.Y, Color.White);
                    }
                }
            }

            if (renderPivot)
            {
                Util3D.SetRenderFlag(context, BasicRendererFlags.WireFrame | BasicRendererFlags.DisableDepthTest);

                // create few temp matrics to
                Matrix4F toWorld  = new Matrix4F();
                Matrix4F PV       = new Matrix4F();
                Matrix4F sc       = new Matrix4F();
                Matrix4F bl       = new Matrix4F();
                Matrix4F recXform = new Matrix4F();
                foreach (object obj in objects)
                {
                    ITransformable trans = obj.As <ITransformable>();
                    IBoundable     bnode = obj.As <IBoundable>();
                    if (trans == null || bnode == null || bnode.BoundingBox.IsEmpty || obj.Is <IGameObjectFolder>())
                    {
                        continue;
                    }

                    Path <DomNode> path = new Path <DomNode>(trans.Cast <DomNode>().GetPath());
                    toWorld.Set(Vec3F.ZeroVector);
                    TransformUtils.CalcPathTransform(toWorld, path, path.Count - 1);

                    // Offset by pivot
                    PV.Set(trans.Pivot);
                    toWorld.Mul(PV, toWorld);
                    Vec3F pos = toWorld.Translation;

                    const float pivotDiameter = 16; // in pixels
                    float       s             = Util.CalcAxisScale(Camera, pos, pivotDiameter, Height);
                    sc.Scale(s);
                    Util.CreateBillboard(bl, pos, Camera.WorldEye, Camera.Up, Camera.LookAt);
                    recXform = sc * bl;
                    Util3D.DrawPivot(context, recXform, Color.Yellow);
                }
            }
        }
Exemplo n.º 15
0
        public void Render(GUILayer.SimpleRenderingContext context, Camera cam)
        {
            GameEngine.SetRendererFlag(context, BasicRendererFlags.WireFrame);
            IGrid grid = this.As <IGrid>();

            if (grid.Visible == false)
            {
                return;
            }

            float s = grid.Size;

            Matrix4F scale = new Matrix4F();

            scale.Scale(new Vec3F(s, s, s));

            Matrix4F gridXform = new Matrix4F();

            if (cam.Frustum.IsOrtho)
            {
                float     dist = cam.ViewMatrix.Translation.Z;
                ViewTypes vt   = cam.ViewType;
                if (vt == ViewTypes.Top)
                {
                    gridXform.Translation
                        = new Vec3F(0, dist, 0);
                }
                else if (vt == ViewTypes.Bottom)
                {
                    gridXform.Translation
                        = new Vec3F(0, -dist, 0);
                }
                else if (vt == ViewTypes.Right)
                {
                    gridXform.RotZ(MathHelper.PiOver2);
                    gridXform.Translation
                        = new Vec3F(dist, 0, 0);
                }
                else if (vt == ViewTypes.Left)
                {
                    gridXform.RotZ(MathHelper.PiOver2);
                    gridXform.Translation
                        = new Vec3F(-dist, 0, 0);
                }
                else if (vt == ViewTypes.Front)
                {
                    gridXform.RotX(MathHelper.PiOver2);
                    gridXform.Translation
                        = new Vec3F(0, 0, dist);
                }
                else if (vt == ViewTypes.Back)
                {
                    gridXform.RotX(MathHelper.PiOver2);
                    gridXform.Translation
                        = new Vec3F(0, 0, -dist);
                }
                gridXform.Mul(scale, gridXform);
            }
            else
            {
                Matrix4F trans = new Matrix4F();
                trans.Translation = new Vec3F(0, grid.Height, 0);
                gridXform         = Matrix4F.Multiply(scale, trans);
            }

            GameEngine.DrawPrimitive(context, PrimitiveType.LineList, m_gridVBId, 0, m_gridVertexCount, Color.LightGray,
                                     Matrix4F.Multiply(gridXform, cam.AxisSystem));

            GameEngine.DrawPrimitive(context, PrimitiveType.LineList, m_basisAxesVBId, 0, m_basisAxesVertexCount, Color.White,
                                     gridXform);
        }
Exemplo n.º 16
0
 public static void SetRenderFlag(GUILayer.SimpleRenderingContext context, BasicRendererFlags flags)
 {
     GameEngine.SetRendererFlag(context, flags);
 }
Exemplo n.º 17
0
 /// <summary>
 /// Sets render flags used for basic drawing.</summary>
 public static void SetRendererFlag(GUILayer.SimpleRenderingContext context, BasicRendererFlags renderFlags)
 {
     context.InitState(
         (renderFlags & BasicRendererFlags.DisableDepthTest) == 0,
         (renderFlags & BasicRendererFlags.DisableDepthWrite) == 0);
 }