Held block/arm now renders properly at any position, including millions of coords away from zero.

(i.e. always rendered at origin position)
This commit is contained in:
UnknownShadow200 2018-07-02 20:42:54 +10:00
parent 92db25cea9
commit 4c47fb9f8b
8 changed files with 16 additions and 26 deletions

View File

@ -73,15 +73,12 @@ namespace ClassicalSharp.Entities {
public abstract void RenderName();
public virtual void ContextLost() { }
public virtual void ContextRecreated() { }
public virtual void ContextRecreated() { }
/// <summary> Gets the position of the player's eye in the world. </summary>
public Vector3 EyePosition {
get { return new Vector3(Position.X,
Position.Y + Model.GetEyeY(this) * ModelScale.Y, Position.Z); }
get { return new Vector3(Position.X, Position.Y + EyeHeight, Position.Z); }
}
public float EyeHeight { get { return Model.GetEyeY(this) * ModelScale.Y; } }
public Matrix4 TransformMatrix(Vector3 scale, Vector3 pos) {
Matrix4 m = Matrix4.Identity, tmp;

View File

@ -19,7 +19,6 @@ namespace ClassicalSharp {
const float uv2Scale = 15.99f/16f;
/// <summary> Draws the left face of the given cuboid region. </summary>
public void Left(int count, int col, int texLoc, VertexP3fT2fC4b[] vertices, ref int index) {
float vOrigin = (texLoc % Atlas1D.TilesPerAtlas) * Atlas1D.invTileSize;
float u1 = minBB.Z, u2 = (count - 1) + maxBB.Z * uv2Scale;
@ -34,7 +33,6 @@ namespace ClassicalSharp {
v.Z = z2 + (count - 1); v.U = u2; vertices[index++] = v;
}
/// <summary> Draws the right face of the given cuboid region. </summary>
public void Right(int count, int col, int texLoc, VertexP3fT2fC4b[] vertices, ref int index) {
float vOrigin = (texLoc % Atlas1D.TilesPerAtlas) * Atlas1D.invTileSize;
float u1 = (count - minBB.Z), u2 = (1 - maxBB.Z) * uv2Scale;
@ -49,7 +47,6 @@ namespace ClassicalSharp {
v.Z = z1; v.U = u1; vertices[index++] = v;
}
/// <summary> Draws the front face of the given cuboid region. </summary>
public void Front(int count, int col, int texLoc, VertexP3fT2fC4b[] vertices, ref int index) {
float vOrigin = (texLoc % Atlas1D.TilesPerAtlas) * Atlas1D.invTileSize;
float u1 = (count - minBB.X), u2 = (1 - maxBB.X) * uv2Scale;
@ -64,7 +61,6 @@ namespace ClassicalSharp {
v.X = x2 + (count - 1); v.U = u2; vertices[index++] = v;
}
/// <summary> Draws the back face of the given cuboid region. </summary>
public void Back(int count, int col, int texLoc, VertexP3fT2fC4b[] vertices, ref int index) {
float vOrigin = (texLoc % Atlas1D.TilesPerAtlas) * Atlas1D.invTileSize;
float u1 = minBB.X, u2 = (count - 1) + maxBB.X * uv2Scale;
@ -79,7 +75,6 @@ namespace ClassicalSharp {
v.X = x2 + (count - 1); v.U = u2; vertices[index++] = v;
}
/// <summary> Draws the bottom face of the given cuboid region. </summary>
public void Bottom(int count, int col, int texLoc, VertexP3fT2fC4b[] vertices, ref int index) {
float vOrigin = (texLoc % Atlas1D.TilesPerAtlas) * Atlas1D.invTileSize;
float u1 = minBB.X, u2 = (count - 1) + maxBB.X * uv2Scale;
@ -94,7 +89,6 @@ namespace ClassicalSharp {
v.X = x2 + (count - 1); v.U = u2; vertices[index++] = v;
}
/// <summary> Draws the top face of the given cuboid region. </summary>
public void Top(int count, int col, int texLoc, VertexP3fT2fC4b[] vertices, ref int index) {
float vOrigin = (texLoc % Atlas1D.TilesPerAtlas) * Atlas1D.invTileSize;
float u1 = minBB.X, u2 = (count - 1) + maxBB.X * uv2Scale;

View File

@ -21,8 +21,6 @@ namespace ClassicalSharp.Network {
game.SupportsCPEBlocks = false;
}
/// <summary> Sets fields / updates network handles based on the server
/// indicating it supports the given CPE extension. </summary>
public void HandleEntry(string ext, int version, NetworkProcessor net) {
ServerExtensionsCount--;

View File

@ -86,7 +86,7 @@ namespace ClassicalSharp.Renderers {
static Vector3 sOffset = new Vector3(0.46f, -0.52f, -0.72f);
void SetMatrix() {
Player p = game.LocalPlayer;
Vector3 eyePos = p.EyePosition;
Vector3 eyePos = Vector3.Zero; eyePos.Y = p.EyeHeight;
Matrix4 m, lookAt;
Matrix4.LookAt(eyePos, eyePos - Vector3.UnitZ, Vector3.UnitY, out lookAt);
@ -97,7 +97,8 @@ namespace ClassicalSharp.Renderers {
void ResetHeldState() {
// Based off details from http://pastebin.com/KFV0HkmD (Thanks goodlyay!)
Player p = game.LocalPlayer;
held.Position = p.EyePosition;
Vector3 eyePos = Vector3.Zero; eyePos.Y = p.EyeHeight;
held.Position = eyePos;
held.Position.X -= game.Camera.bobbingHor;
held.Position.Y -= game.Camera.bobbingVer;

View File

@ -29,7 +29,6 @@ namespace ClassicalSharp {
public const int StringLength = 64;
/// <summary> Returns a string with all the colour codes stripped from it. </summary>
public static string StripColours(string value) {
if (value.IndexOf('&') == -1) return value;
char[] output = new char[value.Length];
@ -81,8 +80,6 @@ namespace ClassicalSharp {
}
#if !LAUNCHER
/// <summary> Attempts to caselessly parse the given string as a Key enum member,
/// returning defValue if there was an error parsing. </summary>
public static bool TryParseEnum<T>(string value, T defValue, out T result) {
T mapping;
try {
@ -128,7 +125,6 @@ namespace ClassicalSharp {
return SkinType.Invalid;
}
/// <summary> Returns whether the specified string starts with http:// or https:// </summary>
public static bool IsUrlPrefix(string value, int index) {
int http = value.IndexOf("http://", index);
int https = value.IndexOf("https://", index);

View File

@ -83,9 +83,11 @@ void Entity_Init(Entity* entity) {
}
Vector3 Entity_GetEyePosition(Entity* entity) {
Vector3 pos = entity->Position;
pos.Y += entity->Model->GetEyeY(entity) * entity->ModelScale.Y;
return pos;
Vector3 pos = entity->Position; pos.Y += Entity_GetEyeHeight(entity); return pos;
}
Real32 Entity_GetEyeHeight(Entity* entity) {
return entity->Model->GetEyeY(entity) * entity->ModelScale.Y;
}
void Entity_GetTransform(Entity* entity, Vector3 pos, Vector3 scale) {

View File

@ -90,6 +90,7 @@ typedef struct Entity_ {
void Entity_Init(Entity* entity);
Vector3 Entity_GetEyePosition(Entity* entity);
Real32 Entity_GetEyeHeight(Entity* entity);
void Entity_GetTransform(Entity* entity, Vector3 pos, Vector3 scale);
void Entity_GetPickingBounds(Entity* entity, AABB* bb);
void Entity_GetBounds(Entity* entity, AABB* bb);

View File

@ -44,8 +44,8 @@ static void HeldBlockRenderer_RenderModel(void) {
}
static void HeldBlockRenderer_SetMatrix(void) {
Entity* player = &LocalPlayer_Instance.Base;
Vector3 eyePos = Entity_GetEyePosition(player);
Entity* player = &LocalPlayer_Instance.Base;
Vector3 eyePos = VECTOR3_CONST(0.0f, Entity_GetEyeHeight(player), 0.0f);
Vector3 up = Vector3_UnitY;
Vector3 target = eyePos; target.Z -= 1.0f; /* Look straight down*/
@ -58,7 +58,8 @@ static void HeldBlockRenderer_SetMatrix(void) {
static void HeldBlockRenderer_ResetHeldState(void) {
/* Based off details from http://pastebin.com/KFV0HkmD (Thanks goodlyay!) */
Entity* player = &LocalPlayer_Instance.Base;
held_entity.Position = Entity_GetEyePosition(player);
Vector3 eyePos = VECTOR3_CONST(0.0f, Entity_GetEyeHeight(player), 0.0f);
held_entity.Position = eyePos;
held_entity.Position.X -= Camera_BobbingHor;
held_entity.Position.Y -= Camera_BobbingVer;