Exemplo n.º 1
0
            /// <summary>
            /// Plants one item
            /// </summary>
            /// <param name="scene">Scene</param>
            /// <param name="pos">Position</param>
            /// <param name="size">Size</param>
            /// <param name="res">Resulting item</param>
            /// <returns>Returns true if an item has been planted</returns>
            private static bool Plant(Scene scene, Vector3 pos, Vector2 size, out VertexBillboard res)
            {
                var ray = scene.GetTopDownRay(pos);

                bool found = scene.PickFirst(
                    ray,
                    RayPickingParams.FacingOnly | RayPickingParams.Geometry,
                    SceneObjectUsages.Ground,
                    out var r);

                if (found && r.Item.Normal.Y > 0.5f)
                {
                    res = new VertexBillboard()
                    {
                        Position = r.Position,
                        Size     = size,
                    };

                    return(true);
                }

                res = new VertexBillboard();

                return(false);
            }
Exemplo n.º 2
0
        public override void Build(Cube c, int numParticles, GraphicsDevice g)
        {
            int numVertices = numParticles * 4;             // each billboard is a quad

            particles = new VertexBillboard[numVertices];

            Random rand = new Random();
            int    i    = 0;

            while (i < numVertices)
            {
                Vector2 scale = new Vector2(rand.Next(1, 4) / 10.0f, rand.Next(40, 80) / 10.0f);
                Vector3 pos   = new Vector3(rand.Next((int)c.W), rand.Next((int)c.H), rand.Next((int)c.L));
                particles[i++] = new VertexBillboard(pos, Vector3.Right, Vector3.One, new Vector2(0, 0), scale);
                particles[i++] = new VertexBillboard(pos, Vector3.Right, Vector3.One, new Vector2(1, 0), scale);
                particles[i++] = new VertexBillboard(pos, Vector3.Right, Vector3.One, new Vector2(1, 1), scale);
                particles[i++] = new VertexBillboard(pos, Vector3.Right, Vector3.One, new Vector2(0, 1), scale);
            }

            int[] indices = new int[numParticles * 6];
            for (i = 0; i < numParticles; i++)
            {
                indices[i * 6]     = i * 4;
                indices[i * 6 + 1] = i * 4 + 1;
                indices[i * 6 + 2] = i * 4 + 2;
                indices[i * 6 + 3] = i * 4;
                indices[i * 6 + 4] = i * 4 + 2;
                indices[i * 6 + 5] = i * 4 + 3;
            }

            vBuffer = new VertexBuffer(g, VertexBillboard.SizeInBytes * particles.Length, BufferUsage.WriteOnly);
            vBuffer.SetData(particles);
            iBuffer = new IndexBuffer(g, typeof(int), indices.Length, BufferUsage.WriteOnly);
            iBuffer.SetData(indices);

            Effect.Parameters["vOrigin"].SetValue(c.Origin);
            Effect.Parameters["fHeight"].SetValue(c.H);
            Effect.Parameters["fWidth"].SetValue(c.W);
            Effect.Parameters["fLength"].SetValue(c.L);
        }