Esempio n. 1
0
        /// <summary>
        /// Add a new model to the OcTree structure, creating a new node if it
        /// is necessary.
        /// </summary>
        /// <param name="model">Reference to the model to be added.</param>
        /// <returns>true if the model was added, false otherwise.</returns>
        public int AddModel(DrawableModel model)
        {
            OcTreeNode node = SearchNode(model.Position);

            NodeType type = NodeType.None;

            if (model.Model.FileName == "Content/Models/CubeBaseFrontStaircase2-1")
            {
                type = NodeType.Staircase1Down;
            }
            else if (model.Model.FileName == "Content/Models/CubeBaseFrontStaircase2-2")
            {
                type = NodeType.Staircase2Down;
            }
            else if (model.Model.FileName == "Content/Models/CubeBaseFrontLadder")
            {
                type = NodeType.Ladder;
            }
            else if (model.Model.FileName.Contains("Door"))
            {
                type = NodeType.Door;
            }

            return(node.AddModel(type, model));
        }
Esempio n. 2
0
        internal Drawable(DrawableModel drawableModel)
        {
            if (drawableModel.ShaderGroup != null)
            {
                Materials = new List <Material>(drawableModel.ShaderGroup.Shaders.Count);
                foreach (var info in drawableModel.ShaderGroup.Shaders)
                {
                    Materials.Add(new Material(info));
                }
            }
            else
            {
                Materials = new List <Material>();
            }

            if (drawableModel.Skeleton != null)
            {
                Skeleton = new Skeleton(drawableModel.Skeleton);
            }

            Models = new List <Model>(drawableModel.ModelCollection.Length);
            foreach (var info in drawableModel.ModelCollection)
            {
                Models.Add(new Model(info));
            }

            AttachedTexture = drawableModel.ShaderGroup.TextureDictionary;
        }
Esempio n. 3
0
        /// <summary>
        /// Add a new model to the list of models contained in the <c>OcTreeNode</c>.
        /// </summary>
        /// <param name="type">Type of the node.</param>
        /// <param name="model">Reference to the model.</param>
        /// <returns></returns>
        public int AddModel(NodeType type, DrawableModel model)
        {
            if (_childList.Count == 0)
            {
                _modelList.Add(new KeyValuePair <NodeType, DrawableModel>(type, model));
                if (_size == 1f && _modelList.Count != 0)// && _modelList[0].Key != NodeType.None)
                {
                    CalcBoundingPlane();
                }

                bool maxObjectsReached = (_modelList.Count > OcTree.MaxObjectsInNode);
                bool minSizeNotReached = (_size > OcTree.MinSize);
                if (maxObjectsReached && minSizeNotReached)
                {
                    CreateChildNodes();
                    foreach (KeyValuePair <NodeType, DrawableModel> currentModel in _modelList)
                    {
                        Distribute(currentModel.Key, currentModel.Value);
                    }
                    _modelList.Clear();
                }
            }
            else
            {
                Distribute(type, model);
            }

            return(model.ModelID);
        }
Esempio n. 4
0
        public static bool FinerCheck2(DrawableModel model1, DrawableModel model2)
        {
            // if (CoarseCheck(model1, model2) == false)
            //   return false;

            bool collision = false;

            foreach (ModelMesh mesh1 in model1.Model.Meshes)
            {
                BoundingSphere origSphere1  = mesh1.BoundingSphere;
                Matrix         trans1       = model1.OriginalTransforms[mesh1.ParentBone.Index] * model1.WorldMatrix * Matrix.CreateScale(0.0000000001f);
                BoundingSphere transSphere1 =
                    XNAUtils.TransformBoundingSphere(origSphere1, trans1);

                foreach (ModelMesh mesh2 in model2.Model.Meshes)
                {
                    BoundingSphere origSphere2  = mesh2.BoundingSphere;
                    Matrix         trans2       = model2.OriginalTransforms[mesh2.ParentBone.Index] * model2.WorldMatrix * Matrix.CreateScale(0.000000001f);
                    BoundingSphere transSphere2 =
                        XNAUtils.TransformBoundingSphere(origSphere2, trans2);

                    if (transSphere1.Intersects(transSphere2))
                    {
                        collision = true;
                    }
                }
            }

            return(collision);
        }
Esempio n. 5
0
        /// <summary>
        /// Constructor of the <c>NewGameScreen</c> class.
        /// </summary>
        /// <param name="name">Name of the screen.</param>
        /// <param name="menuEntriesSeparation">Separation between the menu entries.</param>
        public NewGameScreen(string name, int menuEntriesSeparation)
        {
            GameGraphicsDevice = EngineManager.GameGraphicsDevice;

            Name = name;

            TransitionOnTime  = TimeSpan.FromSeconds(0.5f);
            TransitionOffTime = TimeSpan.FromSeconds(0.5f);

            _menuEntriesSeparation = menuEntriesSeparation;
            _menuEntrySize         = ScreenManager.FontEntries.MeasureString("Example");
            _initialPosition       = new Vector2(50f, (GameSettings.DefaultInstance.ResolutionHeight / 2) -
                                                 (((_menuEntrySize.Y * 2) + TextureManager.GetTexture("EasyDifficult").BaseTexture.Height +
                                                   (_menuEntriesSeparation * 2)) / 2));
            _currentPosition = _initialPosition;

            _selectedEnd       = false;
            _selectedDifficult = 0;
            _selectedOption    = false;

            _model = new DrawableModel((GameModel)ModelManager.GetModel("AnimatedMonster"),
                                       new Vector3(12.5f, 10, 0), new Vector3(0, MathHelper.ToRadians(180), 0), Vector3.One * 10f, 0);

            _animation = new ObjectAnimation(Vector3.Zero, Vector3.Zero,
                                             _model.Rotation, _model.Rotation + new Vector3(MathHelper.TwoPi, 0, 0),
                                             TimeSpan.FromSeconds(5f), true);
        }
Esempio n. 6
0
 public MoveModel1(DrawableModel model, GameModel gameModel, Game1 game, EGGEditor eggEditor)
 {
     InitializeComponent();
     this.model     = model;
     this.gameModel = gameModel;
     this.game      = game;
     this.eggEditor = eggEditor;
 }
Esempio n. 7
0
        public void DrawableModelMaterialTest()
        {
            Test(() =>
            {
                BuildModel("dude.fbx");
                RunTheBuild();

                var dude = new DrawableModel(Content.Load <Model>("dude"));

                Assert.IsInstanceOfType(dude.Material, typeof(SkinnedMaterial));
                Assert.AreEqual(true, dude.IsAnimated);
                Assert.AreEqual(true, dude.IsSkinned);
                Assert.AreEqual(1, dude.Alpha);
                Assert.AreEqual(1, dude.Animations.Animations.Count);
                Assert.AreEqual(true, dude.LightingEnabled);
                Assert.AreEqual(true, dude.CastShadow);
                Assert.AreEqual(false, dude.ReceiveShadow);
                Assert.AreEqual(true, dude.Visible);

                Assert.IsTrue(dude.ModelParts.Count > 1);
                foreach (var modelPart in dude.ModelParts)
                {
                    Assert.IsInstanceOfType(modelPart.Material, typeof(SkinnedMaterial));
                    Assert.AreNotEqual(dude.Material, modelPart.Material);
                }

                // Change material
                dude.Material = new BasicMaterial(GraphicsDevice)
                {
                    Alpha = 0.5f
                };
                foreach (var modelPart in dude.ModelParts)
                {
                    Assert.IsInstanceOfType(modelPart.Material, typeof(BasicMaterial));
                    Assert.AreNotEqual(dude.Material, modelPart.Material);
                    Assert.AreEqual(0.5f, ((BasicMaterial)modelPart.Material).Alpha);
                }

                // Set material to null
                dude.Material = null;
                Assert.IsInstanceOfType(dude.Material, typeof(SkinnedMaterial));
                foreach (var modelPart in dude.ModelParts)
                {
                    Assert.IsInstanceOfType(modelPart.Material, typeof(SkinnedMaterial));
                    Assert.AreNotEqual(dude.Material, modelPart.Material);
                }

                // Change part material
                dude.ModelParts[0].Material = new BasicMaterial(GraphicsDevice);
                for (int i = 1; i < dude.ModelParts.Count; i++)
                {
                    var modelPart = dude.ModelParts[i];
                    Assert.IsInstanceOfType(modelPart.Material, typeof(SkinnedMaterial));
                    Assert.AreNotEqual(dude.Material, modelPart.Material);
                }
                Assert.IsInstanceOfType(dude.ModelParts[0].Material, typeof(BasicMaterial));
            });
        }
Esempio n. 8
0
        /// <summary>
        /// Distribute the models between the child nodes.
        /// </summary>
        /// <param name="type">Type of the node.</param>
        /// <param name="model">Model to be distributed.</param>
        private void Distribute(NodeType type, DrawableModel model)
        {
            Vector3 position = model.Position;

            if (position.Y > _center.Y)         // UP
            {
                if (position.Z < _center.Z)     // FORWARD
                {
                    if (position.X < _center.X) // LEFT
                    {
                        _childList[1].AddModel(type, model);
                    }
                    else                        // RIGHT
                    {
                        _childList[0].AddModel(type, model);
                    }
                }
                else                            // BACKWARD
                {
                    if (position.X < _center.X) // LEFT
                    {
                        _childList[3].AddModel(type, model);
                    }
                    else                        // RIGHT
                    {
                        _childList[2].AddModel(type, model);
                    }
                }
            }
            else                                // DOWN
            {
                if (position.Z < _center.Z)     // FORWARD
                {
                    if (position.X < _center.X) // LEFT
                    {
                        _childList[5].AddModel(type, model);
                    }
                    else                        // RIGHT
                    {
                        _childList[4].AddModel(type, model);
                    }
                }
                else                            // BACKWARD
                {
                    if (position.X < _center.X) // LEFT
                    {
                        _childList[7].AddModel(type, model);
                    }
                    else                        // RIGHT
                    {
                        _childList[6].AddModel(type, model);
                    }
                }
            }
        }
Esempio n. 9
0
        public static bool CoarseCheck(DrawableModel model1, DrawableModel model2)
        {
            BoundingSphere origSphere1 = (BoundingSphere)model1.Model.Tag;
            BoundingSphere sphere1     = XNAUtils.TransformBoundingSphere(origSphere1, model1.WorldMatrix);

            BoundingSphere origSphere2 = (BoundingSphere)model2.Model.Tag;
            BoundingSphere sphere2     = XNAUtils.TransformBoundingSphere(origSphere2, model2.WorldMatrix);

            bool collision = sphere1.Intersects(sphere2);

            return(collision);
        }
Esempio n. 10
0
        /// <summary>
        /// Constructor of the <c>Gun</c> class.
        /// </summary>
        /// <param name="modelName">Name of the model that represents the gun.</param>
        /// <param name="gunType">Type of the ammo of the gun.</param>
        /// <param name="player">Reference to the player.</param>
        /// <param name="attack">Attack made by the gun.</param>
        /// <param name="maxAmmo">Max ammo stored by the gun.</param>
        public Gun(string modelName, ShotType gunType, Player player, int attack, int maxAmmo)
        {
            _player = player;

            _gunType = gunType;

            _attack      = attack;
            _currentAmmo = maxAmmo;
            _maxAmmo     = maxAmmo;

            _model = new DrawableModel((GameModel)ModelManager.GetModel(modelName),
                                       _player.Position, _player.Rotation, _player.Scale, 0);
        }
Esempio n. 11
0
 private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (deletion == false)
     {
         DrawableModel item      = (DrawableModel)listBox1.SelectedItem;
         MoveModel1    moveModel = new MoveModel1(item, new GameModel(), game, this);
         moveModel.Show();
     }
     else
     {
         deletion = true;
     }
 }
Esempio n. 12
0
 private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
 {
     if (treeView1.SelectedNode.Text == "Player1")
     {
         string        name      = game.GetName();
         DrawableModel newModel  = new DrawableModel(game.Content.Load <Model>(name), Matrix.Identity);
         GameModel     gameModel = new GameModel();
         game.models.Add(newModel);
         MoveModel1 moveModel = new MoveModel1(newModel, gameModel, game, this);
         moveModel.Show();
         listBox1.Items.Add(newModel);
         propertyGrid1.SelectedObject = newModel;
     }
 }
Esempio n. 13
0
        public DrawableModel findModel(int modelID)
        {
            DrawableModel dModel = null;

            for (int index = 0; index < modelList.Count; index++)
            {
                if (modelList[index].ModelID == modelID)
                {
                    dModel = modelList[index];
                    return(dModel);
                }
            }
            return(null);
        }
Esempio n. 14
0
        private void Distribute(DrawableModel dModel)
        {
            Vector3 position = dModel.Position;

            if (position.Y > center.Y)          //Up
            {
                if (position.Z < center.Z)      //Forward
                {
                    if (position.X < center.X)  //Left
                    {
                        nodeUFL.AddDrawableModel(dModel);
                    }
                    else                        //Right
                    {
                        nodeUFR.AddDrawableModel(dModel);
                    }
                }
                else                            //Back
                if (position.X < center.X)      //Left
                {
                    nodeUBL.AddDrawableModel(dModel);
                }
                else                            //Right
                {
                    nodeUBR.AddDrawableModel(dModel);
                }
            }
            else                                //Down
            if (position.Z < center.Z)          //Forward
            {
                if (position.X < center.X)      //Left
                {
                    nodeDFL.AddDrawableModel(dModel);
                }
                else                            //Right
                {
                    nodeDFR.AddDrawableModel(dModel);
                }
            }
            else                                //Back
            if (position.X < center.X)          //Left
            {
                nodeDBL.AddDrawableModel(dModel);
            }
            else                                //Right
            {
                nodeDBR.AddDrawableModel(dModel);
            }
        }
Esempio n. 15
0
 private void LoadLevel(SerializeUtils <LevelData> levelData)
 {
     models.Clear();
     foreach (GameModel model in levelData.Data.models)
     {
         string        name      = GetName();
         Model         modelType = Content.Load <Model>(name);
         DrawableModel newModel  = new DrawableModel(modelType, Matrix.Identity);
         newModel.Position = model.position;
         models.Add(newModel);
         form.AddToListBox(newModel);
         form.Prop_ChangeSelected(newModel);
     }
     form.IncrementProgressBar(50);
 }
Esempio n. 16
0
        public DrawableModel RemoveDrawableModel(int modelID)
        {
            DrawableModel dModel = findModel(modelID);
            int           child  = 0;

            if (null != dModel)
            {
                modelList.Remove(dModel);
            }

            while ((dModel == null) && (child < childList.Count))
            {
                dModel = childList[child++].RemoveDrawableModel(modelID);
            }

            return(dModel);
        }
Esempio n. 17
0
        private bool isFlyingOutOfBoundry(DrawableModel model)
        {
            int     FLYING_OUT_ZONE = 500;
            Vector3 modelPosition   = model.Position;
            float   modelXDirection = model.Direction.X;
            float   modelZDirection = model.Direction.Z;

            float boundryInX = (modelXDirection > 0) ? boundryRight : boundryLeft;
            float boundryInZ = (modelZDirection > 0) ? boundryNear : boundryFar;

            if (Math.Abs(modelPosition.X - boundryInX) <= FLYING_OUT_ZONE)
            {
                return(true);
            }
            if (Math.Abs(modelPosition.Z - boundryInZ) <= FLYING_OUT_ZONE)
            {
                return(true);
            }
            return(false);
        }
Esempio n. 18
0
        private void playerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            progressBar1.Show();
            progressBar1.Select();
            progressBar1.Step = 50;
            string        name      = game.GetName();
            Model         model     = game.Content.Load <Model>(name);
            GameModel     gameModel = new GameModel();
            DrawableModel newModel  = new DrawableModel(model, Matrix.Identity);

            progressBar1.PerformStep();
            game.models.Add(newModel);
            game.Add(gameModel);
            MoveModel1 moveModel = new MoveModel1(newModel, gameModel, game, this);

            moveModel.Show();
            listBox1.Items.Add(newModel);
            propertyGrid1.SelectedObject = newModel;
            progressBar1.PerformStep();
            progressBar1.Value = 0;
        }
Esempio n. 19
0
        /// <summary>
        /// Add a new model to the OcTree structure, creating a new node if it
        /// is necessary.
        /// </summary>
        /// <param name="model">Reference to the model to be added.</param>
        /// <param name="position">Position of the model.</param>
        /// <param name="rotation">Rotation of the mode.</param>
        /// <param name="scale">Scale of the model.</param>
        /// <returns>true if the model was added, false otherwise.</returns>
        public int AddModel(GameModel model, Vector3 position, Vector3 rotation, Vector3 scale)
        {
            OcTreeNode node = SearchNode(position);

            DrawableModel newModel = new DrawableModel(model, position, rotation, scale, _modelsStoredInQuadTree++);
            NodeType      type     = NodeType.None;

            if (newModel.Model.FileName == "Content/Models/CubeBaseFrontStaircase2-1")
            {
                if (rotation.X == MathHelper.ToRadians(270))
                {
                    type = NodeType.Staircase1Up;
                }
                else
                {
                    type = NodeType.Staircase1Down;
                }
            }
            else if (newModel.Model.FileName == "Content/Models/CubeBaseFrontStaircase2-2")
            {
                if (rotation.X == MathHelper.ToRadians(270))
                {
                    type = NodeType.Staircase2Up;
                }
                else
                {
                    type = NodeType.Staircase2Down;
                }
            }
            else if (newModel.Model.FileName == "Content/Models/CubeBaseFrontLadder")
            {
                type = NodeType.Ladder;
            }
            else if (newModel.Model.FileName.Contains("Door"))
            {
                type = NodeType.Door;
            }

            return(node.AddModel(type, newModel));
        }
Esempio n. 20
0
        private void AddDrawableModel(DrawableModel dModel)
        {
            if (childList.Count == 0)
            {
                modelList.Add(dModel);

                bool maxObjectsReached = (modelList.Count > maxObjectsInNode);
                bool minSizeNotReached = (size > minSize);
                if (maxObjectsReached && minSizeNotReached)
                {
                    CreateChildNodes();
                    foreach (DrawableModel currentDModel in modelList)
                    {
                        Distribute(currentDModel);
                    }
                    modelList.Clear();
                }
            }
            else
            {
                Distribute(dModel);
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Remove a model that exists in the <c>OcTree</c> structure.
        /// </summary>
        /// <param name="modelID">Identifier of the model.</param>
        /// <returns>true if the model was removed, false otherwise.</returns>
        public DrawableModel RemoveModel(int modelID)
        {
            OcTreeNode node = SearchNode(modelID);

            if (node != null)
            {
                DrawableModel model = null;
                for (int i = 0; i < node.ModelList.Count; i++)
                {
                    if (node.ModelList[i].Value.ModelID == modelID)
                    {
                        model = node.ModelList[i].Value;
                        node.ModelList.Remove(node.ModelList[i]);
                    }
                }

                return(model);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 22
0
 public void GetUpdatedModels(ref List <DrawableModel> models)
 {
     if (modelList.Count > 0)
     {
         for (int i = 0; i < modelList.Count; i++)
         {
             DrawableModel deletedModel = modelList[i];
             modelList.RemoveAt(i);
             i--;
             deletedModel.Update();
             if (!IsModelOutOfOctree(deletedModel))
             {
                 models.Add(deletedModel);
             }
         }
     }
     else
     {
         foreach (OcTreeNode node in childList)
         {
             node.GetUpdatedModels(ref models);
         }
     }
 }
Esempio n. 23
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            levelData.models = new List <GameModel>();
            //levelData.positions = new List<Vector3>();
            camera         = new FPSCamera(GraphicsDevice.Viewport);
            FPS_Counter_On = config.SettingGroups["DebugFeatures"].Settings["FPSCounterOn"].GetValueAsBool();

            string name = config.SettingGroups["Filenames"].Settings["person"].GetValueAsString();

            person1 = new DrawableModel(Content.Load <Model>(name), Matrix.Identity);

            name    = config.SettingGroups["Filenames"].Settings["terrain"].GetValueAsString();
            terrain = new Model();
            terrain = Content.Load <Model>(name);

            sky = Content.Load <Sky>("Models\\sky1");
            // Comment this to remove the framerate counter
            if (FPS_Counter_On == true)
            {
                Components.Add(new FrameRateCounter(this));
            }

            base.Initialize();
        }
Esempio n. 24
0
 public void Prop_ChangeSelected(DrawableModel model)
 {
     propertyGrid1.SelectedObject = model;
 }
Esempio n. 25
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            _font = Content.Load<SpriteFont>(@"Fonts\TestFont");

            // TODO: use this.Content to load your game content here
            _imageKK = Content.Load<Texture2D>(@"Images\KK");
            var imageFloor = Content.Load<Texture2D>(@"Images\FloorWoodLight");
            var imageBox = Content.Load<Texture2D>(@"Images\BoxSides");
            var imageBall = Content.Load<Texture2D>(@"Images\football");
            var imageSpikyBall = Content.Load<Texture2D>(@"Images\spiky");

            _levelSearch = new Search3DSimple<FacetRef>();

            var model = new KModel();
            model.TexCoordsAreInPixels = false;
            int size = 100;
            model.AddQuad(
                model.AddVertex(new Vector3(-size, -size, 0)),
                model.AddVertex(new Vector3(size, -size, 0)),
                model.AddVertex(new Vector3(-size, size, 0)),
                model.AddVertex(new Vector3(size, size, 0)),
                new Rectangle(0, 0, 10, 10));
            _drawableKK = new DrawableModel(model, imageFloor, GraphicsDevice, false);
            ModelSearch.AddModel(_levelSearch, model);

            model = new KModel();
            var boxes = new List<Vector3>
            {
                new Vector3(1, 1, 0), new Vector3(2, 1, 0), new Vector3(2, 1, 1), new Vector3(2, 1, 2),
                new Vector3(3, 1, 0), new Vector3(3, 1, 1), new Vector3(3, 1, 2),
                new Vector3(-2, 1, 0), new Vector3(-2, 1, 1),
                new Vector3(-3, -3, 0), new Vector3(-3, -3, 1), new Vector3(-3, -3, 2), new Vector3(-3, -3, 3),
                new Vector3(-3, -6, 0), new Vector3(-3, -6, 1), new Vector3(-3, -6, 2), new Vector3(-3, -6, 3),
                new Vector3(-3, -4, 3), new Vector3(-3, -5, 3),
            };
            for (int j = 0; j < 5; j++)
                for (int i = -20; i < 20; i++)
                {
                    //boxes.Add(new Vector3(i, -20, j));
                    boxes.Add(new Vector3(-20, i + 1, j));
                    boxes.Add(new Vector3(i + 1, 20, j));
                    boxes.Add(new Vector3(20, i, j));
                }
            foreach (var corner in boxes)
                model.AddBox(new BoundingBox(corner, corner + new Vector3(1, 1, 1)), new Rectangle(0, 128, 225, 225), false);
            /*            model.AddBox(new BoundingBox(new Vector3(3, 3, 1), new Vector3(5, 5, 3)), new Rectangle(0, 0, 64, 64), true);
                        model.AddBox(new BoundingBox(new Vector3(-5, -5, 1), new Vector3(-3, -3, 3)), new Rectangle(0, 0, 64, 64), true); */
            model.AddBox(new BoundingBox(new Vector3(2, -5, 0), new Vector3(2, -5, 0) + new Vector3(2.5f, 2.5f, 2.5f)), new Rectangle(0, 128, 225, 225), false);
            _drawableBox = new DrawableModel(model, imageBox, GraphicsDevice, false);
            ModelSearch.AddModel(_levelSearch, model);

            model = GeometricalPrimitives.CreateBall(2, new Rectangle(0, 0, 1, 1));
            model.TexCoordsAreInPixels = false;
            _drawableBall = new DrawableModel(model, imageBall, GraphicsDevice, true);

            model = GeometricalPrimitives.CreateSpikyBall(3, 0.2f, new Rectangle(0, 0, 1, 1));
            model.TexCoordsAreInPixels = false;
            _drawableSpikyBall = new DrawableModel(model, imageSpikyBall, GraphicsDevice, true);

            SceneRenderer.EnableShadows(GraphicsDevice, Content.Load<Effect>(@"Shaders\ShadowCasting"), 4, 2048);

            InitLights();
        }
Esempio n. 26
0
        public static JObject Deamon_GetModelData(DrawableModel model)
        {
            var data = new JObject()
            {
                ["shaderMapping"] = new JArray(),
                ["geometries"]    = new JArray()
            };

            var jShaderMapping = (JArray)data["shaderMapping"];
            var jGeometries    = (JArray)data["geometries"];

            for (int i = 0; i < model.ShaderMapping.Count; i++)
            {
                jShaderMapping.Add(model.ShaderMapping[i].Value);
            }

            for (int i = 0; i < model.Geometries.Count; i++)
            {
                var geometry = model.Geometries[i];

                var jGeometry = new JObject()
                {
                    ["vertices"]  = new JArray(),
                    ["triangles"] = new JArray()
                };

                var jTriangles = (JArray)jGeometry["triangles"];
                var jVertices  = (JArray)jGeometry["vertices"];

                var vertices = new List <Vector3>();

                var vb = geometry.VertexData.VertexBytes;
                var vs = geometry.VertexData.VertexStride;
                var vc = geometry.VertexData.VertexCount;

                for (int j = 0; j < vc; j++)
                {
                    var jVertex = new JObject()
                    {
                        ["type"] = geometry.VertexData.VertexType.ToString()
                    };

                    switch (geometry.VertexData.VertexType)
                    {
                    case VertexType.Default:
                    {
                        var vt = MetaUtils.ConvertData <VertexTypeDefault>(vb, j * vs);

                        vertices.Add(vt.Position);

                        jVertex["position"] = new JObject()
                        {
                            ["x"] = vt.Position.X, ["y"] = vt.Position.Y, ["z"] = vt.Position.Z
                        };
                        jVertex["normal"] = new JObject()
                        {
                            ["x"] = vt.Normal.X, ["y"] = vt.Normal.Y, ["z"] = vt.Normal.Z
                        };
                        jVertex["colour"]   = vt.Colour;
                        jVertex["texCoord"] = new JObject()
                        {
                            ["x"] = vt.Texcoord.X, ["y"] = vt.Texcoord.Y
                        };

                        break;
                    }

                    case VertexType.DefaultEx:
                    {
                        var vt = MetaUtils.ConvertData <VertexTypeDefaultEx>(vb, j * vs);

                        vertices.Add(vt.Position);

                        jVertex["position"] = new JObject()
                        {
                            ["x"] = vt.Position.X, ["y"] = vt.Position.Y, ["z"] = vt.Position.Z
                        };
                        jVertex["normal"] = new JObject()
                        {
                            ["x"] = vt.Normal.X, ["y"] = vt.Normal.Y, ["z"] = vt.Normal.Z
                        };
                        jVertex["colour"]   = vt.Colour;
                        jVertex["texCoord"] = new JObject()
                        {
                            ["x"] = vt.Texcoord.X, ["y"] = vt.Texcoord.Y
                        };

                        break;
                    }

                    case VertexType.PNCCT:
                    {
                        var vt = MetaUtils.ConvertData <VertexTypePNCCT>(vb, j * vs);

                        vertices.Add(vt.Position);

                        jVertex["position"] = new JObject()
                        {
                            ["x"] = vt.Position.X, ["y"] = vt.Position.Y, ["z"] = vt.Position.Z
                        };
                        jVertex["normal"] = new JObject()
                        {
                            ["x"] = vt.Normal.X, ["y"] = vt.Normal.Y, ["z"] = vt.Normal.Z
                        };
                        jVertex["texCoord"] = new JObject()
                        {
                            ["x"] = vt.Texcoord.X, ["y"] = vt.Texcoord.Y
                        };

                        break;
                    }

                    case VertexType.PNCCTTTT:
                    {
                        var vt = MetaUtils.ConvertData <VertexTypePNCCTTTT>(vb, j * vs);

                        vertices.Add(vt.Position);

                        jVertex["position"] = new JObject()
                        {
                            ["x"] = vt.Position.X, ["y"] = vt.Position.Y, ["z"] = vt.Position.Z
                        };
                        jVertex["normal"] = new JObject()
                        {
                            ["x"] = vt.Normal.X, ["y"] = vt.Normal.Y, ["z"] = vt.Normal.Z
                        };

                        break;
                    }

                    case VertexType.PNCTTTX:
                    {
                        var vt = MetaUtils.ConvertData <VertexTypePNCTTTX>(vb, j * vs);

                        vertices.Add(vt.Position);

                        jVertex["position"] = new JObject()
                        {
                            ["x"] = vt.Position.X, ["y"] = vt.Position.Y, ["z"] = vt.Position.Z
                        };
                        jVertex["normal"] = new JObject()
                        {
                            ["x"] = vt.Normal.X, ["y"] = vt.Normal.Y, ["z"] = vt.Normal.Z
                        };
                        jVertex["colour"] = vt.Colour;

                        break;
                    }

                    case VertexType.PNCTTTX_2:
                    {
                        var vt = MetaUtils.ConvertData <VertexTypePNCTTTX_2>(vb, j * vs);

                        vertices.Add(vt.Position);

                        jVertex["position"] = new JObject()
                        {
                            ["x"] = vt.Position.X, ["y"] = vt.Position.Y, ["z"] = vt.Position.Z
                        };
                        jVertex["normal"] = new JObject()
                        {
                            ["x"] = vt.Normal.X, ["y"] = vt.Normal.Y, ["z"] = vt.Normal.Z
                        };
                        jVertex["colour"] = vt.Colour;

                        break;
                    }

                    case VertexType.PNCTTTX_3:
                    {
                        var vt = MetaUtils.ConvertData <VertexTypePNCTTTX_3>(vb, j * vs);

                        vertices.Add(vt.Position);

                        jVertex["position"] = new JObject()
                        {
                            ["x"] = vt.Position.X, ["y"] = vt.Position.Y, ["z"] = vt.Position.Z
                        };
                        jVertex["normal"] = new JObject()
                        {
                            ["x"] = vt.Normal.X, ["y"] = vt.Normal.Y, ["z"] = vt.Normal.Z
                        };
                        jVertex["colour"] = vt.Colour;

                        break;
                    }

                    case VertexType.PNCTTX:
                    {
                        var vt = MetaUtils.ConvertData <VertexTypePNCTTX>(vb, j * vs);

                        vertices.Add(vt.Position);

                        jVertex["position"] = new JObject()
                        {
                            ["x"] = vt.Position.X, ["y"] = vt.Position.Y, ["z"] = vt.Position.Z
                        };
                        jVertex["normal"] = new JObject()
                        {
                            ["x"] = vt.Normal.X, ["y"] = vt.Normal.Y, ["z"] = vt.Normal.Z
                        };
                        jVertex["colour"] = vt.Colour;

                        break;
                    }

                    case VertexType.PNCCTTX:
                    {
                        var vt = MetaUtils.ConvertData <VertexTypePNCCTTX>(vb, j * vs);

                        vertices.Add(vt.Position);

                        jVertex["position"] = new JObject()
                        {
                            ["x"] = vt.Position.X, ["y"] = vt.Position.Y, ["z"] = vt.Position.Z
                        };
                        jVertex["normal"] = new JObject()
                        {
                            ["x"] = vt.Normal.X, ["y"] = vt.Normal.Y, ["z"] = vt.Normal.Z
                        };

                        break;
                    }

                    case VertexType.PNCCTTX_2:
                    {
                        var vt = MetaUtils.ConvertData <VertexTypePNCCTTX_2>(vb, j * vs);

                        vertices.Add(vt.Position);

                        jVertex["position"] = new JObject()
                        {
                            ["x"] = vt.Position.X, ["y"] = vt.Position.Y, ["z"] = vt.Position.Z
                        };
                        jVertex["normal"] = new JObject()
                        {
                            ["x"] = vt.Normal.X, ["y"] = vt.Normal.Y, ["z"] = vt.Normal.Z
                        };

                        break;
                    }

                    case VertexType.PNCCTTTX:
                    {
                        var vt = MetaUtils.ConvertData <VertexTypePNCCTTTX>(vb, j * vs);

                        vertices.Add(vt.Position);

                        jVertex["position"] = new JObject()
                        {
                            ["x"] = vt.Position.X, ["y"] = vt.Position.Y, ["z"] = vt.Position.Z
                        };
                        jVertex["normal"] = new JObject()
                        {
                            ["x"] = vt.Normal.X, ["y"] = vt.Normal.Y, ["z"] = vt.Normal.Z
                        };

                        break;
                    }

                    case VertexType.PNCCTT:
                    {
                        var vt = MetaUtils.ConvertData <VertexTypePNCCTT>(vb, j * vs);

                        vertices.Add(vt.Position);

                        jVertex["position"] = new JObject()
                        {
                            ["x"] = vt.Position.X, ["y"] = vt.Position.Y, ["z"] = vt.Position.Z
                        };
                        jVertex["normal"] = new JObject()
                        {
                            ["x"] = vt.Normal.X, ["y"] = vt.Normal.Y, ["z"] = vt.Normal.Z
                        };

                        break;
                    }

                    case VertexType.PNCCTX:
                    {
                        var vt = MetaUtils.ConvertData <VertexTypePNCCTX>(vb, j * vs);

                        vertices.Add(vt.Position);

                        jVertex["position"] = new JObject()
                        {
                            ["x"] = vt.Position.X, ["y"] = vt.Position.Y, ["z"] = vt.Position.Z
                        };
                        jVertex["normal"] = new JObject()
                        {
                            ["x"] = vt.Normal.X, ["y"] = vt.Normal.Y, ["z"] = vt.Normal.Z
                        };
                        jVertex["texCoord"] = new JObject()
                        {
                            ["x"] = vt.Texcoord.X, ["y"] = vt.Texcoord.Y
                        };

                        break;
                    }

                    case VertexType.PTT:
                    {
                        var vt = MetaUtils.ConvertData <VertexTypePTT>(vb, j * vs);

                        vertices.Add(vt.Position);

                        jVertex["position"] = new JObject()
                        {
                            ["x"] = vt.Position.X, ["y"] = vt.Position.Y, ["z"] = vt.Position.Z
                        };;

                        break;
                    }

                    case VertexType.PNC:
                    {
                        var vt = MetaUtils.ConvertData <VertexTypePNC>(vb, j * vs);

                        vertices.Add(vt.Position);

                        jVertex["position"] = new JObject()
                        {
                            ["x"] = vt.Position.X, ["y"] = vt.Position.Y, ["z"] = vt.Position.Z
                        };
                        jVertex["normal"] = new JObject()
                        {
                            ["x"] = vt.Normal.X, ["y"] = vt.Normal.Y, ["z"] = vt.Normal.Z
                        };
                        jVertex["colour"] = vt.Colour;

                        break;
                    }

                    case VertexType.PCT:
                    {
                        var vt = MetaUtils.ConvertData <VertexTypePCT>(vb, j * vs);

                        vertices.Add(vt.Position);

                        jVertex["position"] = new JObject()
                        {
                            ["x"] = vt.Position.X, ["y"] = vt.Position.Y, ["z"] = vt.Position.Z
                        };
                        jVertex["colour"]   = vt.Colour;
                        jVertex["texCoord"] = new JObject()
                        {
                            ["x"] = vt.Texcoord.X, ["y"] = vt.Texcoord.Y
                        };

                        break;
                    }

                    case VertexType.PT:
                    {
                        var vt = MetaUtils.ConvertData <VertexTypePT>(vb, j * vs);

                        vertices.Add(vt.Position);

                        jVertex["position"] = new JObject()
                        {
                            ["x"] = vt.Position.X, ["y"] = vt.Position.Y, ["z"] = vt.Position.Z
                        };
                        jVertex["texCoord"] = new JObject()
                        {
                            ["x"] = vt.Texcoord.X, ["y"] = vt.Texcoord.Y
                        };

                        break;
                    }

                    default: break;
                    }

                    jVertices.Add(jVertex);
                }

                for (int j = 0; j < geometry.IndexBuffer.Indices.Count - 2; j += 3)
                {
                    var triangle = new JArray()
                    {
                        geometry.IndexBuffer.Indices[j + 0].Value,
                        geometry.IndexBuffer.Indices[j + 1].Value,
                        geometry.IndexBuffer.Indices[j + 2].Value
                    };

                    jTriangles.Add(triangle);
                }

                jGeometries.Add(jGeometry);
            }

            return(data);
        }
Esempio n. 27
0
        private FbxModel TryConvertModel(FbxNode mnode)
        {
            FbxNode geonode  = null;
            var     matnodes = new List <FbxNode>();

            foreach (var cnode in mnode.Connections)
            {
                if (cnode == null)
                {
                    continue;
                }
                switch (cnode.Name)
                {
                case "Geometry":
                    geonode = cnode;
                    break;

                case "Material":
                    matnodes.Add(cnode);
                    break;
                }
            }

            if (geonode == null)
            {
                return(null);
            }
            if (matnodes.Count == 0)
            {
                return(null);                                 //need atleast one material...
            }
            var fnEdges   = geonode["Edges"]?.Value as int[]; //do we need this? maybe for collision/navmesh
            var fnVerts   = geonode["Vertices"]?.Value as double[];
            var fnIndices = geonode["PolygonVertexIndex"]?.Value as int[];

            if ((fnVerts == null) || (fnIndices == null))
            {
                return(null);
            }                //no mesh data.. abort!

            var fnNormals   = new List <FbxNode>();
            var fnBinormals = new List <FbxNode>();
            var fnTangents  = new List <FbxNode>();
            var fnTexcoords = new List <FbxNode>();
            var fnColours   = new List <FbxNode>();
            var fnMaterials = new List <FbxNode>();

            foreach (var cnode in geonode.Nodes)
            {
                if (cnode == null)
                {
                    continue;
                }
                switch (cnode.Name)
                {
                case "LayerElementNormal": fnNormals.Add(cnode); break;

                case "LayerElementBinormal": fnBinormals.Add(cnode); break;

                case "LayerElementTangent": fnTangents.Add(cnode); break;

                case "LayerElementUV": fnTexcoords.Add(cnode); break;

                case "LayerElementColor": fnColours.Add(cnode); break;

                case "LayerElementMaterial": fnMaterials.Add(cnode); break;

                case "LayerElementSmoothing": break; //ignore currently

                case "Layer": break;                 //ignore- merge all layers data instead
                }
            }

            var nNormals   = fnNormals.Count;
            var nBinormals = fnBinormals.Count;
            var nTangents  = fnTangents.Count;
            var nTexcoords = fnTexcoords.Count;
            var nColours   = fnColours.Count;
            var nMaterials = fnMaterials.Count;

            var fPolys      = new List <FbxPolygon>();
            var fPolyVerts  = new List <FbxVertex>();
            var fPolysByMat = new List <FbxPolygon> [matnodes.Count];

            foreach (var fnIndex in fnIndices) //build the polygons.
            {
                var pVert = new FbxVertex();
                pVert.Position  = GetVector3FromDoubleArray(fnVerts, (fnIndex < 0) ? (-fnIndex - 1) : fnIndex);
                pVert.Normals   = nNormals > 0 ? new Vector3[nNormals] : null;
                pVert.Binormals = nBinormals > 0 ? new Vector3[nBinormals] : null;
                pVert.Tangents  = nTangents > 0 ? new Vector3[nTangents] : null;
                pVert.Texcoords = nTexcoords > 0 ? new Vector2[nTexcoords] : null;
                pVert.Colours   = nColours > 0 ? new Vector4[nColours] : null;
                fPolyVerts.Add(pVert);
                if (fnIndex < 0) //yeah because negative index means end of polygon...
                {
                    var fPoly = new FbxPolygon();
                    fPoly.Vertices  = fPolyVerts.ToArray();
                    fPoly.Materials = nMaterials > 0 ? new FbxNode[nMaterials] : null;
                    fPolyVerts.Clear();
                    fPolys.Add(fPoly);
                    if (fPoly.Vertices.Length > 3)
                    {
                    }   //more than 3 vertices in this poly! will need to split it into triangles!! but do it later since all poly verts are needed for next steps
                }
            }

            for (int i = 0; i < nNormals; i++)
            {
                var fnNorms = fnNormals[i];
                var arNorms = fnNorms["Normals"]?.Value as double[];
                var aiNorms = fnNorms["NormalIndex"]?.Value as int[];
                if (!IsByPolygonVertexMapType(fnNorms))
                {
                    continue;
                }
                var indexed = IsIndexToDirectRefType(fnNorms);
                if (indexed && (aiNorms == null))
                {
                    continue;
                }             //need the index array if it's IndexToDirect!
                int j = 0;
                foreach (var fPoly in fPolys)
                {
                    foreach (var fVert in fPoly.Vertices)
                    {
                        var ai = indexed ? aiNorms[j] : j;
                        fVert.Normals[i] = GetVector3FromDoubleArray(arNorms, ai);
                        j++;
                    }
                }
            }
            for (int i = 0; i < nBinormals; i++)
            {
                var fnBinorms = fnBinormals[i];
                var arBinorms = fnBinorms["Binormals"]?.Value as double[];
                var aiBinorms = fnBinorms["BinormalIndex"]?.Value as int[];
                if (!IsByPolygonVertexMapType(fnBinorms))
                {
                    continue;
                }
                var indexed = IsIndexToDirectRefType(fnBinorms);
                if (indexed && (aiBinorms == null))
                {
                    continue;
                }             //need the index array if it's IndexToDirect!
                int j = 0;
                foreach (var fPoly in fPolys)
                {
                    foreach (var fVert in fPoly.Vertices)
                    {
                        var ai = indexed ? aiBinorms[j] : j;
                        fVert.Binormals[i] = GetVector3FromDoubleArray(arBinorms, ai);
                        j++;
                    }
                }
            }
            for (int i = 0; i < nTangents; i++)
            {
                var fnTangs = fnTangents[i];
                var arTangs = fnTangs["Tangents"]?.Value as double[];
                var aiTangs = fnTangs["TangentIndex"]?.Value as int[];
                if (!IsByPolygonVertexMapType(fnTangs))
                {
                    continue;
                }
                var indexed = IsIndexToDirectRefType(fnTangs);
                if (indexed && (aiTangs == null))
                {
                    continue;
                }             //need the index array if it's IndexToDirect!
                int j = 0;
                foreach (var fPoly in fPolys)
                {
                    foreach (var fVert in fPoly.Vertices)
                    {
                        var ai = indexed ? aiTangs[j] : j;
                        fVert.Tangents[i] = GetVector3FromDoubleArray(arTangs, ai);
                        j++;
                    }
                }
            }
            for (int i = 0; i < nTexcoords; i++)
            {
                var fnTexcs = fnTexcoords[i];
                var arTexcs = fnTexcs["UV"]?.Value as double[];
                var aiTexcs = fnTexcs["UVIndex"]?.Value as int[];
                if (!IsByPolygonVertexMapType(fnTexcs))
                {
                    continue;
                }
                var indexed = IsIndexToDirectRefType(fnTexcs);
                if (indexed && (aiTexcs == null))
                {
                    continue;
                }             //need the index array if it's IndexToDirect!
                int j = 0;
                foreach (var fPoly in fPolys)
                {
                    foreach (var fVert in fPoly.Vertices)
                    {
                        var ai = indexed ? aiTexcs[j] : j;
                        var tc = GetVector2FromDoubleArray(arTexcs, ai);
                        fVert.Texcoords[i] = InvertTexcoordV ? new Vector2(tc.X, -tc.Y) : tc;//whyyyy
                        j++;
                    }
                }
            }
            for (int i = 0; i < nColours; i++)
            {
                var fnCols = fnColours[i];
                var arCols = fnCols["Colors"]?.Value as double[];
                var aiCols = fnCols["ColorIndex"]?.Value as int[];
                if (!IsByPolygonVertexMapType(fnCols))
                {
                    continue;
                }
                var indexed = IsIndexToDirectRefType(fnCols);
                if (indexed && (aiCols == null))
                {
                    continue;
                }             //need the index array if it's IndexToDirect!
                int j = 0;
                foreach (var fPoly in fPolys)
                {
                    foreach (var fVert in fPoly.Vertices)
                    {
                        var ai = indexed ? aiCols[j] : j;
                        fVert.Colours[i] = GetVector4FromDoubleArray(arCols, ai);
                        j++;
                    }
                }
            }
            for (int i = 0; i < nMaterials; i++)
            {
                var fnMats  = fnMaterials[i];
                var arMats  = fnMats["Materials"]?.Value as int[];
                var mapType = fnMats["MappingInformationType"]?.Value as string;
                var refType = fnMats["ReferenceInformationType"]?.Value as string;
                var allSame = false;
                switch (mapType)
                {
                case "ByPolygon": break;

                case "AllSame": allSame = true; break;

                default:
                    continue;
                }
                switch (refType)
                {
                case "IndexToDirect": break;

                default:
                    continue;
                }
                for (int j = 0; j < fPolys.Count; j++)
                {
                    var fPoly = fPolys[j];
                    var iMat  = allSame ? arMats[0] : arMats[j];
                    fPoly.Materials[i] = matnodes[iMat];

                    //group all the polygons by material...
                    var matPolys = fPolysByMat[iMat];
                    if (matPolys == null)
                    {
                        matPolys          = new List <FbxPolygon>();
                        fPolysByMat[iMat] = matPolys;
                    }
                    matPolys.Add(fPoly);
                }
            }



            var dModel = new DrawableModel();

            var dGeoms     = new List <DrawableGeometry>();
            var dGeomAABBs = new List <AABB_s>();
            var dModelAABB = new AABB_s();

            for (int i = 0; i < fPolysByMat.Length; i++)
            {
                AABB_s dGeomAABB;
                var    dGeom = TryConvertGeometry(fPolysByMat[i], matnodes[i], out dGeomAABB);
                if (dGeom != null)
                {
                    dGeoms.Add(dGeom);
                    dGeomAABBs.Add(dGeomAABB);
                }
            }
            if (dGeomAABBs.Count > 1)//need to include whole model AABB first, if more than one geometry..
            {
                var dGeomAABBs2 = new List <AABB_s>();
                dModelAABB.Min = new Vector4(float.MaxValue);
                dModelAABB.Max = new Vector4(float.MinValue);
                foreach (var aabb in dGeomAABBs)
                {
                    dModelAABB.Min = Vector4.Min(dModelAABB.Min, aabb.Min);
                    dModelAABB.Max = Vector4.Max(dModelAABB.Max, aabb.Max);
                }
                dGeomAABBs2.Add(dModelAABB);
                dGeomAABBs2.AddRange(dGeomAABBs);
                dGeomAABBs = dGeomAABBs2;
            }


            dModel.VFT              = 1080101496; //is this needed?
            dModel.Unknown_4h       = 1;
            dModel.RenderMaskFlags  = 0x00FF;     //GIMS "Mask"
            dModel.Geometries       = dGeoms.ToArray();
            dModel.GeometriesCount1 = (ushort)dGeoms.Count;
            dModel.GeometriesCount2 = (ushort)dGeoms.Count;
            dModel.GeometriesCount3 = (ushort)dGeoms.Count;
            dModel.BoundsData       = dGeomAABBs.ToArray();
            //shader mappings array will be added when adding models to drawable.



            var fModel = new FbxModel();

            fModel.Name  = (mnode.Properties.Count > 1) ? (mnode.Properties[1] as string)?.Replace("Model::", "") : null;
            fModel.Node  = mnode;
            fModel.Model = dModel;

            return(fModel);
        }
        /// <summary>
        /// Load and calculate all the necessary content of the game.
        /// </summary>
        public override void Load()
        {
            base.Load();

            // Set the camera
            CameraManager.AddCamera(CameraManager.DefaultCamera,
                                    new TargetCamera(new Vector3(0, 0, 70), new Vector3(0, 0, 0)));
            CameraManager.SetActiveCamera(CameraManager.DefaultCamera);

            // Create the post processing elements
            renderCapture = new RenderCapture();
            postProcessor = new GaussianBlur(10);//2f);

            // Load all needed textures
            TextureManager.AddTexture(backgroundTexture, new GameTexture("Content/Textures/MenuBackground", true));
            TextureManager.AddTexture("DeadBackground", new GameTexture("Content/Textures/DeadBackground", true));
            TextureManager.AddTexture("SeparationBar", new GameTexture("Content/Textures/SeparationBar", true));
            TextureManager.AddTexture("SelectedMenuEntry", new GameTexture("Content/Textures/SelectedMenuEntry", true));
            TextureManager.AddTexture("DummyTexture15T", new GameTexture("Content/Textures/DummyTexture15T", true));
            TextureManager.AddTexture("DummyTexture", new GameTexture("Content/Textures/DummyTexture", true));
            TextureManager.AddTexture("BarTexture", new GameTexture("Content/Textures/BarTexture", true));
            TextureManager.AddTexture("DialogBackground", new GameTexture("Content/Textures/DialogBackground", true));
            TextureManager.AddTexture("EasyDifficult", new GameTexture("Content/Textures/EasyDifficult", true));
            TextureManager.AddTexture("NormalDifficult", new GameTexture("Content/Textures/NormalDifficult", true));
            TextureManager.AddTexture("HardDifficult", new GameTexture("Content/Textures/HardDifficult", true));
            TextureManager.AddTexture("LoadingBackground", new GameTexture("Content/Textures/LoadingBackground", true));

            // Load all needed sounds
            SoundManager.AddSound("Menu", new GameSound("Content/Sounds/Menu", true));
            SoundManager.GetSound("Menu").Volume = GameSettings.DefaultInstance.MusicVolume;
            SoundManager.GetSound("Menu").Play(true, true);

            SoundManager.AddSound("MenuSelect", new GameSound("Content/Sounds/MenuSelect", true));
            SoundManager.GetSound("MenuSelect").Volume = GameSettings.DefaultInstance.SoundVolume;
            SoundManager.AddSound("MenuAccept", new GameSound("Content/Sounds/MenuAccept", true));
            SoundManager.GetSound("MenuAccept").Volume = GameSettings.DefaultInstance.SoundVolume;

            // Load all needed models
            ModelManager.AddModel(spacecraftModel, new GameModel("Content/Models/Spacecraft", true));
            ModelManager.AddModel("AnimatedMonster", new GameModel("Content/Models/AnimatedMonster", true));
            _model = new DrawableModel((GameModel)ModelManager.GetModel(spacecraftModel),
                                       new Vector3(-10, 20, 0), new Vector3(-45, 120, 0), new Vector3(1.25f, 1.25f, 1.25f), 0);

            // Fix the animation elements
            _animationRing1 = new ObjectAnimation(Vector3.Zero, Vector3.Zero,
                                                  _model.Rotation, _model.Rotation + new Vector3(0, MathHelper.TwoPi, 0),
                                                  TimeSpan.FromSeconds(1f), true);

            _animationRing2 = new ObjectAnimation(Vector3.Zero, Vector3.Zero,
                                                  _model.Rotation + new Vector3(0, MathHelper.Pi, 0),
                                                  _model.Rotation + new Vector3(0, MathHelper.TwoPi + MathHelper.Pi, 0),
                                                  TimeSpan.FromSeconds(1f), true);

            _individualTransformations.Add("polySurface26",
                                           Matrix.CreateScale(_animationRing1.Scale) *
                                           Matrix.CreateRotationX(_animationRing1.Rotation.X) *
                                           Matrix.CreateRotationY(_animationRing1.Rotation.Y) *
                                           Matrix.CreateRotationZ(_animationRing1.Rotation.Z) *
                                           Matrix.CreateTranslation(_animationRing1.Position));

            _individualTransformations.Add("polySurface27",
                                           Matrix.CreateScale(_animationRing2.Scale) *
                                           Matrix.CreateRotationX(_animationRing2.Rotation.X) *
                                           Matrix.CreateRotationY(_animationRing2.Rotation.Y) *
                                           Matrix.CreateRotationZ(_animationRing2.Rotation.Z) *
                                           Matrix.CreateTranslation(_animationRing2.Position));
        }
Esempio n. 29
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            imageKK = Content.Load<Texture2D>(@"Images\KK");
            imageBox = Content.Load<Texture2D>(@"Images\BoxSides");
            imageBall = Content.Load<Texture2D>(@"Images\football");
            imageSpikyBall = Content.Load<Texture2D>(@"Images\spiky");

            var model = new KModel();
            model.TexCoordsAreInPixels = false;
            for (int i = 3; i < 100; i = i+2)
            {
                var z = -i / 2;
                model.AddQuad(
                    model.AddVertex(new Vector3(-i, -i, z)),
                    model.AddVertex(new Vector3(i, -i, z)),
                    model.AddVertex(new Vector3(-i, i, z)),
                    model.AddVertex(new Vector3(i, i, z)),
                    new Rectangle(0, 0, 1, 1));
            }
            _drawableKK = new DrawableModel(model, imageKK, GraphicsDevice, false);

            model = new KModel();
            model.AddBox(new BoundingBox(new Vector3(-5, 3, 1), new Vector3(-3, 5, 3)), new Rectangle(0, 64, 64, 64), true);
            model.AddBox(new BoundingBox(new Vector3(3, 3, 1), new Vector3(5, 5, 3)), new Rectangle(0, 0, 64, 64), true);
            model.AddBox(new BoundingBox(new Vector3(-5, -5, 1), new Vector3(-3, -3, 3)), new Rectangle(0, 0, 64, 64), true);

            for (int i = 0; i < 11; i++)
                for (int j = 0; j < 11; j++)
                    if (i % 2 == 0 || j % 2 == 0)
                    {
                        model.AddBox(new BoundingBox(new Vector3(3 + 2*i, -5 - 2*j, 1), new Vector3(5 + 2*i, -3 - 2*j, 3)), new Rectangle(0, 128, 225, 225), false);
                    }
            _drawableBox = new DrawableModel(model, imageBox, GraphicsDevice, false);

            model = GeometricalPrimitives.CreateBall(2, new Rectangle(0, 0, 1, 1));
            model.TexCoordsAreInPixels = false;
            _drawableBall = new DrawableModel(model, imageBall, GraphicsDevice, true);

            model = GeometricalPrimitives.CreateSpikyBall(3, 0.2f, new Rectangle(0, 0, 1, 1));
            model.TexCoordsAreInPixels = false;
            _drawableSpikyBall = new DrawableModel(model, imageSpikyBall, GraphicsDevice, true);

            // Matrix test
            var mat = Matrix.CreateTranslation(1, 2, 3);
            Console.WriteLine(mat);
        }
Esempio n. 30
0
 public void AddToListBox(DrawableModel model)
 {
     listBox1.Items.Add(model);
 }
Esempio n. 31
0
 public void DeleteFromListBox(DrawableModel model)
 {
     listBox1.Items.Remove(model);
 }
Esempio n. 32
0
 public void UpdatePropertyGrid(DrawableModel model)
 {
     propertyGrid1.Update();
 }