コード例 #1
0
ファイル: LineRenderer.cs プロジェクト: Joelone/FFWD
        public override void Draw(Microsoft.Xna.Framework.Graphics.GraphicsDevice device, Camera cam)
        {
            if (!useWorldSpace)
            {
                //transform local positions to world space
                for (int i = 0; i < pointCnt; i++)
                {
                    transformedPositions[i] = transform.TransformPoint(positions[i]);
                }
                Rebuild(transformedPositions, pointCnt, cam.transform.position);
            }
            else
            {
                Rebuild(positions, pointCnt, cam.transform.position);
            }

            material.SetTextureState(cam.BasicEffect);
            material.SetBlendState(device);

            cam.BasicEffect.VertexColorEnabled = true;
            cam.BasicEffect.LightingEnabled = false;

            foreach (EffectPass pass in cam.BasicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.DrawUserIndexedPrimitives<VertexPositionColorTexture>(
                    PrimitiveType.TriangleList,
                    vertexPositionColorTextures,
                    0,
                    pointCnt * 2,
                    triangleIndexData,
                    0,
                    (pointCnt-1) * 2
                );
            }
        }
コード例 #2
0
ファイル: LocationObjCommand.cs プロジェクト: abordt/Viking
        public override void OnDraw(Microsoft.Xna.Framework.Graphics.GraphicsDevice graphicsDevice,
                                    VikingXNA.Scene scene,
                                    Microsoft.Xna.Framework.Graphics.BasicEffect basicEffect)
        {
            if (this.oldMouse == null)
                return;

            if (basicEffect == null)
                throw new ArgumentNullException("basicEffect");

            if (scene == null)
                throw new ArgumentNullException("scene");

            //Draw a line from the selected location to the new location if we are holding left button down
            if (this.oldMouse.Button == MouseButtons.Left)
            {
                SectionLocationsViewModel sectionAnnotations = AnnotationOverlay.GetAnnotationsForSection(Parent.Section.Number);
                if (sectionAnnotations == null)
                    return;

                GridVector2 selectedPos = selected.VolumePosition;
                /*bool found = sectionAnnotations.TryGetPositionForLocation(selected, out selectedPos);
                if (found == false)
                    return;
                */

                //PORT XNA 4
                /*
                VertexDeclaration oldVertexDeclaration = graphicsDevice.VertexDeclaration;
                graphicsDevice.VertexDeclaration = Parent.VertexPositionColorDeclaration;
                graphicsDevice.RenderState.PointSize = 5.0f;
                */

                basicEffect.Texture = null;
                basicEffect.TextureEnabled = false;
                basicEffect.VertexColorEnabled = true;

                //PORT XNA 4
                //basicEffect.CommitChanges();

                //Draw the new location
                if (LocType != null && selected.Section == Parent.Section.Number)
                {
                    Microsoft.Xna.Framework.Color color = new Microsoft.Xna.Framework.Color(LocType.Color.R,
                        LocType.Color.G,
                        LocType.Color.B,
                        128);

                    GlobalPrimitives.DrawCircle(graphicsDevice, basicEffect, this.oldWorldPosition, selected.Radius, color);
                }
                else
                {

                    VertexPositionColor[] verts = new VertexPositionColor[] {
                                                        new VertexPositionColor(new Vector3((float)selectedPos.X, (float)selectedPos.Y, 0f), Color.Gold),
                                                        new VertexPositionColor(new Vector3((float)this.oldWorldPosition.X, (float)oldWorldPosition.Y, 0f), Color.Gold)};

                    int[] indicies = new int[] { 0, 1 };

                    //PORT XNA 4
                    //basicEffect.Begin();

                    foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
                    {
                        //PORT XNA 4
                        //pass.Begin();
                        pass.Apply();

                        if (verts != null && verts.Length > 0)
                            graphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.LineList, verts, 0, verts.Length, indicies, 0, indicies.Length / 2);

                        //PORT XNA 4
                        //pass.End();
                    }

                    //PORT XNA 4
                    //basicEffect.End();
                }

                //PORT XNA 4
                //graphicsDevice.VertexDeclaration = oldVertexDeclaration;
            }

            basicEffect.VertexColorEnabled = false;
            //PORT XNA 4
            //basicEffect.CommitChanges();

            base.OnDraw(graphicsDevice, scene, basicEffect);
        }
コード例 #3
0
ファイル: RectangleCommand.cs プロジェクト: abordt/Viking
        public override void OnDraw(Microsoft.Xna.Framework.Graphics.GraphicsDevice graphicsDevice, VikingXNA.Scene scene, Microsoft.Xna.Framework.Graphics.BasicEffect basicEffect)
        {
            if (CommandActive == false)
                return;

            //PORT XNA 4
            //VertexDeclaration oldVertexDeclaration = graphicsDevice.VertexDeclaration;

            //PORT XNA 4
            //graphicsDevice.VertexDeclaration = Parent.VertexPositionColorDeclaration;

            basicEffect.VertexColorEnabled = true;
            basicEffect.TextureEnabled = false;
            //PORT XNA 4
            //basicEffect.CommitChanges();

            VertexPositionColor[] verts = new VertexPositionColor[] { new VertexPositionColor( new Vector3((float)MyRect.Left, (float)MyRect.Bottom, 1), Color.Yellow),
                                                                       new VertexPositionColor( new Vector3((float)MyRect.Right, (float)MyRect.Bottom, 1), Color.Yellow),
                                                                        new VertexPositionColor( new Vector3((float)MyRect.Right, (float)MyRect.Top, 1), Color.Yellow),
                                                                         new VertexPositionColor( new Vector3((float)MyRect.Left, (float)MyRect.Top, 1), Color.Yellow)};

            Color CrossColor = new Color(Color.Yellow.R, Color.Yellow.G, Color.Yellow.B, 0.25f);
            float EightWidth = (float)(MyRect.Width / 16);
            float EightHeight = (float)(MyRect.Height / 16);

            VertexPositionColor[] crossVerts = new VertexPositionColor[] { new VertexPositionColor( new Vector3((float)MyRect.Center.X - EightWidth, (float)MyRect.Center.Y, 1), CrossColor),
                                                                       new VertexPositionColor( new Vector3((float)MyRect.Center.X + EightWidth, (float)MyRect.Center.Y, 1), CrossColor),
                                                                        new VertexPositionColor( new Vector3((float)MyRect.Center.X, (float)MyRect.Center.Y - EightHeight, 1), CrossColor),
                                                                         new VertexPositionColor( new Vector3((float)MyRect.Center.X, (float)MyRect.Center.Y + EightHeight, 1), CrossColor)};

            int[] indicies = new int[] { 0, 1, 2, 3, 0 };
            int[] crossIndicies = new int[] { 0, 1, 2, 3 };

            //PORT XNA 4
            //basicEffect.Begin();

            foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
            {
                //PORT XNA 4
                //pass.Begin();
                pass.Apply();

                //if(gridIndicies.Count > 0)

            //    MyRect.Draw(graphicsDevice);

                graphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.LineStrip, verts, 0, verts.Length, indicies, 0, indicies.Length - 1);
                graphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.LineList, crossVerts, 0, crossVerts.Length, crossIndicies, 0, crossIndicies.Length / 2);

            //                graphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, this.verticies, 0, verticies.Length, gridIndicies, 0, gridIndicies.Length / 3);
                // graphicsDevice.DrawUserPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, this.verticies, 0, verticies.Length / 3);
                //  GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, GridVerticies, 0, GridVerticies.Length, GridIndicies, 2, 2);
                // graphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, this.verticies, 0, verticies.Length, gridIndicies, 0, 1);

                //PORT XNA 4
                //pass.End();
            }

            //PORT XNA 4
            //basicEffect.End();

            //PORT XNA 4
            //graphicsDevice.VertexDeclaration = oldVertexDeclaration;

            basicEffect.TextureEnabled = true;
            basicEffect.VertexColorEnabled = false;

            base.OnDraw(graphicsDevice,scene, basicEffect);
        }