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]; } }
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; }
public void RenderWater(WorldRenderer WR, float X, float Y) { Render(WR, X, Y, PASS_WATER); }
public void Render(WorldRenderer WR, float X, float Y) { Render(WR, X, Y, PASS_GROUND); }
void Render(WorldRenderer WR, float X, float Y, int Pass) { GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.ColorArray); GL.EnableClientState(ArrayCap.NormalArray); int mincx = Floor(X / CHUNK_SIZE) - VIEW_DIST; int mincy = Floor(Y / CHUNK_SIZE) - VIEW_DIST; for (int cx = mincx; cx < mincx + VIEW_DIST + VIEW_DIST + 1; ++cx) { for (int cy = mincy; cy < mincy + VIEW_DIST + VIEW_DIST + 1; ++cy) { if (InFrustrum(cx, cy)) { int cox = cx - mincx; int coy = cy - mincy; cox = Abs(cox - VIEW_DIST); coy = Abs(coy - VIEW_DIST); int d = 1;//(int)(Math.Sqrt(cox * cox + coy * coy)); int LOD = 32; LOD >>= d; if (LOD < 1) LOD = 1; int x = cx % NUM_RENDER_CHUNKS; int y = cy % NUM_RENDER_CHUNKS; if (x < 0) x += NUM_RENDER_CHUNKS; if (y < 0) y += NUM_RENDER_CHUNKS; if (_renchunks [x] [y] == null || _renchunks [x] [y].X != cx || _renchunks [x] [y].Y != cy || _renchunks [x] [y].LOD != LOD) _renchunks [x] [y] = new RenderChunk(_for, _p2d, cx, cy, LOD); switch (Pass) { case PASS_GROUND: _renchunks [x] [y].Render(WR); break; case PASS_WATER: _renchunks [x] [y].RenderWater(WR); break; default: throw new ArgumentException("Pass " + Pass + " out of range"); } } } } GL.DisableClientState(ArrayCap.VertexArray); GL.DisableClientState(ArrayCap.NormalArray); GL.DisableClientState(ArrayCap.ColorArray); }
public override void Render(WorldRenderer In) { In.PushMatrix(); const double angleoffset = 0.6; const float offsetscale = 0.1f; float sinyaw = (float)Math.Sin(-Yaw - angleoffset); float cosyaw = (float)Math.Cos(-Yaw - angleoffset); In.Translate(_pos.X - sinyaw * offsetscale, In.Pos.Y - 0.12f, _pos.Z - cosyaw * offsetscale); In.Rotate(Vector3.UnitY, -Yaw); const float arange = (float)(Math.PI * 0.01); const double afreq = Math.PI * 0.01; float swingX = (float)(Math.PI * 0.5 * Math.Sin(Math.PI * _swingFrame / SWING_FRAMES)); float swingZ = (float)(Math.PI * 0.5 * Math.Sin(Math.PI * _swingFrame / SWING_FRAMES)); In.Rotate(Vector3.UnitX, arange * (float)Math.Sin(afreq * In.GetFrame() + 2 * arange) - swingX); In.Rotate(Vector3.UnitZ, arange * (float)Math.Cos(afreq * In.GetFrame()) + swingZ); _sword.Render(In); In.PopMatrix(); }
public override void Render(WorldRenderer WR) { WR.PushMatrix(); WR.Translate(_pos.X, _pos.Y, _pos.Z); WR.PushMatrix(); WR.Rotate(Vector3.UnitY, Yaw); if (_runDeath) { int angleFrame = (_deathAnimFrame < DEATH_ANIM_FRAMES) ? _deathAnimFrame : DEATH_ANIM_FRAMES; float angle = (float)(Math.PI * Math.Sin(angleFrame / (2.0 * DEATH_ANIM_FRAMES) * Math.PI) * 0.5); WR.Rotate(Vector3.UnitX, angle); ++_deathAnimFrame; if (_deathAnimFrame > DEATH_SHOW_TIME) { Dead = true; } } if (_hurtFrames < HURT_SHOW_FRAMES) { ++_hurtFrames; WR.SetHighlight(2); } _mdl.Render(WR); WR.SetHighlight(1); WR.PopMatrix(); if (_runDeath) { WR.Translate(0, 3.5f, 0); WR.Rotate(Vector3.UnitX, (float)(Math.PI)); WR.Rotate(Vector3.UnitY, WR.Yaw); _quote.Second.Render(); } WR.PopMatrix(); }
public abstract void Render(WorldRenderer In);
public void RenderWater(WorldRenderer WR) { if (_water) { //Bind texture. WR.BindTexture(_wtex); //Bind vertex data GL.BindBuffer(BufferTarget.ArrayBuffer, _wbuffer); GL.InterleavedArrays(InterleavedArrayFormat.T2fC4fN3fV3f, 0, (IntPtr)0); GL.DrawElements(BeginMode.Triangles, _windicies.Length, DrawElementsType.UnsignedShort, _windicies); //Unbind buffer GL.BindBuffer(BufferTarget.ArrayBuffer, 0); } }
public void Render(WorldRenderer WR) { //Bind texture. WR.BindTexture(_texid); //Bind vertex data GL.BindBuffer(BufferTarget.ArrayBuffer, _buffs [VERT_INDEX]); GL.InterleavedArrays(InterleavedArrayFormat.T2fC4fN3fV3f, 0, (IntPtr)0); GL.DrawArrays(BeginMode.Triangles, 0, _numverts); //Unbind buffer GL.BindBuffer(BufferTarget.ArrayBuffer, 0); }