Exemple #1
0
		public void Render(ITessellator tessellator)
		{
			var color = tessellator.CurrentColor;

			// TODO: If this is an entity tile, then don't adjust the color...?

			// This will cause tile images to become darker as they move into the background layers.
			var layer =  -tessellator.Transform(Vector3.Zero).Z;
			if (layer < _numChunkLayers)
			{
				var multiplier = 1.0 - (_numChunkLayers - layer) / (_numChunkLayers * 2); // + 0.25f;
				tessellator.BindColor(Color.FromArgb((int)MathHelper.Clamp(color.R * multiplier, 0, 255), (int)MathHelper.Clamp(color.G * multiplier, 0, 255), (int)MathHelper.Clamp(color.B * multiplier, 0, 255)));
			}

			if (Transform != null)
			{
				tessellator.PushTransform();
				Transform.Apply(tessellator);

				_tileSet.Render(tessellator, TileIndex, Transform.MirrorX, Transform.MirrorY);
				tessellator.PopTransform();
			}
			else
			{
				_tileSet.Render(tessellator, TileIndex);
			}

			tessellator.BindColor(color);
		}
Exemple #2
0
        private void RenderFieldOfView(int[,] fovMap, ITessellator tessellator, Camera <OrthographicProjection> camera, IChunkAccess chunk, int minX, int maxX, int minY, int maxY)
        {
            tessellator.PushTransform();
            tessellator.Translate(0, 0, -1 * (int)ChunkLayer.Lights);
            tessellator.BindTexture(null);

            for (var y = 0; y < fovMap.GetLength(0); y++)
            {
                for (var x = 0; x < fovMap.GetLength(1); x++)
                {
                    if (fovMap[y, x] == 255)
                    {
                        continue;
                    }

                    tessellator.BindColor(Color.FromArgb(255 - fovMap[y, x], 0, 0, 0));
                    tessellator.Translate(minX + x, minY + y);
                    tessellator.AddPoint(0, 0);
                    tessellator.AddPoint(0, 1);
                    tessellator.AddPoint(1, 1);
                    tessellator.AddPoint(1, 0);
                    tessellator.Translate(-(minX + x), -(minY + y));
                }
            }

            tessellator.PopTransform();
        }
Exemple #3
0
        public void Render(ITessellator tessellator)
        {
            var color = tessellator.CurrentColor;

            // TODO: If this is an entity tile, then don't adjust the color...?

            // This will cause tile images to become darker as they move into the background layers.
            var layer = -tessellator.Transform(Vector3.Zero).Z;

            if (layer < _numChunkLayers)
            {
                var multiplier = 1.0 - (_numChunkLayers - layer) / (_numChunkLayers * 2);                 // + 0.25f;
                tessellator.BindColor(Color.FromArgb((int)MathHelper.Clamp(color.R * multiplier, 0, 255), (int)MathHelper.Clamp(color.G * multiplier, 0, 255), (int)MathHelper.Clamp(color.B * multiplier, 0, 255)));
            }

            if (Transform != null)
            {
                tessellator.PushTransform();
                Transform.Apply(tessellator);

                _tileSet.Render(tessellator, TileIndex, Transform.MirrorX, Transform.MirrorY);
                tessellator.PopTransform();
            }
            else
            {
                _tileSet.Render(tessellator, TileIndex);
            }

            tessellator.BindColor(color);
        }
Exemple #4
0
		public void Render(ITessellator tessellator)
		{
			tessellator.PushTransform();
			tessellator.Translate(Bounds.X, Bounds.Y);

			RenderContent(tessellator);

			tessellator.PopTransform();
		}
Exemple #5
0
        public void Render(ITessellator tessellator)
        {
            tessellator.PushTransform();
            tessellator.Translate(Bounds.X, Bounds.Y);

            RenderContent(tessellator);

            tessellator.PopTransform();
        }
Exemple #6
0
        /// <summary>
        /// Calculate a scale according to the current position.
        /// </summary>
        /// <remarks>
        /// This assumes you are inside of RenderContent, and handles pushing and popping the current transformation accordingly.
        /// </remarks>
        protected void Scale(ITessellator tessellator, float scale)
        {
            var position = tessellator.Transform(Vector2.Zero);

            tessellator.PopTransform();
            tessellator.PushTransform();
            tessellator.Scale(scale, scale);
            tessellator.Translate(position);
        }
Exemple #7
0
 /// <summary>
 /// Render a solid rectangle.
 /// </summary>
 protected void RenderRectangle(ITessellator tessellator, Color color, int tileWidth, int tileHeight)
 {
     tessellator.PushTransform();
     tessellator.BindColor(color);
     for (var y = 0; y < tileHeight; y++)
     {
         for (var x = 0; x < tileWidth; x++)
         {
             UI_ASCII.Render(tessellator, ASCII_SOLID);
             tessellator.Translate(UI_ASCII.Width, 0);
         }
         tessellator.Translate(-UI_ASCII.Width * tileWidth, UI_ASCII.Height);
     }
     tessellator.PopTransform();
 }
        private void Render(ITessellator tessellator, PlayerEntity entity)
        {
            tessellator.PushTransform();

            var origin = tessellator.Transform(Vector3.Zero);

            tessellator.LoadIdentity();
            tessellator.Scale(entity.Size, entity.Size);
            tessellator.Translate(origin);
            //tessellator.Translate(0.1f, 0.1f); // center on the current tile position

            tessellator.Translate(entity.Position);             // move to the entity's position

            _playerTile.Render(tessellator);
            tessellator.PopTransform();
        }
		private void Render(ITessellator tessellator, BlockEntity entity)
		{
			var color = tessellator.CurrentColor;
			tessellator.BindColor(Color.FromArgb(196, entity.IsSelected ? Color.Red : Color.White));
			tessellator.PushTransform();

			var origin = tessellator.Transform(Vector3.Zero);

			tessellator.LoadIdentity();
			tessellator.Scale(entity.Size, entity.Size);
			tessellator.Translate(-entity.Size / 2, -entity.Size / 2); // center the rotation
			tessellator.Rotate(entity.Rotation, 0, 0, 1);
			tessellator.Translate(entity.Size, entity.Size);
			tessellator.Translate(origin);
			//tessellator.Translate(entity.Size, entity.Size); // center on the current tile position
			tessellator.Translate(entity.Position); // move to the entity's position

			BlockRegistry.Instance.GetById(entity.BlockID).Renderer.Render(tessellator);

			tessellator.PopTransform();
			tessellator.BindColor(color); // TODO: Is this still needed?
		}
        private void Render(ITessellator tessellator, BlockEntity entity)
        {
            var color = tessellator.CurrentColor;

            tessellator.BindColor(Color.FromArgb(196, entity.IsSelected ? Color.Red : Color.White));
            tessellator.PushTransform();

            var origin = tessellator.Transform(Vector3.Zero);

            tessellator.LoadIdentity();
            tessellator.Scale(entity.Size, entity.Size);
            tessellator.Translate(-entity.Size / 2, -entity.Size / 2);             // center the rotation
            tessellator.Rotate(entity.Rotation, 0, 0, 1);
            tessellator.Translate(entity.Size, entity.Size);
            tessellator.Translate(origin);
            //tessellator.Translate(entity.Size, entity.Size); // center on the current tile position
            tessellator.Translate(entity.Position);             // move to the entity's position

            BlockRegistry.Instance.GetById(entity.BlockID).Renderer.Render(tessellator);

            tessellator.PopTransform();
            tessellator.BindColor(color);             // TODO: Is this still needed?
        }
Exemple #11
0
        /// <summary>
        /// Renders a light map around each entity.
        /// </summary>
        /// <remarks>
        /// Also takes line-of-sight into account.
        /// </remarks>
        private void RenderLightMap(ITessellator tessellator, IChunkAccess chunk, int minX, int maxX, int minY, int maxY)
        {
            tessellator.PushTransform();
            tessellator.Translate(0, 0, -1 * (int)ChunkLayer.Lights);
            tessellator.BindTexture(null);

            int[,] lightMap = new int[maxY - minY + 1, maxX - minX + 1];
            foreach (var entity in chunk.Entities)
            {
                var originX = (int)(entity.Position.X);
                var originY = (int)(entity.Position.Y);

                var considered = new List <Vector2I>();
                //for (var angle = 0.0f; angle < 360.0f; angle += (9.0f - distance)) // hit more angles as you move further out
                for (var angle = 0.0f; angle < 360.0f; angle += 1.0f)
                {
                    for (var distance = 0.0f; distance < chunk.AmbientLightLevel * 2.0f; distance++)
                    {
                        var x      = (int)(originX + distance * Math.Cos(OpenTK.MathHelper.DegreesToRadians(angle)));
                        var y      = (int)(originY + distance * Math.Sin(OpenTK.MathHelper.DegreesToRadians(angle)));
                        var vector = new Vector2I(y - minY, x - minX);
                        if (!considered.Contains(vector))
                        {
                            considered.Add(vector);

                            if (CommonCore.Math.MathHelper.IsInRange(y - minY, 0, maxY - minY + 1) && CommonCore.Math.MathHelper.IsInRange(x - minX, 0, maxX - minX + 1))
                            {
                                //var alpha = (8.0f - distance) / 8.0f;
                                var alpha = 1.0f / Math.Pow((distance + 1) / chunk.AmbientLightLevel, 2);

                                lightMap[y - minY, x - minX] = OpenTK.MathHelper.Clamp((int)(lightMap[y - minY, x - minX] + alpha * 255.0f), 0, 255);
                            }
                            else
                            {
                                break;
                            }
                        }

                        if (chunk[ChunkLayer.Blocking, x, y] != 0)
                        {
                            break;
                        }
                    }
                }
            }

            for (var y = 0; y < lightMap.GetLength(0); y++)
            {
                for (var x = 0; x < lightMap.GetLength(1); x++)
                {
                    tessellator.BindColor(Color.FromArgb(255 - lightMap[y, x], 0, 0, 0));
                    tessellator.Translate(minX + x, minY + y);
                    tessellator.AddPoint(0, 0);
                    tessellator.AddPoint(0, 1);
                    tessellator.AddPoint(1, 1);
                    tessellator.AddPoint(1, 0);
                    tessellator.Translate(-(minX + x), -(minY + y));
                }
            }

            tessellator.PopTransform();
        }
Exemple #12
0
		/// <summary>
		/// Calculate a scale according to the current position.
		/// </summary>
		/// <remarks>
		/// This assumes you are inside of RenderContent, and handles pushing and popping the current transformation accordingly.
		/// </remarks>
		protected void Scale(ITessellator tessellator, float scale)
		{
			var position = tessellator.Transform(Vector2.Zero);
			tessellator.PopTransform();
			tessellator.PushTransform();
			tessellator.Scale(scale, scale);
			tessellator.Translate(position);
		}
Exemple #13
0
		/// <summary>
		/// Render a solid rectangle.
		/// </summary>
		protected void RenderRectangle(ITessellator tessellator, Color color, int tileWidth, int tileHeight)
		{
			tessellator.PushTransform();
			tessellator.BindColor(color);
			for (var y = 0; y < tileHeight; y++)
			{
				for (var x = 0; x < tileWidth; x++)
				{
					UI_ASCII.Render(tessellator, ASCII_SOLID);
					tessellator.Translate(UI_ASCII.Width, 0);
				}
				tessellator.Translate(-UI_ASCII.Width * tileWidth, UI_ASCII.Height);
			}
			tessellator.PopTransform();
		}
		/// <summary>
		/// Renders a light map around each entity.
		/// </summary>
		/// <remarks>
		/// Also takes line-of-sight into account.
		/// </remarks>
		private void RenderLightMap(ITessellator tessellator, IChunkAccess chunk, int minX, int maxX, int minY, int maxY)
		{
			tessellator.PushTransform();
			tessellator.Translate(0, 0, -1 * (int)ChunkLayer.Lights);
			tessellator.BindTexture(null);

			int[,] lightMap = new int[maxY - minY + 1, maxX - minX + 1];
			foreach (var entity in chunk.Entities)
			{
				var originX = (int)(entity.Position.X);
				var originY = (int)(entity.Position.Y);

				var considered = new List<Vector2I>();
				//for (var angle = 0.0f; angle < 360.0f; angle += (9.0f - distance)) // hit more angles as you move further out
				for (var angle = 0.0f; angle < 360.0f; angle += 1.0f)
				{
					for (var distance = 0.0f; distance < chunk.AmbientLightLevel * 2.0f; distance++)
					{
						var x = (int)(originX + distance * Math.Cos(OpenTK.MathHelper.DegreesToRadians(angle)));
						var y = (int)(originY + distance * Math.Sin(OpenTK.MathHelper.DegreesToRadians(angle)));
						var vector = new Vector2I(y - minY, x - minX);
						if (!considered.Contains(vector))
						{
							considered.Add(vector);

							if (CommonCore.Math.MathHelper.IsInRange(y - minY, 0, maxY - minY + 1) && CommonCore.Math.MathHelper.IsInRange(x - minX, 0, maxX - minX + 1))
							{
								//var alpha = (8.0f - distance) / 8.0f;
								var alpha = 1.0f / Math.Pow((distance + 1) / chunk.AmbientLightLevel, 2);

								lightMap[y - minY, x - minX] = OpenTK.MathHelper.Clamp((int)(lightMap[y - minY, x - minX] + alpha * 255.0f), 0, 255);
							}
							else
							{
								break;
							}
						}

						if (chunk[ChunkLayer.Blocking, x, y] != 0)
						{
							break;
						}
					}
				}
			}

			for (var y = 0; y < lightMap.GetLength(0); y++)
			{
				for (var x = 0; x < lightMap.GetLength(1); x++)
				{
					tessellator.BindColor(Color.FromArgb(255 - lightMap[y, x], 0, 0, 0));
					tessellator.Translate(minX + x, minY + y);
					tessellator.AddPoint(0, 0);
					tessellator.AddPoint(0, 1);
					tessellator.AddPoint(1, 1);
					tessellator.AddPoint(1, 0);
					tessellator.Translate(-(minX + x), -(minY + y));
				}
			}

			tessellator.PopTransform();
		}
		private void RenderFieldOfView(int[,] fovMap, ITessellator tessellator, Camera<OrthographicProjection> camera, IChunkAccess chunk, int minX, int maxX, int minY, int maxY)
		{
			tessellator.PushTransform();
			tessellator.Translate(0, 0, -1 * (int)ChunkLayer.Lights);
			tessellator.BindTexture(null);

			for (var y = 0; y < fovMap.GetLength(0); y++)
			{
				for (var x = 0; x < fovMap.GetLength(1); x++)
				{
					if (fovMap[y, x] == 255)
					{
						continue;
					}

					tessellator.BindColor(Color.FromArgb(255 - fovMap[y, x], 0, 0, 0));
					tessellator.Translate(minX + x, minY + y);
					tessellator.AddPoint(0, 0);
					tessellator.AddPoint(0, 1);
					tessellator.AddPoint(1, 1);
					tessellator.AddPoint(1, 0);
					tessellator.Translate(-(minX + x), -(minY + y));
				}
			}

			tessellator.PopTransform();
		}
		private void Render(ITessellator tessellator, PlayerEntity entity)
		{
			tessellator.PushTransform();

			var origin = tessellator.Transform(Vector3.Zero);

			tessellator.LoadIdentity();
			tessellator.Scale(entity.Size, entity.Size);
			tessellator.Translate(origin);
			//tessellator.Translate(0.1f, 0.1f); // center on the current tile position

			tessellator.Translate(entity.Position); // move to the entity's position

			_playerTile.Render(tessellator);
			tessellator.PopTransform();
		}