Add torch renderer
Supports all torch orientations, but does not support the usual particles.
This commit is contained in:
parent
62f14516eb
commit
750c1c48f4
Binary file not shown.
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
@ -25,7 +25,7 @@ namespace TrueCraft.Client.Linux.Rendering.Blocks
|
|||||||
};
|
};
|
||||||
|
|
||||||
public override VertexPositionNormalTexture[] Render(BlockDescriptor descriptor, Vector3 offset,
|
public override VertexPositionNormalTexture[] Render(BlockDescriptor descriptor, Vector3 offset,
|
||||||
Tuple<int, int> textureMap, int indiciesOffset, out int[] indicies)
|
Tuple<int, int> textureMap, int indiciesOffset, out int[] indicies)
|
||||||
{
|
{
|
||||||
var overhead = new Vector3(0.5f, 0.5f, 0.5f);
|
var overhead = new Vector3(0.5f, 0.5f, 0.5f);
|
||||||
var cube = CreateUniformCube(overhead, Texture, indiciesOffset, out indicies);
|
var cube = CreateUniformCube(overhead, Texture, indiciesOffset, out indicies);
|
||||||
|
108
TrueCraft.Client.Linux/Rendering/Blocks/TorchRenderer.cs
Normal file
108
TrueCraft.Client.Linux/Rendering/Blocks/TorchRenderer.cs
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using TrueCraft.Core.Logic.Blocks;
|
||||||
|
using TrueCraft.API.Logic;
|
||||||
|
|
||||||
|
namespace TrueCraft.Client.Linux.Rendering.Blocks
|
||||||
|
{
|
||||||
|
public class TorchRenderer : BlockRenderer
|
||||||
|
{
|
||||||
|
static TorchRenderer()
|
||||||
|
{
|
||||||
|
BlockRenderer.RegisterRenderer(TorchBlock.BlockID, new TorchRenderer());
|
||||||
|
for (int i = 0; i < Texture.Length; i++)
|
||||||
|
Texture[i] /= 256f;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Vector2 TextureMap = new Vector2(7, 85); // Note: this is in pixels (torch texture is not a full block)
|
||||||
|
private static Vector2[] Texture =
|
||||||
|
{
|
||||||
|
// Positive Z
|
||||||
|
TextureMap + new Vector2(2, 10),
|
||||||
|
TextureMap + new Vector2(0, 10),
|
||||||
|
TextureMap,
|
||||||
|
TextureMap + new Vector2(2, 0),
|
||||||
|
// Negative Z
|
||||||
|
TextureMap + new Vector2(2, 10),
|
||||||
|
TextureMap + new Vector2(0, 10),
|
||||||
|
TextureMap,
|
||||||
|
TextureMap + new Vector2(2, 0),
|
||||||
|
// Positive X
|
||||||
|
TextureMap + new Vector2(2, 10),
|
||||||
|
TextureMap + new Vector2(0, 10),
|
||||||
|
TextureMap,
|
||||||
|
TextureMap + new Vector2(2, 0),
|
||||||
|
// Negative X
|
||||||
|
TextureMap + new Vector2(2, 10),
|
||||||
|
TextureMap + new Vector2(0, 10),
|
||||||
|
TextureMap,
|
||||||
|
TextureMap + new Vector2(2, 0),
|
||||||
|
// Positive Y
|
||||||
|
TextureMap + new Vector2(2, 2),
|
||||||
|
TextureMap + new Vector2(0, 2),
|
||||||
|
TextureMap,
|
||||||
|
TextureMap + new Vector2(2, 0),
|
||||||
|
// Negative Y
|
||||||
|
TextureMap + new Vector2(0, 10),
|
||||||
|
TextureMap + new Vector2(0, 10),
|
||||||
|
TextureMap,
|
||||||
|
TextureMap + new Vector2(2, 0),
|
||||||
|
};
|
||||||
|
|
||||||
|
public override VertexPositionNormalTexture[] Render(BlockDescriptor descriptor, Vector3 offset,
|
||||||
|
Tuple<int, int> textureMap, int indiciesOffset, out int[] indicies)
|
||||||
|
{
|
||||||
|
var overhead = new Vector3(0.5f, 0.5f, 0.5f);
|
||||||
|
var centerized = new Vector3(7f / 16f, 0, 7f / 16f);
|
||||||
|
var cube = CreateUniformCube(overhead, Texture, indiciesOffset, out indicies);
|
||||||
|
for (int i = 0; i < cube.Length; i++)
|
||||||
|
{
|
||||||
|
cube[i].Position.X *= 1f / 8f;
|
||||||
|
cube[i].Position.Z *= 1f / 8f;
|
||||||
|
if (cube[i].Position.Y > 0)
|
||||||
|
cube[i].Position.Y *= 5f / 8f;
|
||||||
|
switch ((TorchBlock.TorchDirection)descriptor.Metadata)
|
||||||
|
{
|
||||||
|
case TorchBlock.TorchDirection.West:
|
||||||
|
if (cube[i].Position.Y == 0)
|
||||||
|
cube[i].Position.X += 8f / 16f;
|
||||||
|
else
|
||||||
|
cube[i].Position.X += 3f / 16f;
|
||||||
|
cube[i].Position.Y += 5f / 16f;
|
||||||
|
break;
|
||||||
|
case TorchBlock.TorchDirection.East:
|
||||||
|
if (cube[i].Position.Y == 0)
|
||||||
|
cube[i].Position.X -= 8f / 16f;
|
||||||
|
else
|
||||||
|
cube[i].Position.X -= 3f / 16f;
|
||||||
|
cube[i].Position.Y += 5f / 16f;
|
||||||
|
break;
|
||||||
|
case TorchBlock.TorchDirection.North:
|
||||||
|
if (cube[i].Position.Y == 0)
|
||||||
|
cube[i].Position.Z += 8f / 16f;
|
||||||
|
else
|
||||||
|
cube[i].Position.Z += 3f / 16f;
|
||||||
|
cube[i].Position.Y += 5f / 16f;
|
||||||
|
break;
|
||||||
|
case TorchBlock.TorchDirection.South:
|
||||||
|
if (cube[i].Position.Y == 0)
|
||||||
|
cube[i].Position.Z -= 8f / 16f;
|
||||||
|
else
|
||||||
|
cube[i].Position.Z -= 3f / 16f;
|
||||||
|
cube[i].Position.Y += 5f / 16f;
|
||||||
|
break;
|
||||||
|
case TorchBlock.TorchDirection.Ground:
|
||||||
|
default:
|
||||||
|
// nop
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
cube[i].Position += offset;
|
||||||
|
cube[i].Position += centerized;
|
||||||
|
cube[i].Position -= overhead;
|
||||||
|
}
|
||||||
|
return cube;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -86,6 +86,7 @@
|
|||||||
<Compile Include="Rendering\Blocks\CraftingTableRenderer.cs" />
|
<Compile Include="Rendering\Blocks\CraftingTableRenderer.cs" />
|
||||||
<Compile Include="Rendering\Blocks\TNTRenderer.cs" />
|
<Compile Include="Rendering\Blocks\TNTRenderer.cs" />
|
||||||
<Compile Include="Rendering\Blocks\SnowRenderer.cs" />
|
<Compile Include="Rendering\Blocks\SnowRenderer.cs" />
|
||||||
|
<Compile Include="Rendering\Blocks\TorchRenderer.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -30,6 +30,8 @@ namespace TrueCraft.Core.Logic.Blocks
|
|||||||
public override byte Luminance { get { return 13; } }
|
public override byte Luminance { get { return 13; } }
|
||||||
|
|
||||||
public override bool Opaque { get { return false; } }
|
public override bool Opaque { get { return false; } }
|
||||||
|
|
||||||
|
public override bool RenderOpaque { get { return true; } }
|
||||||
|
|
||||||
public override string DisplayName { get { return "Torch"; } }
|
public override string DisplayName { get { return "Torch"; } }
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user