Beispiel #1
0
        private void SpawnBall()
        {
            if (sBallMeshes == null)
            {
                var cols = new [] {
                    new Color(0.2f, 0.6f, 1.0f),
                    Color.OrangeRed,
                };

                var ballMeshes = new List <GpuMesh>();

                for (var i = 0; i < cols.Length; i++)
                {
                    var g = Program.Inst.GraphicsDevice;
                    var m = MeshGen.Sphere(0.1f).Color(cols[i % cols.Length]);
                    ballMeshes.Add(m.Gpu(g));
                    sBallAabb = m.Aabb();
                }

                sBallMeshes = ballMeshes.ToArray();
            }

            var rnd = new Random();

            var vx = -3.0f - (float)rnd.NextDouble() * 1.0f;
            var vy = (float)rnd.NextDouble() - 1.4f;
            var vz = ((float)rnd.NextDouble() - 0.5f) * 0.5f;

            var num = rnd.Next(sBallMeshes.Length);

            Program.Inst.Scene.AddEntity(new EcsEntity(
                                             new CMesh {
                Mesh = sBallMeshes[num]
            },
                                             new CAabb {
                Aabb = sBallAabb
            },
                                             new CBall {
                Radius = 0.1f
            },
                                             new CVel {
                Vel = new Vector3(vx, vy, vz)
            },
                                             new CShadow {
            },
                                             new CSort {
                SortVal = 1 - num
            },
                                             new CPos {
                Pos = new Vector3(4.8f, 0.7f, -1.0f)
            }));
        }