Skip to content

Commit

Permalink
Initial work on arm in hand.
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Aug 18, 2017
1 parent b4a5cfc commit 32e24eb
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 25 deletions.
76 changes: 58 additions & 18 deletions ClassicalSharp/Entities/Model/HumanModels.cs
Expand Up @@ -35,8 +35,8 @@ public class ChibiModel : HumanoidModel {
public override AABB PickingBounds {
get { return new AABB(-4/16f, 0, -4/16f, 4/16f, 16/16f, 4/16f); }
}
}
}
public class SittingModel : IModel {

public SittingModel(Game window) : base(window) {
Expand All @@ -53,11 +53,11 @@ public class SittingModel : IModel {
public override float GetEyeY(Entity entity) { return (26 - sitOffset)/16f; }

public override Vector3 CollisionSize {
get { return new Vector3(8/16f + 0.6f/16f, (28.1f - sitOffset)/16f, 8/16f + 0.6f/16f); }
get { return new Vector3(8/16f + 0.6f/16f, (28.1f - sitOffset)/16f, 8/16f + 0.6f/16f); }
}

public override AABB PickingBounds {
get { return new AABB(-8/16f, 0, -4/16f, 8/16f, (32 - sitOffset)/16f, 4/16f); }
get { return new AABB(-8/16f, 0, -4/16f, 8/16f, (32 - sitOffset)/16f, 4/16f); }
}

protected internal override Matrix4 TransformMatrix(Entity p, Vector3 pos) {
Expand All @@ -72,23 +72,13 @@ public class SittingModel : IModel {
IModel model = game.ModelCache.Models[0].Instance;
model.SetupState(p);
model.DrawModel(p);
}
}
}

public class HumanoidHeadModel : HumanoidModel {

public HumanoidHeadModel(Game window) : base(window) { }

public ModelPart Head, Hat;
public override void CreateParts() {
vertices = new ModelVertex[boxVertices * 2];
head = MakeBoxBounds(-4, 0, -4, 4, 8, 4).RotOrigin(0, 4, 0);

Head = BuildBox(head.TexOrigin(0, 0));
Hat = BuildBox(head.TexOrigin(32, 0).Expand(offset));
}

public override float NameYOffset { get { return 8/16f + 0.5f/16f; } }
public override void CreateParts() { }

public override float GetEyeY(Entity entity) { return 6/16f; }

Expand All @@ -99,14 +89,64 @@ public class HumanoidHeadModel : HumanoidModel {
public override AABB PickingBounds {
get { return new AABB(-4/16f, 0, -4/16f, 4/16f, 8/16f, 4/16f); }
}

protected internal override Matrix4 TransformMatrix(Entity p, Vector3 pos) {
pos.Y -= (24 / 16f) * p.ModelScale.Y;
return p.TransformMatrix(p.ModelScale, pos);
}

protected override void RenderParts(Entity p) {
DrawRotate(-p.HeadXRadians, 0, 0, Head, true);
HumanoidModel human = (HumanoidModel)game.ModelCache.Models[0].Instance;
human.cols = cols;
human.cosHead = cosHead; human.sinHead = sinHead;
human.uScale = uScale; human.vScale = vScale;
vertices = human.vertices;

DrawRotate(-p.HeadXRadians, 0, 0, human.Set.Head, true);
UpdateVB();

game.Graphics.AlphaTest = true;
index = 0;
DrawRotate(-p.HeadXRadians, 0, 0, Hat, true);
DrawRotate(-p.HeadXRadians, 0, 0, human.Set.Hat, true);
UpdateVB();
}
}

public class ArmModel : HumanoidModel {

public ArmModel(Game window) : base(window) { }
public override void CreateParts() { }

public override float NameYOffset { get { return 2.075f; } }

public override float GetEyeY(Entity entity) { return 26/16f; }

public override Vector3 CollisionSize {
get { return new Vector3(8/16f + 0.6f/16f, 28.1f/16f, 8/16f + 0.6f/16f); }
}

public override AABB PickingBounds {
get { return new AABB(-4/16f, 0, -4/16f, 4/16f, 32/16f, 4/16f); }
}

protected internal override Matrix4 TransformMatrix(Entity p, Vector3 pos) {
pos.X -= (6 / 16f) * p.ModelScale.X;
pos.Y -= (18 / 16f) * p.ModelScale.Y;
return p.TransformMatrix(p.ModelScale, pos);
}

protected override void RenderParts(Entity p) {
HumanoidModel human = (HumanoidModel)game.ModelCache.Models[0].Instance;
human.cols = cols;
human.cosHead = cosHead; human.sinHead = sinHead;
human.uScale = uScale; human.vScale = vScale;
vertices = human.vertices;

SkinType skinType = p.SkinType;
ModelSet model = skinType == SkinType.Type64x64Slim ? human.SetSlim :
(skinType == SkinType.Type64x64 ? human.Set64 : human.Set);

DrawRotate(0, 0, 120 * Utils.Deg2Rad, model.RightArm, false);
UpdateVB();
}
}
Expand Down
6 changes: 3 additions & 3 deletions ClassicalSharp/Entities/Model/IModel.cs
Expand Up @@ -74,8 +74,8 @@ public abstract class IModel {
/// assuming that the model is not rotated at all.</summary>
public abstract AABB PickingBounds { get; }

protected float cosHead, sinHead;
protected float uScale, vScale;
protected internal float cosHead, sinHead;
protected internal float uScale, vScale;

/// <summary> Returns whether the model should be rendered based on the given entity's position. </summary>
public static bool ShouldRender(Entity p, FrustumCulling culling) {
Expand Down Expand Up @@ -158,7 +158,7 @@ public abstract class IModel {
return p.TransformMatrix(p.ModelScale, pos);
}

protected int[] cols = new int[6];
protected internal int[] cols = new int[6];
protected internal ModelVertex[] vertices;
protected internal int index, texIndex;

Expand Down
1 change: 1 addition & 0 deletions ClassicalSharp/Entities/Model/ModelCache.cs
Expand Up @@ -107,6 +107,7 @@ public class ModelCache : IDisposable {
Register("head", "char.png", new HumanoidHeadModel(game));
Register("sit", "char.png", new SittingModel(game));
Register("sitting", "char.png", new SittingModel(game));
Register("arm", "char.png", new ArmModel(game));
}

void TextureChanged(object sender, TextureEventArgs e) {
Expand Down
16 changes: 12 additions & 4 deletions ClassicalSharp/Rendering/HeldBlockRenderer.cs
Expand Up @@ -17,7 +17,6 @@ namespace ClassicalSharp.Renderers {
public class HeldBlockRenderer : IGameComponent {

internal BlockID block;
IModel model;
internal HeldBlockAnimation anim;

Game game;
Expand All @@ -26,7 +25,6 @@ public class HeldBlockRenderer : IGameComponent {

public void Init(Game game) {
this.game = game;
model = game.ModelCache.Get("block");
held = new FakePlayer(game);
game.Events.ProjectionChanged += ProjectionChanged;

Expand Down Expand Up @@ -59,9 +57,18 @@ public class HeldBlockRenderer : IGameComponent {

SetPos();
game.Graphics.FaceCulling = true;

IModel model;
if (BlockInfo.Draw[block] == DrawType.Gas) {
model = game.ModelCache.Get("arm");
held.ModelScale = new Vector3(1.0f);
} else {
model = game.ModelCache.Get("block");
held.ModelScale = new Vector3(0.4f);
}
model.Render(held);
game.Graphics.FaceCulling = false;

game.Graphics.FaceCulling = false;
game.Graphics.LoadMatrix(ref game.View);
game.Graphics.SetMatrixMode(MatrixType.Projection);
game.Graphics.LoadMatrix(ref game.Projection);
Expand All @@ -86,7 +93,6 @@ public class HeldBlockRenderer : IGameComponent {
bool sprite = BlockInfo.Draw[block] == DrawType.Sprite;
Vector3 offset = sprite ? sOffset : nOffset;
Player p = game.LocalPlayer;
held.ModelScale = new Vector3(0.4f);

held.Position = p.EyePosition + anim.pos;
held.Position += offset;
Expand All @@ -103,6 +109,8 @@ public class HeldBlockRenderer : IGameComponent {
held.RotY = -45 + anim.angleY;
held.HeadX = 0;
held.ModelBlock = block;
held.SkinType = p.SkinType;
held.TextureId = p.TextureId;
}

void ProjectionChanged(object sender, EventArgs e) {
Expand Down

0 comments on commit 32e24eb

Please sign in to comment.