예제 #1
0
        public void setEffects(BFModel model)
        {
            List<Texture2D> ltextures = new List<Texture2D>();
            foreach (ModelMesh mesh in model.model.Meshes)
            {
                foreach(Effect cureffect in mesh.Effects)
                {
                    try
                    {
                        ltextures.Add(cureffect.Parameters["Texture"].GetValueTexture2D());
                    }
                    catch(Exception ex)
                    {
                        return;
                    }
                }
            }

            foreach (ModelMesh mesh in model.model.Meshes)
            {
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    meshPart.Effect = effect.Clone();
                }
            }

            //now set up the textures of the model
            model.Textures = ltextures.ToArray();
        }
예제 #2
0
        public void draw(BFModel model,Matrix world,Matrix view,Matrix projection,
            string technique,Vector3 lightPos,float lightPow,float ambientPow)
        {
            Matrix[] modelTransformations = new Matrix[model.model.Bones.Count];
            model.model.CopyAbsoluteBoneTransformsTo(modelTransformations);
            int i = 0;
            foreach(ModelMesh mesh in model.model.Meshes)
            {
                foreach(Effect currentEffect in mesh.Effects)
                {
                    Matrix worldMatrix = modelTransformations[mesh.ParentBone.Index] * world;
                   // currentEffect.CurrentTechnique = effect.Techniques[technique];
                    currentEffect.Parameters["xWorldViewProjection"].SetValue(worldMatrix * view * projection);
                    currentEffect.Parameters["xTexture"].SetValue(model.Textures[i++]);
                    currentEffect.Parameters["xWorld"].SetValue(worldMatrix);

                    currentEffect.Parameters["xLightPos"].SetValue(lightPos);
                    currentEffect.Parameters["xLightPower"].SetValue(lightPow);
                    currentEffect.Parameters["xAmbient"].SetValue(ambientPow);
                }
                mesh.Draw();
            }
        }
예제 #3
0
        public bool loadRoom(string roomAddress, ContentManager content, Shader shader, GraphicsDevice device,string[] selectCombatants)
        {
            //load the menu
            Texture2D exit = content.Load<Texture2D>("Exit");
            Texture2D resume = content.Load<Texture2D>("Resume");

            Combatant.PauseMenu = new Menu(4, new Rectangle(
                parent.ScreenWidth / 2 - (exit.Width / 2),
                parent.ScreenHeight / 2 - (exit.Height / 2 * 2),
                exit.Width,
                exit.Height),
                resume, exit);
            hasWon = false;
            BFFileReader reader = new BFFileReader(roomAddress);
            reader.Open();

            Dictionary<string, RefModel> modelDefs = new Dictionary<string, RefModel>();
            string line;
            //read all of the info in the script
            #region room parser
            while ((line = reader.ReadLine()) != null)
            {
                string[] param = line.Split(' ');

                //read the param
                switch (param[0])
                {
                    case "ModelDef":
                        {
                            //add the new modelname to the hashtable
                            BFModel model = new BFModel();//***
                            model.model = content.Load<Model>(param[1]);
                            shader.setEffects(model);
                            //add the model to the hashtable of models
                            models.Add(param[1], model);
                            break;
                        }
                    case "Music":
                        {
                            //set music
                            music = content.Load<SoundEffect>(param[1]);
                            break;
                        }
                    case "Model":
                        {
                            string modelName = param[1];
                            RefModel refModel = new RefModel();
                            while ((line = reader.ReadLine()) != null && line != "}")
                            {
                                //keep reading into this modelRef
                                param = line.Split(' ');
                                switch (param[0])
                                {
                                    case "ModelID":
                                        {
                                            //set the model id of this ref mode
                                            refModel.ModelID = param[1];

                                            break;
                                        }
                                    case "CollideType":
                                        {
                                            switch (param[1].ToUpper())
                                            {
                                                case "AABB":
                                                    {
                                                        refModel.ORIGEN = new AABB();
                                                        refModel.CollisionType = Origen.Collision_Type.AABB;

                                                        break;
                                                    }
                                                case "NONE":
                                                    {
                                                        refModel.CollisionType = Origen.Collision_Type.NONE;
                                                        break;
                                                    }
                                                case "BC":
                                                    {
                                                        refModel.ORIGEN = new BC();
                                                        refModel.CollisionType = Origen.Collision_Type.BC;
                                                        break;
                                                    }
                                                case "BS":
                                                    {
                                                        refModel.ORIGEN = new BS();
                                                        refModel.CollisionType = Origen.Collision_Type.BS;
                                                        break;
                                                    }
                                            }
                                            break;
                                        }
                                    case "OrigenX":
                                        {
                                            refModel.X = float.Parse(param[1]);
                                            break;
                                        }
                                    case "OrigenY":
                                        {
                                            refModel.Y = float.Parse(param[1]);
                                            break;
                                        }
                                    case "OrigenZ":
                                        {
                                            refModel.Z = float.Parse(param[1]);
                                            break;
                                        }
                                    case "RotX":
                                        {
                                            refModel.RotX = float.Parse(param[1]);
                                            break;
                                        }
                                    case "RotY":
                                        {
                                            refModel.RotY = float.Parse(param[1]);
                                            break;
                                        }
                                    case "RotZ":
                                        {
                                            refModel.RotZ = float.Parse(param[1]);
                                            break;
                                        }
                                    case "HalfWidth":
                                        {
                                            refModel.HalfWidth = float.Parse(param[1]);
                                            break;
                                        }
                                    case "HalfHeight":
                                        {
                                            refModel.HalfHeight = float.Parse(param[1]);
                                            break;
                                        }
                                    case "HalfLength":
                                        {
                                            refModel.HalfLength = float.Parse(param[1]);
                                            break;
                                        }
                                    case "Radius":
                                        {
                                            refModel.Radius = float.Parse(param[1]);
                                            break;
                                        }
                                    case "TransX":
                                        {
                                            refModel.TransX = float.Parse(param[1]);
                                            break;
                                        }
                                    case "TransY":
                                        {
                                            refModel.TransY = float.Parse(param[1]);
                                            break;
                                        }
                                    case "TransZ":
                                        {
                                            refModel.TransZ = float.Parse(param[1]);
                                            break;
                                        }
                                }

                            }

                            refModel.updateMatrix();
                            //add the refmodel to the list of modelsDefs
                            modelDefs.Add(modelName, refModel);
                            break;
                        }

                    case "DrinkSpawner":
                        {
                            string modelID = "";
                            float X = 0, Y = 0, Z = 0, RotX = 0, RotY = 0, RotZ = 0,spawnTime = 0,drinkStrength = 0,
                                halfWidth = 0,halfLength = 0,halfHeight = 0,transX = 0,transY = 0,transZ = 0;
                            while ((line = reader.ReadLine()) != null && line != "}")
                            {
                                param = line.Split(' ');
                                switch (param[0])
                                {
                                    case "X":
                                        {
                                            X = float.Parse(param[1]);
                                            break;
                                        }
                                    case "Y":
                                        {
                                            Y = float.Parse(param[1]);
                                            break;
                                        }
                                    case "Z":
                                        {
                                            Z = float.Parse(param[1]);
                                            break;
                                        }
                                    case "RotX":
                                        {
                                            RotX = float.Parse(param[1]);
                                            break;
                                        }
                                    case "RotY":
                                        {
                                            RotY = float.Parse(param[1]);
                                            break;
                                        }
                                    case "RotZ":
                                        {
                                            RotZ = float.Parse(param[1]);
                                            break;
                                        }
                                    case "ModelID":
                                        {
                                            modelID = param[1];
                                            break;
                                        }
                                    case "SpawnTime":
                                        {
                                            spawnTime = float.Parse(param[1]);
                                            break;
                                        }
                                    case "DrinkStrength":
                                        {
                                            drinkStrength = float.Parse(param[1]);
                                            break;
                                        }
                                    case "HalfWidth":
                                        {
                                            halfWidth = float.Parse(param[1]);
                                            break;
                                        }
                                    case "HalfHeight":
                                        {
                                            halfHeight= float.Parse(param[1]);
                                            break;
                                        }
                                    case "HalfLength":
                                        {
                                            halfLength = float.Parse(param[1]);
                                            break;
                                        }
                                    case "TransX":
                                        {
                                            transX = float.Parse(param[1]);
                                            break;
                                        }
                                    case "TransZ":
                                        {
                                            transZ = float.Parse(param[1]);
                                            break;
                                        }
                                    case "TransY":
                                        {
                                            transY = float.Parse(param[1]);
                                            break;
                                        }

                                }

                            }

                            DrinkSpawner drinkSpawner = new DrinkSpawner();
                            drinkSpawner.CollisionType = Origen.Collision_Type.AABB;
                            drinkSpawner.ORIGEN = new AABB();
                            drinkSpawner.X = X;
                            drinkSpawner.Y = Y;
                            drinkSpawner.Z = Z;
                            drinkSpawner.StartX = X;
                            drinkSpawner.StartY = Y;
                            drinkSpawner.StartZ = Z;
                            drinkSpawner.DrinkStrength = drinkStrength;
                            drinkSpawner.HalfHeight = halfHeight;
                            drinkSpawner.HalfLength = halfLength;
                            drinkSpawner.HalfWidth = halfWidth;
                            drinkSpawner.ModelID = modelID;
                            drinkSpawner.RotX = RotX;
                            drinkSpawner.RotY = RotY;
                            drinkSpawner.RotZ = RotZ;
                            drinkSpawner.TransX = transX;
                            drinkSpawner.TransY = transY;
                            drinkSpawner.TransZ = transZ;
                            drinkSpawner.DrinkSpawnTime = spawnTime;
                            drinkSpawner.SpawnTime = spawnTime;
                            drinkSpawner.updateMatrix();
                            drinks.Add(drinkSpawner);
                            break;
                        }

                    case "ModelGroup":
                        {
                            List<string> includedModels = new List<string>();
                            float X = 0, Y = 0, Z = 0, RotX = 0, RotY = 0, RotZ = 0;
                            while ((line = reader.ReadLine()) != null && line != "}")
                            {
                                param = line.Split(' ');
                                switch (param[0])
                                {
                                    case "X":
                                        {
                                            X = float.Parse(param[1]);
                                            break;
                                        }
                                    case "Y":
                                        {
                                            Y = float.Parse(param[1]);
                                            break;
                                        }
                                    case "Z":
                                        {
                                            Z = float.Parse(param[1]);
                                            break;
                                        }
                                    case "RotX":
                                        {
                                            RotX = float.Parse(param[1]);
                                            break;
                                        }
                                    case "RotY":
                                        {
                                            RotY = float.Parse(param[1]);
                                            break;
                                        }
                                    case "RotZ":
                                        {
                                            RotZ = float.Parse(param[1]);
                                            break;
                                        }
                                    case "IncludeModel":
                                        {
                                            includedModels.Add(param[1]);
                                            break;
                                        }
                                }

                            }

                            //now add the models to the scenes models
                            foreach (string modelName in includedModels)
                            {
                                //load the model to copy the model data from
                                RefModel temp = (RefModel)modelDefs[modelName];
                                RefModel copy = new RefModel();
                                copy.ORIGEN = new AABB();
                                copy.ORIGEN.Type = Origen.Collision_Type.AABB;
                                copy.HalfHeight = temp.HalfHeight;
                                copy.HalfLength = temp.HalfLength;
                                copy.HalfWidth = temp.HalfWidth;
                                copy.X = temp.X + X;
                                copy.Y = temp.Y + Y;
                                copy.Z = temp.Z + Z;
                                copy.RotX = temp.RotX + RotX;
                                copy.RotY = temp.RotY + RotY;
                                copy.RotZ = temp.RotZ + RotZ;
                                copy.TransX = temp.TransX;
                                copy.TransY = temp.TransY;
                                copy.TransZ = temp.TransZ;
                                copy.ModelID = temp.ModelID;
                                copy.updateMatrix();
                                //add the copy
                                parts.Add(copy);
                            }
                            break;
                        }

                    case "XWidth":
                        {
                            xWidth = float.Parse(param[1]);
                            break;
                        }

                    case "YWidth":
                        {
                            yWidth = float.Parse(param[1]);
                            break;
                        }

                    case "ZWidth":
                        {
                            zWidth = float.Parse(param[1]);
                            break;
                        }
                    case "LeftWallTexture":
                        {
                            leftWallTex = content.Load<Texture2D>(param[1]);
                            break;
                        }
                    case "RightWallTexture":
                        {
                            rightWallTex = content.Load<Texture2D>(param[1]);
                            break;
                        }
                    case "FrontWallTexture":
                        {
                            frontWallTex = content.Load<Texture2D>(param[1]);
                            break;
                        }
                    case "BackWallTexture":
                        {
                            backWallTex = content.Load<Texture2D>(param[1]);
                            break;
                        }
                    case "CeilingTexture":
                        {
                            ceilingTex = content.Load<Texture2D>(param[1]);
                            break;
                        }
                    case "FloorTexture":
                        {
                            floorTex = content.Load<Texture2D>(param[1]);
                            break;
                        }

                    case "Light":
                        {
                            switch (param[1])
                            {
                                case "X":
                                    {
                                        lightPos.X = float.Parse(param[2]);
                                        break;
                                    }
                                case "Y":
                                    {
                                        lightPos.Y = float.Parse(param[2]);
                                        break;
                                    }
                                case "Z":
                                    {
                                        lightPos.Z = float.Parse(param[2]);
                                        break;
                                    }
                                case "Power":
                                    {
                                        lightPower = float.Parse(param[2]);
                                        break;
                                    }
                                case "Ambient":
                                    {
                                        ambientPower = float.Parse(param[2]);
                                        break;
                                    }

                            }
                            break;
                        }
                    case "FloorXDensity":
                        {
                            floorXDensity = float.Parse(param[1]);
                            break;
                        }
                    case "FloorYDensity":
                        {
                            floorYDensity = float.Parse(param[1]);
                            break;
                        }
                    case "WallXDensity":
                        {
                            wallXDensity = float.Parse(param[1]);
                            break;
                        }
                    case "WallYDensity":
                        {
                            wallYDensity = float.Parse(param[1]);
                            break;
                        }
                    case "BarX":
                        {
                            barX = float.Parse(param[1]);
                            break;
                        }
                    case "BarY":
                        {
                            barY = float.Parse(param[1]);
                            break;
                        }
                    case "BarWidth":
                        {
                            barWidth = float.Parse(param[1]);
                            break;
                        }

                }
            }
            #endregion
            //close the file
            reader.Close();

            //play the music if the music exists
            if (music != null)
            {
                instance = music.CreateInstance();
                instance.IsLooped = true;
                instance.Play();
            }

            winSong = content.Load<SoundEffect>("WinSong").CreateInstance();
            winSong.IsLooped = true;
            //set up the bounding box for the room

            //init the buffers
            initBuffers(device);

            bounds = new AABB(0, 0, 0, xWidth, yWidth, zWidth);
            //load the combatants after clearing the list of the old ones
            combatants.Clear();
            loadCombatants(content,selectCombatants,parent.NumOfPlayers);

            return true;
        }