From ad18567f69de49472e7b9dcf776439fc1eba937d Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 3 Sep 2015 18:40:25 +1000 Subject: [PATCH] Fix bug with StringBuffer/UnsafeString being drawn way too wide on some Windows versions, fixes #46. (Thanks Cheesse) --- ClassicalSharp/Entities/Player.Rendering.cs | 9 ++++----- ClassicalSharp/Model/BlockModel.cs | 1 - ClassicalSharp/Model/ChickenModel.cs | 1 - ClassicalSharp/Model/CreeperModel.cs | 1 - ClassicalSharp/Model/IModel.cs | 2 +- ClassicalSharp/Model/PigModel.cs | 1 - ClassicalSharp/Model/PlayerModel.cs | 1 - ClassicalSharp/Model/SkeletonModel.cs | 1 - ClassicalSharp/Model/SpiderModel.cs | 1 - ClassicalSharp/Model/ZombieModel.cs | 1 - ClassicalSharp/Utils/StringBuffer.cs | 2 +- ClassicalSharp/Utils/Utils.cs | 4 ++++ 12 files changed, 10 insertions(+), 15 deletions(-) diff --git a/ClassicalSharp/Entities/Player.Rendering.cs b/ClassicalSharp/Entities/Player.Rendering.cs index 7d3bc580e..52befba88 100644 --- a/ClassicalSharp/Entities/Player.Rendering.cs +++ b/ClassicalSharp/Entities/Player.Rendering.cs @@ -44,11 +44,10 @@ namespace ClassicalSharp { Vector3 pos = Position; pos.Y += Model.NameYOffset; - // Inlined translation + rotation Y axis - api.texVerts[0] = new VertexPos3fTex2f( cosA * x1 + pos.X, y1 + pos.Y, sinA * x1 + pos.Z, nameTex.U1, nameTex.V1 ); - api.texVerts[1] = new VertexPos3fTex2f( cosA * x2 + pos.X, y1 + pos.Y, sinA * x2 + pos.Z, nameTex.U2, nameTex.V1 ); - api.texVerts[2] = new VertexPos3fTex2f( cosA * x2 + pos.X, y2 + pos.Y, sinA * x2 + pos.Z, nameTex.U2, nameTex.V2 ); - api.texVerts[3] = new VertexPos3fTex2f( cosA * x1 + pos.X, y2 + pos.Y, sinA * x1 + pos.Z, nameTex.U1, nameTex.V2 ); + 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.BeginVbBatch( VertexFormat.Pos3fTex2f ); api.DrawDynamicIndexedVb( DrawMode.Triangles, api.texVb, api.texVerts, 4, 6 ); diff --git a/ClassicalSharp/Model/BlockModel.cs b/ClassicalSharp/Model/BlockModel.cs index bc7d11880..cfa788499 100644 --- a/ClassicalSharp/Model/BlockModel.cs +++ b/ClassicalSharp/Model/BlockModel.cs @@ -1,6 +1,5 @@ using System; using ClassicalSharp.GraphicsAPI; -using ClassicalSharp.Renderers; using OpenTK; namespace ClassicalSharp.Model { diff --git a/ClassicalSharp/Model/ChickenModel.cs b/ClassicalSharp/Model/ChickenModel.cs index d582e8e91..6d7b44b2a 100644 --- a/ClassicalSharp/Model/ChickenModel.cs +++ b/ClassicalSharp/Model/ChickenModel.cs @@ -1,6 +1,5 @@ using System; using ClassicalSharp.GraphicsAPI; -using ClassicalSharp.Renderers; using OpenTK; namespace ClassicalSharp.Model { diff --git a/ClassicalSharp/Model/CreeperModel.cs b/ClassicalSharp/Model/CreeperModel.cs index 58a8a698e..8836fcacb 100644 --- a/ClassicalSharp/Model/CreeperModel.cs +++ b/ClassicalSharp/Model/CreeperModel.cs @@ -1,6 +1,5 @@ using System; using ClassicalSharp.GraphicsAPI; -using ClassicalSharp.Renderers; using OpenTK; namespace ClassicalSharp.Model { diff --git a/ClassicalSharp/Model/IModel.cs b/ClassicalSharp/Model/IModel.cs index a95b74ba4..f8c57b1b4 100644 --- a/ClassicalSharp/Model/IModel.cs +++ b/ClassicalSharp/Model/IModel.cs @@ -11,7 +11,7 @@ namespace ClassicalSharp.Model { protected IGraphicsApi graphics; protected const int planeVertices = 4; protected const int partVertices = 6 * planeVertices; - + public IModel( Game window ) { this.window = window; graphics = window.Graphics; diff --git a/ClassicalSharp/Model/PigModel.cs b/ClassicalSharp/Model/PigModel.cs index 66128deed..77bcd414c 100644 --- a/ClassicalSharp/Model/PigModel.cs +++ b/ClassicalSharp/Model/PigModel.cs @@ -1,6 +1,5 @@ using System; using ClassicalSharp.GraphicsAPI; -using ClassicalSharp.Renderers; using OpenTK; namespace ClassicalSharp.Model { diff --git a/ClassicalSharp/Model/PlayerModel.cs b/ClassicalSharp/Model/PlayerModel.cs index 43e288ddb..2b38782c9 100644 --- a/ClassicalSharp/Model/PlayerModel.cs +++ b/ClassicalSharp/Model/PlayerModel.cs @@ -1,7 +1,6 @@ using System; using System.Drawing; using ClassicalSharp.GraphicsAPI; -using ClassicalSharp.Renderers; using OpenTK; namespace ClassicalSharp.Model { diff --git a/ClassicalSharp/Model/SkeletonModel.cs b/ClassicalSharp/Model/SkeletonModel.cs index 3b532dd1e..b98b55648 100644 --- a/ClassicalSharp/Model/SkeletonModel.cs +++ b/ClassicalSharp/Model/SkeletonModel.cs @@ -1,6 +1,5 @@ using System; using ClassicalSharp.GraphicsAPI; -using ClassicalSharp.Renderers; using OpenTK; namespace ClassicalSharp.Model { diff --git a/ClassicalSharp/Model/SpiderModel.cs b/ClassicalSharp/Model/SpiderModel.cs index f88d19c21..e8687ead6 100644 --- a/ClassicalSharp/Model/SpiderModel.cs +++ b/ClassicalSharp/Model/SpiderModel.cs @@ -1,6 +1,5 @@ using System; using ClassicalSharp.GraphicsAPI; -using ClassicalSharp.Renderers; using OpenTK; namespace ClassicalSharp.Model { diff --git a/ClassicalSharp/Model/ZombieModel.cs b/ClassicalSharp/Model/ZombieModel.cs index bf2540832..54cc4e42b 100644 --- a/ClassicalSharp/Model/ZombieModel.cs +++ b/ClassicalSharp/Model/ZombieModel.cs @@ -1,6 +1,5 @@ using System; using ClassicalSharp.GraphicsAPI; -using ClassicalSharp.Renderers; using OpenTK; namespace ClassicalSharp.Model { diff --git a/ClassicalSharp/Utils/StringBuffer.cs b/ClassicalSharp/Utils/StringBuffer.cs index 8ded0008f..13b3076bd 100644 --- a/ClassicalSharp/Utils/StringBuffer.cs +++ b/ClassicalSharp/Utils/StringBuffer.cs @@ -144,7 +144,7 @@ namespace ClassicalSharp { /// The underlying string - ***do not*** store this because it is mutable! /// You should only use this string for temporary measuring and drawing. public string UpdateCachedString() { - return supportsLengthSetting ? value : value.TrimEnd( trimEnd ); + return supportsLengthSetting ? SetLength( Length ) : value.TrimEnd( trimEnd ); } static char[] trimEnd = { '\0' }; diff --git a/ClassicalSharp/Utils/Utils.cs b/ClassicalSharp/Utils/Utils.cs index f818b8b59..a3ffa5817 100644 --- a/ClassicalSharp/Utils/Utils.cs +++ b/ClassicalSharp/Utils/Utils.cs @@ -128,6 +128,10 @@ 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 float DistanceSquared( Vector3 p1, Vector3 p2 ) { float dx = p2.X - p1.X; float dy = p2.Y - p1.Y;