Move rotation origin setting to part definitions, not at draw method.

This commit is contained in:
UnknownShadow200 2016-03-22 19:14:04 +11:00
parent e1c6e1f015
commit 0a7d368c53
4 changed files with 45 additions and 24 deletions

View File

@ -29,7 +29,7 @@ namespace ClassicalSharp.Model {
const float y1 = 1/64f, y2 = 5/16f, z2 = 1/16f, z1 = -2/16f;
YQuad( 32, 0, 3, 3, x2/16f, x1/16f, z1, z2, y1 ); // bottom feet
ZQuad( 36, 3, 1, 5, legX1/16f, legX2/16f, y1, y2, z2 ); // vertical part of leg
return new ModelPart( index - 2 * 4, 2 * 4 );
return new ModelPart( index - 2 * 4, 2 * 4, 0, 0, 0 );
}
public override bool Bobbing { get { return true; } }

View File

@ -13,19 +13,25 @@ namespace ClassicalSharp.Model {
Set = new ModelSet();
Set.Head = BuildBox( MakeBoxBounds( -4, 24, -4, 4, 32, 4 )
.SetTexOrigin( 0, 0 ) );
.SetTexOrigin( 0, 0 )
.SetRotOrigin( 0, 24, 0 ) );
Set.Torso = BuildBox( MakeBoxBounds( -4, 12, -2, 4, 24, 2 )
.SetTexOrigin( 16, 16 ) );
Set.LeftLeg = BuildBox( MakeBoxBounds( 0, 0, -2, -4, 12, 2 )
.SetTexOrigin( 0, 16 ) );
Set.RightLeg = BuildBox( MakeBoxBounds( 0, 0, -2, 4, 12, 2 ).
SetTexOrigin( 0, 16 ) );
.SetTexOrigin( 0, 16 )
.SetRotOrigin( 0, 12, 0 ) );
Set.RightLeg = BuildBox( MakeBoxBounds( 0, 0, -2, 4, 12, 2 )
.SetTexOrigin( 0, 16 )
.SetRotOrigin( 0, 12, 0 ) );
Set.Hat = BuildBox( MakeBoxBounds( -4, 24, -4, 4, 32, 4 )
.SetTexOrigin( 32, 0 ).ExpandBounds( 0.5f ) );
.SetTexOrigin( 32, 0 ).ExpandBounds( 0.5f )
.SetRotOrigin( 0, 24, 0 ) );
Set.LeftArm = BuildBox( MakeBoxBounds( -4, 12, -2, -8, 24, 2 )
.SetTexOrigin( 40, 16 ) );
.SetTexOrigin( 40, 16 )
.SetRotOrigin( -5, 22, 0 ) );
Set.RightArm = BuildBox( MakeBoxBounds( 4, 12, -2, 8, 24, 2 )
.SetTexOrigin( 40, 16 ) );
.SetTexOrigin( 40, 16 )
.SetRotOrigin( 5, 22, 0 ) );
SetSlim = new ModelSet();
SetSlim.Head = Set.Head;
@ -33,9 +39,11 @@ namespace ClassicalSharp.Model {
SetSlim.LeftLeg = Set.LeftLeg;
SetSlim.RightLeg = Set.RightLeg;
SetSlim.LeftArm = BuildBox( MakeBoxBounds( -7, 12, -2, -4, 24, 2 )
.SetTexOrigin( 32, 48 ) );
.SetTexOrigin( 32, 48 )
.SetRotOrigin( -5, 22, 0 ) );
SetSlim.RightArm = BuildBox( MakeBoxBounds( 4, 12, -2, 7, 24, 2 )
.SetTexOrigin( 40, 16 ) );
.SetTexOrigin( 40, 16 )
.SetRotOrigin( 5, 22, 0 ) );
SetSlim.Hat = Set.Hat;
}
@ -61,20 +69,20 @@ namespace ClassicalSharp.Model {
SkinType skinType = p.SkinType;
_64x64 = skinType != SkinType.Type64x32;
ModelSet model = skinType == SkinType.Type64x64Slim ? SetSlim : Set;
DrawHeadRotate( 0, 24/16f, 0, -p.PitchRadians, 0, 0, model.Head );
DrawHeadRotate( -p.PitchRadians, 0, 0, model.Head );
DrawPart( model.Torso );
DrawRotate( 0, 12/16f, 0, p.anim.legXRot, 0, 0, model.LeftLeg );
DrawRotate( 0, 12/16f, 0, -p.anim.legXRot, 0, 0, model.RightLeg );
DrawRotate( p.anim.legXRot, 0, 0, model.LeftLeg );
DrawRotate( -p.anim.legXRot, 0, 0, model.RightLeg );
Rotate = RotateOrder.XZY;
DrawRotate( -5/16f, 22/16f, 0, p.anim.leftXRot, 0, p.anim.leftZRot, model.LeftArm );
DrawRotate( 5/16f, 22/16f, 0, p.anim.rightXRot, 0, p.anim.rightZRot, model.RightArm );
DrawRotate( p.anim.leftXRot, 0, p.anim.leftZRot, model.LeftArm );
DrawRotate( p.anim.rightXRot, 0, p.anim.rightZRot, model.RightArm );
Rotate = RotateOrder.ZYX;
graphics.UpdateDynamicIndexedVb( DrawMode.Triangles, cache.vb, cache.vertices, index, index * 6 / 4 );
graphics.AlphaTest = true;
index = 0;
DrawHeadRotate( 0, 24f/16f, 0, -p.PitchRadians, 0, 0, model.Hat );
DrawHeadRotate( -p.PitchRadians, 0, 0, model.Hat );
graphics.UpdateDynamicIndexedVb( DrawMode.Triangles, cache.vb, cache.vertices, index, index * 6 / 4 );
}

View File

@ -75,6 +75,7 @@ namespace ClassicalSharp.Model {
public struct BoxDescription {
public int TexX, TexY, SidesW, BodyW, BodyH;
public float X1, X2, Y1, Y2, Z1, Z2;
public float RotX, RotY, RotZ;
public BoxDescription SetTexOrigin( int x, int y ) {
TexX = x; TexY = y; return this;
@ -93,6 +94,11 @@ namespace ClassicalSharp.Model {
Z1 -= amount / 16f; Z2 += amount / 16f;
return this;
}
public BoxDescription SetRotOrigin( sbyte x, sbyte y, sbyte z ) {
RotX = x / 16f; RotY = y / 16f; RotZ = z / 16f;
return this;
}
}
protected BoxDescription MakeBoxBounds( int x1, int y1, int z1, int x2, int y2, int z2 ) {
@ -138,7 +144,7 @@ namespace ClassicalSharp.Model {
ZQuad( x + sidesW + bodyW + sidesW, y + sidesW, bodyW, bodyH, x1, x2, y1, y2, z2 ); // back
XQuad( x, y + sidesW, sidesW, bodyH, z2, z1, y1, y2, x2 ); // left
XQuad( x + sidesW + bodyW, y + sidesW, sidesW, bodyH, z1, z2, y1, y2, x1 ); // right
return new ModelPart( index - 6 * 4, 6 * 4 );
return new ModelPart( index - 6 * 4, 6 * 4, desc.RotX, desc.RotY, desc.RotZ );
}
/// <summary>Builds a box model assuming the follow texture layout:<br/>
@ -173,7 +179,7 @@ namespace ClassicalSharp.Model {
float z = vertex.Z; vertex.Z = vertex.Y; vertex.Y = z;
vertices[i] = vertex;
}
return new ModelPart( index - 6 * 4, 6 * 4 );
return new ModelPart( index - 6 * 4, 6 * 4, desc.RotX, desc.RotY, desc.RotZ );
}
protected void XQuad( int texX, int texY, int texWidth, int texHeight,
@ -224,6 +230,14 @@ namespace ClassicalSharp.Model {
DrawRotated( x, y, z, angleX, angleY, angleZ, part, true );
}
protected void DrawRotate( float angleX, float angleY, float angleZ, ModelPart part ) {
DrawRotated( part.RotX, part.RotY, part.RotZ, angleX, angleY, angleZ, part, false );
}
protected void DrawHeadRotate( float angleX, float angleY, float angleZ, ModelPart part ) {
DrawRotated( part.RotX, part.RotY, part.RotZ, angleX, angleY, angleZ, part, true );
}
protected void DrawRotated( float x, float y, float z, float angleX, float angleY, float angleZ, ModelPart part, bool head ) {
float cosX = (float)Math.Cos( -angleX ), sinX = (float)Math.Sin( -angleX );
float cosY = (float)Math.Cos( -angleY ), sinY = (float)Math.Sin( -angleY );

View File

@ -8,17 +8,16 @@ namespace ClassicalSharp {
public struct ModelPart {
public int Offset, Count;
public float RotX, RotY, RotZ;
public ModelPart( int vertexOffset, int vertexCount ) {
Offset = vertexOffset;
Count = vertexCount;
public ModelPart( int offset, int count, float rotX, float rotY, float rotZ ) {
Offset = offset; Count = count;
RotX = rotX; RotY = rotY; RotZ = rotZ;
}
}
/// <summary> Describes the type of skin that a humanoid model uses. </summary>
public enum SkinType {
Type64x32,
Type64x64,
Type64x64Slim,
Type64x32, Type64x64, Type64x64Slim,
}
}