From 875ec23b5b357f4d28212bbf6864d2c6be3f62a2 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 3 Sep 2015 20:14:10 +1000 Subject: [PATCH] Add proper brightness to entities, closes #45. (Thanks Goodlyay) --- ClassicalSharp/ClassicalSharp.csproj | 2 +- ClassicalSharp/Map/Map.cs | 10 ++++++++++ ClassicalSharp/Model/IModel.cs | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ClassicalSharp/ClassicalSharp.csproj b/ClassicalSharp/ClassicalSharp.csproj index 868ec3ac4..11ad0451e 100644 --- a/ClassicalSharp/ClassicalSharp.csproj +++ b/ClassicalSharp/ClassicalSharp.csproj @@ -47,7 +47,7 @@ Project - x86 + AnyCPU ..\output\debug\ true Full diff --git a/ClassicalSharp/Map/Map.cs b/ClassicalSharp/Map/Map.cs index a23e61fdd..e0d341691 100644 --- a/ClassicalSharp/Map/Map.cs +++ b/ClassicalSharp/Map/Map.cs @@ -175,6 +175,16 @@ namespace ClassicalSharp { } } + public bool IsLit( int x, int y, int z ) { + if( !IsValidPos( x, y, z ) ) return true; + return y > heightmap[z * Width + x]; + } + + public bool IsLit( Vector3I p ) { + if( !IsValidPos( p.X, p.Y, p.Z ) ) return true; + return p.Y > heightmap[p.Z * Width + p.X]; + } + public void SetBlock( int x, int y, int z, byte blockId ) { int index = ( y * Length + z ) * Width + x; byte oldBlock = mapData[index]; diff --git a/ClassicalSharp/Model/IModel.cs b/ClassicalSharp/Model/IModel.cs index c90ae7471..03fef6d5f 100644 --- a/ClassicalSharp/Model/IModel.cs +++ b/ClassicalSharp/Model/IModel.cs @@ -32,6 +32,7 @@ namespace ClassicalSharp.Model { pos = p.Position; cosA = (float)Math.Cos( p.YawRadians ); sinA = (float)Math.Sin( p.YawRadians ); + curCol = game.Map.IsLit( Vector3I.Floor( p.EyePosition ) ) ? (byte)255 : (byte)178; graphics.BeginVbBatch( VertexFormat.Pos3fTex2fCol4b ); DrawPlayerModel( p ); @@ -45,6 +46,7 @@ namespace ClassicalSharp.Model { public int DefaultTexId; protected FastColour col = new FastColour( 178, 178, 178 ); + protected byte curCol = 178; protected VertexPos3fTex2fCol4b[] vertices; protected int index; @@ -114,6 +116,7 @@ namespace ClassicalSharp.Model { VertexPos3fTex2fCol4b vertex = vertices[part.Offset + i]; Vector3 newPos = Utils.RotateY( vertex.X, vertex.Y, vertex.Z, cosA, sinA ) + pos; vertex.X = newPos.X; vertex.Y = newPos.Y; vertex.Z = newPos.Z; + vertex.R = curCol; vertex.G = curCol; vertex.B = curCol; cache.vertices[index++] = vertex; } } @@ -134,6 +137,7 @@ namespace ClassicalSharp.Model { Vector3 newPos = Utils.RotateY( loc.X, loc.Y, loc.Z, cosA, sinA ) + offset; vertex.X = newPos.X; vertex.Y = newPos.Y; vertex.Z = newPos.Z; + vertex.R = curCol; vertex.G = curCol; vertex.B = curCol; cache.vertices[index++] = vertex; } }