Fix torch rendering, track the highlighted face
The second bit will allow the client to start doing things like placing blocks.
This commit is contained in:
parent
10a84b94ee
commit
2eaaf219a8
@ -77,10 +77,9 @@ namespace TrueCraft.API
|
||||
/// <summary>
|
||||
/// Returns the distance along the ray where it intersects the specified bounding box, if it intersects at all.
|
||||
/// </summary>
|
||||
/// <param name="box">The bounding box to check intersection with.</param>
|
||||
/// <returns></returns>
|
||||
public double? Intersects(BoundingBox box)
|
||||
public double? Intersects(BoundingBox box, out BlockFace face)
|
||||
{
|
||||
face = BlockFace.PositiveY;
|
||||
//first test if start in box
|
||||
if (Position.X >= box.Min.X
|
||||
&& Position.X <= box.Max.X
|
||||
@ -131,6 +130,12 @@ namespace TrueCraft.API
|
||||
coord = Position.Y + maxT.X * Direction.Y;
|
||||
if (coord < box.Min.Y || coord > box.Max.Y)
|
||||
return null;
|
||||
|
||||
if (Position.X < box.Min.X)
|
||||
face = BlockFace.NegativeX;
|
||||
else if (Position.X > box.Max.X)
|
||||
face = BlockFace.PositiveX;
|
||||
|
||||
return maxT.X;
|
||||
}
|
||||
if (maxT.Y > maxT.X && maxT.Y > maxT.Z)
|
||||
@ -145,6 +150,12 @@ namespace TrueCraft.API
|
||||
coord = Position.X + maxT.Y * Direction.X;
|
||||
if (coord < box.Min.X || coord > box.Max.X)
|
||||
return null;
|
||||
|
||||
if (Position.Y < box.Min.Y)
|
||||
face = BlockFace.NegativeY;
|
||||
else if (Position.Y > box.Max.Y)
|
||||
face = BlockFace.PositiveY;
|
||||
|
||||
return maxT.Y;
|
||||
}
|
||||
else //Z
|
||||
@ -159,6 +170,12 @@ namespace TrueCraft.API
|
||||
coord = Position.Y + maxT.Z * Direction.Y;
|
||||
if (coord < box.Min.Y || coord > box.Max.Y)
|
||||
return null;
|
||||
|
||||
if (Position.Z < box.Min.Z)
|
||||
face = BlockFace.NegativeZ;
|
||||
else if (Position.Z > box.Max.Z)
|
||||
face = BlockFace.PositiveZ;
|
||||
|
||||
return maxT.Z;
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using TrueCraft.Client.Input;
|
||||
using TrueCraft.Client.Rendering;
|
||||
using TrueCraft.API;
|
||||
using System;
|
||||
|
||||
namespace TrueCraft.Client.Modules
|
||||
{
|
||||
@ -20,6 +22,9 @@ namespace TrueCraft.Client.Modules
|
||||
Game = game;
|
||||
Font = font;
|
||||
SpriteBatch = new SpriteBatch(Game.GraphicsDevice);
|
||||
#if DEBUG
|
||||
Enabled = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
public bool KeyDown(GameTime gameTime, KeyboardKeyEventArgs e)
|
||||
@ -63,25 +68,38 @@ namespace TrueCraft.Client.Modules
|
||||
const int yOffset = 25;
|
||||
|
||||
SpriteBatch.Begin();
|
||||
Font.DrawText(SpriteBatch, xOrigin, yOrigin, string.Format("§lRunning at {0}{1} FPS",
|
||||
GetFPSColor(fps), fps), 1);
|
||||
Font.DrawText(SpriteBatch, xOrigin, yOrigin + (yOffset * 1), string.Format("§o{0} vertices, {1} indicies",
|
||||
Mesh.VerticiesRendered, Mesh.IndiciesRendered), 1);
|
||||
Font.DrawText(SpriteBatch, xOrigin, yOrigin, string.Format(
|
||||
ChatFormat.Bold + "Running at {0}{1} FPS", GetFPSColor(fps), fps));
|
||||
|
||||
Font.DrawText(SpriteBatch, xOrigin, yOrigin + (yOffset * 1),
|
||||
string.Format(ChatFormat.Italic + "{0} vertices, {1} indicies",
|
||||
Mesh.VerticiesRendered, Mesh.IndiciesRendered));
|
||||
|
||||
Font.DrawText(SpriteBatch, xOrigin, yOrigin + (yOffset * 2),
|
||||
string.Format("§o{0} chunks", Game.ChunkModule.ChunksRendered), 1);
|
||||
string.Format(ChatFormat.Italic + "{0} chunks", Game.ChunkModule.ChunksRendered));
|
||||
|
||||
Font.DrawText(SpriteBatch, xOrigin, yOrigin + (yOffset * 3),
|
||||
string.Format("§o<{0:N2}, {1:N2}, {2:N2}>",
|
||||
Game.Client.Position.X, Game.Client.Position.Y, Game.Client.Position.Z), 1);
|
||||
string.Format(ChatFormat.Italic + "<{0:N2}, {1:N2}, {2:N2}>",
|
||||
Game.Client.Position.X, Game.Client.Position.Y, Game.Client.Position.Z));
|
||||
|
||||
Font.DrawText(SpriteBatch, xOrigin, yOrigin + (yOffset * 3),
|
||||
string.Format(ChatFormat.Italic + "<{0:N2}, {1:N2}, {2:N2}>",
|
||||
Game.Client.Position.X, Game.Client.Position.Y, Game.Client.Position.Z));
|
||||
|
||||
Font.DrawText(SpriteBatch, xOrigin, yOrigin + (yOffset * 4),
|
||||
string.Format(ChatColor.Gray + "Looking at {0} ({1})", Game.HighlightedBlock,
|
||||
Enum.GetName(typeof(BlockFace), Game.HighlightedBlockFace)));
|
||||
|
||||
SpriteBatch.End();
|
||||
}
|
||||
|
||||
private string GetFPSColor(int fps)
|
||||
{
|
||||
if (fps <= 16)
|
||||
return "§c";
|
||||
return ChatColor.Red;
|
||||
if (fps <= 32)
|
||||
return "§e";
|
||||
return "§a";
|
||||
return ChatColor.Yellow;
|
||||
return ChatColor.BrightGreen;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ namespace TrueCraft.Client.Modules
|
||||
{
|
||||
public TrueCraftGame Game { get; set; }
|
||||
|
||||
private Coordinates3D HighlightedBlock { get; set; }
|
||||
private BasicEffect HighlightEffect { get; set; }
|
||||
private static readonly VertexPositionColor[] CubeVerticies;
|
||||
private static readonly short[] CubeIndicies;
|
||||
@ -59,10 +58,11 @@ namespace TrueCraft.Client.Modules
|
||||
Game.BlockRepository, TrueCraftGame.Reach, TrueCraftGame.Reach + 2);
|
||||
|
||||
if (cast == null)
|
||||
HighlightedBlock = -Coordinates3D.One;
|
||||
Game.HighlightedBlock = -Coordinates3D.One;
|
||||
else
|
||||
{
|
||||
HighlightedBlock = cast.Item1;
|
||||
Game.HighlightedBlock = cast.Item1;
|
||||
Game.HighlightedBlockFace = cast.Item2;
|
||||
HighlightEffect.World =
|
||||
Matrix.CreateTranslation(new XVector3(-0.5f)) *
|
||||
Matrix.CreateScale(1.01f) *
|
||||
@ -75,7 +75,7 @@ namespace TrueCraft.Client.Modules
|
||||
{
|
||||
Game.Camera.ApplyTo(HighlightEffect);
|
||||
|
||||
if (HighlightedBlock != -Coordinates3D.One)
|
||||
if (Game.HighlightedBlock != -Coordinates3D.One)
|
||||
{
|
||||
foreach (var pass in HighlightEffect.CurrentTechnique.Passes)
|
||||
{
|
||||
|
@ -55,7 +55,8 @@ namespace TrueCraft.Client.Rendering.Blocks
|
||||
{
|
||||
var overhead = new Vector3(0.5f, 0.5f, 0.5f);
|
||||
var centerized = new Vector3(7f / 16f, 0, 7f / 16f);
|
||||
var cube = CreateUniformCube(overhead, Texture, VisibleFaces.All, indiciesOffset, out indicies, Color.White);
|
||||
var cube = CreateUniformCube(Vector3.Zero, Texture, VisibleFaces.All,
|
||||
indiciesOffset, out indicies, Color.White);
|
||||
for (int i = 0; i < cube.Length; i++)
|
||||
{
|
||||
cube[i].Position.X *= 1f / 8f;
|
||||
@ -100,7 +101,6 @@ namespace TrueCraft.Client.Rendering.Blocks
|
||||
|
||||
cube[i].Position += offset;
|
||||
cube[i].Position += centerized;
|
||||
cube[i].Position -= overhead;
|
||||
}
|
||||
return cube;
|
||||
}
|
||||
|
@ -48,6 +48,7 @@
|
||||
<DebugType>
|
||||
</DebugType>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DefineConstants>$(DefineConstants);DEBUG</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
</PropertyGroup>
|
||||
|
@ -31,6 +31,8 @@ namespace TrueCraft.Client
|
||||
public double Bobbing { get; set; }
|
||||
public ChunkModule ChunkModule { get; set; }
|
||||
public float ScaleFactor { get; set; }
|
||||
public Coordinates3D HighlightedBlock { get; set; }
|
||||
public BlockFace HighlightedBlockFace { get; set; }
|
||||
|
||||
private List<IGameplayModule> Modules { get; set; }
|
||||
private SpriteBatch SpriteBatch { get; set; }
|
||||
|
@ -21,6 +21,7 @@ namespace TrueCraft.Client
|
||||
|
||||
double min = negmax * 2;
|
||||
var pick = -Coordinates3D.One;
|
||||
var face = BlockFace.PositiveY;
|
||||
for (int x = -posmax; x <= posmax; x++)
|
||||
{
|
||||
for (int y = -negmax; y <= posmax; y++)
|
||||
@ -37,11 +38,13 @@ namespace TrueCraft.Client
|
||||
var box = provider.BoundingBox;
|
||||
if (box != null)
|
||||
{
|
||||
var distance = ray.Intersects(box.Value.OffsetBy(coords));
|
||||
BlockFace _face;
|
||||
var distance = ray.Intersects(box.Value.OffsetBy(coords), out _face);
|
||||
if (distance != null && distance.Value < min)
|
||||
{
|
||||
min = distance.Value;
|
||||
pick = coords;
|
||||
face = _face;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -50,7 +53,7 @@ namespace TrueCraft.Client
|
||||
}
|
||||
if (pick == -Coordinates3D.One)
|
||||
return null;
|
||||
return new Tuple<Coordinates3D, BlockFace>(pick, BlockFace.PositiveY);
|
||||
return new Tuple<Coordinates3D, BlockFace>(pick, face);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user