From 09757d631681ced4ee2e05f0391b7d439dcc9ee1 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 28 Dec 2015 22:12:23 +1100 Subject: [PATCH] Fix isometric blocks not respecting fullbright (Thanks Empy), fix 'stepping/walking' physics not working with custom stairs. --- ClassicalSharp/2D/IsometricBlockDrawer.cs | 6 ++-- ClassicalSharp/Entities/PhysicsEntity.cs | 42 +++++++++++++---------- ClassicalSharp/Model/PlayerModel.cs | 2 +- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/ClassicalSharp/2D/IsometricBlockDrawer.cs b/ClassicalSharp/2D/IsometricBlockDrawer.cs index 4b43990ae..f8a710716 100644 --- a/ClassicalSharp/2D/IsometricBlockDrawer.cs +++ b/ClassicalSharp/2D/IsometricBlockDrawer.cs @@ -14,6 +14,7 @@ namespace ClassicalSharp { static float scale; static Vector3 minBB, maxBB; const float invElemSize = TerrainAtlas2D.invElementSize; + static bool fullBright; static FastColour colNormal, colXSide, colZSide, colYBottom; static float cosX, sinX, cosY, sinY; @@ -33,6 +34,7 @@ namespace ClassicalSharp { atlas = game.TerrainAtlas; minBB = info.MinBB[block]; maxBB = info.MaxBB[block]; + fullBright = info.FullBright[block]; if( info.IsSprite[block] ) { minBB = Vector3.Zero; maxBB = Vector3.One; } @@ -94,7 +96,7 @@ namespace ClassicalSharp { static void ZQuad( byte block, float z, int side ) { int texId = info.GetTextureLoc( block, side ); TextureRec rec = atlas.GetTexRec( texId ); - FastColour col = colZSide; + FastColour col = fullBright ? colNormal : colZSide; float uOrigin = rec.U1, vOrigin = rec.V1; rec.U1 = uOrigin + minBB.X * invElemSize; @@ -119,7 +121,7 @@ namespace ClassicalSharp { static void XQuad( byte block, float x, int side ) { int texId = info.GetTextureLoc( block, side ); TextureRec rec = atlas.GetTexRec( texId ); - FastColour col = colXSide; + FastColour col = fullBright ? colNormal : colXSide; float uOrigin = rec.U1, vOrigin = rec.V1; rec.U1 = uOrigin + minBB.Z * invElemSize; diff --git a/ClassicalSharp/Entities/PhysicsEntity.cs b/ClassicalSharp/Entities/PhysicsEntity.cs index 908f58ade..41f1375d3 100644 --- a/ClassicalSharp/Entities/PhysicsEntity.cs +++ b/ClassicalSharp/Entities/PhysicsEntity.cs @@ -92,8 +92,7 @@ namespace ClassicalSharp { for( int y = min.Y; y <= max.Y; y++ ) { for( int z = min.Z; z <= max.Z; z++ ) { for( int x = min.X; x <= max.X; x++ ) { - byte blockId = GetPhysicsBlockId( x, y, z ); - + byte blockId = GetPhysicsBlockId( x, y, z ); if( !GetBoundingBox( blockId, x, y, z, ref blockBB ) ) continue; if( !entityExtentBB.Intersects( blockBB ) ) continue; // necessary for some non whole blocks. (slabs) @@ -133,22 +132,22 @@ namespace ClassicalSharp { Position.Y = blockBB.Min.Y - size.Y - Adjustment; ClipY( ref size, ref entityBB, ref entityExtentBB ); } else if( finalBB.Min.X + Adjustment >= blockBB.Max.X ) { - if( !wasOn || !DidSlide( ref blockBB, ref size, ref finalBB, ref entityBB, ref entityExtentBB ) ) { + if( !wasOn || !DidSlide( blockBB, ref size, finalBB, ref entityBB, ref entityExtentBB ) ) { Position.X = blockBB.Max.X + size.X / 2 + Adjustment; ClipX( ref size, ref entityBB, ref entityExtentBB ); } } else if( finalBB.Max.X - Adjustment <= blockBB.Min.X ) { - if( !wasOn || !DidSlide( ref blockBB, ref size, ref finalBB, ref entityBB, ref entityExtentBB ) ) { + if( !wasOn || !DidSlide( blockBB, ref size, finalBB, ref entityBB, ref entityExtentBB ) ) { Position.X = blockBB.Min.X - size.X / 2 - Adjustment; ClipX( ref size, ref entityBB, ref entityExtentBB ); } } else if( finalBB.Min.Z + Adjustment >= blockBB.Max.Z ) { - if( !wasOn || !DidSlide( ref blockBB, ref size, ref finalBB, ref entityBB, ref entityExtentBB ) ) { + if( !wasOn || !DidSlide( blockBB, ref size, finalBB, ref entityBB, ref entityExtentBB ) ) { Position.Z = blockBB.Max.Z + size.Z / 2 + Adjustment; ClipZ( ref size, ref entityBB, ref entityExtentBB ); } } else if( finalBB.Max.Z - Adjustment <= blockBB.Min.Z ) { - if( !wasOn || !DidSlide( ref blockBB, ref size, ref finalBB, ref entityBB, ref entityExtentBB ) ) { + if( !wasOn || !DidSlide( blockBB, ref size,finalBB, ref entityBB, ref entityExtentBB ) ) { Position.Z = blockBB.Min.Z - size.Z / 2 - Adjustment; ClipZ( ref size, ref entityBB, ref entityExtentBB ); } @@ -156,20 +155,25 @@ namespace ClassicalSharp { } } - bool DidSlide( ref BoundingBox blockBB, ref Vector3 size, ref BoundingBox finalBB, + bool DidSlide( BoundingBox blockBB, ref Vector3 size, BoundingBox finalBB, ref BoundingBox entityBB, ref BoundingBox entityExtentBB ) { float yDist = blockBB.Max.Y - entityBB.Min.Y; - if( yDist > 0 && yDist <= StepSize + 0.01f ) { - // Adjust entity bounding box to include the block being tested - BoundingBox adjFinalBB = finalBB; - adjFinalBB.Min.X = Math.Min( finalBB.Min.X, blockBB.Min.X + Adjustment ); - adjFinalBB.Max.X = Math.Max( finalBB.Max.X, blockBB.Max.X - Adjustment ); - adjFinalBB.Min.Y = blockBB.Max.Y + Adjustment; - adjFinalBB.Max.Y = adjFinalBB.Min.Y + size.Y; - adjFinalBB.Min.Z = Math.Min( finalBB.Min.Z, blockBB.Min.Z + Adjustment ); - adjFinalBB.Max.Z = Math.Max( finalBB.Max.Z, blockBB.Max.Z - Adjustment ); + if( yDist > 0 && yDist <= StepSize + 0.01f ) { + float blockXMin = blockBB.Min.X, blockZMin = blockBB.Min.Z; + blockBB.Min.X = Math.Max( blockBB.Min.X, blockBB.Max.X - size.X / 2 ); + blockBB.Max.X = Math.Min( blockBB.Max.X, blockXMin + size.X / 2 ); + blockBB.Min.Z = Math.Max( blockBB.Min.Z, blockBB.Max.Z - size.Z / 2 ); + blockBB.Max.Z = Math.Min( blockBB.Max.Z, blockZMin + size.Z / 2 ); - if( !CanSlideThrough( ref adjFinalBB ) ) + BoundingBox adjBB = finalBB; + adjBB.Min.X = Math.Min( finalBB.Min.X, blockBB.Min.X + Adjustment ); + adjBB.Max.X = Math.Max( finalBB.Max.X, blockBB.Max.X - Adjustment ); + adjBB.Min.Y = blockBB.Max.Y + Adjustment; + adjBB.Max.Y = adjBB.Min.Y + size.Y; + adjBB.Min.Z = Math.Min( finalBB.Min.Z, blockBB.Min.Z + Adjustment ); + adjBB.Max.Z = Math.Max( finalBB.Max.Z, blockBB.Max.Z - Adjustment ); + + if( !CanSlideThrough( ref adjBB ) ) return false; Position.Y = blockBB.Max.Y + Adjustment; onGround = true; @@ -191,8 +195,8 @@ namespace ClassicalSharp { Vector3 min = new Vector3( x, y, z ) + info.MinBB[block]; Vector3 max = new Vector3( x, y, z ) + info.MaxBB[block]; - BoundingBox blockBB = new BoundingBox( min, max ); - if( !blockBB.Intersects( adjFinalBB ) ) + BoundingBox blockBB = new BoundingBox( min, max ); + if( !blockBB.Intersects( adjFinalBB ) ) continue; if( info.CollideType[GetPhysicsBlockId( x, y, z )] == BlockCollideType.Solid ) return false; diff --git a/ClassicalSharp/Model/PlayerModel.cs b/ClassicalSharp/Model/PlayerModel.cs index 330a49df2..35085b647 100644 --- a/ClassicalSharp/Model/PlayerModel.cs +++ b/ClassicalSharp/Model/PlayerModel.cs @@ -53,7 +53,7 @@ namespace ClassicalSharp.Model { } public override Vector3 CollisionSize { - get { return new Vector3( 8/16f, 28.5f/16f, 8/16f ); } + get { return new Vector3( 8/16f - 0.005f, 28.5f/16f - 0.005f, 8/16f - 0.005f ); } } public override BoundingBox PickingBounds {