Exemple #1
0
        void DrawGL(int renderWidth, int renderHeight)
        {
            //Set state
            renderTarget.BindFramebuffer();
            rstate.Cull = true;
            var cc = rstate.ClearColor;

            rstate.DepthEnabled = true;
            rstate.ClearColor   = Color4.CornflowerBlue * new Color4(0.3f, 0.3f, 0.3f, 1f);
            rstate.ClearAll();
            vps.Push(0, 0, renderWidth, renderHeight);
            var cam = new LookAtCamera();

            cam.Update(renderWidth, renderHeight, new Vector3(zoom, 0, 0), Vector3.Zero);
            buffer.StartFrame(rstate);
            polyline.SetCamera(cam);
            billboards.Begin(cam, buffer);
            debug.StartFrame(cam, rstate);
            instance.Draw(polyline, billboards, debug, transform, sparam);
            polyline.FrameEnd();
            billboards.End();
            buffer.DrawOpaque(rstate);
            rstate.DepthWrite = false;
            buffer.DrawTransparent(rstate);
            rstate.DepthWrite = true;
            debug.Render();
            //Restore state
            rstate.Cull         = false;
            rstate.BlendMode    = BlendMode.Normal;
            rstate.DepthEnabled = false;
            rstate.ClearColor   = cc;
            RenderTarget2D.ClearBinding();
            vps.Pop();
        }
Exemple #2
0
        void DrawGL(int renderWidth, int renderHeight)
        {
            var       cam = new LookAtCamera();
            Matrix4x4 rot = Matrix4x4.CreateRotationX(aleViewport.CameraRotation.Y) *
                            Matrix4x4.CreateRotationY(aleViewport.CameraRotation.X);
            var dir = Vector3.Transform(-Vector3.UnitZ, rot);
            var to  = aleViewport.CameraOffset + (dir * 10);

            if (aleViewport.Mode == CameraModes.Arcball)
            {
                to = Vector3.Zero;
            }
            cam.Update(renderWidth, renderHeight, aleViewport.CameraOffset, to, rot);
            buffer.StartFrame(rstate);
            polyline.SetCamera(cam);
            debug.StartFrame(cam, rstate);
            instance.Draw(transform, sparam);
            pool.Draw(cam, polyline, res, debug);
            polyline.FrameEnd();
            buffer.DrawOpaque(rstate);
            rstate.DepthWrite = false;
            buffer.DrawTransparent(rstate);
            rstate.DepthWrite = true;
            debug.Render();
        }
        public override void Draw()
        {
            viewport.Begin();
            var       cam = new LookAtCamera();
            Matrix4x4 rot = Matrix4x4.CreateRotationX(viewport.CameraRotation.Y) *
                            Matrix4x4.CreateRotationY(viewport.CameraRotation.X);
            var dir = Vector3.Transform(-Vector3.UnitZ, rot);
            var to  = Vector3.Zero;

            cam.Update(viewport.RenderWidth, viewport.RenderHeight, viewport.CameraOffset, to, rot);
            shader.SetViewProjection(cam);
            var w = Matrix4x4.Identity;
            var n = Matrix4x4.Identity;

            shader.SetWorld(ref w, ref n);
            shader.Shader.SetVector3(cameraPositionIndex, cam.Position);
            tex.BindTo(0);
            shader.UseProgram();
            for (int i = 0; i < 6; i++)
            {
                sphere.GetDrawParameters((CubeMapFace)i, out int start, out int count, out _);
                sphere.VertexBuffer.Draw(PrimitiveTypes.TriangleList, 0, start, count);
            }
            viewport.End();
        }
        void DrawGL(int renderWidth, int renderHeight)
        {
            //Set state
            renderTarget.BindFramebuffer();
            rstate.Cull = true;
            var cc = rstate.ClearColor;

            rstate.DepthEnabled = true;
            rstate.ClearColor   = background;
            rstate.ClearAll();
            vps.Push(0, 0, renderWidth, renderHeight);
            //Draw Model
            var cam = new LookAtCamera();

            cam.Update(renderWidth, renderHeight, new Vector3(zoom, 0, 0), Vector3.Zero);
            drawable.Update(cam, TimeSpan.Zero, TimeSpan.Zero);
            if (viewMode != M_NONE)
            {
                buffer.StartFrame(rstate);
                if (drawable is CmpFile)
                {
                    DrawCmp(cam, false);
                }
                else
                {
                    DrawSimple(cam, false);
                }
                buffer.DrawOpaque(rstate);
                rstate.DepthWrite = false;
                buffer.DrawTransparent(rstate);
                rstate.DepthWrite = true;
            }
            if (doWireframe)
            {
                buffer.StartFrame(rstate);
                GL.PolygonOffset(1, 1);
                rstate.Wireframe = true;
                if (drawable is CmpFile)
                {
                    DrawCmp(cam, true);
                }
                else
                {
                    DrawSimple(cam, false);
                }
                GL.PolygonOffset(0, 0);
                buffer.DrawOpaque(rstate);
                rstate.Wireframe = false;
            }
            //Draw hardpoints
            DrawHardpoints(cam);
            //Restore state
            rstate.Cull         = false;
            rstate.BlendMode    = BlendMode.Normal;
            rstate.DepthEnabled = false;
            rstate.ClearColor   = cc;
            RenderTarget2D.ClearBinding();
            vps.Pop();
        }
Exemple #5
0
        void Render()
        {
            colladaViewport.Begin();
            var cam = new LookAtCamera();

            cam.Update(colladaViewport.RenderWidth, colladaViewport.RenderHeight, new Vector3(colladaViewport.Zoom, 0, 0), Vector3.Zero);
            normalMaterial.World  = Matrix4.CreateRotationX(colladaViewport.Rotation.Y) * Matrix4.CreateRotationY(colladaViewport.Rotation.X);
            normalMaterial.Camera = cam;
            normalMaterial.Use(win.RenderState, new VertexPositionNormalDiffuseTextureTwo(), ref Lighting.Empty);
            foreach (var drawcall in selected.Geometry.Drawcalls)
            {
                vbo.Draw(PrimitiveTypes.TriangleList, drawcall.Start, drawcall.TriCount);
            }
            colladaViewport.End();
        }
Exemple #6
0
        void DrawGL(int renderWidth, int renderHeight)
        {
            var cam = new LookAtCamera();

            cam.Update(renderWidth, renderHeight, new Vector3(aleViewport.Zoom, 0, 0), Vector3.Zero);
            buffer.StartFrame(rstate);
            polyline.SetCamera(cam);
            billboards.Begin(cam, buffer);
            debug.StartFrame(cam, rstate);
            instance.Draw(polyline, billboards, debug, transform, sparam);
            polyline.FrameEnd();
            billboards.End();
            buffer.DrawOpaque(rstate);
            rstate.DepthWrite = false;
            buffer.DrawTransparent(rstate);
            rstate.DepthWrite = true;
            debug.Render();
        }
Exemple #7
0
        void DrawGL(int renderWidth, int renderHeight)
        {
            //Draw Model
            var cam = new LookAtCamera();

            cam.Update(renderWidth, renderHeight, new Vector3(modelViewport.Zoom, 0, 0), Vector3.Zero);
            drawable.Update(cam, TimeSpan.Zero, TimeSpan.Zero);
            if (viewMode != M_NONE)
            {
                buffer.StartFrame(rstate);
                if (drawable is CmpFile)
                {
                    DrawCmp(cam, false);
                }
                else
                {
                    DrawSimple(cam, false);
                }
                buffer.DrawOpaque(rstate);
                rstate.DepthWrite = false;
                buffer.DrawTransparent(rstate);
                rstate.DepthWrite = true;
            }
            if (doWireframe)
            {
                buffer.StartFrame(rstate);
                GL.PolygonOffset(1, 1);
                rstate.Wireframe = true;
                if (drawable is CmpFile)
                {
                    DrawCmp(cam, true);
                }
                else
                {
                    DrawSimple(cam, true);
                }
                GL.PolygonOffset(0, 0);
                buffer.DrawOpaque(rstate);
                rstate.Wireframe = false;
            }
            //Draw hardpoints
            DrawHardpoints(cam);
        }
Exemple #8
0
        void DrawGL(int renderWidth, int renderHeight)
        {
            var     cam = new LookAtCamera();
            Matrix4 rot = Matrix4.CreateRotationX(aleViewport.CameraRotation.Y) *
                          Matrix4.CreateRotationY(aleViewport.CameraRotation.X);
            var dir = rot.Transform(Vector3.Forward);
            var to  = aleViewport.CameraOffset + (dir * 10);

            cam.Update(renderWidth, renderHeight, aleViewport.CameraOffset, to, rot);
            buffer.StartFrame(rstate);
            polyline.SetCamera(cam);
            billboards.Begin(cam, buffer);
            debug.StartFrame(cam, rstate);
            instance.Draw(polyline, billboards, debug, transform, sparam);
            polyline.FrameEnd();
            billboards.End();
            buffer.DrawOpaque(rstate);
            rstate.DepthWrite = false;
            buffer.DrawTransparent(rstate);
            rstate.DepthWrite = true;
            debug.Render();
        }
        void DrawGL(int renderWidth, int renderHeight)
        {
            ICamera cam;
            //Draw Model
            var     lookAtCam = new LookAtCamera();
            Matrix4 rot       = Matrix4.CreateRotationX(modelViewport.CameraRotation.Y) *
                                Matrix4.CreateRotationY(modelViewport.CameraRotation.X);
            var dir = rot.Transform(Vector3.Forward);
            var to  = modelViewport.CameraOffset + (dir * 10);

            lookAtCam.Update(renderWidth, renderHeight, modelViewport.CameraOffset, to, rot);
            ThnCamera tcam  = null;
            float     znear = 0;
            float     zfar  = 0;

            if (doCockpitCam)
            {
                var vp = new Viewport(0, 0, renderWidth, renderHeight);
                tcam = new ThnCamera(vp);
                tcam.Transform.AspectRatio = renderWidth / (float)renderHeight;
                var tr = cameraPart.GetTransform(Matrix4.Identity);
                tcam.Transform.Orientation = Matrix4.CreateFromQuaternion(tr.ExtractRotation());
                tcam.Transform.Position    = tr.Transform(Vector3.Zero);
                znear = cameraPart.Camera.Znear;
                zfar  = cameraPart.Camera.Zfar;
                tcam.Transform.Znear = 0.001f;
                tcam.Transform.Zfar  = 1000;
                tcam.Transform.FovH  = MathHelper.RadiansToDegrees(cameraPart.Camera.Fovx);
                tcam.frameNo         = fR++;
                tcam.Update();
                cam = tcam;
            }
            else
            {
                cam = lookAtCam;
            }
            _window.DebugRender.StartFrame(cam, rstate);

            drawable.Update(cam, TimeSpan.Zero, TimeSpan.FromSeconds(_window.TotalTime));
            if (viewMode != M_NONE)
            {
                int drawCount = doCockpitCam ? 2 : 1;
                for (int i = 0; i < drawCount; i++)
                {
                    buffer.StartFrame(rstate);
                    if (i == 1)
                    {
                        rstate.ClearDepth();
                        tcam.Transform.Zfar  = zfar;
                        tcam.Transform.Znear = znear;
                        tcam.frameNo         = fR++;
                        tcam.Update();
                    }
                    if (drawable is CmpFile)
                    {
                        DrawCmp(cam, false);
                    }
                    else
                    {
                        DrawSimple(cam, false);
                    }
                    buffer.DrawOpaque(rstate);
                    rstate.DepthWrite = false;
                    buffer.DrawTransparent(rstate);
                    rstate.DepthWrite = true;
                }
            }
            if (doWireframe)
            {
                buffer.StartFrame(rstate);
                GL.PolygonOffset(1, 1);
                rstate.Wireframe = true;
                if (drawable is CmpFile)
                {
                    DrawCmp(cam, true);
                }
                else
                {
                    DrawSimple(cam, true);
                }
                GL.PolygonOffset(0, 0);
                buffer.DrawOpaque(rstate);
                rstate.Wireframe = false;
            }
            if (drawVMeshWire)
            {
                if (drawable is CmpFile)
                {
                    WireCmp();
                }
                else if (drawable is ModelFile)
                {
                    Wire3db();
                }
            }
            //Draw VMeshWire (if used)
            _window.DebugRender.Render();
            //Draw Sur
            if (surs != null)
            {
                RenderSurs(cam);
            }
            //Draw hardpoints
            DrawHardpoints(cam);
            // if (drawSkeleton) DrawSkeleton(cam);
        }
        void DrawGL(int renderWidth, int renderHeight, bool viewport)
        {
            if (_window.Config.BackgroundGradient && viewport && doBackground)
            {
                _window.Renderer2D.Start(renderWidth, renderHeight);
                _window.Renderer2D.DrawVerticalGradient(new Rectangle(0, 0, renderWidth, renderHeight), _window.Config.Background, _window.Config.Background2);
                _window.Renderer2D.Finish();
            }
            rstate.DepthEnabled = true;
            rstate.Cull         = true;
            ICamera cam;
            //Draw Model
            var lookAtCam = new LookAtCamera();
            var rot       = Matrix4x4.CreateRotationX(modelViewport.CameraRotation.Y) *
                            Matrix4x4.CreateRotationY(modelViewport.CameraRotation.X);
            var dir = Vector3.Transform(-Vector3.UnitZ, rot);
            var to  = modelViewport.CameraOffset + (dir * 10);

            if (modelViewport.Mode == CameraModes.Arcball)
            {
                to = Vector3.Zero;
            }
            lookAtCam.Update(renderWidth, renderHeight, modelViewport.CameraOffset, to, rot);
            ThnCamera tcam  = null;
            float     znear = 0;
            float     zfar  = 0;

            if (modelViewport.Mode == CameraModes.Cockpit)
            {
                var vp = new Viewport(0, 0, renderWidth, renderHeight);
                tcam = new ThnCamera(vp);
                tcam.Transform.AspectRatio = renderWidth / (float)renderHeight;
                var tr = Matrix4x4.Identity;
                if (!string.IsNullOrEmpty(cameraPart.Construct?.ParentName))
                {
                    tr = cameraPart.Construct.LocalTransform *
                         vmsModel.Parts[cameraPart.Construct.ParentName].LocalTransform;
                }
                else if (cameraPart.Construct != null)
                {
                    tr = cameraPart.Construct.LocalTransform;
                }
                tcam.Transform.Orientation = Matrix4x4.CreateFromQuaternion(tr.ExtractRotation());
                tcam.Transform.Position    = Vector3.Transform(Vector3.Zero, tr);
                znear = cameraPart.Camera.Znear;
                zfar  = cameraPart.Camera.Zfar;
                tcam.Transform.Znear = 0.001f;
                tcam.Transform.Zfar  = 1000;
                tcam.Transform.FovH  = MathHelper.RadiansToDegrees(cameraPart.Camera.Fovx);
                tcam.frameNo         = fR++;
                tcam.Update();
                cam = tcam;
            }
            else
            {
                cam = lookAtCam;
            }
            if (showGrid && viewport &&
                !(drawable is SphFile) &&
                modelViewport.Mode != CameraModes.Starsphere)
            {
                GridRender.Draw(rstate, cam, _window.Config.GridColor);
            }
            _window.DebugRender.StartFrame(cam, rstate);
            if (drawable is DF.DfmFile dfm)
            {
                skel.UploadBoneData(buffer.BonesBuffer);
                dfm.SetSkinning(skel.BodySkinning);
                dfm.Update(cam, TimeSpan.Zero, TimeSpan.FromSeconds(_window.TotalTime));
            }
            if (vmsModel != null)
            {
                vmsModel.UpdateTransform();
                vmsModel.Update(cam, TimeSpan.FromSeconds(_window.TotalTime), _window.Resources);
            }
            if (viewMode != M_NONE)
            {
                int drawCount = (modelViewport.Mode == CameraModes.Cockpit) ? 2 : 1;
                for (int i = 0; i < drawCount; i++)
                {
                    buffer.StartFrame(rstate);
                    if (i == 1)
                    {
                        rstate.ClearDepth();
                        tcam.Transform.Zfar  = zfar;
                        tcam.Transform.Znear = znear;
                        tcam.frameNo         = fR++;
                        tcam.Update();
                    }
                    DrawSimple(cam, false);
                    buffer.DrawOpaque(rstate);
                    rstate.DepthWrite = false;
                    buffer.DrawTransparent(rstate);
                    rstate.DepthWrite = true;
                }
            }
            if (doWireframe)
            {
                buffer.StartFrame(rstate);
                GL.PolygonOffset(1, 1);
                rstate.Wireframe = true;
                DrawSimple(cam, true);
                GL.PolygonOffset(0, 0);
                buffer.DrawOpaque(rstate);
                rstate.Wireframe = false;
            }
            if (drawVMeshWire)
            {
                DrawWires();
            }
            //Draw VMeshWire (if used)
            _window.DebugRender.Render();
            //Draw Sur
            if (surs != null)
            {
                RenderSurs(cam);
            }
            //Draw hardpoints
            DrawHardpoints(cam);
            if (drawSkeleton)
            {
                DrawSkeleton(cam);
            }
        }