And get player animations working again.

This commit is contained in:
UnknownShadow200 2015-09-03 20:06:30 +10:00
parent afb758eb3e
commit 9a69dba8c5
4 changed files with 32 additions and 18 deletions

View File

@ -44,10 +44,10 @@ namespace ClassicalSharp {
Vector3 pos = Position;
pos.Y += Model.NameYOffset;
api.texVerts[0] = new VertexPos3fTex2f( Utils.RotateY( x1, y1, 0, pos, cosA, sinA ), nameTex.U1, nameTex.V1 );
api.texVerts[1] = new VertexPos3fTex2f( Utils.RotateY( x2, y1, 0, pos, cosA, sinA ), nameTex.U2, nameTex.V1 );
api.texVerts[2] = new VertexPos3fTex2f( Utils.RotateY( x2, y2, 0, pos, cosA, sinA ), nameTex.U2, nameTex.V2 );
api.texVerts[3] = new VertexPos3fTex2f( Utils.RotateY( x1, y2, 0, pos, cosA, sinA ), nameTex.U1, nameTex.V2 );
api.texVerts[0] = new VertexPos3fTex2f( Utils.RotateY( x1, y1, 0, cosA, sinA ) + pos, nameTex.U1, nameTex.V1 );
api.texVerts[1] = new VertexPos3fTex2f( Utils.RotateY( x2, y1, 0, cosA, sinA ) + pos, nameTex.U2, nameTex.V1 );
api.texVerts[2] = new VertexPos3fTex2f( Utils.RotateY( x2, y2, 0, cosA, sinA ) + pos, nameTex.U2, nameTex.V2 );
api.texVerts[3] = new VertexPos3fTex2f( Utils.RotateY( x1, y2, 0, cosA, sinA ) + pos, nameTex.U1, nameTex.V2 );
api.BeginVbBatch( VertexFormat.Pos3fTex2f );
api.DrawDynamicIndexedVb( DrawMode.Triangles, api.texVb, api.texVerts, 4, 6 );

View File

@ -112,7 +112,7 @@ namespace ClassicalSharp.Model {
protected void DrawPart( ModelPart part ) {
for( int i = 0; i < part.Count; i++ ) {
VertexPos3fTex2fCol4b vertex = vertices[part.Offset + i];
Vector3 newPos = Utils.RotateY( vertex.X, vertex.Y, vertex.Z, pos, cosA, sinA );
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;
cache.vertices[index++] = vertex;
}
@ -120,17 +120,22 @@ namespace ClassicalSharp.Model {
protected void DrawRotate( float x, float y, float z, float angleX, float angleY, float angleZ, ModelPart part ) {
Matrix4 mat = Matrix4.Translate( x, y, z );
if( angleZ != 0 ) {
mat = Matrix4.RotateZ( angleZ ) * mat;
float cosX = (float)Math.Cos( -angleX ), sinX = (float)Math.Sin( -angleX );
float cosY = (float)Math.Cos( -angleY ), sinY = (float)Math.Sin( -angleY );
float cosZ = (float)Math.Cos( -angleZ ), sinZ = (float)Math.Sin( -angleZ );
Vector3 offset = new Vector3( x, y, z ) + pos;
for( int i = 0; i < part.Count; i++ ) {
VertexPos3fTex2fCol4b vertex = vertices[part.Offset + i];
Vector3 loc = new Vector3( vertex.X - x, vertex.Y - y, vertex.Z - z );
loc = Utils.RotateZ( loc.X, loc.Y, loc.Z, cosZ, sinZ );
loc = Utils.RotateY( loc.X, loc.Y, loc.Z, cosY, sinY );
loc = Utils.RotateX( loc.X, loc.Y, loc.Z, cosX, sinX );
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;
cache.vertices[index++] = vertex;
}
if( angleY != 0 ) {
mat = Matrix4.RotateY( angleY ) * mat;
}
if( angleX != 0 ) {
mat = Matrix4.RotateX( angleX ) * mat;
}
mat = Matrix4.Translate( -x, -y, -z ) * mat;
DrawPart( part );
}
}
}

View File

@ -52,7 +52,7 @@ namespace ClassicalSharp.Model {
}
ModelPart MakeHead( bool _64x64 ) {
return MakePart( 0, 0, 8, 8, 8, 8, 8, 8, -4f/16, 4f/16, 24f/16f, 2f, -4f/16, 4f/16, _64x64 );
return MakePart( 0, 0, 8, 8, 8, 8, 8, 8, -4f/16, 4f/16, 24f/16f, 32f/16f, -4f/16, 4f/16, _64x64 );
}
ModelPart MakeTorso( bool _64x64 ) {

View File

@ -121,6 +121,7 @@ namespace ClassicalSharp {
float sinA = (float)Math.Sin( angle );
return new Vector3( cosA * v.X - sinA * v.Z, v.Y, sinA * v.X + cosA * v.Z );
}
public static Vector3 RotateY( float x, float y, float z, float angle ) {
float cosA = (float)Math.Cos( angle );
@ -128,8 +129,16 @@ namespace ClassicalSharp {
return new Vector3( cosA * x - sinA * z, y, sinA * x + cosA * z );
}
public static Vector3 RotateY( float x, float y, float z, Vector3 translate, float cosA, float sinA ) {
return new Vector3( cosA * x - sinA * z + translate.X, y + translate.Y, sinA * x + cosA * z + translate.Z );
public static Vector3 RotateX( float x, float y, float z, float cosA, float sinA ) {
return new Vector3( x, cosA * y + sinA * z, -sinA * y + cosA * z );
}
public static Vector3 RotateY( float x, float y, float z, float cosA, float sinA ) {
return new Vector3( cosA * x - sinA * z, y, sinA * x + cosA * z );
}
public static Vector3 RotateZ( float x, float y, float z, float cosA, float sinA ) {
return new Vector3( cosA * x + sinA * y, -sinA * x + cosA * y, z );
}
public static float DistanceSquared( Vector3 p1, Vector3 p2 ) {