From 9a69dba8c50c463e927b1d1766e498c790aa386d Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 3 Sep 2015 20:06:30 +1000 Subject: [PATCH] And get player animations working again. --- ClassicalSharp/Entities/Player.Rendering.cs | 8 +++--- ClassicalSharp/Model/IModel.cs | 27 ++++++++++++--------- ClassicalSharp/Model/PlayerModel.cs | 2 +- ClassicalSharp/Utils/Utils.cs | 13 ++++++++-- 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/ClassicalSharp/Entities/Player.Rendering.cs b/ClassicalSharp/Entities/Player.Rendering.cs index 52befba88..5a6512b68 100644 --- a/ClassicalSharp/Entities/Player.Rendering.cs +++ b/ClassicalSharp/Entities/Player.Rendering.cs @@ -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 ); diff --git a/ClassicalSharp/Model/IModel.cs b/ClassicalSharp/Model/IModel.cs index b23bb1325..c90ae7471 100644 --- a/ClassicalSharp/Model/IModel.cs +++ b/ClassicalSharp/Model/IModel.cs @@ -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 ); } } } \ No newline at end of file diff --git a/ClassicalSharp/Model/PlayerModel.cs b/ClassicalSharp/Model/PlayerModel.cs index 6fe6c5fb3..b6b30cc45 100644 --- a/ClassicalSharp/Model/PlayerModel.cs +++ b/ClassicalSharp/Model/PlayerModel.cs @@ -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 ) { diff --git a/ClassicalSharp/Utils/Utils.cs b/ClassicalSharp/Utils/Utils.cs index a3ffa5817..fa30efbc1 100644 --- a/ClassicalSharp/Utils/Utils.cs +++ b/ClassicalSharp/Utils/Utils.cs @@ -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 ) {