Fix cube mesh generation (and rendering overall)

This commit is contained in:
Drew DeVault 2015-05-14 17:04:30 -06:00
parent dca02aace0
commit c3fcb50499
5 changed files with 25 additions and 23 deletions

View File

@ -97,18 +97,17 @@ namespace TrueCraft.Client.Linux
{
int[] i;
var v = CreateUniformCube(new Vector3(chunk.X * Chunk.Width + x, y, chunk.Z * Chunk.Depth + z),
textureMap, indicies.Count, out i);
textureMap, verticies.Count, out i);
verticies.AddRange(v);
indicies.AddRange(i);
}
}
}
}
Console.WriteLine("Created mesh for {0}, {0}", chunk.X, chunk.Z);
return new Mesh(Graphics, verticies.ToArray(), indicies.ToArray());
}
private VertexPositionNormalTexture[] CreateUniformCube(Vector3 offset, Tuple<int, int> textureMap, int indiciesOffset, out int[] indicies)
public VertexPositionNormalTexture[] CreateUniformCube(Vector3 offset, Tuple<int, int> textureMap, int indiciesOffset, out int[] indicies)
{
var texCoords = new Vector2(textureMap.Item1, textureMap.Item2);
var texture = new[]

View File

@ -40,9 +40,9 @@ namespace TrueCraft.Client.Linux.Rendering
public static VertexPositionNormalTexture[] CreateQuad(CubeFace face, Vector3 offset, Vector2[] texture, int indiciesOffset, out int[] indicies)
{
indicies = new[] { 1, 0, 3, 1, 3, 2 };
indicies = new[] { 0, 1, 3, 1, 2, 3 };
for (int i = 0; i < indicies.Length; i++)
indicies[i] += ((int)face * 6) + indiciesOffset;
indicies[i] += ((int)face * 4) + indiciesOffset;
var quad = new VertexPositionNormalTexture[4];
var unit = CubeMesh[(int)face];
var normal = CubeNormals[(int)face];
@ -81,50 +81,50 @@ namespace TrueCraft.Client.Linux.Rendering
CubeMesh[0] = new[] // Positive Z face
{
new Vector3(0.5f, 0.5f, 0.5f),
new Vector3(-0.5f, 0.5f, 0.5f),
new Vector3(0.5f, -0.5f, 0.5f),
new Vector3(-0.5f, -0.5f, 0.5f),
new Vector3(0.5f, -0.5f, 0.5f)
new Vector3(-0.5f, 0.5f, 0.5f),
new Vector3(0.5f, 0.5f, 0.5f)
};
CubeMesh[1] = new[] // Negative Z face
{
new Vector3(-0.5f, 0.5f, -0.5f),
new Vector3(0.5f, 0.5f, -0.5f),
new Vector3(-0.5f, -0.5f, -0.5f),
new Vector3(0.5f, -0.5f, -0.5f),
new Vector3(-0.5f, -0.5f, -0.5f)
new Vector3(0.5f, 0.5f, -0.5f),
new Vector3(-0.5f, 0.5f, -0.5f)
};
CubeMesh[2] = new[] // Positive X face
{
new Vector3(0.5f, 0.5f, -0.5f),
new Vector3(0.5f, 0.5f, 0.5f),
new Vector3(0.5f, -0.5f, -0.5f),
new Vector3(0.5f, -0.5f, 0.5f),
new Vector3(0.5f, -0.5f, -0.5f)
new Vector3(0.5f, 0.5f, 0.5f),
new Vector3(0.5f, 0.5f, -0.5f)
};
CubeMesh[3] = new[] // Negative X face
{
new Vector3(-0.5f, 0.5f, 0.5f),
new Vector3(-0.5f, 0.5f, -0.5f),
new Vector3(-0.5f, -0.5f, 0.5f),
new Vector3(-0.5f, -0.5f, -0.5f),
new Vector3(-0.5f, -0.5f, 0.5f)
new Vector3(-0.5f, 0.5f, -0.5f),
new Vector3(-0.5f, 0.5f, 0.5f)
};
CubeMesh[4] = new[] // Positive Y face
{
new Vector3(-0.5f, 0.5f, -0.5f),
new Vector3(-0.5f, 0.5f, 0.5f),
new Vector3(0.5f, 0.5f, 0.5f),
new Vector3(-0.5f, 0.5f, 0.5f),
new Vector3(-0.5f, 0.5f, -0.5f),
new Vector3(0.5f, 0.5f, -0.5f)
};
CubeMesh[5] = new[] // Negative Y face
{
new Vector3(0.5f, -0.5f, -0.5f),
new Vector3(0.5f, -0.5f, 0.5f),
new Vector3(-0.5f, -0.5f, -0.5f),
new Vector3(-0.5f, -0.5f, 0.5f),
new Vector3(-0.5f, -0.5f, -0.5f)
new Vector3(0.5f, -0.5f, 0.5f)
};
}

View File

@ -23,6 +23,8 @@ namespace TrueCraft.Client.Linux
private DateTime NextPhysicsUpdate { get; set; }
private List<Mesh> ChunkMeshes { get; set; }
private object ChunkMeshesLock = new object();
private float rotationX = 0;
private float rotationY = 0;
private BasicEffect effect;
@ -148,10 +150,11 @@ namespace TrueCraft.Client.Linux
GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp;
GraphicsDevice.SamplerStates[1] = SamplerState.PointClamp;
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
//GraphicsDevice.RasterizerState = RasterizerState.CullNone;
effect.View = cameraMatrix;
effect.Projection = projectionMatrix;
effect.World = Matrix.CreateTranslation(Microsoft.Xna.Framework.Vector3.Zero);
effect.World = Matrix.Identity;
lock (ChunkMeshesLock)
{
foreach (var chunk in ChunkMeshes)

View File

@ -33,6 +33,7 @@
<Optimize>false</Optimize>
<OutputPath>bin\Client</OutputPath>
<WarningLevel>4</WarningLevel>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize>

View File

@ -127,7 +127,6 @@ namespace TrueCraft.Core.World
if (!Chunks.ContainsKey(position))
Chunks.Add(position, chunk);
chunk.IsModified = true;
chunk.Coordinates = position;
chunk.LastAccessed = DateTime.Now;
Chunks[position] = chunk;
}