コード例 #1
0
ファイル: Utils.cs プロジェクト: Yash-Codemaster/KoduGameLab
        //
        //
        //  2D Stuff
        //
        //


        /// <summary>
        /// Draw a line in screenspace using pixel coords.
        /// </summary>
        /// <param name="p0"></param>
        /// <param name="p1"></param>
        /// <param name="color"></param>
        public static void Draw2DLine(Vector2 p0, Vector2 p1, Vector4 color)
        {
            // Add a half pixel offset to get things to line up cleanly.
            p0 += new Vector2(0.5f, 0.5f);
            p1 += new Vector2(0.5f, 0.5f);

            // Convert from pixel coords to homogeneous coords.
            p0.X = p0.X / BokuGame.bokuGame.GraphicsDevice.Viewport.Width * 2.0f - 1.0f;
            p0.Y = -(p0.Y / BokuGame.bokuGame.GraphicsDevice.Viewport.Height * 2.0f - 1.0f);
            p1.X = p1.X / BokuGame.bokuGame.GraphicsDevice.Viewport.Width * 2.0f - 1.0f;
            p1.Y = -(p1.Y / BokuGame.bokuGame.GraphicsDevice.Viewport.Height * 2.0f - 1.0f);

            // Create the vertices.
            UtilsVertex[] verts = new UtilsVertex[2];
            verts[0] = new UtilsVertex(new Vector3(p0, 0.0f), color);
            verts[1] = new UtilsVertex(new Vector3(p1, 0.0f), color);

            effect.CurrentTechnique = effect.Techniques["Screenspace2D"];

            GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;

            // Render all passes.
            for (int i = 0; i < effect.CurrentTechnique.Passes.Count; i++)
            {
                EffectPass pass = effect.CurrentTechnique.Passes[i];
                pass.Apply();
                try
                {
                    device.DrawUserPrimitives(PrimitiveType.LineList, verts, 0, 1);
                }
                catch
                {
                }
            }
        }   // end of Draw2DLine()
コード例 #2
0
ファイル: Utils.cs プロジェクト: Yash-Codemaster/KoduGameLab
        public static void DrawLine(Camera camera, Vector3 p0, Vector3 p1, Vector4 color, ref Matrix worldMatrix)
        {
            Matrix viewMatrix = camera.ViewMatrix;
            Matrix projMatrix = camera.ProjectionMatrix;

            Matrix worldViewProjMatrix = worldMatrix * viewMatrix * projMatrix;

            effect.Parameters["WorldViewProjMatrix"].SetValue(worldViewProjMatrix);
            effect.Parameters["WorldMatrix"].SetValue(worldMatrix);

            // Create the vertices.
            UtilsVertex[] verts = new UtilsVertex[2];
            verts[0] = new UtilsVertex(p0, color);
            verts[1] = new UtilsVertex(p1, color);

            effect.CurrentTechnique = effect.Techniques["NoTexture"];

            GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;

            // Render all passes.
            for (int i = 0; i < effect.CurrentTechnique.Passes.Count; i++)
            {
                EffectPass pass = effect.CurrentTechnique.Passes[i];
                pass.Apply();
                device.DrawUserPrimitives(PrimitiveType.LineList, verts, 0, 1);
            }
        }   // end of Utils DrawLine()
コード例 #3
0
ファイル: Utils.cs プロジェクト: Yash-Codemaster/KoduGameLab
        /// <summary>
        /// Draw a series of line segments. That means pts must have even number positions.
        /// </summary>
        /// <param name="camera"></param>
        /// <param name="pts"></param>
        /// <param name="color"></param>
        /// <param name="localToWorld"></param>
        public static void DrawLines(Camera camera, List <Vector3> pts, Vector4 color, ref Matrix localToWorld)
        {
            if (pts.Count > 0)
            {
                Matrix viewMatrix = camera.ViewMatrix;
                Matrix projMatrix = camera.ProjectionMatrix;

                Matrix worldViewProjMatrix = localToWorld * viewMatrix * projMatrix;
                effect.Parameters["WorldViewProjMatrix"].SetValue(worldViewProjMatrix);
                effect.Parameters["WorldMatrix"].SetValue(localToWorld);

                // Create the vertices.
                if (vertsScratch.Length < pts.Count)
                {
                    vertsScratch = new UtilsVertex[pts.Count];
                }

                for (int i = 0; i < pts.Count; ++i)
                {
                    ///UtilsVertex is a struct, so no real new here.
                    vertsScratch[i] = new UtilsVertex(pts[i], color);
                }

                effect.CurrentTechnique = effect.Techniques["NoTexture"];

                GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;

                // Render all passes.
                for (int i = 0; i < effect.CurrentTechnique.Passes.Count; i++)
                {
                    EffectPass pass = effect.CurrentTechnique.Passes[i];
                    pass.Apply();
                    device.DrawUserPrimitives(PrimitiveType.LineList, vertsScratch, 0, pts.Count / 2);
                }
            }
        }