Beispiel #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);
        }
        // render the scene.
        public void Render()
        {
            bool skipRender =
                SurfaceId == 0 ||
                GameEngine.IsInError ||
                Width == 0 ||
                Height == 0 ||
                DesignView.Context == null;

            if (skipRender)
            {
                return;
            }

            m_clk.Start();
            GameEngine.SetObjectProperty(swapChainId, SurfaceId, BkgColorPropId, DesignView.BackColor);
            GameEngine.SetRenderState(RenderState);
            GameEngine.Begin(SurfaceId, Camera.ViewMatrix, Camera.ProjectionMatrix);

            IGame        game       = DesignView.Context.As <IGame>();
            GridRenderer gridRender = game.Grid.Cast <GridRenderer>();

            gridRender.Render(Camera);

            bool renderSelected = RenderState.DisplayBound == DisplayFlagModes.Selection ||
                                  RenderState.DisplayCaption == DisplayFlagModes.Selection ||
                                  RenderState.DisplayPivot == DisplayFlagModes.Selection;


            if (renderSelected)
            {
                // for testing draw bounds for selected objects
                var selection = DesignView.Context.As <ISelectionContext>().Selection;
                IEnumerable <DomNode> rootDomNodes = DomNode.GetRoots(selection.AsIEnumerable <DomNode>());
                RenderProperties(rootDomNodes,
                                 RenderState.DisplayCaption == DisplayFlagModes.Selection,
                                 RenderState.DisplayBound == DisplayFlagModes.Selection,
                                 RenderState.DisplayPivot == DisplayFlagModes.Selection);
            }

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

            GameEngine.RenderGame();


            if (DesignView.Manipulator != null)
            {
                DesignView.Manipulator.Render(this);
            }

            string str = string.Format("View Type: {0}   time-per-frame: {1:0.00} ms", ViewType, m_clk.Milliseconds);

            GameEngine.DrawText2D(str, Util3D.CaptionFont, 1, 1, Color.White);

            RenderSystemAxis();
            GameEngine.End();
        }
        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);
            }
        }
Beispiel #4
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);
                }
            }
        }
Beispiel #5
0
        // render the scene.
        public override void Render()
        {
            bool skipRender =
                SurfaceId == 0 ||
                GameEngine.IsInError ||
                Width == 0 ||
                Height == 0 ||
                DesignView.Context == null;

            if (skipRender)
            {
                return;
            }

            m_clk.Start();
            GameEngine.SetObjectProperty(swapChainId, SurfaceId, BkgColorPropId, DesignView.BackColor);
            GameEngine.SetRenderState(RenderState);
            GameEngine.Begin(SurfaceId, Camera.ViewMatrix, Camera.ProjectionMatrix);

            IGame        game       = DesignView.Context.As <IGame>();
            GridRenderer gridRender = game.Grid.Cast <GridRenderer>();

            gridRender.Render(Camera);

            GameEngine.RenderGame();

            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(rootDomNodes,
                                 RenderState.DisplayCaption == DisplayFlagModes.Selection,
                                 RenderState.DisplayBound == DisplayFlagModes.Selection,
                                 RenderState.DisplayPivot == DisplayFlagModes.Selection);
            }

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

            GameEngine.SetRendererFlag(BasicRendererFlags.Foreground | BasicRendererFlags.Lit);
            if (DesignView.Manipulator != null)
            {
                DesignView.Manipulator.Render(this);
            }

            string str = string.Format("View Type: {0}   time per frame-render call: {1:0.00} ms", ViewType, m_clk.Milliseconds);

            GameEngine.DrawText2D(str, Util3D.CaptionFont, 1, 1, Color.White);
            GameEngine.End();

            if (IsPicking)
            {// todo: use Directx to draw marque.
                using (Graphics g = CreateGraphics())
                {
                    Rectangle rect = MakeRect(FirstMousePoint, CurrentMousePoint);
                    if (rect.Width > 0 && rect.Height > 0)
                    {
                        g.DrawRectangle(s_marqueePen, rect);
                    }
                }
            }
        }
        private void RenderProperties(IEnumerable <object> objects, bool renderCaption, bool renderBound, bool renderPivot)
        {
            bool renderAny = renderCaption || renderBound || renderPivot;

            if (renderAny == false)
            {
                return;
            }

            Util3D.RenderFlag = 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(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.RenderFlag = 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;

                    float s;
                    Util.CalcAxisLengths(Camera, pos, out s);
                    s /= 12.0f;
                    sc.Scale(s);
                    Util.CreateBillboard(bl, pos, Camera.WorldEye, Camera.Up, Camera.LookAt);

                    Matrix4F.Multiply(sc, bl, recXform);

                    Util3D.DrawPivot(recXform, Color.Yellow);
                }
            }
        }
Beispiel #7
0
            // render the scene.
            public void Render()
            {
                if (GameEngine.IsInError ||
                    SurfaceId == 0 ||
                    Visible == false ||
                    Width == 0 ||
                    Height == 0 ||
                    Game == null)
                {
                    return;
                }


                NativeObjectAdapter gameLevel = GameEngine.GetGameLevel();

                try
                {
                    NativeObjectAdapter game = Game.As <NativeObjectAdapter>();
                    GameEngine.SetGameLevel(game);
                    GameEngine.SetRenderState(m_renderState);
                    if (Game.RootGameObjectFolder.GameObjects.Count > 0)
                    {
                        GameEngine.Update(0, 0, true);
                    }

                    if (ResetCamera)
                    {
                        // save view type
                        ViewTypes viewtype = this.ViewType;
                        ViewType = ViewTypes.Perspective;
                        Size       sz        = ClientSize;
                        float      aspect    = (float)sz.Width / (float)sz.Height;
                        IBoundable boundable = Game.RootGameObjectFolder.Cast <IBoundable>();
                        Sce.Atf.VectorMath.Sphere3F sphere = boundable.BoundingBox.ToSphere();
                        float nearZ = sphere.Radius * 0.01f;
                        nearZ = Math.Min(0.1f, nearZ);
                        Camera.SetPerspective(
                            (float)Math.PI / 4,
                            aspect,
                            nearZ,
                            sphere.Radius * 10.0f);

                        Vec3F camPos = sphere.Center + new Vec3F(sphere.Radius, sphere.Radius, sphere.Radius) * 1.2f;
                        Camera.Set(camPos, sphere.Center, new Vec3F(0, 1, 0));
                        ViewType    = viewtype;
                        ResetCamera = false;
                    }

                    GameEngine.Begin(SurfaceId, Camera.ViewMatrix, Camera.ProjectionMatrix);
                    if (Game.RootGameObjectFolder.GameObjects.Count > 0)
                    {
                        GameEngine.RenderGame();
                    }
                    string str = "View Type: " + ViewType.ToString();
                    GameEngine.DrawText2D(str, Util3D.CaptionFont, 1, 1, Color.White);
                    GameEngine.End();
                }
                finally
                {
                    GameEngine.SetGameLevel(gameLevel);
                }
            }