コード例 #1
0
        /// <summary>
        /// Display a <see cref="BoundingSphere"/> as a wireframe model
        /// </summary>
        /// <param name="engine">The engine to use for rendering</param>
        /// <param name="sphere">The sphere to be display</param>
        public static void DrawBoundingSphere(this Engine engine, BoundingSphere sphere)
        {
            #region Sanity checks
            if (engine == null)
            {
                throw new ArgumentNullException(nameof(engine));
            }
            #endregion

            using (new ProfilerEvent("Draw bounding sphere"))
            {
                // Backup current render states
                Matrix   lastWorldTransform = engine.State.WorldTransform;
                Cull     lastCullMode       = engine.State.CullMode;
                FillMode lastFillMode       = engine.State.FillMode;
                bool     lastLighting       = engine.State.FfpLighting;

                // Set new states
                engine.State.WorldTransform = Matrix.Scaling(new Vector3(sphere.Radius)) * Matrix.Translation(sphere.Center);
                engine.State.CullMode       = Cull.None;
                engine.State.FillMode       = FillMode.Wireframe;
                engine.State.FfpLighting    = false;

                // Render the sphere
                engine.State.SetTexture(null);
                engine.SimpleSphere.DrawSubset(0);

                // Restore the old states
                engine.State.WorldTransform = lastWorldTransform;
                engine.State.CullMode       = lastCullMode;
                engine.State.FillMode       = lastFillMode;
                engine.State.FfpLighting    = lastLighting;
            }
        }
コード例 #2
0
        /// <summary>
        /// Display a <see cref="BoundingBox"/> as a wireframe model
        /// </summary>
        /// <param name="engine">The engine to use for rendering</param>
        /// <param name="box">The box to be display</param>
        public static void DrawBoundingBox(this Engine engine, BoundingBox box)
        {
            #region Sanity checks
            if (engine == null)
            {
                throw new ArgumentNullException(nameof(engine));
            }
            #endregion

            using (new ProfilerEvent("Draw bounding box"))
            {
                // Backup current render states
                Matrix   lastWorldTransform = engine.State.WorldTransform;
                Cull     lastCullMode       = engine.State.CullMode;
                FillMode lastFillMode       = engine.State.FillMode;
                bool     lastLighting       = engine.State.FfpLighting;

                // Set new states
                Vector3 boxCenter = box.Minimum + (box.Maximum - box.Minimum) * 0.5f;
                engine.State.WorldTransform = Matrix.Scaling(box.Maximum - box.Minimum) * Matrix.Translation(boxCenter);
                engine.State.CullMode       = Cull.None;
                engine.State.FillMode       = FillMode.Wireframe;
                engine.State.FfpLighting    = false;

                // Render the box
                engine.State.SetTexture(null);
                engine.SimpleBox.DrawSubset(0);

                // Restore the old states
                engine.State.WorldTransform = lastWorldTransform;
                engine.State.CullMode       = lastCullMode;
                engine.State.FillMode       = lastFillMode;
                engine.State.FfpLighting    = lastLighting;
            }
        }
コード例 #3
0
        private void followAxis(Device device, float x0, float y0, float x1, float y1, int color, int stipplePattern)
        {
            Line line = GraphicViewManager.Instance.ResourceManager.SnapLines[1];

            line.Pattern = stipplePattern;
            float w = line.Width;

            line.Width = 2.0f;

            Cull cull        = device.RenderState.CullMode;
            bool alphaEnable = device.RenderState.AlphaBlendEnable;

            device.RenderState.CullMode         = Cull.None;
            device.RenderState.AlphaBlendEnable = true;
            device.RenderState.SourceBlend      = Blend.BothSourceAlpha;
            device.RenderState.DestinationBlend = Blend.DestinationColor;

            line.Begin();
            line.Draw(new Vector2[] { new Vector2(x0, y0), new Vector2(x1, y1) }, color);
            line.End();

            device.RenderState.AlphaBlendEnable = alphaEnable;
            device.RenderState.CullMode         = cull;

            line.Width = w;
        }
コード例 #4
0
ファイル: Compass3D.cs プロジェクト: zhongshuiyuan/WorldWind
        private void RenderCompass(DrawArgs drawArgs)
        {
            /*if (m_nVertices == null)
             *  CreateVertices(ref m_nVertices, 0.25f * (float)Math.PI, 0.75f * (float)Math.PI, samples, System.Drawing.Color.Red.ToArgb());
             * if (m_wVertices == null)
             *  CreateVertices(ref m_wVertices, 0.78f * (float)Math.PI, 1.22f * (float)Math.PI, samples, System.Drawing.Color.Gray.ToArgb());
             * if (m_sVertices == null)
             *  CreateVertices(ref m_sVertices, 1.25f * (float)Math.PI, 1.75f * (float)Math.PI, samples, System.Drawing.Color.Gray.ToArgb());
             * if (m_eVertices == null)
             *  CreateVertices(ref m_eVertices, 1.78f * (float)Math.PI, 2.22f * (float)Math.PI, samples, System.Drawing.Color.Gray.ToArgb());
             * if (m_arrowVertices == null)
             *  CreateArrows(ref m_arrowVertices);
             */

            if (m_compassVertices == null)
            {
                CreateBitmapVertices(drawArgs);
            }

            drawArgs.device.Transform.World  = Matrix.RotationZ((float)drawArgs.WorldCamera.Heading.Radians);
            drawArgs.device.Transform.World *= Matrix.RotationX(0.7f * (float)drawArgs.WorldCamera.Tilt.Radians);

            drawArgs.device.Transform.View = Matrix.LookAtLH(
                new Vector3(0, 0, -1.5f),
                new Vector3(0, 0, 0),
                new Vector3(0, 1, 0));

            bool lighting = drawArgs.device.RenderState.Lighting;

            drawArgs.device.RenderState.Lighting = false;
            drawArgs.device.Transform.Projection = Matrix.PerspectiveFovLH(0.45f * (float)Math.PI, (float)m_Size.Width / (float)m_Size.Height, 0.0f, 10.0f);
            Cull cull = drawArgs.device.RenderState.CullMode;

            drawArgs.device.RenderState.CullMode = Cull.None;

            /*drawArgs.device.VertexFormat = CustomVertex.PositionColored.Format;
             *
             * drawArgs.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, m_nVertices.Length - 2, m_nVertices);
             * drawArgs.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, m_wVertices.Length - 2, m_wVertices);
             * drawArgs.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, m_eVertices.Length - 2, m_eVertices);
             * drawArgs.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, m_sVertices.Length - 2, m_sVertices);
             * drawArgs.device.DrawUserPrimitives(PrimitiveType.TriangleList, m_arrowVertices.Length / 3, m_arrowVertices);
             */
            drawArgs.device.VertexFormat = CustomVertex.PositionColoredTextured.Format;
            drawArgs.device.TextureState[0].ColorOperation = TextureOperation.Modulate;
            drawArgs.device.TextureState[0].ColorArgument1 = TextureArgument.Diffuse;
            drawArgs.device.TextureState[0].ColorArgument2 = TextureArgument.TextureColor;
            drawArgs.device.TextureState[0].AlphaOperation = TextureOperation.Modulate;
            drawArgs.device.TextureState[0].AlphaArgument1 = TextureArgument.Diffuse;
            drawArgs.device.TextureState[0].AlphaArgument2 = TextureArgument.TextureColor;
            drawArgs.device.SetTexture(0, m_compassTexture);
            drawArgs.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, m_compassVertices.Length - 2, m_compassVertices);

            drawArgs.device.RenderState.Lighting = lighting;
            drawArgs.device.RenderState.CullMode = cull;
            drawArgs.device.Transform.World      = drawArgs.WorldCamera.WorldMatrix;
            drawArgs.device.Transform.View       = drawArgs.WorldCamera.ViewMatrix;
            drawArgs.device.Transform.Projection = drawArgs.WorldCamera.ProjectionMatrix;
        }
コード例 #5
0
ファイル: CanvasOptions.cs プロジェクト: xiangnanyue/DDD
 public CanvasOptions()
 {
     this._bWindowed  = true;
     this._shader     = ShadeMode.Flat;
     this._culling    = Cull.None;
     this._background = Color.Black;
     this._ambient    = Color.White;
     this._device     = DeviceType.Software;
 }
コード例 #6
0
ファイル: RenderObjectXX.cs プロジェクト: ymilv/SB3Utility
        private void DrawAnimationMeshContainer(AnimationMeshContainer meshContainer)
        {
            device.SetRenderState(RenderState.ZEnable, ZBufferType.UseZBuffer);
            device.SetRenderState(RenderState.Lighting, true);

            Cull culling = (Gui.Renderer.Culling) ? Cull.Counterclockwise : Cull.None;

            device.SetRenderState(RenderState.CullMode, culling);

            FillMode fill = (Gui.Renderer.Wireframe) ? FillMode.Wireframe : FillMode.Solid;

            device.SetRenderState(RenderState.FillMode, fill);

            int matIdx = meshContainer.MaterialIndex;

            device.Material = ((matIdx >= 0) && (matIdx < Materials.Length)) ? Materials[matIdx] : nullMaterial;

            int     texIdx = meshContainer.TextureIndex;
            Texture tex    = ((texIdx >= 0) && (texIdx < Textures.Length)) ? Textures[texIdx] : null;

            device.SetTexture(0, tex);

            meshContainer.MeshData.Mesh.DrawSubset(0);

            if (HighlightSubmesh.Contains(submeshNum))
            {
                device.SetRenderState(RenderState.ZEnable, ZBufferType.DontUseZBuffer);
                device.SetRenderState(RenderState.FillMode, FillMode.Wireframe);
                device.Material = highlightMaterial;
                device.SetTexture(0, null);
                meshContainer.MeshData.Mesh.DrawSubset(0);
            }

            if (Gui.Renderer.ShowNormals)
            {
                device.SetRenderState(RenderState.ZEnable, ZBufferType.UseZBuffer);
                device.SetRenderState(RenderState.Lighting, false);
                device.Material = nullMaterial;
                device.SetTexture(0, null);
                device.VertexFormat = PositionBlendWeightsIndexedColored.Format;
                device.DrawUserPrimitives(PrimitiveType.LineList, meshContainer.NormalLines.Length / 2, meshContainer.NormalLines);
            }

            if (Gui.Renderer.ShowBones && (meshContainer.BoneLines != null))
            {
                device.SetRenderState(RenderState.ZEnable, ZBufferType.DontUseZBuffer);
                device.SetRenderState(RenderState.VertexBlend, VertexBlend.Weights1);
                device.SetRenderState(RenderState.Lighting, false);
                device.Material = nullMaterial;
                device.SetTexture(0, null);
                device.VertexFormat = PositionBlendWeightIndexedColored.Format;
                device.DrawUserPrimitives(PrimitiveType.LineList, meshContainer.BoneLines.Length / 2, meshContainer.BoneLines);
            }
        }
コード例 #7
0
ファイル: CullModeMapper.cs プロジェクト: HaKDMoDz/Psy
 public static CullMode MapFrom(Cull cullMode)
 {
     switch (cullMode)
     {
         case Cull.None:
             return CullMode.None;
         case Cull.Counterclockwise:
             return CullMode.CCW;
         case Cull.Clockwise:
             return CullMode.CW;
         default:
             throw new ArgumentOutOfRangeException("cullMode");
     }
 }
コード例 #8
0
        private void drawPointSymbol(Device device, float x, float y, PointMagnetType type, byte alpha)
        {
            // Get color
            Color color;

            if (alpha == 255)
            {
                color = Color.Gold;
            }
            else
            {
                color = Color.FromArgb(alpha, Color.OrangeRed);
            }

            Cull cull        = device.RenderState.CullMode;
            bool alphaEnable = device.RenderState.AlphaBlendEnable;

            device.RenderState.CullMode         = Cull.None;
            device.RenderState.AlphaBlendEnable = true;
            device.RenderState.SourceBlend      = Blend.BothSourceAlpha;
            device.RenderState.DestinationBlend = Blend.DestinationColor;

            switch (type)
            {
            case PointMagnetType.EndPoint:
                drawEndPoint(device, x, y, color);
                break;

            case PointMagnetType.Intersection:
                drawIntersectPoint(device, x, y, color);
                break;

            case PointMagnetType.MidPoint:
                drawMidPoint(device, x, y, color);
                break;

            case PointMagnetType.Perpendicular:
                drawPerpPoint(device, x, y, color);
                break;

            case PointMagnetType.SimplePoint:
                drawSimplePoint(device, x, y, color);
                break;
            }

            device.RenderState.AlphaBlendEnable = alphaEnable;
            device.RenderState.CullMode         = cull;
        }
コード例 #9
0
        void RenderStaticPlaneShape(Mesh mesh)
        {
            Cull cullMode = device.GetRenderState <Cull>(RenderState.CullMode);

            device.SetRenderState(RenderState.CullMode, Cull.None);
            planeShader.Begin();
            Matrix matrix = device.GetTransform(TransformState.World);

            planeShader.SetValue("World", matrix);
            matrix = device.GetTransform(TransformState.View) * device.GetTransform(TransformState.Projection);
            planeShader.SetValue("ViewProjection", matrix);
            planeShader.BeginPass(0);
            mesh.DrawSubset(0);
            planeShader.EndPass();
            planeShader.End();
            device.SetRenderState(RenderState.CullMode, cullMode);
        }
コード例 #10
0
        public override void Paint(Device device)
        {
            Cull cull = device.RenderState.CullMode;

            //bool alphaEnable = device.RenderState.AlphaBlendEnable;

            device.RenderState.CullMode = Cull.None;
            //device.RenderState.AlphaBlendEnable = true;
            //    device.RenderState.SourceBlend = Blend.BothSourceAlpha;
            //    device.RenderState.DestinationBlend = Blend.DestinationColor;

            //device.SetStreamSource(0, m_roiVB, 0);
            device.VertexFormat = CustomVertex.TransformedColored.Format;
            //device.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);
            device.DrawUserPrimitives(PrimitiveType.LineList, 1, verts);
            //device.RenderState.AlphaBlendEnable = alphaEnable;
            device.RenderState.CullMode = cull;
        }
コード例 #11
0
        internal Cull GetCullMode(bool reverseCull)
        {
            Cull mode = (Cull)(((((_mode >> 6) & 3) ^ 2)) + 1);

            if (reverseCull)
            {
                switch (mode)
                {
                case Cull.Clockwise:
                    return(Cull.Counterclockwise);

                case Cull.Counterclockwise:
                    return(Cull.Clockwise);
                }
            }

            return(mode);
        }
コード例 #12
0
 public void Render(DrawArgs drawArgs)
 {
     try
     {
         if (this.m_Visible)
         {
             Cull cullMode = drawArgs.device.RenderState.CullMode;
             drawArgs.device.RenderState.ZBufferEnable = false;
             this.RenderCompass(drawArgs);
             drawArgs.device.Transform.World                = drawArgs.WorldCamera.WorldMatrix;
             drawArgs.device.RenderState.CullMode           = cullMode;
             drawArgs.device.TextureState[0].ColorOperation = TextureOperation.Disable;
             drawArgs.device.RenderState.ZBufferEnable      = true;
         }
     }
     catch (Exception exception)
     {
         Log.Write(exception);
     }
 }
コード例 #13
0
ファイル: RenderObjectXX.cs プロジェクト: ymilv/SB3Utility
        private void DrawMorphMeshContainer(MorphMeshContainer meshContainer)
        {
            device.SetRenderState(RenderState.ZEnable, ZBufferType.UseZBuffer);
            device.SetRenderState(RenderState.Lighting, true);

            Cull culling = (Gui.Renderer.Culling) ? Cull.Counterclockwise : Cull.None;

            device.SetRenderState(RenderState.CullMode, culling);

            FillMode fill = (Gui.Renderer.Wireframe) ? FillMode.Wireframe : FillMode.Solid;

            device.SetRenderState(RenderState.FillMode, fill);

            int matIdx = meshContainer.MaterialIndex;

            device.Material = ((matIdx >= 0) && (matIdx < Materials.Length)) ? Materials[matIdx] : nullMaterial;

            int     texIdx = meshContainer.TextureIndex;
            Texture tex    = ((texIdx >= 0) && (texIdx < Textures.Length)) ? Textures[texIdx] : null;

            device.SetTexture(0, tex);

            device.SetRenderState(RenderState.VertexBlend, VertexBlend.Tweening);
            device.SetRenderState(RenderState.TweenFactor, meshContainer.TweenFactor);

            device.VertexDeclaration = tweeningVertDec;
            device.Indices           = meshContainer.IndexBuffer;
            device.SetStreamSource(0, meshContainer.StartBuffer, 0, Marshal.SizeOf(typeof(TweeningMeshesVertexBufferFormat.Stream0)));
            device.SetStreamSource(1, meshContainer.EndBuffer, 0, Marshal.SizeOf(typeof(TweeningMeshesVertexBufferFormat.Stream1)));
            device.SetStreamSource(2, meshContainer.CommonBuffer, 0, Marshal.SizeOf(typeof(TweeningMeshesVertexBufferFormat.Stream2)));
            device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, meshContainer.VertexCount, 0, meshContainer.FaceCount);

            if (HighlightSubmesh.Contains(submeshNum))
            {
                device.SetRenderState(RenderState.ZEnable, ZBufferType.DontUseZBuffer);
                device.SetRenderState(RenderState.FillMode, FillMode.Wireframe);
                device.Material = highlightMaterial;
                device.SetTexture(0, null);
                device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, meshContainer.VertexCount, 0, meshContainer.FaceCount);
            }
        }
コード例 #14
0
        public void PaintPoint(Device device, Vector3 screenPosition)
        {
            Cull cull        = device.RenderState.CullMode;
            bool alphaEnable = device.RenderState.AlphaBlendEnable;

            device.RenderState.CullMode         = Cull.None;
            device.RenderState.AlphaBlendEnable = true;

            device.RenderState.SourceBlend      = Blend.BothSourceAlpha;
            device.RenderState.DestinationBlend = Blend.DestinationColor;

            pointVerts[0].X     = screenPosition.X;
            pointVerts[0].Y     = screenPosition.Y;
            pointVerts[0].Color = Color.Red.ToArgb();

            device.VertexFormat = CustomVertex.TransformedColored.Format;
            device.DrawUserPrimitives(PrimitiveType.PointList, 1, pointVerts);

            device.RenderState.AlphaBlendEnable = alphaEnable;
            device.RenderState.CullMode         = cull;
        }
コード例 #15
0
        private void RenderCompass(DrawArgs drawArgs)
        {
            if (this.m_nVertices == null)
            {
                this.CreateVertices(ref this.m_nVertices, 0.7853982f, 2.356194f, this.samples, this.northColor.ToArgb());
            }
            if (this.m_wVertices == null)
            {
                this.CreateVertices(ref this.m_wVertices, 2.450442f, 3.832743f, this.samples, this.normalColor.ToArgb());
            }
            if (this.m_sVertices == null)
            {
                this.CreateVertices(ref this.m_sVertices, 3.926991f, 5.497787f, this.samples, this.normalColor.ToArgb());
            }
            if (this.m_eVertices == null)
            {
                this.CreateVertices(ref this.m_eVertices, 5.592035f, 6.974336f, this.samples, this.normalColor.ToArgb());
            }
            if (this.m_arrowVertices == null)
            {
                this.CreateArrows(ref this.m_arrowVertices);
            }
            drawArgs.device.Transform.World      = Microsoft.DirectX.Matrix.RotationZ((float)-drawArgs.WorldCamera.Heading.Radians);
            drawArgs.device.Transform.View       = Microsoft.DirectX.Matrix.LookAtLH(new Microsoft.DirectX.Vector3(0f, 0f, 2f), new Microsoft.DirectX.Vector3(0f, 0f, 0f), new Microsoft.DirectX.Vector3(0f, 1f, 0f));
            drawArgs.device.Transform.Projection = Microsoft.DirectX.Matrix.PerspectiveFovLH(3.141593f, 1f, 0f, 10f);
            Cull cullMode = drawArgs.device.RenderState.CullMode;

            drawArgs.device.RenderState.CullMode = Cull.None;
            drawArgs.device.VertexFormat         = VertexFormats.Diffuse | VertexFormats.Position;
            drawArgs.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, this.m_nVertices.Length - 2, this.m_nVertices);
            drawArgs.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, this.m_wVertices.Length - 2, this.m_wVertices);
            drawArgs.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, this.m_eVertices.Length - 2, this.m_eVertices);
            drawArgs.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, this.m_sVertices.Length - 2, this.m_sVertices);
            drawArgs.device.DrawUserPrimitives(PrimitiveType.TriangleList, this.m_arrowVertices.Length / 3, this.m_arrowVertices);
            drawArgs.device.RenderState.CullMode = cullMode;
            drawArgs.device.Transform.World      = drawArgs.WorldCamera.WorldMatrix;
            drawArgs.device.Transform.View       = drawArgs.WorldCamera.ViewMatrix;
            drawArgs.device.Transform.Projection = drawArgs.WorldCamera.ProjectionMatrix;
        }
コード例 #16
0
        private void RemoveDeadEnemies(object sender, string e)
        {
            List <Enemy> ToRem = new List <Enemy>()
            {
            };

            foreach (Enemy EDeadCheck in this.CurrentEnemies)
            {
                if (EDeadCheck.Health <= 0)
                {
                    ToRem.Add(EDeadCheck);
                }
            }
            foreach (Enemy Cull in ToRem)
            {
                //LOG
                Log.UpdateLog($"{Cull.Name} was defeated");
                Cull.dead();
                this.CurrentEnemies.Remove(Cull);
                this.GameSectionMap[this.CurrentSection].Enemies--;
            }
        }
コード例 #17
0
        public void PaintLine(Device device, Vector3 iPos, Vector3 jPos)
        {
            Cull cull        = device.RenderState.CullMode;
            bool alphaEnable = device.RenderState.AlphaBlendEnable;

            device.RenderState.CullMode         = Cull.None;
            device.RenderState.AlphaBlendEnable = true;

            device.RenderState.SourceBlend      = Blend.BothSourceAlpha;
            device.RenderState.DestinationBlend = Blend.DestinationColor;

            Line l1 = GraphicViewManager.Instance.ResourceManager.SnapLines[2];
            Line l2 = GraphicViewManager.Instance.ResourceManager.SnapLines[1];

            View.GraphicView gv = View.GraphicViewManager.Instance.ActiveView;
            gv.Project(ref iPos);
            gv.Project(ref jPos);

            if (GraphicViewManager.Instance.Layout != GraphicViewManager.ViewportsLayout.OneView)
            {
                Viewport vp = device.Viewport;
                iPos.X -= vp.X;
                iPos.Y -= vp.Y;
                jPos.X -= vp.X;
                jPos.Y -= vp.Y;
            }

            l1.Begin();
            l1.Draw(new Vector2[] { new Vector2(iPos.X, iPos.Y), new Vector2(jPos.X, jPos.Y) }, Color.FromArgb(192, Color.SteelBlue));
            l1.End();

            l2.Begin();
            l2.Draw(new Vector2[] { new Vector2(iPos.X, iPos.Y), new Vector2(jPos.X, jPos.Y) }, Color.FromArgb(128, Color.White));
            l2.End();

            device.RenderState.AlphaBlendEnable = alphaEnable;
            device.RenderState.CullMode         = cull;
        }
コード例 #18
0
        public void Paint(Device device)
        {
            Cull      cull        = device.RenderState.CullMode;
            bool      alphaEnable = device.RenderState.AlphaBlendEnable;
            ShadeMode shadeMode   = device.RenderState.ShadeMode;

            device.RenderState.CullMode         = Cull.None;
            device.RenderState.AlphaBlendEnable = true;
            device.RenderState.ShadeMode        = ShadeMode.Flat;

            device.RenderState.SourceBlend      = Blend.BothSourceAlpha;
            device.RenderState.DestinationBlend = Blend.DestinationColor;

            device.VertexFormat = CustomVertex.TransformedColored.Format;
            device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, verts);

            device.RenderState.AlphaBlendEnable = alphaEnable;
            device.RenderState.CullMode         = cull;

            device.DrawUserPrimitives(PrimitiveType.LineStrip, 4, lineVertices);

            device.RenderState.ShadeMode = shadeMode;
        }
コード例 #19
0
ファイル: PolygonFeature.cs プロジェクト: sigswj/WorldWind
        public override void Render(DrawArgs drawArgs)
        {
            if (!Inited || m_vertices == null || drawArgs.WorldCamera.Altitude < m_minimumDisplayAltitude ||
                drawArgs.WorldCamera.Altitude > m_maximumDisplayAltitude)
            {
                return;
            }

            if (!drawArgs.WorldCamera.ViewFrustum.Intersects(BoundingBox))
            {
                return;
            }

            try {
                if (m_lineFeature != null)
                {
                    m_lineFeature.Render(drawArgs);
                }

                Cull currentCull = drawArgs.Device.RenderState.CullMode;
                drawArgs.Device.RenderState.CullMode = Cull.CounterClockwise;
                //	drawArgs.device.RenderState.ZBufferEnable = false;
                drawArgs.Device.Transform.World = Matrix.Translation((float)-drawArgs.WorldCamera.ReferenceCenter.X, (float)-drawArgs.WorldCamera.ReferenceCenter.Y, (float)-drawArgs.WorldCamera.ReferenceCenter.Z);
                if (m_vertices != null)
                {
                    drawArgs.Device.VertexFormat = CustomVertex.PositionNormalColored.Format;
                    drawArgs.Device.TextureState[0].ColorOperation = TextureOperation.Disable;
                    drawArgs.Device.DrawUserPrimitives(PrimitiveType.TriangleList, m_vertices.Length / 3, m_vertices);
                }
                //	drawArgs.device.RenderState.ZBufferEnable = true;
                drawArgs.Device.Transform.World      = drawArgs.WorldCamera.WorldMatrix;
                drawArgs.Device.RenderState.CullMode = currentCull;
            }
            catch (Exception ex) {
                Log.Write(ex);
            }
        }
コード例 #20
0
        public override void Paint(Device device)
        {
            int numPoints = points.Count;

            if (numPoints < 1)
            {
                return;                // Cannot paint polygon with less than 3 points (2 stored + mouse position)
            }
            device.VertexFormat = CustomVertex.TransformedColored.Format;

            recalcPoints();

            if (numPoints > 1)
            {
                Cull      cull        = device.RenderState.CullMode;
                bool      alphaEnable = device.RenderState.AlphaBlendEnable;
                ShadeMode shadeMode   = device.RenderState.ShadeMode;

                // Draw Triangles
                device.RenderState.CullMode         = Cull.None;
                device.RenderState.AlphaBlendEnable = true;
                device.RenderState.ShadeMode        = ShadeMode.Flat;

                device.RenderState.SourceBlend      = Blend.BothSourceAlpha;
                device.RenderState.DestinationBlend = Blend.DestinationColor;

                device.DrawUserPrimitives(PrimitiveType.TriangleFan, numPoints - 1, verts);

                device.RenderState.AlphaBlendEnable = alphaEnable;
                device.RenderState.CullMode         = cull;
                device.RenderState.ShadeMode        = shadeMode;
            }

            // Draw Polygon Contour
            device.DrawUserPrimitives(PrimitiveType.LineStrip, numPoints + ((numPoints > 1) ? 1 : 0), lineVertices);
        }
コード例 #21
0
        public override void OnRender(DrawArgs drawArgs)
        {
            if (!this.IsInitialized)
            {
                return;
            }
            Matrix4d proj  = drawArgs.WorldCamera.ProjectionMatrix;
            Cull     cull  = drawArgs.device.RenderState.CullMode;
            bool     iszub = drawArgs.device.RenderState.ZBufferEnable;

            float  aspectRatio          = (float)drawArgs.WorldCamera.Viewport.Width / drawArgs.WorldCamera.Viewport.Height;
            float  zNear                = (float)drawArgs.WorldCamera.Altitude * 0.1f;
            double distToCenterOfPlanet = (drawArgs.WorldCamera.Altitude + World.EquatorialRadius);
            double tangentalDistance    = Math.Sqrt(distToCenterOfPlanet * distToCenterOfPlanet - World.EquatorialRadius * World.EquatorialRadius);
            double amosphereThickness   = Math.Sqrt(OutterRadius * OutterRadius + World.EquatorialRadius * World.EquatorialRadius);

            drawArgs.device.Transform.Projection = Matrix.PerspectiveFovRH((float)drawArgs.WorldCamera.Fov.Radians, aspectRatio, zNear, (float)(tangentalDistance + amosphereThickness));

            this.Engine.RenderFrame(drawArgs);

            drawArgs.device.RenderState.CullMode      = cull;
            drawArgs.device.RenderState.ZBufferEnable = iszub;
            drawArgs.device.Transform.Projection      = ConvertDX.FromMatrix4d(proj);
        }
コード例 #22
0
ファイル: CtObjectGL.cs プロジェクト: Zulkir/Beholder
 public static bool CullEnable(Cull bCull)
 {
     switch (bCull)
     {
         case Cull.None: return false;
         case Cull.Frontface:
         case Cull.Backface: return true;
         default: throw new ArgumentOutOfRangeException("bCull");
     }
 }
コード例 #23
0
ファイル: CtObjectGL.cs プロジェクト: Zulkir/Beholder
 public static CullFaceMode CullFace(Cull bCull)
 {
     switch (bCull)
     {
         // Swap is intentional: we render everything upside-down in the FBO
         case Cull.None: return CullFaceMode.FrontAndBack;
         case Cull.Frontface: return CullFaceMode.Back;
         case Cull.Backface: return CullFaceMode.Front;
         default: throw new ArgumentOutOfRangeException("bCull");
     }
 }
コード例 #24
0
        public void RenderSoftBody(SoftBody softBody)
        {
            Cull cullMode = device.GetRenderState <Cull>(RenderState.CullMode);

            device.SetRenderState(RenderState.CullMode, Cull.None);

            AlignedFaceArray faces = softBody.Faces;
            int faceCount          = faces.Count;

            if (faceCount > 0)
            {
                PositionedNormal[] vectors = new PositionedNormal[faceCount * 6];
                int v = 0;

                int i;
                for (i = 0; i < faceCount; i++)
                {
                    NodePtrArray nodes = faces[i].N;
                    Node         n0    = nodes[0];
                    Node         n1    = nodes[1];
                    Node         n2    = nodes[2];
                    n0.GetX(out vectors[v].Position);
                    n0.GetNormal(out vectors[v].Normal);
                    n1.GetX(out vectors[v + 1].Position);
                    n1.GetNormal(out vectors[v + 1].Normal);
                    n2.GetX(out vectors[v + 2].Position);
                    n2.GetNormal(out vectors[v + 2].Normal);
                    v += 3;
                }

                device.VertexFormat = VertexFormat.PositionNormal;
                device.DrawUserPrimitives(PrimitiveType.TriangleList, faces.Count, vectors);
            }
            else
            {
                AlignedTetraArray tetras = softBody.Tetras;
                int tetraCount           = tetras.Count;

                if (tetraCount > 0)
                {
                    PositionedNormal[] vectors = new PositionedNormal[tetraCount * 12];
                    int v = 0;

                    for (int i = 0; i < tetraCount; i++)
                    {
                        NodePtrArray        nodes = tetras[i].Nodes;
                        BulletSharp.Vector3 v0    = nodes[0].X;
                        BulletSharp.Vector3 v1    = nodes[1].X;
                        BulletSharp.Vector3 v2    = nodes[2].X;
                        BulletSharp.Vector3 v3    = nodes[3].X;
                        BulletSharp.Vector3 v10   = v1 - v0;
                        BulletSharp.Vector3 v02   = v0 - v2;

                        BulletSharp.Vector3 normal = BulletSharp.Vector3.Cross(v10, v02);
                        normal.Normalize();
                        vectors[v].Position     = v0;
                        vectors[v].Normal       = normal;
                        vectors[v + 1].Position = v1;
                        vectors[v + 1].Normal   = normal;
                        vectors[v + 2].Position = v2;
                        vectors[v + 2].Normal   = normal;

                        normal = BulletSharp.Vector3.Cross(v10, v3 - v0);
                        normal.Normalize();
                        vectors[v + 3].Position = v0;
                        vectors[v + 3].Normal   = normal;
                        vectors[v + 4].Position = v1;
                        vectors[v + 4].Normal   = normal;
                        vectors[v + 5].Position = v3;
                        vectors[v + 5].Normal   = normal;

                        normal = BulletSharp.Vector3.Cross(v2 - v1, v3 - v1);
                        normal.Normalize();
                        vectors[v + 6].Position = v1;
                        vectors[v + 6].Normal   = normal;
                        vectors[v + 7].Position = v2;
                        vectors[v + 7].Normal   = normal;
                        vectors[v + 8].Position = v3;
                        vectors[v + 8].Normal   = normal;

                        normal = BulletSharp.Vector3.Cross(v02, v3 - v2);
                        normal.Normalize();
                        vectors[v + 9].Position  = v2;
                        vectors[v + 9].Normal    = normal;
                        vectors[v + 10].Position = v0;
                        vectors[v + 10].Normal   = normal;
                        vectors[v + 11].Position = v3;
                        vectors[v + 11].Normal   = normal;
                        v += 12;
                    }
                    device.VertexFormat = VertexFormat.PositionNormal;
                    device.DrawUserPrimitives(PrimitiveType.TriangleList, tetraCount * 4, vectors);
                }
                else if (softBody.Links.Count > 0)
                {
                    AlignedLinkArray links = softBody.Links;
                    int linkCount          = links.Count;
                    int linkColor          = System.Drawing.Color.Black.ToArgb();

                    device.VertexFormat = VertexFormat.Position | VertexFormat.Diffuse;

                    PositionColored[] linkArray = new PositionColored[linkCount * 2];

                    for (int i = 0; i < linkCount; i++)
                    {
                        Link link = links[i];
                        linkArray[i * 2].Position     = link.Nodes[0].X;
                        linkArray[i * 2].Color        = linkColor;
                        linkArray[i * 2 + 1].Position = link.Nodes[1].X;
                        linkArray[i * 2 + 1].Color    = linkColor;
                    }
                    device.DrawUserPrimitives(PrimitiveType.LineList, links.Count, linkArray);
                }
            }

            device.SetRenderState(RenderState.CullMode, cullMode);
        }
コード例 #25
0
            internal void LoadTextures( Device device )
            {
                string path = GetTextureFileName( baseTextureName );
                if( path != null )
                {
                    try
                    {
                        ImageInformation info = new ImageInformation();

                        diffuse = TextureLoader.FromFile( device, path, 0, 0, 0, Usage.None,
                            Format.Unknown, Pool.Managed, Filter.Triangle, Filter.Triangle, 0, ref info );

                        switch( info.Format )
                        {
                        case Format.A8R8G8B8:
                        case Format.A8B8G8R8:
                            alphaTest = Compare.Greater;
                            alphaRef = 127;
                            cullMode = Cull.None;
                            break;
                        }
                    }
                    catch( IOException )
                    {
                        return;
                    }
                }

                string normPath = GetTextureFileName( Path.ChangeExtension( baseTextureName, null ) + "_n.tga" );
                if( normPath != null )
                {
                    try
                    {
                        normal = TextureLoader.FromFile( device, normPath, 0, 0, 0, Usage.None,
                            Format.A8B8G8R8, Pool.Managed, Filter.Triangle, Filter.None, 0 );

                        Helpers.GenerateNormalMapMips( normal );
                    }
                    catch( IOException )
                    {
                    }
                }
            }
コード例 #26
0
 static extern void RenderDevice_SetCullMode(IntPtr handle, Cull mode);
 public static RenderStateDescriptor Cull(Cull value) => new RenderStateDescriptor
 {
     type = RenderStateType.Cull, value = $"Cull {value}"
 };
コード例 #28
0
ファイル: CanvasOptions.cs プロジェクト: wshanshan/DDD
        public CanvasOptions()
        {
            this._bWindowed = true;
            this._shader = ShadeMode.Flat;
            this._culling = Cull.None;
            this._background = Color.Black;
            this._ambient = Color.White;
            this._device = DeviceType.Software;

        }
コード例 #29
0
        public override void Render(DrawArgs drawArgs)
        {
            if (!isInitialized || drawArgs.WorldCamera.Altitude < m_minimumDisplayAltitude || drawArgs.WorldCamera.Altitude > m_maximumDisplayAltitude)
            {
                return;
            }

            try
            {
                if (m_lineString != null)
                {
                    return;
                }

                Cull currentCull = drawArgs.device.RenderState.CullMode;
                drawArgs.device.RenderState.CullMode = Cull.None;

                Vector3 rc = new Vector3(
                    (float)drawArgs.WorldCamera.ReferenceCenter.X,
                    (float)drawArgs.WorldCamera.ReferenceCenter.Y,
                    (float)drawArgs.WorldCamera.ReferenceCenter.Z
                    );

                drawArgs.device.Transform.World = Matrix.Translation(
                    (float)-drawArgs.WorldCamera.ReferenceCenter.X,
                    (float)-drawArgs.WorldCamera.ReferenceCenter.Y,
                    (float)-drawArgs.WorldCamera.ReferenceCenter.Z
                    );

                if (m_wallVertices != null)
                {
                    drawArgs.device.RenderState.ZBufferEnable = true;

                    if (m_texture != null && !m_texture.Disposed)
                    {
                        drawArgs.device.SetTexture(0, m_texture);
                        drawArgs.device.TextureState[0].AlphaOperation = TextureOperation.Modulate;
                        drawArgs.device.TextureState[0].ColorOperation = TextureOperation.Add;
                        drawArgs.device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;
                    }
                    else
                    {
                        drawArgs.device.TextureState[0].ColorOperation = TextureOperation.Disable;
                    }

                    drawArgs.device.VertexFormat = CustomVertex.PositionColoredTextured.Format;

                    drawArgs.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, m_wallVertices.Length - 2, m_wallVertices);

                    if (m_outline)
                    {
                        drawArgs.device.TextureState[0].ColorOperation = TextureOperation.Disable;
                        drawArgs.device.VertexFormat = CustomVertex.PositionColored.Format;
                        drawArgs.device.DrawUserPrimitives(PrimitiveType.LineStrip, m_topVertices.Length - 1, m_topVertices);

                        if (m_bottomVertices != null)
                        {
                            drawArgs.device.DrawUserPrimitives(PrimitiveType.LineStrip, m_bottomVertices.Length - 1, m_bottomVertices);
                        }

                        if (m_sideVertices != null)
                        {
                            drawArgs.device.DrawUserPrimitives(PrimitiveType.LineList, m_sideVertices.Length / 2, m_sideVertices);
                        }
                    }
                }
                else
                {
                    drawArgs.device.TextureState[0].ColorOperation = TextureOperation.Disable;
                    drawArgs.device.VertexFormat = CustomVertex.PositionColored.Format;
                    drawArgs.device.DrawUserPrimitives(PrimitiveType.LineStrip, m_topVertices.Length - 1, m_topVertices);
                }

                drawArgs.device.Transform.World      = drawArgs.WorldCamera.WorldMatrix;
                drawArgs.device.RenderState.CullMode = currentCull;
            }
            catch            //(Exception ex)
            {
                //Utility.Log.Write(ex);
            }
        }
コード例 #30
0
 /// <summary>
 /// Creates the viewport interface.
 /// </summary>
 /// <param name="owner">The form the viewport interface is contained within.</param>
 public void CreateViewport( Form owner )
 {
     _owner = owner;
     _fillMode = FillMode.WireFrame;
     _cullMode = Cull.CounterClockwise;
 }
コード例 #31
0
ファイル: LineFeature.cs プロジェクト: qaz734913414/MFW3DNet
        public override void Render(DrawArgs drawArgs)
        {
            using (new DirectXProfilerEvent("LineFeature::Render"))
            {
                if (!isInitialized || drawArgs.WorldCamera.Altitude < m_minimumDisplayAltitude || drawArgs.WorldCamera.Altitude > m_maximumDisplayAltitude)
                {
                    return;
                }

                try
                {
                    if (m_lineString != null)
                    {
                        return;
                    }

                    Cull currentCull = drawArgs.device.RenderState.CullMode;
                    drawArgs.device.RenderState.CullMode = Cull.None;

                    bool currentAlpha = drawArgs.device.RenderState.AlphaBlendEnable;
                    drawArgs.device.RenderState.AlphaBlendEnable = true;

                    drawArgs.device.Transform.World = Matrix.Translation(
                        (float)-drawArgs.WorldCamera.ReferenceCenter.X + m_localOrigin.X,
                        (float)-drawArgs.WorldCamera.ReferenceCenter.Y + m_localOrigin.Y,
                        (float)-drawArgs.WorldCamera.ReferenceCenter.Z + m_localOrigin.Z
                        );

                    //Fix for sunshading screwing with everything
                    bool lighting = drawArgs.device.RenderState.Lighting;
                    drawArgs.device.RenderState.Lighting = m_enableLighting;

                    if (m_wallVertices != null)
                    {
                        drawArgs.device.RenderState.ZBufferEnable = true;

                        if (m_texture != null && !m_texture.Disposed)
                        {
                            drawArgs.device.SetTexture(0, m_texture);
                            drawArgs.device.TextureState[0].AlphaOperation = TextureOperation.Modulate;
                            drawArgs.device.TextureState[0].ColorOperation = TextureOperation.Add;
                            drawArgs.device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;
                        }
                        else
                        {
                            // drawArgs.device.TextureState[0].ColorOperation = TextureOperation.Disable;

                            drawArgs.device.TextureState[0].ColorArgument1 = TextureArgument.Diffuse;
                            drawArgs.device.TextureState[0].ColorOperation = TextureOperation.SelectArg1;

                            drawArgs.device.TextureState[0].AlphaArgument1 = TextureArgument.Diffuse;
                            drawArgs.device.TextureState[0].AlphaOperation = TextureOperation.SelectArg1;
                        }

                        Material mat = new Material();
                        mat.Diffuse = mat.Ambient = finalPolygonColor; // this.m_polygonColor;

                        drawArgs.device.Material = mat;

                        if (m_texture != null && !m_texture.Disposed)
                        {
                            drawArgs.device.VertexFormat = CustomVertex.PositionNormalTextured.Format;
                            drawArgs.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, m_wallVertices.Length - 2, m_wallVertices);
                        }
                        else
                        {
                            drawArgs.device.VertexFormat = CustomVertex.PositionColored.Format;
                            drawArgs.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, m_colorWallVertices.Length - 2, m_colorWallVertices);
                        }

                        if (m_outline)
                        {
                            // drawArgs.device.TextureState[0].ColorOperation = TextureOperation.Disable;

                            drawArgs.device.TextureState[0].ColorArgument1 = TextureArgument.Diffuse;
                            drawArgs.device.TextureState[0].ColorOperation = TextureOperation.SelectArg1;

                            drawArgs.device.TextureState[0].AlphaArgument1 = TextureArgument.Diffuse;
                            drawArgs.device.TextureState[0].AlphaOperation = TextureOperation.SelectArg1;

                            drawArgs.device.VertexFormat = CustomVertex.PositionColored.Format;
                            drawArgs.device.DrawUserPrimitives(PrimitiveType.LineStrip, m_topVertices.Length - 1, m_topVertices);

                            if (m_bottomVertices != null)
                            {
                                drawArgs.device.DrawUserPrimitives(PrimitiveType.LineStrip, m_bottomVertices.Length - 1, m_bottomVertices);
                            }

                            if (m_sideVertices != null)
                            {
                                drawArgs.device.DrawUserPrimitives(PrimitiveType.LineList, m_sideVertices.Length / 2, m_sideVertices);
                            }
                        }
                    }
                    else
                    {
                        // drawArgs.device.TextureState[0].ColorOperation = TextureOperation.Disable;
                        drawArgs.device.TextureState[0].ColorArgument1 = TextureArgument.Diffuse;
                        drawArgs.device.TextureState[0].ColorOperation = TextureOperation.SelectArg1;

                        drawArgs.device.TextureState[0].AlphaArgument1 = TextureArgument.Diffuse;
                        drawArgs.device.TextureState[0].AlphaOperation = TextureOperation.SelectArg1;

                        drawArgs.device.VertexFormat = CustomVertex.PositionColored.Format;
                        drawArgs.device.DrawUserPrimitives(PrimitiveType.LineStrip, m_topVertices.Length - 1, m_topVertices);
                    }

                    drawArgs.device.Transform.World              = drawArgs.WorldCamera.WorldMatrix;
                    drawArgs.device.RenderState.CullMode         = currentCull;
                    drawArgs.device.RenderState.AlphaBlendEnable = currentAlpha;


                    //put lighting back like it was (see above fix)
                    drawArgs.device.RenderState.Lighting = lighting;
                }
                catch//(Exception ex)
                {
                    //Utility.Log.Write(ex);
                }
            }
        }
コード例 #32
0
ファイル: GPU.cs プロジェクト: vetuomia/rocket
        /// <summary>
        /// Configures the rendering pipeline.
        /// </summary>
        /// <param name="cull">The polygon culling options.</param>
        /// <param name="depth">The depth processing options.</param>
        /// <param name="stencil">The stenciling mode.</param>
        /// <param name="blend">The blending mode.</param>
        public static void Use(Cull cull, Depth depth, Stencil stencil, Blend blend)
        {
            if (gl.HasPendingPops)
            {
                throw new InvalidOperationException("Cannot change GPU state while the attribute stack is active.");
            }

            if (currentCull != cull)
            {
                if (cull == Cull.None)
                {
                    gl.Disable(GL.CULL_FACE);
                }
                else
                {
                    gl.Enable(GL.CULL_FACE);

                    switch (cull)
                    {
                        case Cull.Front:
                            gl.CullFace(GL.FRONT);
                            break;

                        case Cull.Back:
                            gl.CullFace(GL.BACK);
                            break;

                        case Cull.Front | Cull.Back:
                            gl.CullFace(GL.FRONT_AND_BACK);
                            break;
                    }
                }

                currentCull = cull;
            }

            if (currentDepth != depth)
            {
                if (depth == Depth.None)
                {
                    gl.Disable(GL.DEPTH_TEST);
                }
                else
                {
                    gl.Enable(GL.DEPTH_TEST);

                    if ((depth & Depth.Test) == Depth.Test)
                    {
                        if ((depth & Depth.TestReversed) == Depth.TestReversed)
                        {
                            gl.DepthFunc(GL.GREATER);
                        }
                        else
                        {
                            gl.DepthFunc(GL.LEQUAL);
                        }
                    }
                    else
                    {
                        gl.DepthFunc(GL.ALWAYS);
                    }

                    if ((depth & Depth.Write) == Depth.Write)
                    {
                        gl.DepthMask(true);
                    }
                    else
                    {
                        gl.DepthMask(false);
                    }

                    if ((depth & Depth.Clamp) == Depth.Clamp)
                    {
                        gl.Enable(GL.DEPTH_CLAMP);
                    }
                    else
                    {
                        gl.Disable(GL.DEPTH_CLAMP);
                    }

                    if ((depth & Depth.Offset) == Depth.Offset)
                    {
                        gl.Enable(GL.POLYGON_OFFSET_FILL);
                        gl.PolygonOffset(0.02f, 0);
                    }
                    else
                    {
                        gl.Disable(GL.POLYGON_OFFSET_FILL);
                    }
                }

                currentDepth = depth;
            }

            if (currentStencil != stencil)
            {
                if (stencil == Stencil.None)
                {
                    gl.Disable(GL.STENCIL_TEST);
                }
                else
                {
                    gl.Enable(GL.STENCIL_TEST);

                    switch (stencil)
                    {
                        case Stencil.Shadows:
                            gl.StencilFunc(GL.FRONT_AND_BACK, GL.ALWAYS, 0, 0xFF);
                            gl.StencilOp(GL.FRONT, GL.KEEP, GL.INCR_WRAP, GL.KEEP); // <- increase when going in
                            gl.StencilOp(GL.BACK, GL.KEEP, GL.DECR_WRAP, GL.KEEP);  // <- decrease when going out
                            break;

                        case Stencil.Light:
                            gl.StencilFunc(GL.FRONT_AND_BACK, GL.EQUAL, 0, 0xFF);   // <- if (stencil != 0) { in shadow }
                            gl.StencilOp(GL.FRONT_AND_BACK, GL.KEEP, GL.KEEP, GL.KEEP);
                            break;
                    }
                }

                currentStencil = stencil;
            }

            if (currentBlend != blend)
            {
                if (blend == Blend.None)
                {
                    gl.Disable(GL.BLEND);
                }
                else
                {
                    gl.Enable(GL.BLEND);

                    switch (blend)
                    {
                        case Blend.Additive:
                            gl.BlendFunc(GL.ONE, GL.ONE, GL.ONE, GL.ONE);
                            break;

                        case Blend.Alpha:
                            gl.BlendFunc(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA, GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA);
                            break;
                    }
                }

                currentBlend = blend;
            }
        }
コード例 #33
0
ファイル: Form.cs プロジェクト: qaz734913414/MFW3DNet
 public virtual void Render2(DrawArgs drawArgs)
 {
     if (this.m_Visible)
     {
         if ((this.dblLatitude != double.MinValue) && ((drawArgs.WorldCamera.Altitude > 100.0) || (World.Settings.VerticalExaggeration >= 1f)))
         {
             try
             {
                 drawArgs.device.RenderState.ZBufferEnable = true;
                 Cull cullMode = drawArgs.device.RenderState.CullMode;
                 drawArgs.device.RenderState.CullMode           = Cull.None;
                 drawArgs.device.VertexFormat                   = VertexFormats.Diffuse | VertexFormats.Position;
                 drawArgs.device.TextureState[0].ColorOperation = TextureOperation.Disable;
                 Microsoft.DirectX.Matrix matrix = Microsoft.DirectX.Matrix.Translation((float)-drawArgs.WorldCamera.ReferenceCenter.X, (float)-drawArgs.WorldCamera.ReferenceCenter.Y, (float)-drawArgs.WorldCamera.ReferenceCenter.Z);
                 drawArgs.device.Transform.World = matrix;
                 Microsoft.DirectX.Vector3 vector  = MathEngine.SphericalToCartesian((double)this.dblLatitude, (double)this.dblLongitude, (this.ww.CurrentWorld.EquatorialRadius + (this.ww.CurrentWorld.TerrainAccessor.GetElevationAt((double)this.dblLatitude, (double)this.dblLongitude, 100.0) * World.Settings.VerticalExaggeration)) + this.dblAltitude);
                 Microsoft.DirectX.Vector3 vector2 = new Microsoft.DirectX.Vector3();
                 Microsoft.DirectX.Vector3 vector3 = new Microsoft.DirectX.Vector3();
                 vector2.X = this.m_Location.X + (((float)this.m_Size.Width) / 3f);
                 vector2.Y = (this.m_Location.Y + this.m_Size.Height) - 5;
                 vector2.Z = 0f;
                 vector2.Unproject(drawArgs.device.Viewport, drawArgs.WorldCamera.ProjectionMatrix, drawArgs.WorldCamera.ViewMatrix, drawArgs.device.Transform.World);
                 vector3.X = this.m_Location.X + (2f * (((float)this.m_Size.Width) / 3f));
                 vector3.Y = (this.m_Location.Y + this.m_Size.Height) - 5;
                 vector3.Z = 0f;
                 vector3.Unproject(drawArgs.device.Viewport, drawArgs.WorldCamera.ProjectionMatrix, drawArgs.WorldCamera.ViewMatrix, drawArgs.device.Transform.World);
                 CustomVertex.PositionColored[] vertexStreamZeroData = new CustomVertex.PositionColored[3];
                 vertexStreamZeroData[0].X     = vector.X;
                 vertexStreamZeroData[0].Y     = vector.Y;
                 vertexStreamZeroData[0].Z     = vector.Z;
                 vertexStreamZeroData[0].Color = this.m_BackgroundColor.ToArgb();
                 vertexStreamZeroData[1].X     = vector2.X;
                 vertexStreamZeroData[1].Y     = vector2.Y;
                 vertexStreamZeroData[1].Z     = vector2.Z;
                 vertexStreamZeroData[1].Color = this.m_BackgroundColor.ToArgb();
                 vertexStreamZeroData[2].X     = vector3.X;
                 vertexStreamZeroData[2].Y     = vector3.Y;
                 vertexStreamZeroData[2].Z     = vector3.Z;
                 vertexStreamZeroData[2].Color = this.m_BackgroundColor.ToArgb();
                 drawArgs.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, vertexStreamZeroData.Length - 2, vertexStreamZeroData);
                 drawArgs.device.Transform.World                = drawArgs.WorldCamera.WorldMatrix;
                 drawArgs.device.RenderState.CullMode           = cullMode;
                 drawArgs.device.TextureState[0].ColorOperation = TextureOperation.Disable;
             }
             catch (Exception exception)
             {
                 MessageBox.Show(exception.Message);
             }
         }
         if (this.m_TextFont == null)
         {
             System.Drawing.Font font = new System.Drawing.Font("Arial", 12f, FontStyle.Italic | FontStyle.Bold);
             this.m_TextFont = new Microsoft.DirectX.Direct3D.Font(drawArgs.device, font);
         }
         if (this.m_WorldWindDingsFont == null)
         {
             AddFontResource(Path.Combine(Application.StartupPath, "World Wind Dings 1.04.ttf"));
             PrivateFontCollection fonts = new PrivateFontCollection();
             fonts.AddFontFile(Path.Combine(Application.StartupPath, "World Wind Dings 1.04.ttf"));
             System.Drawing.Font font2 = new System.Drawing.Font(fonts.Families[0], 12f);
             this.m_WorldWindDingsFont = new Microsoft.DirectX.Direct3D.Font(drawArgs.device, font2);
         }
         if (this.m_Resizeble)
         {
             if (((DrawArgs.LastMousePosition.X > (this.AbsoluteLocation.X - this.resizeBuffer)) && (DrawArgs.LastMousePosition.X < (this.AbsoluteLocation.X + this.resizeBuffer))) && ((DrawArgs.LastMousePosition.Y > (this.AbsoluteLocation.Y - this.resizeBuffer)) && (DrawArgs.LastMousePosition.Y < (this.AbsoluteLocation.Y + this.resizeBuffer))))
             {
                 DrawArgs.MouseCursor = CursorType.SizeNWSE;
             }
             else if (((DrawArgs.LastMousePosition.X > ((this.AbsoluteLocation.X - this.resizeBuffer) + this.ClientSize.Width)) && (DrawArgs.LastMousePosition.X < ((this.AbsoluteLocation.X + this.resizeBuffer) + this.ClientSize.Width))) && ((DrawArgs.LastMousePosition.Y > (this.AbsoluteLocation.Y - this.resizeBuffer)) && (DrawArgs.LastMousePosition.Y < (this.AbsoluteLocation.Y + this.resizeBuffer))))
             {
                 DrawArgs.MouseCursor = CursorType.SizeNESW;
             }
             else if (((DrawArgs.LastMousePosition.X > (this.AbsoluteLocation.X - this.resizeBuffer)) && (DrawArgs.LastMousePosition.X < (this.AbsoluteLocation.X + this.resizeBuffer))) && ((DrawArgs.LastMousePosition.Y > ((this.AbsoluteLocation.Y - this.resizeBuffer) + this.ClientSize.Height)) && (DrawArgs.LastMousePosition.Y < ((this.AbsoluteLocation.Y + this.resizeBuffer) + this.ClientSize.Height))))
             {
                 DrawArgs.MouseCursor = CursorType.SizeNESW;
             }
             else if (((DrawArgs.LastMousePosition.X > ((this.AbsoluteLocation.X - this.resizeBuffer) + this.ClientSize.Width)) && (DrawArgs.LastMousePosition.X < ((this.AbsoluteLocation.X + this.resizeBuffer) + this.ClientSize.Width))) && ((DrawArgs.LastMousePosition.Y > ((this.AbsoluteLocation.Y - this.resizeBuffer) + this.ClientSize.Height)) && (DrawArgs.LastMousePosition.Y < ((this.AbsoluteLocation.Y + this.resizeBuffer) + this.ClientSize.Height))))
             {
                 DrawArgs.MouseCursor = CursorType.SizeNWSE;
             }
             else if ((((DrawArgs.LastMousePosition.X > (this.AbsoluteLocation.X - this.resizeBuffer)) && (DrawArgs.LastMousePosition.X < (this.AbsoluteLocation.X + this.resizeBuffer))) && ((DrawArgs.LastMousePosition.Y > (this.AbsoluteLocation.Y - this.resizeBuffer)) && (DrawArgs.LastMousePosition.Y < ((this.AbsoluteLocation.Y + this.resizeBuffer) + this.ClientSize.Height)))) || (((DrawArgs.LastMousePosition.X > ((this.AbsoluteLocation.X - this.resizeBuffer) + this.ClientSize.Width)) && (DrawArgs.LastMousePosition.X < ((this.AbsoluteLocation.X + this.resizeBuffer) + this.ClientSize.Width))) && ((DrawArgs.LastMousePosition.Y > (this.AbsoluteLocation.Y - this.resizeBuffer)) && (DrawArgs.LastMousePosition.Y < ((this.AbsoluteLocation.Y + this.resizeBuffer) + this.ClientSize.Height)))))
             {
                 DrawArgs.MouseCursor = CursorType.SizeWE;
             }
             else if ((((DrawArgs.LastMousePosition.X > (this.AbsoluteLocation.X - this.resizeBuffer)) && (DrawArgs.LastMousePosition.X < ((this.AbsoluteLocation.X + this.resizeBuffer) + this.ClientSize.Width))) && ((DrawArgs.LastMousePosition.Y > (this.AbsoluteLocation.Y - this.resizeBuffer)) && (DrawArgs.LastMousePosition.Y < (this.AbsoluteLocation.Y + this.resizeBuffer)))) || (((DrawArgs.LastMousePosition.X > (this.AbsoluteLocation.X - this.resizeBuffer)) && (DrawArgs.LastMousePosition.X < ((this.AbsoluteLocation.X + this.resizeBuffer) + this.ClientSize.Width))) && ((DrawArgs.LastMousePosition.Y > ((this.AbsoluteLocation.Y - this.resizeBuffer) + this.ClientSize.Height)) && (DrawArgs.LastMousePosition.Y < ((this.AbsoluteLocation.Y + this.resizeBuffer) + this.ClientSize.Height)))))
             {
                 DrawArgs.MouseCursor = CursorType.SizeNS;
             }
         }
         if (this.ClientSize.Height > drawArgs.parentControl.Height)
         {
             this.ClientSize = new Size(this.ClientSize.Width, drawArgs.parentControl.Height);
         }
         if (this.ClientSize.Width > drawArgs.parentControl.Width)
         {
             this.ClientSize = new Size(drawArgs.parentControl.Width, this.ClientSize.Height);
         }
         if (!this.m_AutoHideHeader || (((DrawArgs.LastMousePosition.X >= this.m_Location.X) && (DrawArgs.LastMousePosition.X <= (this.m_Location.X + this.m_Size.Width))) && ((DrawArgs.LastMousePosition.Y >= this.m_Location.Y) && (DrawArgs.LastMousePosition.Y <= (this.m_Location.Y + this.m_Size.Height)))))
         {
             Utilities.DrawBox(this.m_Location.X, this.m_Location.Y, this.m_Size.Width, this.m_HeaderHeight, 0f, this.m_HeaderColor.ToArgb(), drawArgs.device);
             this.m_WorldWindDingsFont.DrawText(null, "E", new Rectangle((this.m_Location.X + this.m_Size.Width) - 15, this.m_Location.Y + 2, this.m_Size.Width, this.m_Size.Height), DrawTextFormat.NoClip, Color.White.ToArgb());
             this.m_OutlineVertsHeader[0].X = this.AbsoluteLocation.X;
             this.m_OutlineVertsHeader[0].Y = this.AbsoluteLocation.Y + this.m_HeaderHeight;
             this.m_OutlineVertsHeader[1].X = this.AbsoluteLocation.X;
             this.m_OutlineVertsHeader[1].Y = this.AbsoluteLocation.Y;
             this.m_OutlineVertsHeader[2].X = this.AbsoluteLocation.X + this.ClientSize.Width;
             this.m_OutlineVertsHeader[2].Y = this.AbsoluteLocation.Y;
             this.m_OutlineVertsHeader[3].X = this.AbsoluteLocation.X + this.ClientSize.Width;
             this.m_OutlineVertsHeader[3].Y = this.AbsoluteLocation.Y + this.m_HeaderHeight;
             if (!this.m_HideBorder)
             {
                 Utilities.DrawLine(this.m_OutlineVertsHeader, this.m_BorderColor.ToArgb(), drawArgs.device);
             }
         }
         Utilities.DrawBox(this.m_Location.X, this.m_Location.Y + this.m_HeaderHeight, this.m_Size.Width, this.m_Size.Height - this.m_HeaderHeight, 0f, this.m_BackgroundColor.ToArgb(), drawArgs.device);
         for (int i = this.m_ChildWidgets.Count - 1; i >= 0; i--)
         {
             IWidget widget = this.m_ChildWidgets[i];
             if (widget != null)
             {
                 if ((widget.ParentWidget == null) || (widget.ParentWidget != this))
                 {
                     widget.ParentWidget = this;
                 }
                 widget.Render(drawArgs);
             }
         }
         this.m_OutlineVerts[0].X = this.AbsoluteLocation.X + this.ClientSize.Width;
         this.m_OutlineVerts[0].Y = this.AbsoluteLocation.Y + this.m_HeaderHeight;
         this.m_OutlineVerts[1].X = this.AbsoluteLocation.X + this.ClientSize.Width;
         this.m_OutlineVerts[1].Y = this.AbsoluteLocation.Y + this.ClientSize.Height;
         this.m_OutlineVerts[2].X = this.AbsoluteLocation.X;
         this.m_OutlineVerts[2].Y = this.AbsoluteLocation.Y + this.ClientSize.Height;
         this.m_OutlineVerts[3].X = this.AbsoluteLocation.X;
         this.m_OutlineVerts[3].Y = this.AbsoluteLocation.Y + this.m_HeaderHeight;
         if (!this.m_HideBorder)
         {
             Utilities.DrawLine(this.m_OutlineVerts, this.m_BorderColor.ToArgb(), drawArgs.device);
         }
     }
 }
コード例 #34
0
        public override void Render(DrawArgs drawArgs)
        {
            if (!isInitialized /*|| m_vertices == null*/ || drawArgs.WorldCamera.Altitude < m_minimumDisplayAltitude || drawArgs.WorldCamera.Altitude > m_maximumDisplayAltitude)
            {
                return;
            }

            if (!drawArgs.WorldCamera.ViewFrustum.Intersects(BoundingBox))
            {
                return;
            }

            try
            {
                Cull currentCull = drawArgs.device.RenderState.CullMode;
                drawArgs.device.RenderState.CullMode = Cull.None;

                drawArgs.device.Transform.World = Matrix.Translation(
                    (float)-drawArgs.WorldCamera.ReferenceCenter.X,
                    (float)-drawArgs.WorldCamera.ReferenceCenter.Y,
                    (float)-drawArgs.WorldCamera.ReferenceCenter.Z
                    );

                //if(m_vertices != null)
                if (primList.Count > 0)
                {
                    drawArgs.device.VertexFormat = CustomVertex.PositionNormalColored.Format;
                    drawArgs.device.TextureState[0].ColorOperation = TextureOperation.Disable;
                    for (int i = 0; i < primList.Count; i++)
                    {
                        int           vertexCount = 0;
                        PrimitiveType primType    = (PrimitiveType)primTypes[i];
                        CustomVertex.PositionNormalColored[] vertices = (CustomVertex.PositionNormalColored[])primList[i];

                        if (primType == PrimitiveType.TriangleList)
                        {
                            vertexCount = vertices.Length / 3;
                        }
                        else
                        {
                            vertexCount = vertices.Length - 2;
                        }

                        drawArgs.device.DrawUserPrimitives(
                            primType,                            //PrimitiveType.TriangleList,
                            vertexCount,
                            vertices);
                    }
                }

                if (m_lineFeature != null)
                {
                    for (int i = 0; i < m_lineFeature.Length; i++)
                    {
                        if (m_lineFeature[i] != null)
                        {
                            m_lineFeature[i].Render(drawArgs);
                        }
                    }
                }

                drawArgs.device.Transform.World      = drawArgs.WorldCamera.WorldMatrix;
                drawArgs.device.RenderState.CullMode = currentCull;
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
        }
コード例 #35
0
 public void SetCullMode(Cull mode)
 {
     RenderDevice_SetCullMode(Handle, mode);
 }
コード例 #36
0
        public override void Render(DrawArgs drawArgs)
        {
            using (new DirectXProfilerEvent("PolygonFeature::Render"))
            {
                if (!isInitialized /*|| m_vertices == null*/ || drawArgs.WorldCamera.Altitude < m_minimumDisplayAltitude || drawArgs.WorldCamera.Altitude > m_maximumDisplayAltitude)
                {
                    return;
                }

                if (!drawArgs.WorldCamera.ViewFrustum.Intersects(BoundingBox))
                {
                    return;
                }

                // save state
                Cull currentCull          = drawArgs.device.RenderState.CullMode;
                bool currentZBufferEnable = drawArgs.device.RenderState.ZBufferEnable;

                try
                {
                    drawArgs.device.RenderState.CullMode      = Cull.None;
                    drawArgs.device.RenderState.ZBufferEnable = m_ZBufferEnable;

                    drawArgs.device.Transform.World = Matrix.Translation(
                        (float)-drawArgs.WorldCamera.ReferenceCenter.X + m_localOrigin.X,
                        (float)-drawArgs.WorldCamera.ReferenceCenter.Y + m_localOrigin.Y,
                        (float)-drawArgs.WorldCamera.ReferenceCenter.Z + m_localOrigin.Z
                        );

                    if (World.Settings.EnableSunShading)
                    {
                        Point3d sunPosition = SunCalculator.GetGeocentricPosition(TimeKeeper.CurrentTimeUtc);
                        Vector3 sunVector   = new Vector3(
                            (float)sunPosition.X,
                            (float)sunPosition.Y,
                            (float)sunPosition.Z);

                        drawArgs.device.RenderState.Lighting = true;
                        Material material = new Material();
                        material.Diffuse = Color.White;
                        material.Ambient = Color.White;

                        drawArgs.device.Material = material;
                        drawArgs.device.RenderState.AmbientColor     = World.Settings.ShadingAmbientColor.ToArgb();
                        drawArgs.device.RenderState.NormalizeNormals = true;
                        drawArgs.device.RenderState.AlphaBlendEnable = true;

                        drawArgs.device.Lights[0].Enabled   = true;
                        drawArgs.device.Lights[0].Type      = LightType.Directional;
                        drawArgs.device.Lights[0].Diffuse   = Color.White;
                        drawArgs.device.Lights[0].Direction = sunVector;

                        drawArgs.device.TextureState[0].ColorOperation = TextureOperation.Modulate;
                        drawArgs.device.TextureState[0].ColorArgument1 = TextureArgument.Diffuse;
                        drawArgs.device.TextureState[0].ColorArgument2 = TextureArgument.TextureColor;
                    }
                    else
                    {
                        drawArgs.device.RenderState.Lighting = false;
                        drawArgs.device.RenderState.Ambient  = World.Settings.StandardAmbientColor;
                    }

                    //if(m_vertices != null)
                    if (this.Fill)
                    {
                        if (primList.Count > 0)
                        {
                            drawArgs.device.VertexFormat = CustomVertex.PositionNormalColored.Format;
                            drawArgs.device.TextureState[0].ColorOperation = TextureOperation.Disable;
                            for (int i = 0; i < primList.Count; i++)
                            {
                                int           vertexCount = 0;
                                PrimitiveType primType    = (PrimitiveType)primTypes[i];
                                CustomVertex.PositionNormalColored[] vertices = (CustomVertex.PositionNormalColored[])primList[i];

                                if (primType == PrimitiveType.TriangleList)
                                {
                                    vertexCount = vertices.Length / 3;
                                }
                                else
                                {
                                    vertexCount = vertices.Length - 2;
                                }

                                drawArgs.device.DrawUserPrimitives(
                                    primType,//PrimitiveType.TriangleList,
                                    vertexCount,
                                    vertices);
                            }
                        }
                    }

                    if (m_lineFeature != null)
                    {
                        for (int i = 0; i < m_lineFeature.Length; i++)
                        {
                            if (m_lineFeature[i] != null)
                            {
                                m_lineFeature[i].Render(drawArgs);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Write(ex);
                }
                finally
                {
                    // restore device state
                    drawArgs.device.Transform.World           = drawArgs.WorldCamera.WorldMatrix;
                    drawArgs.device.RenderState.CullMode      = currentCull;
                    drawArgs.device.RenderState.ZBufferEnable = currentZBufferEnable;
                }
            }
        }
コード例 #37
0
 /// <summary>
 /// Creates the viewport interface.
 /// </summary>
 /// <param name="owner">The form the viewport interface is contained within.</param>
 public void CreateViewport(Form owner)
 {
     _owner    = owner;
     _fillMode = FillMode.WireFrame;
     _cullMode = Cull.CounterClockwise;
 }