Beispiel #1
0
        public void Render(Dictionary <TextureModel, List <Entity> > entities, List <Terrain> terrainList)
        {
            this.depthFrameBuffer.BindFrameBuffer();
            this.shader.Start();
            var enumerator = entities.GetEnumerator();

            //Render Entities
            while (enumerator.MoveNext())
            {
                TextureModel model = enumerator.Current.Key;
                PrepareTextureModel(model.RawModel);
                List <Entity> batch = enumerator.Current.Value;
                for (int i = 0; i < batch.Count; i++)
                {
                    PrepareInstance(batch[i]);
                    Gl.DrawElements(PrimitiveType.Triangles, model.RawModel.VertexCount, DrawElementsType.UnsignedInt, IntPtr.Zero);
                }
                Unbind();
            }

            //Render Terrain
            for (int i = 0; i < terrainList.Count; i++)
            {
                Terrain terrain = terrainList[i];
                PrepareTextureModel(terrain.Model);
                PrepareInstance(terrain);
                Gl.DrawElements(PrimitiveType.Triangles, terrain.Model.VertexCount, DrawElementsType.UnsignedInt, IntPtr.Zero);
                Unbind();
            }

            this.shader.Stop();
            this.depthFrameBuffer.UnbindCurrentFrameBuffer();
        }
Beispiel #2
0
 public Entity(TextureModel textureModel, Vertex3f position, float rotationX, float rotationY, float rotationZ, float scale)
 {
     this.textureModel = textureModel;
     this.position     = position;
     this.rotationX    = rotationX;
     this.rotationY    = rotationY;
     this.rotationZ    = rotationZ;
     this.scale        = scale;
 }
Beispiel #3
0
        private void LoadPlayer(Loader loader, List <Entity> entities)
        {
            ModelTexture personTexture = new ModelTexture(loader.LoadTexture("playerTexture"));

            personTexture.ShineDamper  = 30f;
            personTexture.Reflectivity = 0.3f;
            TextureModel personModel = new TextureModel(OBJLoader.LoadObjModel("person", loader), personTexture);

            this.player = new Player(personModel, new Vertex3f(0, 5, 0), 0, 100, 0, 0.6f);
            entities.Add(this.player);
        }
Beispiel #4
0
        public void ProcessEntity(Entity entity)
        {
            TextureModel entityModel = entity.TextureModel;

            if (this.entities.ContainsKey(entityModel))
            {
                this.entities[entityModel].Add(entity);
            }
            else
            {
                List <Entity> newBatch = new List <Entity>();
                newBatch.Add(entity);
                this.entities.Add(entityModel, newBatch);
            }
        }
Beispiel #5
0
        public void Render(Dictionary <TextureModel, List <Entity> > entities)
        {
            var enumerator = entities.GetEnumerator();

            while (enumerator.MoveNext())
            {
                TextureModel model = enumerator.Current.Key;
                PrepareTextureModel(model);
                List <Entity> batch = enumerator.Current.Value;
                for (int i = 0; i < batch.Count; i++)
                {
                    PrepareInstance(batch[i]);
                    Gl.DrawElements(PrimitiveType.Triangles, model.RawModel.VertexCount, DrawElementsType.UnsignedInt, IntPtr.Zero);
                }

                Unbind();
            }
        }
Beispiel #6
0
        private void PrepareTextureModel(TextureModel model)
        {
            RawModel rawModel = model.RawModel;

            Gl.BindVertexArray(rawModel.VaoID);
            Gl.EnableVertexAttribArray(0); // Position
            Gl.EnableVertexAttribArray(1); // UV 매핑 데이터 Slot 활성
            Gl.EnableVertexAttribArray(2); // Normal

            ModelTexture texture = model.Texture;

            if (texture.HasTransparency)
            {
                MasterRenderer.DisableCulling();
            }

            this.shader.LoadFakeLighting(texture.UseFakeLigihting);
            this.shader.LoadShineVariables(texture.ShineDamper, texture.Reflectivity);
            Gl.ActiveTexture(TextureUnit.Texture0);
            Gl.BindTexture(TextureTarget.Texture2d, texture.TextureID);
        }
Beispiel #7
0
 public Player(TextureModel textureModel, Vertex3f position, float rotationX, float rotationY, float rotationZ, float scale)
     : base(textureModel, position, rotationX, rotationY, rotationZ, scale)
 {
 }
Beispiel #8
0
        private void LoadEntities(Terrain terrain, List <Entity> entities, Loader loader)
        {
            //Tree
            ModelTexture lowPolyTree = new ModelTexture(loader.LoadTexture("bobbleTree"));

            lowPolyTree.ShineDamper  = 30f;
            lowPolyTree.Reflectivity = 0.3f;
            TextureModel lowPolyTreeModel = new TextureModel(OBJLoader.LoadObjModel("bobbleTree", loader), lowPolyTree);

            //Tree
            ModelTexture treeTexture = new ModelTexture(loader.LoadTexture("pine"));

            treeTexture.ShineDamper  = 30f;
            treeTexture.Reflectivity = 0.3f;
            TextureModel treeModel = new TextureModel(OBJLoader.LoadObjModel("pine", loader), treeTexture);

            //Grass
            ModelTexture grassTexture = new ModelTexture(loader.LoadTexture("grassTexture"));

            grassTexture.HasTransparency  = true;
            grassTexture.UseFakeLigihting = true;
            TextureModel grassModel = new TextureModel(OBJLoader.LoadObjModel("grassModel", loader), grassTexture);


            ModelTexture flowerTexture = new ModelTexture(loader.LoadTexture("flower"));

            flowerTexture.HasTransparency  = true;
            flowerTexture.UseFakeLigihting = true;
            TextureModel flowerModel = new TextureModel(OBJLoader.LoadObjModel("grassModel", loader), flowerTexture);

            //Fern
            ModelTexture fernTextureAltas = new ModelTexture(loader.LoadTexture("fernAtlas"));

            fernTextureAltas.NumberOfRows = 2;
            TextureModel fernModel = new TextureModel(OBJLoader.LoadObjModel("fern", loader), fernTextureAltas);

            //Lemp
            ModelTexture lampTexture = new ModelTexture(loader.LoadTexture("lamp"));

            lampTexture.UseFakeLigihting = true;
            lampTexture.Reflectivity     = 0.3f;
            lampTexture.ShineDamper      = 30f;

            TextureModel lampModel = new TextureModel(OBJLoader.LoadObjModel("lamp", loader), lampTexture);

            entities.Add(new Entity(lampModel, GetHeightPosition(terrain, 185, 0f, -293), 0, 0, 0, 1));
            entities.Add(new Entity(lampModel, GetHeightPosition(terrain, 370, 0f, -300), 0, 0, 0, 1));
            entities.Add(new Entity(lampModel, GetHeightPosition(terrain, 293, 0f, -305), 0, 0, 0, 1));

            float x = 100f;
            float z = -50f;
            float y = terrain.GetHeightOfTerrain(x, z);

            entities.Add(new Entity(treeModel, new Vertex3f(x, y, z), 0, 0, 0, 1f));

            x = 100f;
            z = -130f;
            y = terrain.GetHeightOfTerrain(x, z);
            entities.Add(new Entity(treeModel, new Vertex3f(x, y, z), 0, 0, 0, 1.5f));

            x = 50f;
            z = -105f;
            y = terrain.GetHeightOfTerrain(x, z);
            entities.Add(new Entity(treeModel, new Vertex3f(x, y, z), 0, 0, 0, 1.3f));

            x = 70f;
            z = -130f;
            y = terrain.GetHeightOfTerrain(x, z);
            entities.Add(new Entity(treeModel, new Vertex3f(x, y, z), 0, 0, 0, 1f));

            Random random = new Random();

            for (int i = 0; i < 10; i++)
            {
                if (i % 2 == 0)
                {
                    entities.Add(new Entity(fernModel, random.Next(0, 3), GetRadomPosition(terrain, random, Terrain.SIZE, -Terrain.SIZE), 0, 0, 0, 0.6f));
                }

                if (i % 5 == 0)
                {
                    entities.Add(new Entity(lowPolyTreeModel, GetRadomPosition(terrain, random, Terrain.SIZE, -Terrain.SIZE), 0, 0, 0, 1f));
                }

                entities.Add(new Entity(treeModel, GetRadomPosition(terrain, random, Terrain.SIZE, -Terrain.SIZE), 0, 0, 0, 1f));
                entities.Add(new Entity(grassModel, GetRadomPosition(terrain, random, Terrain.SIZE, -Terrain.SIZE), 0, 0, 0, 1));
                entities.Add(new Entity(flowerModel, GetRadomPosition(terrain, random, Terrain.SIZE, -Terrain.SIZE), 0, 0, 0, 1));
            }
        }