Started work on implementing ChangeModel. (zombie model okay, creeper model has weird leg animation)

This commit is contained in:
UnknownShadow200 2015-01-03 18:28:15 +11:00
parent cceecf2ae7
commit 3ec9e3a3e3
14 changed files with 506 additions and 287 deletions

View file

@ -93,12 +93,10 @@
<Compile Include="Blocks\BlockInfo.Optimised.cs" />
<Compile Include="Entities\Entity.cs" />
<Compile Include="Entities\LocalPlayer.cs" />
<Compile Include="Entities\ModelPart.cs" />
<Compile Include="Entities\NetPlayer.cs" />
<Compile Include="Entities\Particle.cs" />
<Compile Include="Entities\ParticleManager.cs" />
<Compile Include="Entities\Player.cs" />
<Compile Include="Entities\PlayerModel.cs" />
<Compile Include="Game\Game.Chat.cs" />
<Compile Include="Game\Game.cs" />
<Compile Include="Game\Game.Events.cs" />
@ -115,6 +113,11 @@
<Compile Include="Map.cs" />
<Compile Include="MeshBuilders\ChunkMeshBuilder.cs" />
<Compile Include="MeshBuilders\ChunkMeshBuilderTex2Col4.cs" />
<Compile Include="Model\CreeperModel.cs" />
<Compile Include="Model\IModel.cs" />
<Compile Include="Model\ModelPart.cs" />
<Compile Include="Model\PlayerModel.cs" />
<Compile Include="Model\ZombieModel.cs" />
<Compile Include="Network\Enums.cs" />
<Compile Include="Network\FastNetReader.cs" />
<Compile Include="Network\FixedBufferStream.cs" />
@ -179,6 +182,7 @@
<Folder Include="Entities" />
<Folder Include="MeshBuilders" />
<Folder Include="Game" />
<Folder Include="Model" />
<Folder Include="Physics" />
</ItemGroup>
</Project>

View file

@ -1,35 +1,35 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
# SharpDevelop 4.3
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassicalSharp", "ClassicalSharp.csproj", "{BEB1C785-5CAD-48FF-A886-876BF0A318D4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Launcher", "Launcher\Launcher.csproj", "{23B9BDA8-4330-46AB-9012-08D87430391A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BEB1C785-5CAD-48FF-A886-876BF0A318D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BEB1C785-5CAD-48FF-A886-876BF0A318D4}.Debug|x86.Build.0 = Debug|Any CPU
{BEB1C785-5CAD-48FF-A886-876BF0A318D4}.Release|Any CPU.Build.0 = Release|Any CPU
{BEB1C785-5CAD-48FF-A886-876BF0A318D4}.Release|x86.Build.0 = Release|Any CPU
{23B9BDA8-4330-46AB-9012-08D87430391A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{23B9BDA8-4330-46AB-9012-08D87430391A}.Debug|x86.Build.0 = Debug|Any CPU
{23B9BDA8-4330-46AB-9012-08D87430391A}.Release|Any CPU.Build.0 = Release|Any CPU
{23B9BDA8-4330-46AB-9012-08D87430391A}.Release|x86.Build.0 = Release|Any CPU
{23B9BDA8-4330-46AB-9012-08D87430391A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{23B9BDA8-4330-46AB-9012-08D87430391A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{23B9BDA8-4330-46AB-9012-08D87430391A}.Release|Any CPU.Build.0 = Release|Any CPU
{23B9BDA8-4330-46AB-9012-08D87430391A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BEB1C785-5CAD-48FF-A886-876BF0A318D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BEB1C785-5CAD-48FF-A886-876BF0A318D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BEB1C785-5CAD-48FF-A886-876BF0A318D4}.Release|Any CPU.Build.0 = Release|Any CPU
{BEB1C785-5CAD-48FF-A886-876BF0A318D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
# SharpDevelop 4.4
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassicalSharp", "ClassicalSharp.csproj", "{BEB1C785-5CAD-48FF-A886-876BF0A318D4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Launcher", "Launcher\Launcher.csproj", "{23B9BDA8-4330-46AB-9012-08D87430391A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BEB1C785-5CAD-48FF-A886-876BF0A318D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BEB1C785-5CAD-48FF-A886-876BF0A318D4}.Debug|x86.Build.0 = Debug|Any CPU
{BEB1C785-5CAD-48FF-A886-876BF0A318D4}.Release|Any CPU.Build.0 = Release|Any CPU
{BEB1C785-5CAD-48FF-A886-876BF0A318D4}.Release|x86.Build.0 = Release|Any CPU
{23B9BDA8-4330-46AB-9012-08D87430391A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{23B9BDA8-4330-46AB-9012-08D87430391A}.Debug|x86.Build.0 = Debug|Any CPU
{23B9BDA8-4330-46AB-9012-08D87430391A}.Release|Any CPU.Build.0 = Release|Any CPU
{23B9BDA8-4330-46AB-9012-08D87430391A}.Release|x86.Build.0 = Release|Any CPU
{23B9BDA8-4330-46AB-9012-08D87430391A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{23B9BDA8-4330-46AB-9012-08D87430391A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{23B9BDA8-4330-46AB-9012-08D87430391A}.Release|Any CPU.Build.0 = Release|Any CPU
{23B9BDA8-4330-46AB-9012-08D87430391A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BEB1C785-5CAD-48FF-A886-876BF0A318D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BEB1C785-5CAD-48FF-A886-876BF0A318D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BEB1C785-5CAD-48FF-A886-876BF0A318D4}.Release|Any CPU.Build.0 = Release|Any CPU
{BEB1C785-5CAD-48FF-A886-876BF0A318D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View file

@ -75,7 +75,7 @@ namespace ClassicalSharp {
bool jumping, speeding, flying, noClip, flyingDown, flyingUp;
float jumpVelocity = 0.42f;
PlayerRenderer renderer;
public float JumpHeight {
get { return jumpVelocity == 0 ? 0 : (float)GetMaxHeight( jumpVelocity ); }
@ -329,7 +329,7 @@ namespace ClassicalSharp {
if( bmp != null ) {
Window.Graphics.DeleteTexture( renderer.TextureId );
renderer.TextureId = Window.Graphics.LoadTexture( bmp );
renderer.SetSkinType( Utils.GetSkinType( bmp ) );
SkinType = Utils.GetSkinType( bmp );
bmp.Dispose();
}
}

View file

@ -8,7 +8,6 @@ namespace ClassicalSharp {
public class NetPlayer : Player {
public PlayerRenderer renderer;
int tickCount = 0;
public NetPlayer( byte id, string displayName, string skinName, Game window ) : base( id, window ) {
@ -70,7 +69,7 @@ namespace ClassicalSharp {
if( bmp != null ) {
Window.Graphics.DeleteTexture( renderer.TextureId );
renderer.TextureId = Window.Graphics.LoadTexture( bmp );
renderer.SetSkinType( Utils.GetSkinType( bmp ) );
SkinType = Utils.GetSkinType( bmp );
bmp.Dispose();
}
tickCount++;

View file

@ -1,5 +1,6 @@
using System;
using OpenTK;
using ClassicalSharp.Renderers;
namespace ClassicalSharp {
@ -26,10 +27,13 @@ namespace ClassicalSharp {
public Game Window;
public byte ID;
public string DisplayName, SkinName;
protected PlayerRenderer renderer;
public SkinType SkinType;
public Player( byte id, Game window ) : base( window ) {
ID = id;
Window = window;
SkinType = Window.DefaultPlayerSkinType;
}
/// <summary> Gets the block just underneath the player's feet position. </summary>

View file

@ -1,132 +0,0 @@
using System;
using ClassicalSharp.GraphicsAPI;
namespace ClassicalSharp.Entities {
public class PlayerModel {
public ModelSet Set64x32, Set64x64, Set64x64Slim;
static readonly FastColour col = new FastColour( 178, 178, 178 );
IGraphicsApi graphics;
VertexPos3fTex2fCol4b[] vertices;
int index = 0;
public PlayerModel( IGraphicsApi graphics ) {
this.graphics = graphics;
vertices = new VertexPos3fTex2fCol4b[6 * 6];
Set64x32 = new ModelSet();
Set64x32.Head = MakeHead( false );
Set64x32.Torso = MakeTorso( false );
Set64x32.LeftLeg = MakeLeftLeg( 0, 16, 0.25f, 0f, false );
Set64x32.RightLeg = MakeRightLeg( 0, 16, 0, 0.25f, false );
Set64x32.LeftArm = MakeLeftArm( 40, 16, 0.5f, 0.25f, 4, false );
Set64x32.RightArm = MakeRightArm( 40, 16, 0.25f, 0.5f, 4, false );
Set64x32.Hat = MakeHat( false );
Set64x64 = new ModelSet();
Set64x64.Head = MakeHead( true );
Set64x64.Torso = MakeTorso( true );
Set64x64.LeftLeg = MakeLeftLeg( 16, 48, 0, 0.25f, true );
Set64x64.RightLeg = MakeRightLeg( 0, 16, 0, 0.25f, true );
Set64x64.LeftArm = MakeLeftArm( 32, 48, 0.25f, 0.5f, 4, true );
Set64x64.RightArm = MakeRightArm( 40, 16, 0.25f, 0.5f, 4, true );
Set64x64.Hat = MakeHat( true );
Set64x64Slim = new ModelSet();
Set64x64Slim.Head = MakeHead( true );
Set64x64Slim.Torso = MakeTorso( true );
Set64x64Slim.LeftLeg = MakeLeftLeg( 16, 48, 0, 0.25f, true );
Set64x64Slim.RightLeg = MakeRightLeg( 0, 16, 0, 0.25f, true );
Set64x64Slim.LeftArm = MakeLeftArm( 32, 48, 0.25f, 0.4375f, 3, true );
Set64x64Slim.RightArm = MakeRightArm( 40, 16, 0.25f, 0.4375f, 3, true );
Set64x64Slim.Hat = MakeHat( true );
vertices = null;
}
public void Dispose() {
Set64x32.Dispose();
Set64x64.Dispose();
Set64x64Slim.Dispose();
}
ModelPart MakeLeftArm( int x, int y, float x1, float x2, int width, bool _64x64 ) {
return MakePart( x, y, 4, 12, width, 4, width, 12, -x2, -x1, 0.875f, 1.625f, -0.125f, 0.125f, _64x64 );
}
ModelPart MakeRightArm( int x, int y, float x1, float x2, int width, bool _64x64 ) {
return MakePart( x, y, 4, 12, width, 4, width, 12, x1, x2, 0.875f, 1.625f, -0.125f, 0.125f, _64x64 );
}
ModelPart MakeHead( bool _64x64 ) {
return MakePart( 0, 0, 8, 8, 8, 8, 8, 8, -0.25f, 0.25f, 1.625f, 2.125f, -0.25f, 0.25f, _64x64 );
}
ModelPart MakeTorso( bool _64x64 ) {
return MakePart( 16, 16, 4, 12, 8, 4, 8, 12, -0.25f, 0.25f, 0.875f, 1.625f, -0.125f, 0.125f, _64x64 );
}
ModelPart MakeHat( bool _64x64 ) {
return MakePart( 32, 0, 8, 8, 8, 8, 8, 8, -0.3125f, 0.3125f, 1.5625f, 2.18775f, -0.3125f, 0.3125f, _64x64 );
}
ModelPart MakeLeftLeg( int x, int y, float x1, float x2, bool _64x64 ) {
return MakePart( x, y, 4, 12, 4, 4, 4, 12, -x2, -x1, 0f, 0.875f, -0.125f, 0.125f, _64x64 );
}
ModelPart MakeRightLeg( int x, int y, float x1, float x2, bool _64x64 ) {
return MakePart( x, y, 4, 12, 4, 4, 4, 12, x1, x2, 0f, 0.875f, -0.125f, 0.125f, _64x64 );
}
ModelPart MakePart( int x, int y, int sidesW, int sidesH, int endsW, int endsH, int bodyW, int bodyH,
float x1, float x2, float y1, float y2, float z1, float z2, bool _64x64 ) {
index = 0;
YPlane( x + sidesW, y, endsW, endsH, x2, x1, z2, z1, y2, _64x64 ); // top
YPlane( x + sidesW + bodyW, y, endsW, endsH, x2, x1, z1, z2, y1, _64x64 ); // bottom
ZPlane( x + sidesW, y + endsH, bodyW, bodyH, x2, x1, y1, y2, z1, _64x64 ); // front
ZPlane( x + sidesW + bodyW + sidesW, y + endsH, bodyW, bodyH, x1, x2, y1, y2, z2, _64x64 ); // back
XPlane( x + sidesW + bodyW, y + endsH, sidesW, sidesH, z1, z2, y1, y2, x1, _64x64 ); // left
XPlane( x, y + endsH, sidesW, sidesH, z2, z1, y1, y2, x2, _64x64 ); // right
return new ModelPart( vertices, graphics );
}
static TextureRectangle SkinTexCoords( int x, int y, int width, int height, float skinWidth, float skinHeight ) {
return new TextureRectangle( x / skinWidth, y / skinHeight, width / skinWidth, height / skinHeight );
}
void XPlane( int texX, int texY, int texWidth, int texHeight,
float z1, float z2, float y1, float y2, float x, bool _64x64 ) {
TextureRectangle rec = SkinTexCoords( texX, texY, texWidth, texHeight, 64, _64x64 ? 64 : 32 );
vertices[index++] = new VertexPos3fTex2fCol4b( x, y1, z1, rec.U1, rec.V2, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x, y2, z1, rec.U1, rec.V1, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x, y2, z2, rec.U2, rec.V1, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x, y2, z2, rec.U2, rec.V1, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x, y1, z2, rec.U2, rec.V2, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x, y1, z1, rec.U1, rec.V2, col );
}
void YPlane( int texX, int texY, int texWidth, int texHeight,
float x1, float x2, float z1, float z2, float y, bool _64x64 ) {
TextureRectangle rec = SkinTexCoords( texX, texY, texWidth, texHeight, 64, _64x64 ? 64 : 32 );
vertices[index++] = new VertexPos3fTex2fCol4b( x1, y, z1, rec.U1, rec.V1, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x2, y, z1, rec.U2, rec.V1, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x2, y, z2, rec.U2, rec.V2, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x2, y, z2, rec.U2, rec.V2, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x1, y, z2, rec.U1, rec.V2, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x1, y, z1, rec.U1, rec.V1, col );
}
void ZPlane( int texX, int texY, int texWidth, int texHeight,
float x1, float x2, float y1, float y2, float z, bool _64x64 ) {
TextureRectangle rec = SkinTexCoords( texX, texY, texWidth, texHeight, 64, _64x64 ? 64 : 32 );
vertices[index++] = new VertexPos3fTex2fCol4b( x1, y1, z, rec.U1, rec.V2, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x2, y1, z, rec.U2, rec.V2, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x2, y2, z, rec.U2, rec.V1, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x2, y2, z, rec.U2, rec.V1, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x1, y2, z, rec.U1, rec.V1, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x1, y1, z, rec.U1, rec.V2, col );
}
}
}

View file

@ -3,8 +3,8 @@ using System.Drawing;
using System.IO;
using System.Net;
using ClassicalSharp.Commands;
using ClassicalSharp.Entities;
using ClassicalSharp.GraphicsAPI;
using ClassicalSharp.Model;
using ClassicalSharp.Network;
using ClassicalSharp.Particles;
using ClassicalSharp.Renderers;
@ -33,7 +33,6 @@ namespace ClassicalSharp {
public int TerrainAtlasTexId = -1;
public TextureAtlas1D TerrainAtlas1D;
public int[] TerrainAtlas1DTexIds;
public int DefaultPlayerTextureId = -1;
public SkinType DefaultPlayerSkinType;
public int ChunkUpdates;
@ -46,7 +45,7 @@ namespace ClassicalSharp {
public ParticleManager ParticleManager;
public PickingRenderer Picking;
public PickedPos SelectedPos;
public PlayerModel ModelCache;
public IModel ModelCache;
internal string skinServer, chatInInputBuffer;
public bool CanUseThirdPersonCamera = true;
FpsScreen fpsScreen;
@ -144,15 +143,11 @@ namespace ClassicalSharp {
protected override void OnLoad( EventArgs e ) {
Graphics = new OpenGLApi();
ModelCache = new PlayerModel( Graphics );
ModelCache = new CreeperModel( this );
AsyncDownloader = new AsyncDownloader( skinServer );
PrintGraphicsInfo();
Bitmap terrainBmp = new Bitmap( "terrain.png" );
LoadAtlas( terrainBmp );
using( Bitmap bmp = new Bitmap( "char.png" ) ) {
DefaultPlayerSkinType = Utils.GetSkinType( bmp );
DefaultPlayerTextureId = Graphics.LoadTexture( bmp );
}
BlockInfo = new BlockInfo();
BlockInfo.Init();
BlockInfo.SetDefaultBlockPermissions( CanPlace, CanDelete );
@ -312,7 +307,6 @@ namespace ClassicalSharp {
NetPlayers[i].Despawn();
}
}
Graphics.DeleteTexture( DefaultPlayerTextureId );
LocalPlayer.Despawn();
Graphics.CheckResources();
AsyncDownloader.Dispose();

94
Model/CreeperModel.cs Normal file
View file

@ -0,0 +1,94 @@
using OpenTK;
using System;
using System.Drawing;
using ClassicalSharp.GraphicsAPI;
using ClassicalSharp.Renderers;
namespace ClassicalSharp.Model {
public class CreeperModel : IModel {
ModelSet Set;
public CreeperModel( Game window ) : base( window ) {
vertices = new VertexPos3fTex2fCol4b[6 * 6];
Set = new ModelSet();
Set.Head = MakeHead();
Set.Torso = MakeTorso();
Set.LeftLegFront = MakeLeg( 0, 16, -0.25f, 0, -0.375f, -0.125f );
Set.RightLegFront = MakeLeg( 0, 16, 0, 0.25f, -0.375f, -0.125f );
Set.LeftLegBack = MakeLeg( 0, 16, -0.25f, 0, 0.125f, 0.375f );
Set.RightLegBack = MakeLeg( 0, 16, 0, 0.25f, 0.125f, 0.375f );
vertices = null;
DefaultSkinTextureId = graphics.LoadTexture( "creeper.png" );
}
ModelPart MakeHead() {
return MakePart( 0, 0, 8, 8, 8, 8, 8, 8, -0.25f, 0.25f, 1.125f, 1.625f, -0.25f, 0.25f, false );
}
ModelPart MakeTorso() {
return MakePart( 16, 16, 4, 12, 8, 4, 8, 12, -0.25f, 0.25f, 0.375f, 1.125f, -0.125f, 0.125f, false );
}
ModelPart MakeLeg( int x, int y, float x1, float x2, float z1, float z2 ) {
return MakePart( x, y, 4, 6, 4, 4, 4, 6, x1, x2, 0f, 0.375f, z1, z2, false );
}
public override float NameYOffset {
get { return 1.7f; }
}
Vector3 pos;
float yaw, pitch;
float leftLegXRot, rightLegXRot;
public override void RenderModel( Player player, PlayerRenderer renderer ) {
pos = player.Position;
yaw = player.YawDegrees;
pitch = player.PitchDegrees;
leftLegXRot = player.leftLegXRot * 180 / (float)Math.PI;
rightLegXRot = player.rightLegXRot * 180 / (float)Math.PI;
graphics.PushMatrix();
graphics.Translate( pos.X, pos.Y, pos.Z );
graphics.RotateY( -yaw );
DrawPlayerModel( player, renderer );
graphics.PopMatrix();
}
private void DrawPlayerModel( Player player, PlayerRenderer renderer ) {
graphics.Texturing = true;
int texId = renderer.TextureId <= 0 ? DefaultSkinTextureId : renderer.TextureId;
graphics.Bind2DTexture( texId );
DrawRotateX( 0, 1.125f, 0, -pitch, Set.Head );
Set.Torso.Render();
DrawRotateX( 0, 0.375f, -0.25f, leftLegXRot, Set.LeftLegFront );
DrawRotateX( 0, 0.375f, -0.25f, rightLegXRot, Set.RightLegFront );
DrawRotateX( 0, 0.375f, 0.25f, rightLegXRot, Set.LeftLegBack );
DrawRotateX( 0, 0.375f, 0.25f, leftLegXRot, Set.RightLegBack );
graphics.AlphaTest = true;
}
public override void Dispose() {
Set.Dispose();
graphics.DeleteTexture( DefaultSkinTextureId );
}
class ModelSet {
public ModelPart Head, Torso, LeftLegFront, RightLegFront, LeftLegBack, RightLegBack;
public void Dispose() {
RightLegFront.Dispose();
LeftLegFront.Dispose();
RightLegBack.Dispose();
LeftLegBack.Dispose();
Torso.Dispose();
Head.Dispose();
}
}
}
}

101
Model/IModel.cs Normal file
View file

@ -0,0 +1,101 @@
using System;
using ClassicalSharp.GraphicsAPI;
using ClassicalSharp.Renderers;
using OpenTK;
namespace ClassicalSharp.Model {
public abstract class IModel {
protected Game window;
protected IGraphicsApi graphics;
public IModel( Game window ) {
this.window = window;
graphics = window.Graphics;
}
public abstract float NameYOffset { get; }
public abstract void RenderModel( Player player, PlayerRenderer renderer );
public abstract void Dispose();
public int DefaultSkinTextureId; //{ get; protected set; }
protected FastColour col = new FastColour( 178, 178, 178 );
protected VertexPos3fTex2fCol4b[] vertices;
protected int index = 0;
protected ModelPart MakePart( int x, int y, int sidesW, int sidesH, int endsW, int endsH, int bodyW, int bodyH,
float x1, float x2, float y1, float y2, float z1, float z2, bool _64x64 ) {
index = 0;
YPlane( x + sidesW, y, endsW, endsH, x2, x1, z2, z1, y2, _64x64 ); // top
YPlane( x + sidesW + bodyW, y, endsW, endsH, x2, x1, z1, z2, y1, _64x64 ); // bottom
ZPlane( x + sidesW, y + endsH, bodyW, bodyH, x2, x1, y1, y2, z1, _64x64 ); // front
ZPlane( x + sidesW + bodyW + sidesW, y + endsH, bodyW, bodyH, x1, x2, y1, y2, z2, _64x64 ); // back
XPlane( x + sidesW + bodyW, y + endsH, sidesW, sidesH, z1, z2, y1, y2, x1, _64x64 ); // left
XPlane( x, y + endsH, sidesW, sidesH, z2, z1, y1, y2, x2, _64x64 ); // right
return new ModelPart( vertices, graphics );
}
protected static TextureRectangle SkinTexCoords( int x, int y, int width, int height, float skinWidth, float skinHeight ) {
return new TextureRectangle( x / skinWidth, y / skinHeight, width / skinWidth, height / skinHeight );
}
protected void XPlane( int texX, int texY, int texWidth, int texHeight,
float z1, float z2, float y1, float y2, float x, bool _64x64 ) {
TextureRectangle rec = SkinTexCoords( texX, texY, texWidth, texHeight, 64, _64x64 ? 64 : 32 );
vertices[index++] = new VertexPos3fTex2fCol4b( x, y1, z1, rec.U1, rec.V2, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x, y2, z1, rec.U1, rec.V1, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x, y2, z2, rec.U2, rec.V1, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x, y2, z2, rec.U2, rec.V1, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x, y1, z2, rec.U2, rec.V2, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x, y1, z1, rec.U1, rec.V2, col );
}
protected void YPlane( int texX, int texY, int texWidth, int texHeight,
float x1, float x2, float z1, float z2, float y, bool _64x64 ) {
TextureRectangle rec = SkinTexCoords( texX, texY, texWidth, texHeight, 64, _64x64 ? 64 : 32 );
vertices[index++] = new VertexPos3fTex2fCol4b( x1, y, z1, rec.U1, rec.V1, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x2, y, z1, rec.U2, rec.V1, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x2, y, z2, rec.U2, rec.V2, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x2, y, z2, rec.U2, rec.V2, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x1, y, z2, rec.U1, rec.V2, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x1, y, z1, rec.U1, rec.V1, col );
}
protected void ZPlane( int texX, int texY, int texWidth, int texHeight,
float x1, float x2, float y1, float y2, float z, bool _64x64 ) {
TextureRectangle rec = SkinTexCoords( texX, texY, texWidth, texHeight, 64, _64x64 ? 64 : 32 );
vertices[index++] = new VertexPos3fTex2fCol4b( x1, y1, z, rec.U1, rec.V2, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x2, y1, z, rec.U2, rec.V2, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x2, y2, z, rec.U2, rec.V1, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x2, y2, z, rec.U2, rec.V1, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x1, y2, z, rec.U1, rec.V1, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x1, y1, z, rec.U1, rec.V2, col );
}
protected void DrawRotateX( float x, float y, float z, float angleX, ModelPart part ) {
graphics.PushMatrix();
graphics.Translate( x, y, z );
graphics.RotateX( angleX );
graphics.Translate( -x, -y, -z );
part.Render();
graphics.PopMatrix();
}
protected void DrawRotateXZ( float x, float y, float z, float angleX, float angleZ, ModelPart part ) {
graphics.PushMatrix();
graphics.Translate( x, y, z );
graphics.RotateZ( angleZ );
graphics.RotateX( angleX );
graphics.Translate( -x, -y, -z );
part.Render();
graphics.PopMatrix();
}
}
}

View file

@ -24,21 +24,6 @@ namespace ClassicalSharp {
}
}
public class ModelSet {
public ModelPart Head, Torso, LeftLeg, RightLeg, LeftArm, RightArm, Hat;
public void Dispose() {
Hat.Dispose();
RightArm.Dispose();
LeftArm.Dispose();
RightLeg.Dispose();
LeftLeg.Dispose();
Torso.Dispose();
Head.Dispose();
}
}
public enum SkinType {
Type64x32,
Type64x64,

147
Model/PlayerModel.cs Normal file
View file

@ -0,0 +1,147 @@
using OpenTK;
using System;
using System.Drawing;
using ClassicalSharp.GraphicsAPI;
using ClassicalSharp.Renderers;
namespace ClassicalSharp.Model {
public class PlayerModel : IModel {
ModelSet Set64x32, Set64x64, Set64x64Slim;
public PlayerModel( Game window ) : base( window ) {
vertices = new VertexPos3fTex2fCol4b[6 * 6];
Set64x32 = new ModelSet();
Set64x32.Head = MakeHead( false );
Set64x32.Torso = MakeTorso( false );
Set64x32.LeftLeg = MakeLeftLeg( 0, 16, 0.25f, 0f, false );
Set64x32.RightLeg = MakeRightLeg( 0, 16, 0, 0.25f, false );
Set64x32.LeftArm = MakeLeftArm( 40, 16, 0.5f, 0.25f, 4, false );
Set64x32.RightArm = MakeRightArm( 40, 16, 0.25f, 0.5f, 4, false );
Set64x32.Hat = MakeHat( false );
Set64x64 = new ModelSet();
Set64x64.Head = MakeHead( true );
Set64x64.Torso = MakeTorso( true );
Set64x64.LeftLeg = MakeLeftLeg( 16, 48, 0, 0.25f, true );
Set64x64.RightLeg = MakeRightLeg( 0, 16, 0, 0.25f, true );
Set64x64.LeftArm = MakeLeftArm( 32, 48, 0.25f, 0.5f, 4, true );
Set64x64.RightArm = MakeRightArm( 40, 16, 0.25f, 0.5f, 4, true );
Set64x64.Hat = MakeHat( true );
Set64x64Slim = new ModelSet();
Set64x64Slim.Head = MakeHead( true );
Set64x64Slim.Torso = MakeTorso( true );
Set64x64Slim.LeftLeg = MakeLeftLeg( 16, 48, 0, 0.25f, true );
Set64x64Slim.RightLeg = MakeRightLeg( 0, 16, 0, 0.25f, true );
Set64x64Slim.LeftArm = MakeLeftArm( 32, 48, 0.25f, 0.4375f, 3, true );
Set64x64Slim.RightArm = MakeRightArm( 40, 16, 0.25f, 0.4375f, 3, true );
Set64x64Slim.Hat = MakeHat( true );
vertices = null;
using( Bitmap bmp = new Bitmap( "char.png" ) ) {
window.DefaultPlayerSkinType = Utils.GetSkinType( bmp );
DefaultSkinTextureId = graphics.LoadTexture( bmp );
}
}
ModelPart MakeLeftArm( int x, int y, float x1, float x2, int width, bool _64x64 ) {
return MakePart( x, y, 4, 12, width, 4, width, 12, -x2, -x1, 0.875f, 1.625f, -0.125f, 0.125f, _64x64 );
}
ModelPart MakeRightArm( int x, int y, float x1, float x2, int width, bool _64x64 ) {
return MakePart( x, y, 4, 12, width, 4, width, 12, x1, x2, 0.875f, 1.625f, -0.125f, 0.125f, _64x64 );
}
ModelPart MakeHead( bool _64x64 ) {
return MakePart( 0, 0, 8, 8, 8, 8, 8, 8, -0.25f, 0.25f, 1.625f, 2.125f, -0.25f, 0.25f, _64x64 );
}
ModelPart MakeTorso( bool _64x64 ) {
return MakePart( 16, 16, 4, 12, 8, 4, 8, 12, -0.25f, 0.25f, 0.875f, 1.625f, -0.125f, 0.125f, _64x64 );
}
ModelPart MakeHat( bool _64x64 ) {
return MakePart( 32, 0, 8, 8, 8, 8, 8, 8, -0.3125f, 0.3125f, 1.5625f, 2.18775f, -0.3125f, 0.3125f, _64x64 );
}
ModelPart MakeLeftLeg( int x, int y, float x1, float x2, bool _64x64 ) {
return MakePart( x, y, 4, 12, 4, 4, 4, 12, -x2, -x1, 0f, 0.875f, -0.125f, 0.125f, _64x64 );
}
ModelPart MakeRightLeg( int x, int y, float x1, float x2, bool _64x64 ) {
return MakePart( x, y, 4, 12, 4, 4, 4, 12, x1, x2, 0f, 0.875f, -0.125f, 0.125f, _64x64 );
}
public override float NameYOffset {
get { return 2.2f; }
}
Vector3 pos;
float yaw, pitch;
ModelSet model;
float rightLegXRot, rightArmXRot, rightArmZRot;
float leftLegXRot, leftArmXRot, leftArmZRot;
public override void RenderModel( Player player, PlayerRenderer renderer ) {
pos = player.Position;
yaw = player.YawDegrees;
pitch = player.PitchDegrees;
leftLegXRot = player.leftLegXRot * 180 / (float)Math.PI;
leftArmXRot = player.leftArmXRot * 180 / (float)Math.PI;
leftArmZRot = player.leftArmZRot * 180 / (float)Math.PI;
rightLegXRot = player.rightLegXRot * 180 / (float)Math.PI;
rightArmXRot = player.rightArmXRot * 180 / (float)Math.PI;
rightArmZRot = player.rightArmZRot * 180 / (float)Math.PI;
model = Set64x32;
SkinType skinType = player.SkinType;
if( skinType == SkinType.Type64x64 ) model = Set64x64;
else if( skinType == SkinType.Type64x64Slim ) model = Set64x64Slim;
graphics.PushMatrix();
graphics.Translate( pos.X, pos.Y, pos.Z );
graphics.RotateY( -yaw );
DrawPlayerModel( player, renderer );
graphics.PopMatrix();
}
private void DrawPlayerModel( Player player, PlayerRenderer renderer ) {
graphics.Texturing = true;
int texId = renderer.TextureId <= 0 ? DefaultSkinTextureId : renderer.TextureId;
graphics.Bind2DTexture( texId );
DrawRotateX( 0, 1.625f, 0, -pitch, model.Head );
model.Torso.Render();
DrawRotateX( 0, 0.875f, 0, leftLegXRot, model.LeftLeg );
DrawRotateX( 0, 0.875f, 0, rightLegXRot, model.RightLeg );
DrawRotateXZ( 0, 1.625f, 0, leftArmXRot, leftArmZRot, model.LeftArm );
DrawRotateXZ( 0, 1.625f, 0, rightArmXRot, rightArmZRot, model.RightArm );
graphics.AlphaTest = true;
DrawRotateX( 0, 1.5625f, 0, -pitch, model.Hat );
}
public override void Dispose() {
Set64x32.Dispose();
Set64x64.Dispose();
Set64x64Slim.Dispose();
graphics.DeleteTexture( DefaultSkinTextureId );
}
class ModelSet {
public ModelPart Head, Torso, LeftLeg, RightLeg, LeftArm, RightArm, Hat;
public void Dispose() {
Hat.Dispose();
RightArm.Dispose();
LeftArm.Dispose();
RightLeg.Dispose();
LeftLeg.Dispose();
Torso.Dispose();
Head.Dispose();
}
}
}
}

110
Model/ZombieModel.cs Normal file
View file

@ -0,0 +1,110 @@
using OpenTK;
using System;
using System.Drawing;
using ClassicalSharp.GraphicsAPI;
using ClassicalSharp.Renderers;
namespace ClassicalSharp.Model {
public class ZombieModel : IModel {
ModelSet Set;
public ZombieModel( Game window ) : base( window ) {
vertices = new VertexPos3fTex2fCol4b[6 * 6];
Set = new ModelSet();
Set.Head = MakeHead();
Set.Torso = MakeTorso();
Set.LeftLeg = MakeLeftLeg( 0, 16, 0.25f, 0f );
Set.RightLeg = MakeRightLeg( 0, 16, 0, 0.25f );
Set.LeftArm = MakeLeftArm( 40, 16, 0.5f, 0.25f, 4 );
Set.RightArm = MakeRightArm( 40, 16, 0.25f, 0.5f, 4 );
vertices = null;
DefaultSkinTextureId = graphics.LoadTexture( "zombie.png" );
}
ModelPart MakeLeftArm( int x, int y, float x1, float x2, int width ) {
return MakePart( x, y, 4, 12, width, 4, width, 12, -x2, -x1, 0.875f, 1.625f, -0.125f, 0.125f, false );
}
ModelPart MakeRightArm( int x, int y, float x1, float x2, int width) {
return MakePart( x, y, 4, 12, width, 4, width, 12, x1, x2, 0.875f, 1.625f, -0.125f, 0.125f, false );
}
ModelPart MakeHead() {
return MakePart( 0, 0, 8, 8, 8, 8, 8, 8, -0.25f, 0.25f, 1.625f, 2.125f, -0.25f, 0.25f, false );
}
ModelPart MakeTorso() {
return MakePart( 16, 16, 4, 12, 8, 4, 8, 12, -0.25f, 0.25f, 0.875f, 1.625f, -0.125f, 0.125f, false );
}
ModelPart MakeLeftLeg( int x, int y, float x1, float x2 ) {
return MakePart( x, y, 4, 12, 4, 4, 4, 12, -x2, -x1, 0f, 0.875f, -0.125f, 0.125f, false );
}
ModelPart MakeRightLeg( int x, int y, float x1, float x2 ) {
return MakePart( x, y, 4, 12, 4, 4, 4, 12, x1, x2, 0f, 0.875f, -0.125f, 0.125f, false );
}
public override float NameYOffset {
get { return 2.2f; }
}
Vector3 pos;
float yaw, pitch;
float rightLegXRot, rightArmXRot, rightArmZRot;
float leftLegXRot, leftArmXRot, leftArmZRot;
public override void RenderModel( Player player, PlayerRenderer renderer ) {
pos = player.Position;
yaw = player.YawDegrees;
pitch = player.PitchDegrees;
leftLegXRot = player.leftLegXRot * 180 / (float)Math.PI;
leftArmXRot = player.leftArmXRot * 180 / (float)Math.PI;
leftArmZRot = player.leftArmZRot * 180 / (float)Math.PI;
rightLegXRot = player.rightLegXRot * 180 / (float)Math.PI;
rightArmXRot = player.rightArmXRot * 180 / (float)Math.PI;
rightArmZRot = player.rightArmZRot * 180 / (float)Math.PI;
graphics.PushMatrix();
graphics.Translate( pos.X, pos.Y, pos.Z );
graphics.RotateY( -yaw );
DrawPlayerModel( player, renderer );
graphics.PopMatrix();
}
private void DrawPlayerModel( Player player, PlayerRenderer renderer ) {
graphics.Texturing = true;
int texId = renderer.TextureId <= 0 ? DefaultSkinTextureId : renderer.TextureId;
graphics.Bind2DTexture( texId );
DrawRotateX( 0, 1.625f, 0, -pitch, Set.Head );
Set.Torso.Render();
DrawRotateX( 0, 0.375f, 0, leftLegXRot, Set.LeftLeg );
DrawRotateX( 0, 0.875f, 0, rightLegXRot, Set.RightLeg );
DrawRotateXZ( 0, 1.625f, 0, leftArmXRot, leftArmZRot, Set.LeftArm );
DrawRotateXZ( 0, 1.625f, 0, rightArmXRot, rightArmZRot, Set.RightArm );
}
public override void Dispose() {
Set.Dispose();
graphics.DeleteTexture( DefaultSkinTextureId );
}
class ModelSet {
public ModelPart Head, Torso, LeftLeg, RightLeg, LeftArm, RightArm;
public void Dispose() {
RightArm.Dispose();
LeftArm.Dispose();
RightLeg.Dispose();
LeftLeg.Dispose();
Torso.Dispose();
Head.Dispose();
}
}
}
}

View file

@ -147,7 +147,7 @@ namespace ClassicalSharp {
// === CPE support list ===
// TextHotKey : unlikely
// ExtPlayerList : yes (only version 1, not 2)
// ChangeModel : no
// ChangeModel : planned
// EnvWeatherType : unlikely
static string[] clientExtensions = new string[] {
"EmoteFix", "ClickDistance", "HeldBlock", "BlockPermissions",

View file

@ -9,31 +9,18 @@ namespace ClassicalSharp.Renderers {
public class PlayerRenderer {
Vector3 pos;
float yaw, pitch;
public Game Window;
public IGraphicsApi Graphics;
public bool Moves;
public ModelSet Model;
public Player Player;
Texture nameTexture;
float nameWidth, nameHeight;
public int TextureId = -1;
int nameTextureId = -1;
float rightLegXRot, rightArmXRot, rightArmZRot;
float leftLegXRot, leftArmXRot, leftArmZRot;
public void SetSkinType( SkinType type ) {
if( type == SkinType.Type64x32 ) Model = Window.ModelCache.Set64x32;
else if( type == SkinType.Type64x64 ) Model = Window.ModelCache.Set64x64;
else if( type == SkinType.Type64x64Slim ) Model = Window.ModelCache.Set64x64Slim;
else Model = Window.ModelCache.Set64x32;
}
public PlayerRenderer( Player player, Game window ) {
Player = player;
Window = window;
Graphics = window.Graphics;
SetSkinType( window.DefaultPlayerSkinType );
List<DrawTextArgs> parts = Utils.SplitText( Graphics, player.DisplayName, true );
Size size = Utils2D.MeasureSize( Utils.StripColours( player.DisplayName ), "Arial", 14, true );
@ -50,88 +37,14 @@ namespace ClassicalSharp.Renderers {
public void Render( double deltaTime ) {
pos = Player.Position;
yaw = Player.YawDegrees;
pitch = Player.PitchDegrees;
leftLegXRot = Player.leftLegXRot * 180 / (float)Math.PI;
leftArmXRot = Player.leftArmXRot * 180 / (float)Math.PI;
leftArmZRot = Player.leftArmZRot * 180 / (float)Math.PI;
rightLegXRot = Player.rightLegXRot * 180 / (float)Math.PI;
rightArmXRot = Player.rightArmXRot * 180 / (float)Math.PI;
rightArmZRot = Player.rightArmZRot * 180 / (float)Math.PI;
Graphics.PushMatrix();
Graphics.Translate( pos.X, pos.Y, pos.Z );
Graphics.RotateY( -yaw );
DrawPlayerModel();
Graphics.PopMatrix();
Window.ModelCache.RenderModel( Player, this );
DrawName();
}
private void DrawPlayerModel() {
Graphics.Texturing = true;
int texId = TextureId == -1 ? Window.DefaultPlayerTextureId : TextureId;
Graphics.Bind2DTexture( texId );
// Head
Graphics.PushMatrix();
Graphics.Translate( 0f, 1.625f, 0f );
Graphics.RotateX( -pitch );
Graphics.Translate( 0f, -1.625f, 0f );
Model.Head.Render();
Graphics.PopMatrix();
// Torso
Model.Torso.Render();
// Left leg
Graphics.PushMatrix();
Graphics.Translate( 0f, 0.875f, 0f );
Graphics.RotateX( leftLegXRot );
Graphics.Translate( 0f, -0.875f, 0f );
Model.LeftLeg.Render();
Graphics.PopMatrix();
// Right leg
Graphics.PushMatrix();
Graphics.Translate( 0f, 0.875f, 0f );
Graphics.RotateX( rightLegXRot );
Graphics.Translate( 0f, -0.875f, 0f );
Model.RightLeg.Render();
Graphics.PopMatrix();
// Left arm
Graphics.PushMatrix();
Graphics.Translate( 0f, 1.625f, 0f );
Graphics.RotateZ( leftArmZRot );
Graphics.RotateX( leftArmXRot );
Graphics.Translate( 0f, -1.625f, 0f );
Model.LeftArm.Render();
Graphics.PopMatrix();
// Right arm
Graphics.PushMatrix();
Graphics.Translate( 0f, 1.625f, 0f );
Graphics.RotateZ( rightArmZRot );
Graphics.RotateX( rightArmXRot );
Graphics.Translate( 0f, -1.625f, 0f );
Model.RightArm.Render();
Graphics.PopMatrix();
// Hat
Graphics.AlphaTest = true;
Graphics.PushMatrix();
Graphics.Translate( 0f, 1.5625f, 0f );
Graphics.RotateX( -pitch );
Graphics.Translate( 0f, -1.5625f, 0f );
Model.Hat.Render();
Graphics.PopMatrix();
}
const float nameScale = 50f;
private void DrawName() {
Graphics.PushMatrix();
Graphics.Translate( pos.X, pos.Y + 2.2f, pos.Z );
Graphics.Translate( pos.X, pos.Y + Window.ModelCache.NameYOffset, pos.Z );
// Do this to always have names facing the player
float yaw = Window.LocalPlayer.YawDegrees;
Graphics.RotateY( 0f - yaw );