Exemplo n.º 1
0
        /// <summary>
        /// Load the model and texture of the JBoundingSphere if we want to render it in the world.
        /// </summary>
        /// <param name="loader"></param>
        public void LoadSphereModel(JLoader loader)
        {
            SphereModelData = JObjFileLoader.LoadObj(SphereModelPath);
            SphereModel     = loader.LoadToVAO(SphereModelData.Vertices, SphereModelData.TextureCoords, SphereModelData.Normals, SphereModelData.Indices);
            JModelTexture texture = new JModelTexture(loader.loadTexture(SphereTexturePathUnselected));

            SphereTexturedModel = new JTexturedModel(SphereModel, texture);
            SphereEntity        = new JEntity(SphereTexturedModel, new Vector3(50, 0, -50), new Vector3(0, 0, 1), 0.5f);
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public List <JEntity> GenerateTrees()
        {
            Console.WriteLine("Generating Trees...");

            List <JEntity> TreeEntities = new List <JEntity>();

            string         TreeTexturePath   = JFileUtils.GetPathToResFile("Tree\\tree_texture_green_brown.png");
            string         TreeModelPath     = JFileUtils.GetPathToResFile("Tree\\tree.obj");
            JModelData     TreeModelData     = JObjFileLoader.LoadObj(TreeModelPath);
            JRawModel      TreeModel         = Loader.LoadToVAO(TreeModelData.Vertices, TreeModelData.TextureCoords, TreeModelData.Normals, TreeModelData.Indices);
            JModelTexture  TreeTexture       = new JModelTexture(Loader.loadTexture(TreeTexturePath));
            JTexturedModel TreeTexturedModel = new JTexturedModel(TreeModel, TreeTexture);
            Random         r = new Random();

            for (int i = 0; i < 200; i++)
            {
                float posX = (float)r.NextDouble() * 800;
                float posZ = -(float)r.NextDouble() * 800;
                float posY = Terrain.GetHeightOfTerrain(posX, posZ);

                while (posY < WaterTile.Height)
                {
                    posX = (float)r.NextDouble() * 800;
                    posZ = -(float)r.NextDouble() * 800;
                    posY = Terrain.GetHeightOfTerrain(posX, posZ);
                }

                Vector3 orientation = new Vector3((float)r.NextDouble(), 0, (float)r.NextDouble());
                orientation.NormalizeFast();

                JEntity entity = new JEntity(TreeTexturedModel, new Vector3(posX, posY, posZ), orientation, 0.25f);
                TreeEntities.Add(entity);
            }

            return(TreeEntities);
        }