Use MinBB/MaxBB in place of +0/+1, except for mesh builder.

This commit is contained in:
UnknownShadow200 2015-12-15 13:36:49 +11:00
parent 00774ae6d2
commit dacd6e4f44
7 changed files with 22 additions and 36 deletions

View File

@ -28,6 +28,8 @@ namespace ClassicalSharp {
}
}
const float angle = 45f * Utils.Deg2Rad;
static readonly Vector3 centre = new Vector3( 0.5f, 0, 0.5f );
internal void RecalculateBB( int block, FastBitmap fastBmp ) {
int elemSize = fastBmp.Width / 16;
int texId = GetTextureLoc( (byte)block, TileSide.Top );
@ -36,10 +38,8 @@ namespace ClassicalSharp {
float leftX = GetSpriteBB_LeftX( elemSize, texId & 0x0F, texId >> 4, fastBmp );
float rightX = GetSpriteBB_RightX( elemSize, texId & 0x0F, texId >> 4, fastBmp );
MinBB[block] = Utils.RotateY( leftX - 0.5f, bottomY, 0, 45f * Utils.Deg2Rad )
+ new Vector3( 0.5f, 0, 0.5f );
MaxBB[block] = Utils.RotateY( rightX - 0.5f, topY, 0, 45f * Utils.Deg2Rad )
+ new Vector3( 0.5f, 0, 0.5f );
MinBB[block] = Utils.RotateY( leftX - 0.5f, bottomY, 0, angle ) + centre;
MaxBB[block] = Utils.RotateY( rightX - 0.5f, topY, 0, angle ) + centre;
}
unsafe float GetSpriteBB_TopY( int size, int tileX, int tileY, FastBitmap fastBmp ) {

View File

@ -25,8 +25,8 @@ namespace ClassicalSharp {
bool GetBoundingBox( byte block, int x, int y, int z, ref BoundingBox box ) {
if( info.CollideType[block] != BlockCollideType.Solid ) return false;
box.Min = new Vector3( x, y, z );
box.Max = new Vector3( x + 1, y + info.Height[block], z + 1 );
box.Min = new Vector3( x, y, z ) + info.MinBB[block];
box.Max = new Vector3( x, y, z ) + info.MaxBB[block];
return true;
}

View File

@ -113,13 +113,12 @@ namespace ClassicalSharp {
}
bool CheckIsFree( PickedPos selected, byte newBlock ) {
Vector3 pos = (Vector3)selected.TranslatedPos;
if( !CannotPassThrough( newBlock ) ) return true;
if( IntersectsOtherPlayers( selected.TranslatedPos, newBlock ) ) return false;
if( IntersectsOtherPlayers( pos, newBlock ) ) return false;
Vector3I pos = selected.TranslatedPos;
float height = game.BlockInfo.Height[newBlock];
BoundingBox blockBB = new BoundingBox( pos.X, pos.Y, pos.Z,
pos.X + 1, pos.Y + height, pos.Z + 1 );
BoundingBox blockBB = new BoundingBox( pos + game.BlockInfo.MinBB[newBlock],
pos + game.BlockInfo.MaxBB[newBlock] );
BoundingBox localBB = game.LocalPlayer.CollisionBounds;
if( game.LocalPlayer.noClip || !localBB.Intersects( blockBB ) ) return true;
@ -132,7 +131,7 @@ namespace ClassicalSharp {
// Push player up if they are jumping and trying to place a block underneath them.
Vector3 p = game.LocalPlayer.Position;
p.Y = pos.Y + height + Entity.Adjustment;
p.Y = pos.Y + game.BlockInfo.Height[newBlock] + Entity.Adjustment;
LocationUpdate update = LocationUpdate.MakePos( p, false );
game.LocalPlayer.SetLocation( update, false );
return true;
@ -178,10 +177,9 @@ namespace ClassicalSharp {
return game.BlockInfo.CollideType[block] == BlockCollideType.Solid;
}
bool IntersectsOtherPlayers( Vector3I pos, byte newType ) {
float height = game.BlockInfo.Height[newType];
BoundingBox blockBB = new BoundingBox( pos.X, pos.Y, pos.Z,
pos.X + 1, pos.Y + height, pos.Z + 1 );
bool IntersectsOtherPlayers( Vector3 pos, byte newType ) {
BoundingBox blockBB = new BoundingBox( pos + game.BlockInfo.MinBB[newType],
pos + game.BlockInfo.MaxBB[newType] );
for( int id = 0; id < 255; id++ ) {
Player player = game.Players[id];

View File

@ -399,9 +399,9 @@ namespace ClassicalSharp.GraphicsAPI {
chat.Add( "&cIntel graphics cards are known to have issues with the OpenGL build." );
chat.Add( "&cVSync may not work, and you may see disappearing clouds and map edges." );
chat.Add( " " );
chat.Add( "&cFor Windows, try downloading the Direct3D 9 build as it doesn't have these problems" );
chat.Add( "&cAlternatively, the disappearing graphics can be partially fixed by " );
chat.Add( "&ctyping \"/client rendertype legacy\" into chat." );
chat.Add( "&cFor Windows, try downloading the Direct3D 9 build as it doesn't have" );
chat.Add( "&cthese problems. Alternatively, the disappearing graphics can be" );
chat.Add( "&cpartially fixed by typing \"/client render legacy\" into chat." );
}
// Based on http://www.opentk.com/doc/graphics/save-opengl-rendering-to-disk

View File

@ -29,10 +29,11 @@ namespace ClassicalSharp {
/// <summary> Mark this as having a selected block, and
/// calculates the closest block face of the selected position. </summary>
public void SetAsValid( Vector3 min, Vector3 max, byte block, Vector3 intersect ) {
public void SetAsValid( int x, int y, int z, Vector3 min, Vector3 max,
byte block, Vector3 intersect ) {
Min = min;
Max = max;
BlockPos = Vector3I.Truncate( Min );
BlockPos = new Vector3I( x, y, z );
Valid = true;
BlockType = block;

View File

@ -73,7 +73,7 @@ namespace ClassicalSharp {
float t0, t1;
if( Intersection.RayIntersectsBox( origin, dir, min, max, out t0, out t1 ) ) {
Vector3 intersect = origin + dir * t0;
pickedPos.SetAsValid( min, max, block, intersect );
pickedPos.SetAsValid( x, y, z, min, max, block, intersect );
return;
}
}

View File

@ -10,20 +10,7 @@ namespace Launcher2 {
public MainScreen( LauncherWindow game ) : base( game ) {
textFont = new Font( "Arial", 16, FontStyle.Bold );
widgets = new LauncherWidget[4];
}
protected override void UnselectWidget( LauncherWidget widget ) {
LauncherButtonWidget button = (LauncherButtonWidget)widget;
button.Active = false;
button.Redraw( drawer, button.Text, textFont );
Dirty = true;
}
protected override void SelectWidget( LauncherWidget widget ) {
LauncherButtonWidget button = (LauncherButtonWidget)widget;
button.Active = true;
button.Redraw( drawer, button.Text, textFont );
Dirty = true;
buttonFont = textFont;
}
void KeyDown( object sender, KeyboardKeyEventArgs e ) {