Exemple #1
0
 public World(HeightMap Terrain, PlayerEntity pe)
 {
     _terrain = Terrain;
     _pe = pe;
     _ents = new LinkedList<IEntity>();
     _ents.AddFirst(pe);
     _buggersKilled = 0;
 }
 public HeightmapRenderer(WorldRenderer In, HeightMap For)
 {
     _in = In;
     _for = For;
     _p2d = new Perlin2D(100);
     _renchunks = new RenderChunk[NUM_RENDER_CHUNKS] [];
     for (int i = 0; i < _renchunks.Length; ++i) {
         _renchunks [i] = new RenderChunk[NUM_RENDER_CHUNKS];
     }
 }
Exemple #3
0
 public void Init(MainClass Main)
 {
     //XXX:Make this better...
     _in = Main;
     //Game world setup.
     HeightMap map = new HeightMap("res/map.map");
     _pe = new PlayerEntity(new Vector3(0, map [0, 0] + 10, 0));
     _world = new World(map, _pe);
     //GFX setup
     _camOffset = new Vector3();
     _ren = new WorldRenderer(Main, _world, (float)Main.Width / Main.Height);
     GL.ClearColor(OpenTK.Graphics.Color4.SkyBlue);
     GL.Enable(EnableCap.DepthTest);
     GL.Enable(EnableCap.Fog);
     float[] fogColor = {
         OpenTK.Graphics.Color4.SkyBlue.R,
         OpenTK.Graphics.Color4.SkyBlue.G,
         OpenTK.Graphics.Color4.SkyBlue.B,
         OpenTK.Graphics.Color4.SkyBlue.A
     };
     GL.Fog(FogParameter.FogColor, fogColor);
     GL.Fog(FogParameter.FogEnd, WorldRenderer.MAX_DEPTH);
     GL.Fog(FogParameter.FogStart, 10f);
     //Input setup.
     System.Windows.Forms.Cursor.Hide();
     Main.Mouse.ButtonDown += ButtonDown;
     Main.Mouse.ButtonUp += ButtonUp;
     Main.Mouse.Move += MouseMove;
     //2D draw setup
     _rects = new LinkedList<Rect2D>();
     _healthbar = new Bitmap(100, 50);
     _healthbarRect = new Rect2D(_healthbar, 0, 0, 100, 50);
     _rects.AddFirst(_healthbarRect);
     //INput setup
     _in.MouseCaptureNeeded = true;
     _in.CaptureMouse = true;
 }
Exemple #4
0
        public RenderChunk(HeightMap In, Perlin2D PColor, int CX, int CY, int Level)
        {
            _lod = Level;

            _cx = CX;
            _cy = CY;

            List<Vertex> verts = new List<Vertex>();
            List<Vertex> wverts = new List<Vertex>();
            List<ushort> indicies = new List<ushort>();
            List<ushort> windicies = new List<ushort>();
            BuildGround(In, verts, indicies);
            if (_water)
                BuildWater(In, wverts, windicies);

            uint[] tmp = new uint[2];
            GL.GenBuffers(2, tmp);
            _buffer = tmp [0];
            _wbuffer = tmp [1];
            //Vertex Data
            GL.BindBuffer(BufferTarget.ArrayBuffer, _buffer);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(verts.Count * Vertex.Size), verts.ToArray(), BufferUsageHint.StaticDraw);
            //Water vertex data
            GL.BindBuffer(BufferTarget.ArrayBuffer, _wbuffer);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(wverts.Count * Vertex.Size), wverts.ToArray(), BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

            #region Texture generation
            _tex = GLUtil.CreateTexture(GenGroundTexture(PColor));
            if (_water)
                _wtex = GLUtil.CreateTexture(GenWaterTexture(PColor));
            #endregion

            _indicies = indicies.ToArray();
            if (_water)
                _windicies = windicies.ToArray();
        }
Exemple #5
0
 void BuildWater(HeightMap In, List<Vertex> V, List<ushort> I)
 {
     int basex = _cx * CHUNK_SIZE;
     int basey = _cy * CHUNK_SIZE;
     int itr = CHUNK_SIZE / _lod;
     for (int x = 0; x < CHUNK_SIZE + itr; x += itr) {
         int xp = basex + x;
         for (int y = 0; y < CHUNK_SIZE + itr; y += itr) {
             int yp = basey + y;
             Vertex tmp = new Vertex();
             SetPos(ref tmp, xp, 0, yp);
             tmp.TexCoord.X = x / (float)CHUNK_SIZE;
             tmp.TexCoord.Y = y / (float)CHUNK_SIZE;
             tmp.Color = new Vector4(1, 1, 1, 1);
             V.Add(tmp);
         }
     }
     for (int x = 0; x < _lod; ++x) {
         for (int y = 0; y < _lod; ++y) {
             int vi = x + y * (_lod + 1);
             I.Add((ushort)(vi + _lod + 1));
             I.Add((ushort)(vi));
             I.Add((ushort)(vi + 1));
             I.Add((ushort)(vi + _lod + 1));
             I.Add((ushort)(vi + 1));
             I.Add((ushort)(vi + _lod + 2));
         }
     }
 }