protected override void InitializeObjects(Loader loader, SharpAudioDevice audioDevice)
        {
            string file = @"Models\T_Rex.fbx";

            _go = loader.LoadGameObjectFromFile(file, Vector3.Zero, new Vector3(0, MathUtil.PiOverTwo, 0));
            Game3DObject g1 = loader.LoadGameObjectFromFile(file, new Vector3(1, 1, 0), Vector3.Zero);
            Game3DObject g2 = loader.LoadGameObjectFromFile(file, new Vector3(-1, 1, 0), Vector3.Zero);
            Game3DObject g3 = loader.LoadGameObjectFromFile(file, Vector3.UnitZ * 2, Vector3.Zero);

            _go.AddChild(g1);
            _go.AddChild(g2);
            _go.AddChild(g3);
            _go.AddScript(new DinoMovementScript());
            AddGameObject(_go);
            AddGameObject(loader.LoadGameObjectFromFile(@"Models\dsa.fbx", Vector3.UnitX * 5, Vector3.Zero));

            _voice  = new SharpAudioVoice(audioDevice, @"Sounds\again.wav");
            _voice2 = new SharpAudioVoice(audioDevice, @"Sounds\again.wav");
        }
        public Game3DObject LoadGameObjectFromFile(string path, Vector3 startPosition, Vector3 startRotation, string texture = null)
        {
            var importer = new AssimpContext();

            importer.SetConfig(new NormalSmoothingAngleConfig(66.0f));
            var          fileScene  = importer.ImportFile(path, PostProcessSteps.Triangulate);
            var          indices    = new List <uint>();
            var          vertices   = new List <Renderer.VertexDataStruct>();
            var          root       = fileScene.RootNode;
            Game3DObject gameObject = null;

            meshList  = new List <MeshObject>();
            materials = new List <Graphics.Material>();
            textures  = new List <Texture>();

            ExtractTextures(fileScene);
            ExtractMaterials(fileScene, texture);
            ExtractMeshes(fileScene, indices, vertices);

            gameObject = new Game3DObject(startPosition, startRotation);
            if (root.HasChildren)
            {
                foreach (var child in root.Children)
                {
                    if (child.HasMeshes)
                    {
                        child.Transform.Decompose(out Vector3D _, out Assimp.Quaternion rotation, out Vector3D position);
                        var childObject = gameObject.AddChild(new Game3DObject(new Vector3(position.X, position.Y, position.Z), ToEulerAngles(rotation)));
                        childObject.AddMeshObject(meshList[child.MeshIndices[0]]);
                        GetChildrenMeshes(ref childObject, child);
                    }
                }
            }
            else
            {
                gameObject.AddMeshObject(meshList[root.MeshIndices[0]]);
            }

            return(gameObject);
        }
Example #3
0
        private void CreatePlayerLoader(Loader loader)
        {
            // создание игрока
            _player = new Game3DObject(new Vector3(0.0f, 10.0f, -5.0f), Vector3.Zero);
            float deltaAngle = Camera.FOVY / Game.RenderForm.ClientSize.Height;

            _player.Tag       = "player";
            _player.Collision = new BoxCollision(1.0f, 1.7f);
            _player.AddComponent(new PhysicsComponent());
            _player.AddScript(new PhysicsScript());
            _player.AddComponent(new ColliderComponent());
            _player.AddScript(new ColliderScript());
            var playerComponent = new PlayerComponent();

            playerComponent.OnArrowsCountChanged += UpdateArrowsCountUI;
            playerComponent.OnHealthChanged      += (count) => _healthProgressBar.Value = count;
            playerComponent.AddArrows(ArrowType.Standart, 5);
            playerComponent.AddArrows(ArrowType.Poison, 2);
            _player.AddComponent(playerComponent);
            _player.AddScript(new PlayerMovement(deltaAngle, 4f, 0.5f, 2.0f));
            _player.AddChild(Camera);
            // доабвление игроку лука
            string file = @"Resources\Models\bow.fbx";
            var    bow  = loader.LoadGameObjectFromFile(file, new Vector3(-0.017f, 0.94f, 0.08f), Vector3.Zero);

            _player.AddChild(bow);
            //добавление точки появления стрел игроку
            var arrowParrent = new Game3DObject(new Vector3(-0.052f, 0.95f, 0.0f), Vector3.Zero);

            arrowParrent.AddComponent(new VisibleComponent());
            arrowParrent.AddScript(new VisibleScript());
            // скрипт стрельбы
            var bowShootScript = new BowShoot(2.0f, 1.0f);

            //создание копируемых стрел для игрока
            //обычная стрела
            file = @"Resources\Models\arrow.fbx";
            var arrow = loader.LoadGameObjectFromFile(file, Vector3.Zero, Vector3.Zero);

            arrow.Collision = new BoxCollision(0.3f, 0.2f, 0.3f);
            var arrowComponents = new List <Func <ObjectComponent> >
            {
                () => new ArrowComponent(),
                () => new PhysicsComponent(0.05f),
                () => new ColliderComponent()
            };
            var arrowScripts = new List <Func <Script> > {
                () => new Arrow(arrowParrent, 20.0f, 5.0f),
                () => new PhysicsScript(),
                () => new ColliderScript()
            };
            var arrowTemplate = new CopyableGameObject(arrow, arrowScripts, arrowComponents);

            bowShootScript.AddArrowTemplate(ArrowType.Standart, arrowTemplate);
            //стрела с ядом
            file            = @"Resources\Models\arrowPoison.fbx";
            arrow           = loader.LoadGameObjectFromFile(file, Vector3.Zero, Vector3.Zero);
            arrow.Collision = new BoxCollision(0.3f, 0.2f, 0.3f);
            arrowComponents = new List <Func <ObjectComponent> >
            {
                () => new ArrowComponent(),
                () => new PhysicsComponent(0.05f),
                () => new ColliderComponent()
            };
            arrowScripts = new List <Func <Script> > {
                () => new PoisonArrow(arrowParrent, 20.0f, 5.0f, 5.0f),
                () => new PhysicsScript(),
                () => new ColliderScript()
            };
            arrowTemplate = new CopyableGameObject(arrow, arrowScripts, arrowComponents);
            bowShootScript.AddArrowTemplate(ArrowType.Poison, arrowTemplate);
            arrowParrent.AddScript(bowShootScript);
            //добавление стрел к точке появления
            file  = @"Resources\Models\arrow.fbx";
            arrow = loader.LoadGameObjectFromFile(file, Vector3.Zero, Vector3.Zero);
            arrowParrent.AddChild(arrow);
            file           = @"Resources\Models\arrowPoison.fbx";
            arrow          = loader.LoadGameObjectFromFile(file, Vector3.Zero, Vector3.Zero);
            arrow.IsHidden = true;
            arrowParrent.AddChild(arrow);
            _player.AddChild(arrowParrent);

            AddGameObject(_player);
        }