Fix last commit

This commit is contained in:
UnknownShadow200 2017-04-09 08:40:06 +10:00
parent 20f638fb67
commit 04cef2f247
4 changed files with 23 additions and 19 deletions

View File

@ -75,7 +75,7 @@ namespace ClassicalSharp.Model {
return base.RenderDistance(p);
}
int lastTexId = -1;
int lastTexId = -1, col;
public override void DrawModel(Entity p) {
// TODO: using 'is' is ugly, but means we can avoid creating
// a string every single time held block changes.

View File

@ -65,6 +65,7 @@ namespace ClassicalSharp.Model {
DrawRotate(0, 0, -Math.Abs(p.anim.armXRot), LeftWing, false);
DrawRotate(0, 0, Math.Abs(p.anim.armXRot), RightWing, false);
int col = cols[0];
for (int i = 0; i < cols.Length; i++) {
cols[i] = FastColour.ScalePacked(col, 0.7f);
}

View File

@ -71,7 +71,9 @@ namespace ClassicalSharp.Model {
public override void DrawModel(Entity p) {
p.anim.legXRot = 1.5f;
game.ModelCache.Models[0].Instance.DrawModel(p);
IModel model = game.ModelCache.Models[0].Instance;
model.SetupState(p);
model.DrawModel(p);
}
}

View File

@ -67,7 +67,6 @@ namespace ClassicalSharp.Model {
/// assuming that the model is not rotated at all.</summary>
public abstract AABB PickingBounds { get; }
protected Vector3 pos;
protected float cosHead, sinHead;
protected float uScale, vScale;
@ -103,22 +102,9 @@ namespace ClassicalSharp.Model {
/// <summary> Sets up the state for, then renders an entity model,
/// based on the given entity's position and orientation. </summary>
public void Render(Entity p) {
index = 0;
pos = p.Position;
Vector3 pos = p.Position;
if (Bobbing) pos.Y += p.anim.bobbingModel;
Vector3I P = Vector3I.Floor(p.EyePosition);
col = game.World.IsValidPos(P) ? game.Lighting.LightCol(P.X, P.Y, P.Z) : game.Lighting.Outside;
uScale = 1 / 64f; vScale = 1 / 32f;
cols[0] = col;
cols[1] = FastColour.ScalePacked(col, FastColour.ShadeYBottom);
cols[2] = FastColour.ScalePacked(col, FastColour.ShadeZ); cols[3] = cols[2];
cols[4] = FastColour.ScalePacked(col, FastColour.ShadeX); cols[5] = cols[4];
float yawDelta = p.HeadY - p.RotY;
cosHead = (float)Math.Cos(yawDelta * Utils.Deg2Rad);
sinHead = (float)Math.Sin(yawDelta * Utils.Deg2Rad);
SetupState(p);
game.Graphics.SetBatchFormat(VertexFormat.P3fT2fC4b);
game.Graphics.PushMatrix();
@ -129,6 +115,22 @@ namespace ClassicalSharp.Model {
game.Graphics.PopMatrix();
}
public void SetupState(Entity p) {
index = 0;
Vector3I P = Vector3I.Floor(p.EyePosition);
int col = game.World.IsValidPos(P) ? game.Lighting.LightCol(P.X, P.Y, P.Z) : game.Lighting.Outside;
uScale = 1 / 64f; vScale = 1 / 32f;
cols[0] = col;
cols[1] = FastColour.ScalePacked(col, FastColour.ShadeYBottom);
cols[2] = FastColour.ScalePacked(col, FastColour.ShadeZ); cols[3] = cols[2];
cols[4] = FastColour.ScalePacked(col, FastColour.ShadeX); cols[5] = cols[4];
float yawDelta = p.HeadY - p.RotY;
cosHead = (float)Math.Cos(yawDelta * Utils.Deg2Rad);
sinHead = (float)Math.Sin(yawDelta * Utils.Deg2Rad);
}
/// <summary> Performs the actual rendering of an entity model. </summary>
public abstract void DrawModel(Entity p);
@ -148,7 +150,6 @@ namespace ClassicalSharp.Model {
return p.TransformMatrix(p.ModelScale, pos);
}
protected int col;
protected int[] cols = new int[6];
protected internal ModelVertex[] vertices;
protected internal int index, texIndex;