Exemplo n.º 1
0
        public static List<Entity> Generate(Scene scene)
        {
            var objects = new List<Entity>();
            var cubeModel = new CubePrimitive(scene.Platform.Graphics);
            var billboardModel = new BillboardPrimitive(scene.Platform.Graphics);
            var teapotModel = new TeapotPrimitive(scene.Platform.Graphics);
            var cylinderModel = new CylinderPrimitive(scene.Platform.Graphics);
            var sphereModel = new SpherePrimitive(scene.Platform.Graphics);
            var torusModel = new TorusPrimitive(scene.Platform.Graphics);

            objects.Add(CreateShapeGO(scene, "Default", cubeModel.Mesh, 2));
            objects.Add(CreateShapeGO(scene, "Default", billboardModel.Mesh));
            objects.Add(CreateShapeGO(scene, "Default", teapotModel.Mesh, 1));
            objects.Add(CreateShapeGO(scene, "Default", cylinderModel.Mesh));
            objects.Add(CreateShapeGO(scene, "Default", sphereModel.Mesh));
            objects.Add(CreateShapeGO(scene, "Default", torusModel.Mesh, 1));
            objects.Add(CreateShapeGO(scene, "Default", torusModel.Mesh, 2));
            objects.Add(CreateShapeGO(scene, "Default", torusModel.Mesh, 0));
            return objects;
        }
Exemplo n.º 2
0
        public override void Start()
        {
            CommonDemoResources.Create (Platform, Engine);

            var lines = Engine.Assets.Load <TextAsset> ("assets/airports.bba")
                .Text
                .Split ('\n')
                .ToList ();

            foreach (var line in lines)
            {
                string[] items = line.Split(',');

                if (items.Length == 11)
                {
                    airports.Add(new Airport(items));
                }
            }

            airports.Shuffle ();

            airports = airports.GetRange (0, 250);

            Console.WriteLine("num airports: " + airports.Count);

            this.Configuration.BackgroundColour = Rgba32.Red;

            returnScene = this;

            float radius = 1.5f;
            // create a sprite
            var sphereMesh = new SpherePrimitive(this.Platform.Graphics);

            var mat = new Material("Default",CommonDemoResources.VertexLitShader);
            mat.SetColour("MaterialColour", Rgba32.LightGrey);
            earthGo = this.SceneGraph.CreateSceneObject("earth");

            Entity camSo = SceneGraph.CreateSceneObject ("Scene 5 Camera");
            camSo.AddTrait<CameraTrait>();
            var lookatTrait = camSo.AddTrait<LookAtSubjectTrait>();
            lookatTrait.Subject = Transform.Origin;
            var orbitTrait = camSo.AddTrait<OrbitAroundSubjectTrait>();
            orbitTrait.CameraSubject = Transform.Origin;

            camSo.Transform.LocalPosition = new Vector3(10f,4f,10f);

            this.RuntimeConfiguration.SetRenderPassCameraTo("Debug", camSo);
            this.RuntimeConfiguration.SetRenderPassCameraTo("Default", camSo);

            earthGo.Transform.LocalScale = new Vector3(2 * radius, 2 * radius, 2 * radius);

            var mr = earthGo.AddTrait<MeshRendererTrait>();
            mr.Mesh = sphereMesh.Mesh;
            mr.Material = mat;

            //var mat2 = new Material("Default", CommonDemoResources.UnlitShader);
            //mat2.SetColour("MaterialColour", Rgba32.Blue);

            foreach (var airport in airports)
            {
                var so = this.SceneGraph.CreateSceneObject(airport.Iata);

                so.Transform.Parent = earthGo.Transform;

                var sodr = so.AddTrait<DebugRendererTrait>();
                //sodr.RenderPass = "******";
                sodr.Colour = Rgba32.Blue;
                //var somr = so.AddTrait<MeshRenderer>();
                //somr.Mesh = sphereMesh;
                //somr.Material = mat2;

                var lat = airport.Latitude;
                var lon = airport.Longitude;

                Vector3 pos = new Vector3(
                    radius * Maths.Cos(Maths.ToRadians(lat)),
                    radius * Maths.Sin(Maths.ToRadians(lat)),
                    0f);

                Single t = Maths.ToRadians (lon);

                Matrix44 rot; Matrix44.CreateRotationY(ref t, out rot);

                Vector3 r; Vector3.Transform(ref pos, ref rot, out r);
                so.Transform.Position = r;
                so.Transform.LocalScale = new Vector3(0.015f, 0.015f, 0.015f);

            }

            this.Engine.InputEventSystem.Tap += this.OnTap;
        }