Reduce code duplication for chibi model.

This commit is contained in:
UnknownShadow200 2016-03-24 19:13:25 +11:00
parent 79eea2d1b7
commit 22c99b10c8

View File

@ -4,38 +4,23 @@ using OpenTK;
namespace ClassicalSharp.Model {
public class ChibiModel : IModel {
public class ChibiModel : HumanoidModel {
public ChibiModel( Game window ) : base( window ) { }
internal override void CreateParts() {
vertices = new ModelVertex[boxVertices * (7 + 2)];
Head = BuildBox( MakeBoxBounds( -4, 12, -4, 4, 20, 4 )
.TexOrigin( 0, 0 )
.RotOrigin( 0, 13, 0 ) );
Hat = BuildBox( MakeBoxBounds( -4, 12, -4, 4, 20, 4 )
.TexOrigin( 32, 0 ).Expand( 0.25f )
.RotOrigin( 0, 13, 0 ) );
Torso = BuildBox( MakeBoxBounds( -4, -6, -2, 4, 6, 2 )
.TexOrigin( 16, 16 )
.SetModelBounds( -2, 6, -1, 2, 12, 1 ) );
LeftLeg = BuildBox( MakeBoxBounds( -2, -6, -2, 2, 6, 2 )
.TexOrigin( 0, 16 )
.SetModelBounds( -0, 0, -1, -2, 6, 1 )
.RotOrigin( 0, 6, 0 ) );
RightLeg = BuildBox( MakeBoxBounds( -2, -6, -2, 2, 6, 2 )
.TexOrigin( 0, 16 )
.SetModelBounds( 0, 0, -1, 2, 6, 1 )
.RotOrigin( 0, 6, 0 ) );
LeftArm = BuildBox( MakeBoxBounds( -2, -6, -2, 2, 6, 2 )
.TexOrigin( 40, 16 )
.SetModelBounds( -2, 6, -1, -4, 12, 1 )
.RotOrigin( -3, 11, 0 ) );
RightArm = BuildBox( MakeBoxBounds( -2, -6, -2, 2, 6, 2 )
.TexOrigin( 40, 16 )
.SetModelBounds( 2, 6, -1, 4, 12, 1 )
.RotOrigin( 3, 11, 0 ) );
protected override void MakeDescriptions() {
head = MakeBoxBounds( -4, 12, -4, 4, 20, 4 ).RotOrigin( 0, 13, 0 );
torso = MakeBoxBounds( -4, -6, -2, 4, 6, 2 )
.SetModelBounds( -2, 6, -1, 2, 12, 1 );
lLeg = MakeBoxBounds( -2, -6, -2, 2, 6, 2 ).RotOrigin( 0, 6, 0 )
.SetModelBounds( -2, 0, -1, 0, 6, 1 );
rLeg = MakeBoxBounds( -2, -6, -2, 2, 6, 2 ).RotOrigin( 0, 6, 0 )
.SetModelBounds( 0, 0, -1, 2, 6, 1 );
lArm = MakeBoxBounds( -2, -6, -2, 2, 6, 2 ).RotOrigin( -3, 11, 0 )
.SetModelBounds( -4, 6, -1, -2, 12, 1 );
rArm = MakeBoxBounds( -2, -6, -2, 2, 6, 2 ).RotOrigin( 3, 11, 0 )
.SetModelBounds( 2, 6, -1, 4, 12, 1 );
offset = 0.25f;
}
public override bool Bobbing { get { return true; } }
@ -51,31 +36,5 @@ namespace ClassicalSharp.Model {
public override BoundingBox PickingBounds {
get { return new BoundingBox( -4/16f, 0, -4/16f, 4/16f, 16/16f, 4/16f ); }
}
protected override void DrawModel( Player p ) {
int texId = p.PlayerTextureId <= 0 ? cache.HumanoidTexId : p.PlayerTextureId;
graphics.BindTexture( texId );
graphics.AlphaTest = false;
SkinType skinType = p.SkinType;
_64x64 = skinType != SkinType.Type64x32;
DrawHeadRotate( -p.PitchRadians, 0, 0, Head );
DrawPart( Torso );
DrawRotate( p.anim.legXRot, 0, 0, LeftLeg );
DrawRotate( -p.anim.legXRot, 0, 0, RightLeg );
Rotate = RotateOrder.XZY;
DrawRotate( p.anim.leftXRot, 0, p.anim.leftZRot, LeftArm );
DrawRotate( p.anim.rightXRot, 0, p.anim.rightZRot, RightArm );
Rotate = RotateOrder.ZYX;
graphics.UpdateDynamicIndexedVb( DrawMode.Triangles, cache.vb, cache.vertices, index, index * 6 / 4 );
graphics.AlphaTest = true;
index = 0;
DrawHeadRotate( -p.PitchRadians, 0, 0, Hat );
graphics.UpdateDynamicIndexedVb( DrawMode.Triangles, cache.vb, cache.vertices, index, index * 6 / 4 );
}
ModelPart Head, Torso, LeftLeg, RightLeg, LeftArm, RightArm, Hat;
}
}