From 9d50aa3585a11b6fd215408d737fd7903b6c1341 Mon Sep 17 00:00:00 2001 From: Goodlyay Date: Thu, 9 Mar 2017 21:52:19 -0800 Subject: [PATCH] Add sitting model --- .../Entities/Components/AnimatedComponent.cs | 2 +- ClassicalSharp/Entities/Model/HumanModels.cs | 81 +++++++++++++++++++ .../Entities/Model/HumanoidModel.cs | 4 +- ClassicalSharp/Entities/Model/ModelCache.cs | 2 + 4 files changed, 86 insertions(+), 3 deletions(-) diff --git a/ClassicalSharp/Entities/Components/AnimatedComponent.cs b/ClassicalSharp/Entities/Components/AnimatedComponent.cs index dbd8e9abf..ff9a02e88 100644 --- a/ClassicalSharp/Entities/Components/AnimatedComponent.cs +++ b/ClassicalSharp/Entities/Components/AnimatedComponent.cs @@ -71,7 +71,7 @@ namespace ClassicalSharp.Entities { tiltY = (float)Math.Sin(walkTime) * swing * (0.15f * Utils.Deg2Rad); } - if (entity.Model is HumanoidModel) + if (entity.Model is HumanoidModel || entity.Model is HumanoidModel) CalcHumanAnim(idleXRot, idleZRot); } diff --git a/ClassicalSharp/Entities/Model/HumanModels.cs b/ClassicalSharp/Entities/Model/HumanModels.cs index 2ef7d9ac5..e896fa53e 100644 --- a/ClassicalSharp/Entities/Model/HumanModels.cs +++ b/ClassicalSharp/Entities/Model/HumanModels.cs @@ -37,6 +37,87 @@ namespace ClassicalSharp.Model { get { return new AABB(-4/16f, 0, -4/16f, 4/16f, 16/16f, 4/16f); } } } + + public class SittingModel : HumanoidModel { + + public SittingModel(Game window) : base(window) { } + + const int sitOffset = 10; + protected override void MakeDescriptions() { + head = MakeBoxBounds(-4, 24-sitOffset, -4, 4, 32-sitOffset, 4).RotOrigin(0, (sbyte)(24-sitOffset), 0); + torso = MakeBoxBounds(-4, 12-sitOffset, -2, 4, 24-sitOffset, 2); + lLeg = MakeBoxBounds(-4, 0-sitOffset, -2, 0, 12-sitOffset, 2).RotOrigin(0, (sbyte)(12-sitOffset), 0); + rLeg = MakeBoxBounds(0, 0-sitOffset, -2, 4, 12-sitOffset, 2).RotOrigin(0, (sbyte)(12-sitOffset), 0); + lArm = MakeBoxBounds(-8, 12-sitOffset, -2, -4, 24-sitOffset, 2).RotOrigin(-5, (sbyte)(22-sitOffset), 0); + rArm = MakeBoxBounds(4, 12-sitOffset, -2, 8, 24-sitOffset, 2).RotOrigin(5, (sbyte)(22-sitOffset), 0); + } + + public override float MaxScale { get { return 2; } } + + public override float ShadowScale { get { return 0.5f; } } + + public override float NameYOffset { get { return (32-sitOffset)/16f + 0.5f/16f; } } + + 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); } + } + + public override AABB PickingBounds { + get { return new AABB(-8/16f, 0, -4/16f, 8/16f, (32-sitOffset)/16f, 4/16f); } + } + + protected override void DrawModel(Entity p) { + game.Graphics.BindTexture(GetTexture(p.TextureId)); + game.Graphics.AlphaTest = false; + + bool _64x64 = p.SkinType != SkinType.Type64x32; + uScale = p.uScale / 64f; + vScale = p.vScale / (_64x64 ? 64 : 32); + RenderParts(p); + } + + protected override void RenderParts(Entity p) { + SkinType skinType = p.SkinType; + ModelSet model = skinType == SkinType.Type64x64Slim ? SetSlim : + (skinType == SkinType.Type64x64 ? Set64 : Set); + + DrawRotate(-p.HeadXRadians, 0, 0, model.Head, true); + DrawPart(model.Torso); + + float legRotateX = 1.5f; + float legRotateZ = 0.1f; + + DrawRotate(legRotateX, 0, -legRotateZ, model.LeftLeg, false); + DrawRotate(legRotateX, 0, legRotateZ, model.RightLeg, false); + Rotate = RotateOrder.XZY; + //DrawRotate(0, 0, -legRotateZ, model.LeftArm, false); + //DrawRotate(0, 0, legRotateZ, model.RightArm, false); + DrawRotate(p.anim.leftXRot, 0, p.anim.leftZRot, model.LeftArm, false); + DrawRotate(p.anim.rightXRot, 0, p.anim.rightZRot, model.RightArm, false); + Rotate = RotateOrder.ZYX; + UpdateVB(); + + game.Graphics.AlphaTest = true; + index = 0; + if (skinType != SkinType.Type64x32) { + DrawPart(model.TorsoLayer); + DrawRotate(legRotateX, 0, -legRotateZ, model.LeftLegLayer, false); + DrawRotate(legRotateX, 0, legRotateZ, model.RightLegLayer, false); + Rotate = RotateOrder.XZY; + + DrawRotate(p.anim.leftXRot, 0, p.anim.leftZRot, model.LeftArmLayer, false); + DrawRotate(p.anim.rightXRot, 0, p.anim.rightZRot, model.RightArmLayer, false); + //DrawRotate(0, 0, -legRotateZ, model.LeftArmLayer, false); + //DrawRotate(0, 0, legRotateZ, model.RightArmLayer, false); + Rotate = RotateOrder.ZYX; + } + DrawRotate(-p.HeadXRadians, 0, 0, model.Hat, true); + UpdateVB(); + } + + } public class HumanoidHeadModel : HumanoidModel { diff --git a/ClassicalSharp/Entities/Model/HumanoidModel.cs b/ClassicalSharp/Entities/Model/HumanoidModel.cs index 1410357e2..9e07aca96 100644 --- a/ClassicalSharp/Entities/Model/HumanoidModel.cs +++ b/ClassicalSharp/Entities/Model/HumanoidModel.cs @@ -9,7 +9,7 @@ namespace ClassicalSharp.Model { public class HumanoidModel : IModel { - ModelSet Set, SetSlim, Set64; + public ModelSet Set, SetSlim, Set64; public HumanoidModel(Game window) : base(window) { } protected BoxDesc head, torso, lLeg, rLeg, lArm, rArm; @@ -123,7 +123,7 @@ namespace ClassicalSharp.Model { UpdateVB(); } - class ModelSet { + public class ModelSet { public ModelPart Head, Torso, LeftLeg, RightLeg, LeftArm, RightArm, Hat, TorsoLayer, LeftLegLayer, RightLegLayer, LeftArmLayer, RightArmLayer; } diff --git a/ClassicalSharp/Entities/Model/ModelCache.cs b/ClassicalSharp/Entities/Model/ModelCache.cs index cb5da0640..167d360ff 100644 --- a/ClassicalSharp/Entities/Model/ModelCache.cs +++ b/ClassicalSharp/Entities/Model/ModelCache.cs @@ -115,6 +115,8 @@ namespace ClassicalSharp.Model { Register("block", null, new BlockModel(game)); Register("chibi", "char.png", new ChibiModel(game)); Register("head", "char.png", new HumanoidHeadModel(game)); + Register("sit", "char.png", new SittingModel(game)); + Register("sitting", "char.png", new SittingModel(game)); } void TextureChanged(object sender, TextureEventArgs e) {