private void BuildItemVertexBuffer(int itemId, string name) { t.StartDrawingTiledQuads(); Vector4 c1 = new Vector4(1, 1, 1, 1); t.ArrayIndex = indexMap[name]; Vector3 normal = new Vector3(0, 0, 1); float s = 1f; t.AddVertexWithColor(new Vector4(0f, 0f, 0, 1.0f), c1, normal); t.AddVertexWithColor(new Vector4(0f, s, 0, 1.0f), c1, normal); t.AddVertexWithColor(new Vector4(s, s, 0, 1.0f), c1, normal); t.AddVertexWithColor(new Vector4(s, 0f, 0, 1.0f), c1, normal); itemVertexBuffers.Add(itemId, t.GetVertexBuffer()); }
internal void Build() { t.StartDrawingColoredQuads(); Vector4 c = entity.Color; Vector3 min = entity.AABB.Min; Vector3 max = entity.AABB.Max; Vector4[] v = new Vector4[] { new Vector4(min.X, min.Y, min.Z, 1), new Vector4(max.X, min.Y, min.Z, 1), new Vector4(max.X, min.Y, max.Z, 1), new Vector4(min.X, min.Y, max.Z, 1), new Vector4(min.X, max.Y, min.Z, 1), new Vector4(max.X, max.Y, min.Z, 1), new Vector4(max.X, max.Y, max.Z, 1), new Vector4(min.X, max.Y, max.Z, 1), }; // left t.AddVertexWithColor(v[0], c); t.AddVertexWithColor(v[4], c); t.AddVertexWithColor(v[7], c); t.AddVertexWithColor(v[3], c); //front t.AddVertexWithColor(v[3], c); t.AddVertexWithColor(v[7], c); t.AddVertexWithColor(v[6], c); t.AddVertexWithColor(v[2], c); //right t.AddVertexWithColor(v[2], c); t.AddVertexWithColor(v[6], c); t.AddVertexWithColor(v[5], c); t.AddVertexWithColor(v[1], c); //back t.AddVertexWithColor(v[1], c); t.AddVertexWithColor(v[5], c); t.AddVertexWithColor(v[4], c); t.AddVertexWithColor(v[0], c); //top t.AddVertexWithColor(v[4], c); t.AddVertexWithColor(v[5], c); t.AddVertexWithColor(v[6], c); t.AddVertexWithColor(v[7], c); //bottom t.AddVertexWithColor(v[0], c); t.AddVertexWithColor(v[3], c); t.AddVertexWithColor(v[2], c); t.AddVertexWithColor(v[1], c); buffer = t.GetVertexBuffer(); }
public HeadUpDisplay() { player = World.Instance.Player; for (int i = 0; i < labels.Length; i++) { labels[i] = new Label(); labels[i].Color = new Vector4(1f, 1f, 0.2f, 1); } t.StartDrawingColoredQuads(); Vector4 Color1 = new Vector4(0.1f, 0.1f, 0.1f, 1); t.AddVertexWithColor(new Vector4(0, 0, 0f, 1f), Color1); t.AddVertexWithColor(new Vector4(0, 1, 0f, 1f), Color1); t.AddVertexWithColor(new Vector4(1, 1, 0f, 1f), Color1); t.AddVertexWithColor(new Vector4(1, 0, 0f, 1f), Color1); background = t.GetVertexBuffer(); }
internal bool Render(bool forceCachedRendering) { // check if this is inside frustum RenewLease(); bool rebuildOccured = false; if ((pass1VertexBuffer.Disposed || chunk.IsDirty) && !forceCachedRendering) { // pass1 VertexBuffer.Dispose(ref pass1VertexBuffer); VertexBuffer.Dispose(ref pass2VertexBuffer); chunk.IsDirty = true; // rebuild vertices for cunk BlockRenderer blockRenderer = new BlockRenderer(); PositionBlock startCorner; chunk.Position.GetMinCornerBlock(out startCorner); int minX = startCorner.X; int minY = startCorner.Y; int minZ = startCorner.Z; int maxX = startCorner.X + 16; int maxY = startCorner.Y + 16; int maxZ = startCorner.Z + 16; PositionBlock blockPos = new PositionBlock(0, 0, 0); List <PositionBlock> pass2Blocks = new List <PositionBlock>(); t.StartDrawingTiledQuads(); for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { for (int z = 0; z < 16; z++) { blockPos.X = x; blockPos.Y = y; blockPos.Z = z; Block block = Block.FromId(chunk.SafeGetLocalBlock(x, y, z)); if (!block.IsTransparent) { blockRenderer.RenderBlock(blockPos, chunk); } else if (block.Id != BlockRepository.Air.Id) { pass2Blocks.Add(blockPos); } } } } pass1VertexBuffer = t.GetVertexBuffer(); // generate vertex buffer for pass2 t.StartDrawingTiledQuadsPass2(); foreach (PositionBlock pass2BlockPos in pass2Blocks) { blockRenderer.RenderBlock(pass2BlockPos, chunk); } pass2VertexBuffer = t.GetVertexBuffer(); chunk.IsDirty = false; rebuildOccured = true; } // draw chunk if drawbuffer has been calculated t.ResetTransformation(); if (pass1VertexBuffer.Vertices != null) { t.StartDrawingTiledQuads(); t.Draw(pass1VertexBuffer); } // draw entities in chunk foreach (EntityStack stack in chunk.StackEntities) { int entitiesToDraw = stack.Count > 2 ? 2 : stack.Count; if (stack.AsBlock != null) { t.Translate = stack.Position; t.Scale = new Vector3(0.5f, 0.5f, 0.5f); t.Rotate = new Vector3(stack.Pitch, stack.Yaw, 0); for (int i = 0; i < entitiesToDraw; i++) { t.StartDrawingTiledQuads(); t.Draw(TileTextures.Instance.GetBlockVertexBuffer(stack.Id)); t.Translate += new Vector3(0.05f, 0.05f, 0.05f); } } else if (stack.AsItem != null) { t.Translate = stack.Position; t.Scale = new Vector3(0.5f, 0.5f, 0.5f); for (int i = 0; i < entitiesToDraw; i++) { Player p = World.Instance.Player; t.Rotate = new Vector3(-p.Pitch, p.Yaw + (float)Math.PI, 0); t.StartDrawingTiledQuadsPass2(); t.Draw(TileTextures.Instance.GetItemVertexBuffer(stack.Id)); t.Translate += new Vector3(0.2f, 0.2f, 0.2f); } } } return(rebuildOccured); }
internal void ProfilerSnapshot() { VertexBuffer.Dispose(ref profileVertexBuffer); t.ResetTransformation(); FontRenderer f = FontRenderer.Instance; Player player = World.Instance.Player; f.BeginBatch(); f.CharScale = 1; string report = p.Report(); float y = TheGame.Instance.Height - FontRenderer.Instance.LineHeight; using (StringReader sr = new StringReader(report)) { string line; while ((line = sr.ReadLine()) != null) { f.RenderTextShadow(line, 0, y); y -= f.LineHeight; } } // log... y -= f.LineHeight; if (World.Instance.PlayerVoxelTrace.Hit) { Vector4 impactpos = World.Instance.PlayerVoxelTrace.ImpactPosition; string line = string.Format(GetVectorAsString("impactpos", impactpos)); f.RenderTextShadow(line, 0, y); y -= f.LineHeight; } else { f.RenderTextShadow("impactpos", 0, y); y -= f.LineHeight; Vector3 pos = new Vector3(player.Position.X, player.Position.Y, player.Position.Z); if (pos.Y > Chunk.MaxSizeY - 1) { pos.Y = Chunk.MaxSizeY - 1; } else if (pos.Y < 0) { pos.Y = 0; } PositionChunk chunkPos = PositionChunk.CreateFrom(pos); Vector3 chunkPos3 = new Vector3(chunkPos.X, chunkPos.Y, chunkPos.Z); f.RenderTextShadow(string.Format(GetVectorAsString("chunkpos", chunkPos3)), 0, y); y -= f.LineHeight; ChunkCache cache = World.Instance.GetCachedChunks(); Chunk c = cache.GetChunk(chunkPos); if (c != null) { f.RenderTextShadow(string.Format("chunk.Stage = {0}", c.Stage.ToString()), 0, y); y -= f.LineHeight; f.RenderTextShadow(string.Format("chunk.col.stage = {0}", c.Column.Stage.ToString()), 0, y); y -= f.LineHeight; f.RenderTextShadow(string.Format("chunk.col.active = {0}", c.Column.Active.ToString()), 0, y); y -= f.LineHeight; f.RenderTextShadow(string.Format("cache.alleighbors= {0}", cache.AllNeighborColumns(c.Column).Where(cc => cc != null).Count()), 0, y); y -= f.LineHeight; List <Chunk> chunks = new List <Chunk>(); for (int i = 0; i < 8; i++) { chunks.Add(cache.GetChunk(new PositionChunk(c.Position.X, i, c.Position.Z))); } } } f.RenderTextShadow(GetVectorAsString("direction", player.Direction), 0, y); y -= f.LineHeight; f.RenderTextShadow(GetVectorAsString("position", player.Position), 0, y); y -= f.LineHeight; y -= f.LineHeight; string[] lastLines = Log.Instance.Last(70); foreach (string line in lastLines) { f.RenderTextShadow(line, 0, y); y -= f.LineHeight; } f.StopBatch(); profileVertexBuffer = t.GetVertexBuffer(); }