Пример #1
0
        private void DrawTerrain_Click(object sender, EventArgs e)
        {
            var vrt = new VRTerrain(vr, new VRNode(vr), 256, 256,
                                    @"C:\Users\casde\Desktop\KettlerProject\VRController\scenes\terrain1.png",
                                    @"C:\NetworkEngine\data\NetworkEngine\textures\tarmac_diffuse.png",
                                    @"C:\NetworkEngine\data\NetworkEngine\textures\terrain\grass_green_d.jpg", 0, 20);

            vrt.getHeight(5, 5);
        }
Пример #2
0
        /// <summary>
        ///     load a preset scene from a file
        /// </summary>
        /// <param name="file">string file</param>
        /// <param name="path">string path</param>
        /// <param name="totalNumber">int totalNumber (of steps to load scene)</param>
        public void loadSceneFromFile(string file, string path, int totalNumber)
        {
            var sceneFile = file;
            var allText   = File.ReadAllText(sceneFile);
            var commands  = allText.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

            vrt = null;
            //totalNumber -= 2;
            notStarted    = false;
            bikeSet       = false;
            changeDaytime = false;

            panel.addEmergencyPanel("LoadingPanel", new[] { 0, 0, -5 }, 0.5f, new[] { 0, 0, 0 }, new[] { 10, 10 },
                                    new[] { 256, 256 }, new[] { 10, 10, 10, 10 });
            loadingPanelUUID = node.getUUID("LoadingPanel");
            updateLoadingPanel(loadingPanelUUID, phase, 0, totalNumber);
            phase = "";

            cameraUUID = node.getUUID("Camera");
            Console.WriteLine("CAMEARUID = " + cameraUUID);


            var oldPath = path;

            foreach (var s in commands)
            {
                var command = s.Split(',');
                var random  = new Random();


                //GetHeight should still be implemented.

                path = @"data\NetworkEngine\";
                switch (command[0].Trim().ToLower())
                {
                case "terrain":
                    //if(vr.started)
                    //    vr.dataChecker(false);
                    phase = "Terrain";
                    updateLoadingPanel(loadingPanelUUID, phase, currentCount, totalNumber);
                    vrt = new VRTerrain(vr, node, int.Parse(command[1]), int.Parse(command[2]),
                                        Path.Combine(oldPath, command[3].Trim()), Path.Combine(path, command[4].Trim()),
                                        Path.Combine(path, command[5].Trim()), int.Parse(command[6]), int.Parse(command[7]));
                    countAdded(10);
                    break;

                case "node":
                    phase = "Nodes";
                    updateLoadingPanel(loadingPanelUUID, phase, currentCount, totalNumber);
                    for (var i = 0; i < int.Parse(command[2]); i++)
                    {
                        //updateLoadingPanel(loadingPanelUUID, phase, currentCount, totalNumber);
                        var scale = 1.0f;
                        if (command[7].Trim() == "true")
                        {
                            scale = random.Next(80, 120) / 100;
                        }
                        var x = random.Next(int.Parse(command[3]), int.Parse(command[4]));
                        var y = random.Next(int.Parse(command[5]), int.Parse(command[6]));
                        var z = vrt.getHeight(x, y);
                        node.addNode((command[1] + i).Trim(), new[] { x, z, y }, scale, new[] { 0, 0, 0 },
                                     Path.Combine(path, command[8].Trim()), true, false, "");
                        countAdded();
                    }
                    break;

                case "water":
                    phase = "Water";
                    updateLoadingPanel(loadingPanelUUID, phase, currentCount, totalNumber);
                    node.addWater(command[1],
                                  new[]
                    {
                        int.Parse(command[2]), vrt.getHeight(int.Parse(command[2]), int.Parse(command[3])),
                        int.Parse(command[3])
                    }, float.Parse(command[4]), new[] { 0, 0, 0 },
                                  new[] { int.Parse(command[5]), int.Parse(command[6]) }, double.Parse(command[7]));
                    countAdded(2);
                    break;

                case "bike":
                    phase = "Bike";
                    updateLoadingPanel(loadingPanelUUID, phase, currentCount, totalNumber);
                    vr.write(Path.Combine(path, command[2].Trim()));
                    node.addParentNode(command[1].Trim(), cameraUUID, new[] { 0, 0, 0 }, 0.01f, new[] { 0, -105, 0 },
                                       Path.Combine(path, command[2].Trim()), true, true, command[3].Trim());

                    bikeUUID = node.getUUID("Bike");
                    Console.WriteLine("BIKE ID = " + bikeUUID);
                    node.updateSpeed(bikeUUID, 0);
                    countAdded(2);
                    break;

                case "panel":
                    phase = "Panel";
                    updateLoadingPanel(loadingPanelUUID, phase, currentCount, totalNumber);
                    panel.addPanel("BikePanel", bikeUUID, new[] { -50, 120, 0 }, 1, new[] { -45, 90, 0 }, new[] { 50, 50 },
                                   new[] { 256, 256 }, new[] { 10, 10, 10, 10 });
                    panelUUID = node.getUUID("BikePanel");
                    //node.deleteNodeUUID(loadingPanelUUID);
                    countAdded(2);
                    break;

                case "route":
                    phase = "Route";
                    double speed = 0;
                    updateLoadingPanel(loadingPanelUUID, phase, currentCount, totalNumber);
                    if (command[1].Trim().ToLower() == "default")
                    {
                        VRr.createRoute(null);
                        VRr.createRoad();
                        speed = double.Parse(command[2]);
                    }
                    else if (command[1].Trim().ToLower() == "custom")
                    {
                        Console.WriteLine("It is in my code");
                        VRr.addRoutePoint(int.Parse(command[2]), int.Parse(command[3]), int.Parse(command[4]),
                                          int.Parse(command[5]), int.Parse(command[6]), int.Parse(command[7]));
                        if (command.Length == 9)
                        {
                            if (command[8] == "true")
                            {
                                VRr.createRoute(VRr.routeNodes);
                                VRr.createRoad();
                            }
                        }
                    }
                    VRr.nodeFollow(cameraUUID, speed, 0.0, "XZ", new[] { 0, 2, 0 }, new[] { 0, 0, 0 });
                    node.updateSpeed(bikeUUID, speed * 0.1);
                    countAdded(2);
                    break;

                case "time":
                    phase = "Time";
                    updateLoadingPanel(loadingPanelUUID, phase, currentCount, totalNumber);
                    VRtime.setTime(double.Parse(command[2]));
                    if (command[1].Trim().ToLower() == "start")
                    {
                        changeDaytime = true;
                    }
                    countAdded(2);
                    break;
                }
            }
            if (!notStarted)
            {
                phase = "Finished";
                updateLoadingPanel(loadingPanelUUID, phase, currentCount, totalNumber);
                node.deleteNodeUUID(loadingPanelUUID);
                startUpdate();
                bike.newStats += UpdatePanel;
                bikeSet        = true;
                notStarted     = true;
                sceneLoaded    = true;
            }
        }