Removed Classes/Models folder, reworked SKinPreview.cs, renamed MouseRay to Ray and changed Renderer3D member names

This commit is contained in:
miku-666
2023-10-01 12:48:28 +02:00
parent 8b4a931673
commit fb5c0e08d0
28 changed files with 438 additions and 2557 deletions

View File

@@ -1,11 +0,0 @@
using System;
namespace PckStudio.Models
{
public enum BackgroundTypes
{
Color,
Gradient,
Texture
}
}

View File

@@ -1,14 +0,0 @@
using System;
namespace PckStudio.Models
{
public enum Backgrounds
{
LightStone,
DarkStone,
DaySky,
NightSky,
Sunset,
Transparent
}
}

View File

@@ -1,158 +0,0 @@
using System;
using System.Drawing;
namespace PckStudio.Models
{
public class Box : Object3D
{
public override Image Image
{
set
{
SetImage(value);
}
}
internal override MinecraftModelView Viewport
{
set
{
base.Viewport = value;
top.Viewport = value;
bottom.Viewport = value;
front.Viewport = value;
back.Viewport = value;
left.Viewport = value;
right.Viewport = value;
Update();
}
}
internal override void Update()
{
Matrix3D a = globalTransformation * localTransformation;
top.LocalTransformation = a * topLocalTransformation;
bottom.LocalTransformation = a * bottomLocalTransformation;
front.LocalTransformation = a * frontLocalTransformation;
back.LocalTransformation = a * backLocalTransformation;
left.LocalTransformation = a * leftLocalTransformation;
right.LocalTransformation = a * rightLocalTransformation;
}
public Box(Image image, Rectangle srcTopBottom, Rectangle srcSides, Point3D origin, Effects effects = Effects.None)
{
this.effects = effects;
Origin = origin;
SetImage(image, srcTopBottom, srcSides);
}
private void SetImage(Image image, Rectangle srcTopBottom, Rectangle srcSides)
{
int num = srcTopBottom.Width / 2;
int height = srcSides.Height;
int height2 = srcTopBottom.Height;
srcTop = new Rectangle(srcTopBottom.Location, new Size(num, height2));
srcBottom = new Rectangle(srcTopBottom.X + num, srcTopBottom.Y, num, height2);
srcFront = new Rectangle(srcSides.X + height2, srcSides.Y, num, height);
srcBack = new Rectangle(srcSides.X + height2 + num + height2, srcSides.Y, num, height);
srcLeft = new Rectangle(srcSides.Location, new Size(height2, height));
srcRight = new Rectangle(srcSides.X + height2 + num, srcSides.Y, height2, height);
SetImage(image);
}
private void SetImage(Image image)
{
bool flag = (byte)(effects & Effects.FlipHorizontally) == 1;
bool flag2 = (byte)(effects & Effects.FlipVertically) == 2;
int width = srcFront.Width;
int height = srcFront.Height;
int width2 = srcLeft.Width;
top = new TexturePlane(image, flag2 ? srcBottom : srcTop, new Point3D(width * 0.5f, width2 * 0.5f, (float)(-(float)height) * 0.5f), new Point3D(0f, 1f, 0f), effects & Effects.FlipHorizontally);
bottom = new TexturePlane(image, flag2 ? srcTop : srcBottom, new Point3D(width / 2f, width2 / 2f, height / 2f), new Point3D(0f, -1f, 0f), effects & Effects.FlipHorizontally);
front = new TexturePlane(image, srcFront, new Point3D(width * 0.5f, height * 0.5f, (float)(-(float)width2) * 0.5f), new Point3D(0f, 0f, 1f), effects);
back = new TexturePlane(image, srcBack, new Point3D(width * 0.5f, height * 0.5f, (float)(-(float)width2) * 0.5f), new Point3D(0f, 0f, -1f), effects);
left = new TexturePlane(image, flag ? srcRight : srcLeft, new Point3D(width2 * 0.5f, height * 0.5f, (float)(-(float)width) * 0.5f), new Point3D(-1f, 0f, 0f), effects);
right = new TexturePlane(image, flag ? srcLeft : srcRight, new Point3D(width2 * 0.5f, height * 0.5f, (float)(-(float)width) * 0.5f), new Point3D(1f, 0f, 0f), effects);
top.Viewport = viewport;
bottom.Viewport = viewport;
front.Viewport = viewport;
back.Viewport = viewport;
left.Viewport = viewport;
right.Viewport = viewport;
}
public override float HitTest(PointF location)
{
float num = -1000f;
float num2 = top.HitTest(location);
if (num2 > num)
{
num = num2;
}
num2 = bottom.HitTest(location);
if (num2 > num)
{
num = num2;
}
num2 = front.HitTest(location);
if (num2 > num)
{
num = num2;
}
num2 = back.HitTest(location);
if (num2 > num)
{
num = num2;
}
num2 = left.HitTest(location);
if (num2 > num)
{
num = num2;
}
num2 = right.HitTest(location);
if (num2 > num)
{
num = num2;
}
return num;
}
private TexturePlane top;
private TexturePlane bottom;
private TexturePlane front;
private TexturePlane back;
private TexturePlane left;
private TexturePlane right;
private Rectangle srcTop;
private Rectangle srcBottom;
private Rectangle srcFront;
private Rectangle srcBack;
private Rectangle srcLeft;
private Rectangle srcRight;
private Matrix3D topLocalTransformation = Matrix3D.CreateRotationX(-1.57079637f);
private Matrix3D bottomLocalTransformation = Matrix3D.CreateRotationX(-1.57079637f);
private Matrix3D frontLocalTransformation = Matrix3D.Identity;
private Matrix3D backLocalTransformation = Matrix3D.CreateRotationY(3.14159274f);
private Matrix3D leftLocalTransformation = Matrix3D.CreateRotationY(-1.57079637f);
private Matrix3D rightLocalTransformation = Matrix3D.CreateRotationY(1.57079637f);
private Effects effects;
}
}

View File

@@ -1,59 +0,0 @@
using System;
using PckStudio.Models;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Drawing;
namespace PckStudio.Models
{
public abstract class ModelBase
{
public ModelBase()
{ }
protected Image[] textures;
public EventHandler OnUpdate;
protected const float OverlayScale = 1.16f;
public Image[] Textures => textures;
public event EventHandler Updatedx
{
add
{
EventHandler eventHandler = OnUpdate;
EventHandler eventHandler2;
do
{
eventHandler2 = eventHandler;
EventHandler value2 = (EventHandler)Delegate.Combine(eventHandler2, value);
eventHandler = Interlocked.CompareExchange(ref OnUpdate, value2, eventHandler2);
}
while (eventHandler != eventHandler2);
}
remove
{
EventHandler eventHandler = OnUpdate;
EventHandler eventHandler2;
do
{
eventHandler2 = eventHandler;
EventHandler value2 = (EventHandler)Delegate.Remove(eventHandler2, value);
eventHandler = Interlocked.CompareExchange(ref OnUpdate, value2, eventHandler2);
}
while (eventHandler != eventHandler2);
}
}
protected void OnUpdated()
{
if (OnUpdate != null)
{
OnUpdate(this, EventArgs.Empty);
}
}
public abstract void AddToModelView(MinecraftModelView modelView);
}
}

View File

@@ -1,88 +0,0 @@
using System;
using System.IO;
using System.Drawing;
using PckStudio.Models;
using PckStudio.Properties;
namespace PckStudio.Models
{
internal class Steve64x32Model : ModelBase
{
public Steve64x32Model(Image texture)
{
textures = new Image[1] { texture };
}
public override void AddToModelView(MinecraftModelView modelView)
{
_ = Textures[0] ?? throw new NullReferenceException(nameof(Textures));
Image source = Textures[0];
Box head = new Box(source, new Rectangle( 8, 0, 16, 8), new Rectangle( 0, 8, 32, 8), new Point3D(0f, 0f, 0f));
Box headOverlay = new Box(source, new Rectangle(40, 0, 16, 8), new Rectangle(32, 8, 32, 8), new Point3D(0f, 0f, 0f));
headOverlay.Scale = OverlayScale;
Box body = new Box(source, new Rectangle(20, 16, 16, 4), new Rectangle(16, 20, 24, 12), new Point3D(0f, 0f, 0f));
Box leftArm = new Box(source, new Rectangle(44, 16, 8, 4), new Rectangle(40, 20, 32, 12), new Point3D(0f, 4f, 0f));
Box rightArm = new Box(source, new Rectangle(44, 16, 8, 4), new Rectangle(40, 20, 32, 12), new Point3D(0f, 4f, 0f));
Box leftLeg = new Box(source, new Rectangle(4, 16, 8, 4), new Rectangle(0, 20, 16, 12), new Point3D(0f, 6f, 0f));
Box rightLeg = new Box(source, new Rectangle(4, 16, 8, 4), new Rectangle(0, 20, 16, 12), new Point3D(0f, 6f, 0f));
Object3DGroup headGroup = new Object3DGroup();
headGroup.RotationOrder = RotationOrders.XY;
headGroup.MinDegrees1 = -80f;
headGroup.MaxDegrees1 = 80f;
headGroup.MinDegrees2 = -57f;
headGroup.MaxDegrees2 = 57f;
headGroup.Add(head);
headGroup.Add(headOverlay);
headGroup.Position = new Point3D(0f, 8f, 0f);
headGroup.Origin = new Point3D(0f, -4f, 0f);
headGroup.RotationOrder = RotationOrders.XY;
body.Position = new Point3D(0f, 2f, 0f);
leftArm.Position = new Point3D(6f, 6f, 0f);
leftArm.RotationOrder = RotationOrders.ZX;
leftArm.MinDegrees1 = 0f;
leftArm.MaxDegrees1 = 160f;
leftArm.MinDegrees2 = -170f;
leftArm.MaxDegrees2 = 60f;
rightArm.Position = new Point3D(-6f, 6f, 0f);
rightArm.RotationOrder = RotationOrders.ZX;
rightArm.MinDegrees1 = -160f;
rightArm.MaxDegrees1 = 0f;
rightArm.MinDegrees2 = -170f;
rightArm.MaxDegrees2 = 60f;
leftLeg.Position = new Point3D(2f, -4f, 0f);
leftLeg.RotationOrder = RotationOrders.ZX;
leftLeg.MinDegrees1 = 0f;
leftLeg.MaxDegrees1 = 70f;
leftLeg.MinDegrees2 = -110f;
leftLeg.MaxDegrees2 = 60f;
rightLeg.Position = new Point3D(-2f, -4f, 0f);
rightLeg.RotationOrder = RotationOrders.ZX;
rightLeg.MinDegrees1 = -70f;
rightLeg.MaxDegrees1 = 0f;
rightLeg.MinDegrees2 = -110f;
rightLeg.MaxDegrees2 = 60f;
modelView.AddDynamic(headGroup);
modelView.AddStatic(body);
modelView.AddDynamic(rightArm);
modelView.AddDynamic(leftArm);
modelView.AddDynamic(rightLeg);
modelView.AddDynamic(leftLeg);
}
public override string ToString() => nameof(Steve64x32Model);
}
}

View File

@@ -1,122 +0,0 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using PckStudio.Internal;
using PckStudio.Models;
namespace PckStudio.Classes.Models.DefaultModels
{
internal class Steve64x64Model : ModelBase
{
SkinANIM _skinANIM;
public Steve64x64Model(Image texture, SkinANIM anim)
{
textures = new Image[1] { texture };
_skinANIM = anim;
}
public override void AddToModelView(MinecraftModelView modelView)
{
_ = Textures[0] ?? throw new NullReferenceException(nameof(Textures));
Image source = Textures[0];
(int top, int side) armWidth = _skinANIM.GetFlag(SkinAnimFlag.SLIM_MODEL) ? (6, 14) : (8, 16);
Box head = new Box(source, new Rectangle(8, 0, 16, 8), new Rectangle(0, 8, 32, 8), new Point3D(0f, 0f, 0f));
Box headOverlay = new Box(source, new Rectangle(40, 0, 16, 8), new Rectangle(32, 8, 32, 8), new Point3D(0f, 0f, 0f));
headOverlay.Scale = OverlayScale;
Box body = new Box(source, new Rectangle(20, 16, 16, 4), new Rectangle(16, 20, 24, 12), new Point3D(0f, 0f, 0f));
Box bodyOverlay = new Box(source, new Rectangle(20, 32, 16, 4), new Rectangle(16, 36, 24, 12), new Point3D(0f, 0f, 0f));
bodyOverlay.Scale = OverlayScale;
Box rightArm = new Box(source, new Rectangle(44, 16, armWidth.top, 4), new Rectangle(40, 20, armWidth.side, 12), new Point3D(0f, 4f, 0f));
Box rightArmOverlay = new Box(source, new Rectangle(44, 32, armWidth.top, 4), new Rectangle(40, 36, armWidth.side, 12), new Point3D(0f, 4f, 0f));
rightArmOverlay.Scale = OverlayScale;
Box leftArm = new Box(source, new Rectangle(36, 48, armWidth.top, 4), new Rectangle(32, 52, armWidth.side, 12), new Point3D(0f, 4f, 0f));
Box leftArmOverlay = new Box(source, new Rectangle(52, 48, armWidth.top, 4), new Rectangle(48, 52, armWidth.side, 12), new Point3D(0f, 4f, 0f));
leftArmOverlay.Scale = OverlayScale;
Box rightLeg = new Box(source, new Rectangle(4, 16, 8, 4), new Rectangle(0, 20, 16, 12), new Point3D(0f, 6f, 0f));
Box rightLegOverlay = new Box(source, new Rectangle(4, 32, 8, 4), new Rectangle(0, 52, 16, 12), new Point3D(0f, 6f, 0f));
rightLegOverlay.Scale = OverlayScale;
Box leftLeg = new Box(source, new Rectangle(20, 48, 8, 4), new Rectangle(16, 52, 16, 12), new Point3D(0f, 6f, 0f));
Box leftLegOverlay = new Box(source, new Rectangle( 4, 48, 8, 4), new Rectangle( 0, 52, 16, 12), new Point3D(0f, 6f, 0f));
leftLegOverlay.Scale = OverlayScale;
Object3DGroup headGroup = new Object3DGroup();
Object3DGroup bodyGroup = new Object3DGroup();
Object3DGroup leftArmGroup = new Object3DGroup();
Object3DGroup rightArmGroup = new Object3DGroup();
Object3DGroup leftLegGroup = new Object3DGroup();
Object3DGroup rightLegGroup = new Object3DGroup();
headGroup.RotationOrder = RotationOrders.XY;
headGroup.MinDegrees1 = -80f;
headGroup.MaxDegrees1 = 80f;
headGroup.MinDegrees2 = -57f;
headGroup.MaxDegrees2 = 57f;
headGroup.Origin = new Point3D(0f, -4f, 0f);
headGroup.RotationOrder = RotationOrders.XY;
headGroup.Position = new Point3D(0f, 8f, 0f);
headGroup.Add(head);
headGroup.Add(headOverlay);
bodyGroup.Position = new Point3D(0f, 2f, 0f);
bodyGroup.Add(body);
bodyGroup.Add(bodyOverlay);
leftArmGroup.Position = new Point3D(6f, 6f, 0f);
leftArmGroup.RotationOrder = RotationOrders.ZX;
leftArmGroup.MinDegrees1 = 0f;
leftArmGroup.MaxDegrees1 = 160f;
leftArmGroup.MinDegrees2 = -170f;
leftArmGroup.MaxDegrees2 = 60f;
leftArmGroup.Add(leftArm);
leftArmGroup.Add(leftArmOverlay);
rightArmGroup.Position = new Point3D(-6f, 6f, 0f);
rightArmGroup.RotationOrder = RotationOrders.ZX;
rightArmGroup.MinDegrees1 = -160f;
rightArmGroup.MaxDegrees1 = 0f;
rightArmGroup.MinDegrees2 = -170f;
rightArmGroup.MaxDegrees2 = 60f;
rightArmGroup.Add(rightArm);
rightArmGroup.Add(rightArmOverlay);
leftLegGroup.Position = new Point3D(2f, -4f, 0f);
leftLegGroup.RotationOrder = RotationOrders.ZX;
leftLegGroup.MinDegrees1 = 0f;
leftLegGroup.MaxDegrees1 = 70f;
leftLegGroup.MinDegrees2 = -110f;
leftLegGroup.MaxDegrees2 = 60f;
leftLegGroup.Add(leftLeg);
leftLegGroup.Add(leftLegOverlay);
rightLegGroup.Position = new Point3D(-2f, -4f, 0f);
rightLegGroup.RotationOrder = RotationOrders.ZX;
rightLegGroup.MinDegrees1 = -70f;
rightLegGroup.MaxDegrees1 = 0f;
rightLegGroup.MinDegrees2 = -110f;
rightLegGroup.MaxDegrees2 = 60f;
rightLegGroup.Add(rightLeg);
rightLegGroup.Add(rightLegOverlay);
modelView.AddDynamic(headGroup);
modelView.AddStatic(bodyGroup);
modelView.AddDynamic(rightArmGroup);
modelView.AddDynamic(leftArmGroup);
modelView.AddDynamic(rightLegGroup);
modelView.AddDynamic(leftLegGroup);
}
}
}

View File

@@ -1,12 +0,0 @@
using System;
namespace PckStudio.Models
{
[Flags]
public enum Effects : byte
{
None = 0,
FlipHorizontally = 1,
FlipVertically = 2
}
}

View File

@@ -1,177 +0,0 @@
using System;
namespace PckStudio.Models
{
public struct Matrix3D
{
public Matrix3D(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44)
{
M11 = m11;
M12 = m12;
M13 = m13;
M14 = m14;
M21 = m21;
M22 = m22;
M23 = m23;
M24 = m24;
M31 = m31;
M32 = m32;
M33 = m33;
M34 = m34;
M41 = m41;
M42 = m42;
M43 = m43;
M44 = m44;
}
public static Matrix3D CreateRotationX(float radians)
{
float num = (float)Math.Sin((double)radians);
float num2 = (float)Math.Cos((double)radians);
return new Matrix3D(1f, 0f, 0f, 0f, 0f, num2, -num, 0f, 0f, num, num2, 0f, 0f, 0f, 0f, 1f);
}
public static Matrix3D CreateRotationX(float sin, float cos)
{
return new Matrix3D(1f, 0f, 0f, 0f, 0f, cos, -sin, 0f, 0f, sin, cos, 0f, 0f, 0f, 0f, 1f);
}
public static Matrix3D CreateRotationY(float radians)
{
float num = (float)Math.Sin((double)radians);
float num2 = (float)Math.Cos((double)radians);
return new Matrix3D(num2, 0f, num, 0f, 0f, 1f, 0f, 0f, -num, 0f, num2, 0f, 0f, 0f, 0f, 1f);
}
public static Matrix3D CreateRotationY(float sin, float cos)
{
return new Matrix3D(cos, 0f, sin, 0f, 0f, 1f, 0f, 0f, -sin, 0f, cos, 0f, 0f, 0f, 0f, 1f);
}
public static Matrix3D CreateRotationZ(float radians)
{
float num = (float)Math.Sin((double)radians);
float num2 = (float)Math.Cos((double)radians);
return new Matrix3D(num2, -num, 0f, 0f, num, num2, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1f);
}
public static Matrix3D CreateRotationZ(float sin, float cos)
{
return new Matrix3D(cos, -sin, 0f, 0f, sin, cos, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1f);
}
public static Matrix3D CreateTranslation(float x, float y, float z)
{
return new Matrix3D(1f, 0f, 0f, x, 0f, 1f, 0f, y, 0f, 0f, 1f, z, 0f, 0f, 0f, 1f);
}
public static Matrix3D CreateTranslation(Point3D point)
{
return new Matrix3D(1f, 0f, 0f, point.X, 0f, 1f, 0f, point.Y, 0f, 0f, 1f, point.Z, 0f, 0f, 0f, 1f);
}
public static Matrix3D CreateScale(float s)
{
return new Matrix3D(s, 0f, 0f, 0f, 0f, s, 0f, 0f, 0f, 0f, s, 0f, 0f, 0f, 0f, 1f);
}
public float Determinant
{
get
{
return M11 * M22 * M33 * M44 + M21 * M32 * M43 * M14 + M31 * M42 * M13 * M24 + M41 * M12 * M23 * M34 - M14 * M23 * M32 * M41 - M24 * M33 * M42 * M11 - M34 * M43 * M12 * M21 - M44 * M13 * M22 * M31;
}
}
public static Matrix3D Identity
{
get
{
return new Matrix3D(1f, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1f);
}
}
public static Matrix3D Transpose(Matrix3D m)
{
return new Matrix3D(m.M11, m.M21, m.M31, m.M41, m.M12, m.M22, m.M32, m.M42, m.M13, m.M23, m.M33, m.M43, m.M14, m.M24, m.M34, m.M44);
}
public static Matrix3D Invert(Matrix3D m)
{
float determinant = m.Determinant;
return new Matrix3D((m.M22 * m.M33 * m.M44 + m.M32 * m.M43 * m.M24 + m.M42 * m.M23 * m.M34 - m.M24 * m.M33 * m.M42 - m.M34 * m.M43 * m.M22 - m.M44 * m.M23 * m.M32) / determinant, -(m.M12 * m.M33 * m.M44 + m.M32 * m.M43 * m.M14 + m.M42 * m.M13 * m.M34 - m.M14 * m.M33 * m.M42 - m.M34 * m.M43 * m.M12 - m.M44 * m.M13 * m.M32) / determinant, (m.M12 * m.M23 * m.M44 + m.M22 * m.M43 * m.M14 + m.M42 * m.M13 * m.M24 - m.M14 * m.M23 * m.M42 - m.M24 * m.M43 * m.M12 - m.M44 * m.M13 * m.M22) / determinant, -(m.M12 * m.M23 * m.M34 + m.M22 * m.M33 * m.M14 + m.M32 * m.M13 * m.M24 - m.M14 * m.M23 * m.M32 - m.M24 * m.M33 * m.M12 - m.M34 * m.M13 * m.M22) / determinant, -(m.M21 * m.M33 * m.M44 + m.M31 * m.M43 * m.M24 + m.M41 * m.M23 * m.M34 - m.M24 * m.M33 * m.M41 - m.M34 * m.M43 * m.M21 - m.M44 * m.M23 * m.M31) / determinant, (m.M11 * m.M33 * m.M44 + m.M31 * m.M43 * m.M14 + m.M41 * m.M13 * m.M34 - m.M14 * m.M33 * m.M41 - m.M34 * m.M43 * m.M11 - m.M44 * m.M13 * m.M31) / determinant, -(m.M11 * m.M23 * m.M44 + m.M21 * m.M43 * m.M14 + m.M41 * m.M13 * m.M24 - m.M14 * m.M23 * m.M41 - m.M24 * m.M43 * m.M11 - m.M44 * m.M13 * m.M21) / determinant, (m.M11 * m.M23 * m.M34 + m.M21 * m.M33 * m.M14 + m.M31 * m.M13 * m.M24 - m.M14 * m.M23 * m.M31 - m.M24 * m.M33 * m.M11 - m.M34 * m.M13 * m.M21) / determinant, (m.M21 * m.M32 * m.M44 + m.M31 * m.M42 * m.M24 + m.M41 * m.M22 * m.M34 - m.M24 * m.M32 * m.M41 - m.M34 * m.M42 * m.M21 - m.M44 * m.M22 * m.M31) / determinant, -(m.M11 * m.M32 * m.M44 + m.M31 * m.M42 * m.M14 + m.M41 * m.M12 * m.M34 - m.M14 * m.M32 * m.M41 - m.M34 * m.M42 * m.M11 - m.M44 * m.M12 * m.M31) / determinant, (m.M11 * m.M32 * m.M44 + m.M21 * m.M42 * m.M14 + m.M41 * m.M12 * m.M24 - m.M14 * m.M22 * m.M41 - m.M24 * m.M42 * m.M11 - m.M44 * m.M12 * m.M21) / determinant, -(m.M11 * m.M22 * m.M34 + m.M21 * m.M32 * m.M14 + m.M31 * m.M12 * m.M24 - m.M14 * m.M22 * m.M31 - m.M24 * m.M32 * m.M11 - m.M34 * m.M12 * m.M21) / determinant, -(m.M21 * m.M32 * m.M43 + m.M31 * m.M42 * m.M23 + m.M41 * m.M22 * m.M33 - m.M23 * m.M32 * m.M41 - m.M33 * m.M42 * m.M21 - m.M43 * m.M22 * m.M31) / determinant, (m.M11 * m.M32 * m.M43 + m.M31 * m.M42 * m.M13 + m.M41 * m.M12 * m.M33 - m.M13 * m.M32 * m.M41 - m.M33 * m.M42 * m.M11 - m.M43 * m.M12 * m.M31) / determinant, -(m.M11 * m.M22 * m.M43 + m.M21 * m.M42 * m.M13 + m.M41 * m.M12 * m.M23 - m.M13 * m.M22 * m.M41 - m.M23 * m.M42 * m.M11 - m.M43 * m.M12 * m.M21) / determinant, (m.M11 * m.M22 * m.M33 + m.M21 * m.M32 * m.M13 + m.M31 * m.M12 * m.M23 - m.M13 * m.M22 * m.M31 - m.M23 * m.M32 * m.M11 - m.M33 * m.M12 * m.M21) / determinant);
}
public static Matrix3D operator +(Matrix3D a, Matrix3D b)
{
return new Matrix3D(a.M11 + b.M11, a.M12 + b.M12, a.M13 + b.M13, a.M14 + b.M14, a.M21 + b.M21, a.M22 + b.M22, a.M23 + b.M23, a.M24 + b.M24, a.M31 + b.M31, a.M32 + b.M32, a.M33 + b.M33, a.M34 + b.M34, a.M41 + b.M41, a.M42 + b.M42, a.M43 + b.M43, a.M44 + b.M44);
}
public static Matrix3D operator -(Matrix3D a, Matrix3D b)
{
return new Matrix3D(a.M11 - b.M11, a.M12 - b.M12, a.M13 - b.M13, a.M14 - b.M14, a.M21 - b.M21, a.M22 - b.M22, a.M23 - b.M23, a.M24 - b.M24, a.M31 - b.M31, a.M32 - b.M32, a.M33 - b.M33, a.M34 - b.M34, a.M41 - b.M41, a.M42 - b.M42, a.M43 - b.M43, a.M44 - b.M44);
}
public static Matrix3D operator *(Matrix3D a, Matrix3D b)
{
return new Matrix3D(a.M11 * b.M11 + a.M12 * b.M21 + a.M13 * b.M31 + a.M14 * b.M41, a.M11 * b.M12 + a.M12 * b.M22 + a.M13 * b.M32 + a.M14 * b.M42, a.M11 * b.M13 + a.M12 * b.M23 + a.M13 * b.M33 + a.M14 * b.M43, a.M11 * b.M14 + a.M12 * b.M24 + a.M13 * b.M34 + a.M14 * b.M44, a.M21 * b.M11 + a.M22 * b.M21 + a.M23 * b.M31 + a.M24 * b.M41, a.M21 * b.M12 + a.M22 * b.M22 + a.M23 * b.M32 + a.M24 * b.M42, a.M21 * b.M13 + a.M22 * b.M23 + a.M23 * b.M33 + a.M24 * b.M43, a.M21 * b.M14 + a.M22 * b.M24 + a.M23 * b.M34 + a.M24 * b.M44, a.M31 * b.M11 + a.M32 * b.M21 + a.M33 * b.M31 + a.M34 * b.M41, a.M31 * b.M12 + a.M32 * b.M22 + a.M33 * b.M32 + a.M34 * b.M42, a.M31 * b.M13 + a.M32 * b.M23 + a.M33 * b.M33 + a.M34 * b.M43, a.M31 * b.M14 + a.M32 * b.M24 + a.M33 * b.M34 + a.M34 * b.M44, a.M41 * b.M11 + a.M42 * b.M21 + a.M43 * b.M31 + a.M44 * b.M41, a.M41 * b.M12 + a.M42 * b.M22 + a.M43 * b.M32 + a.M44 * b.M42, a.M41 * b.M13 + a.M42 * b.M23 + a.M43 * b.M33 + a.M44 * b.M43, a.M41 * b.M14 + a.M42 * b.M24 + a.M43 * b.M34 + a.M44 * b.M44);
}
public static Point3D operator *(Matrix3D m, Point3D p)
{
return new Point3D(p.X * m.M11 + p.Y * m.M12 + p.Z * m.M13 + m.M14, p.X * m.M21 + p.Y * m.M22 + p.Z * m.M23 + m.M24, p.X * m.M31 + p.Y * m.M32 + p.Z * m.M33 + m.M34);
}
public static Matrix3D operator +(Matrix3D m, float n)
{
return new Matrix3D(m.M11 + n, m.M12 + n, m.M13 + n, m.M14 + n, m.M21 + n, m.M22 + n, m.M23 + n, m.M24 + n, m.M31 + n, m.M32 + n, m.M33 + n, m.M34 + n, m.M41 + n, m.M42 + n, m.M43 + n, m.M44 + n);
}
public static Matrix3D operator -(Matrix3D m, float n)
{
return new Matrix3D(m.M11 - n, m.M12 - n, m.M13 - n, m.M14 - n, m.M21 - n, m.M22 - n, m.M23 - n, m.M24 - n, m.M31 - n, m.M32 - n, m.M33 - n, m.M34 - n, m.M41 - n, m.M42 - n, m.M43 - n, m.M44 - n);
}
public static Matrix3D operator *(Matrix3D m, float n)
{
return new Matrix3D(m.M11 * n, m.M12 * n, m.M13 * n, m.M14 * n, m.M21 * n, m.M22 * n, m.M23 * n, m.M24 * n, m.M31 * n, m.M32 * n, m.M33 * n, m.M34 * n, m.M41 * n, m.M42 * n, m.M43 * n, m.M44 * n);
}
public static Matrix3D operator /(Matrix3D m, float n)
{
return new Matrix3D(m.M11 / n, m.M12 / n, m.M13 / n, m.M14 / n, m.M21 / n, m.M22 / n, m.M23 / n, m.M24 / n, m.M31 / n, m.M32 / n, m.M33 / n, m.M34 / n, m.M41 / n, m.M42 / n, m.M43 / n, m.M44 / n);
}
public float M11;
public float M12;
public float M13;
public float M14;
public float M21;
public float M22;
public float M23;
public float M24;
public float M31;
public float M32;
public float M33;
public float M34;
public float M41;
public float M42;
public float M43;
public float M44;
}
}

View File

@@ -1,73 +0,0 @@

namespace PckStudio.Models
{
partial class MinecraftModelView
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && this.components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
private PckStudio.Models.BackgroundTypes backgroundType;
private System.Drawing.Brush backgroundBrush = new System.Drawing.SolidBrush(System.Drawing.Color.SkyBlue);
private System.ComponentModel.BackgroundWorker downloader = new System.ComponentModel.BackgroundWorker();
private System.Drawing.Point mouseLastLocation;
private PckStudio.Models.Object3D rotatingObject3D;
private System.Drawing.Color backgroundColor = System.Drawing.Color.Transparent;
private System.Drawing.Color backgroundGradientColor1 = System.Drawing.SystemColors.ControlDarkDark;
private System.Drawing.Color backgroundGradientColor2 = System.Drawing.SystemColors.ControlLightLight;
private static System.Drawing.Color textShadowColor = System.Drawing.Color.FromArgb(0x3F, 0x3F, 0x3F);
private System.Drawing.Image backgroundTexture;
private System.Drawing.Image usernameImage;
internal PckStudio.Models.Matrix3D GlobalTransformation = PckStudio.Models.Matrix3D.Identity;
private System.Collections.Generic.List<PckStudio.Models.Texel> texelList = new System.Collections.Generic.List<PckStudio.Models.Texel>();
private PckStudio.Models.TexelComparer texelComparer = new PckStudio.Models.TexelComparer();
private System.Collections.Generic.List<PckStudio.Models.Object3D> object3DList = new System.Collections.Generic.List<PckStudio.Models.Object3D>();
private System.Collections.Generic.List<PckStudio.Models.Object3D> dynamicObject3DtList = new System.Collections.Generic.List<PckStudio.Models.Object3D>();
#endregion
}
}

View File

@@ -1,431 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.IO;
using System.Net;
using System.Threading;
using System.Windows.Forms;
namespace PckStudio.Models
{
public partial class MinecraftModelView : Control
{
private const int IsometricFOV = 46;
internal float cameraZ = 31.4285717f;
private int Fov = 70;
private float scale = 1f;
internal float RotationX;
internal float RotationY;
private bool perspective = true;
private float PiBy180 = 0.0174532924f;
protected override void OnBackColorChanged(EventArgs e)
{
base.OnBackColorChanged(e);
backgroundColor = BackColor;
UpdateBackgroundBrush();
Invalidate();
}
[Browsable(true)]
[Category("Appearance")]
public System.Drawing.Color BackGradientColor1
{
get
{
return backgroundGradientColor1;
}
set
{
backgroundGradientColor1 = value;
UpdateBackgroundBrush();
Invalidate();
}
}
[Browsable(true)]
[Category("Appearance")]
public System.Drawing.Color BackGradientColor2
{
get
{
return backgroundGradientColor2;
}
set
{
backgroundGradientColor2 = value;
UpdateBackgroundBrush();
Invalidate();
}
}
[Browsable(true)]
[Category("Appearance")]
public new System.Drawing.Image BackgroundImage
{
get
{
return backgroundTexture;
}
set
{
backgroundTexture = value;
UpdateBackgroundBrush();
Invalidate();
}
}
[Browsable(true)]
[Category("Appearance")]
public BackgroundTypes BackgroundType
{
get
{
return backgroundType;
}
set
{
backgroundType = value;
UpdateBackgroundBrush();
Invalidate();
}
}
[Browsable(true)]
[Category("View")]
public ProjectionTypes Projection
{
get
{
return perspective ? ProjectionTypes.Perspective : ProjectionTypes.Isometric;
}
set
{
perspective = value == ProjectionTypes.Perspective;
SetupProjection();
foreach (Object3D object3D in object3DList)
{
object3D.Update();
}
Invalidate();
}
}
[Browsable(true)]
[Category("View")]
public int FOV
{
get
{
return Fov;
}
set
{
Fov = value;
SetupProjection();
foreach (Object3D object3D in object3DList)
{
object3D.Update();
}
Invalidate();
}
}
[Browsable(true)]
[Category("View")]
public int DegreesX
{
get
{
return (int)RotationX;
}
set
{
RotationX = value;
Matrix3D globalTransformation = Matrix3D.CreateRotationX(RotationX * PiBy180) * Matrix3D.CreateRotationY(RotationY * PiBy180);
foreach (Object3D object3D in object3DList)
{
object3D.GlobalTransformation = globalTransformation;
}
Invalidate();
}
}
[Browsable(true)]
[Category("View")]
public int DegreesY
{
get
{
return (int)RotationY;
}
set
{
RotationY = value;
Matrix3D globalTransformation = Matrix3D.CreateRotationX(RotationX * PiBy180) * Matrix3D.CreateRotationY(RotationY * PiBy180);
foreach (Object3D object3D in object3DList)
{
object3D.GlobalTransformation = globalTransformation;
}
Invalidate();
}
}
public ModelBase Model
{
set
{
Clear();
value.AddToModelView(this);
Matrix3D globalTransformation = Matrix3D.CreateRotationX(RotationX * 3.14159274f / 180f) * Matrix3D.CreateRotationY(RotationY * 3.14159274f / 180f);
foreach (Object3D object3D in object3DList)
{
object3D.GlobalTransformation = globalTransformation;
}
Invalidate();
}
}
private void Clear()
{
texelList.Clear();
object3DList.Clear();
dynamicObject3DtList.Clear();
rotatingObject3D = null;
}
protected override void OnPaintBackground(PaintEventArgs pevent)
{
base.OnPaintBackground(pevent);
System.Drawing.Graphics graphics = pevent.Graphics;
graphics.CompositingQuality = CompositingQuality.HighSpeed;
graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
graphics.PixelOffsetMode = PixelOffsetMode.HighSpeed;
graphics.SmoothingMode = SmoothingMode.HighSpeed;
graphics.CompositingMode = CompositingMode.SourceCopy;
graphics.FillRectangle(backgroundBrush, ClientRectangle);
graphics.CompositingMode = CompositingMode.SourceOver;
}
protected override void OnPaint(PaintEventArgs pe)
{
texelList.Sort(texelComparer);
System.Drawing.Graphics graphics = pe.Graphics;
graphics.TranslateTransform(Width / 2, Height / 2);
graphics.ScaleTransform(scale, -scale);
graphics.CompositingQuality = CompositingQuality.HighSpeed;
graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
graphics.PixelOffsetMode = PixelOffsetMode.HighSpeed;
graphics.SmoothingMode = SmoothingMode.HighSpeed;
graphics.CompositingMode = CompositingMode.SourceCopy;
for (int i = 0; i < texelList.Count; i++)
{
texelList[i].Draw(graphics);
}
}
public System.Drawing.Image RenderToImage(System.Drawing.Size size, System.Drawing.RectangleF crop)
{
if (size.Width / size.Height != crop.Width / crop.Height)
{
throw new ArgumentException("Aspect ratio is ambiguous");
}
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(size.Width, size.Height);
using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap))
{
System.Drawing.Size size2 = new System.Drawing.Size((int)(size.Width / crop.Width), (int)(size.Height / crop.Height));
texelList.Sort(texelComparer);
graphics.TranslateTransform(-crop.Left * size2.Width, -crop.Top * size2.Height);
graphics.TranslateTransform(size2.Width / 2, size2.Height / 2);
float num = Math.Min(size2.Width, size2.Height) * 0.01f / (float)Math.Tan((perspective ? Fov : IsometricFOV) * 3.1415926535897931 / 360.0);
graphics.ScaleTransform(num, -num);
graphics.CompositingQuality = CompositingQuality.HighSpeed;
graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
graphics.PixelOffsetMode = PixelOffsetMode.HighSpeed;
graphics.SmoothingMode = SmoothingMode.HighSpeed;
graphics.Clear(System.Drawing.Color.Transparent);
for (int i = 0; i < texelList.Count; i++)
{
texelList[i].Draw(graphics);
}
}
return bitmap;
}
private System.Drawing.Image RenderVersionText()
{
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(0x154, 0x12);
Version version = new Version(Application.ProductVersion);
string s = string.Format("{0} {1}.{2}{3}", Application.ProductName, version.Major, version.Minor, (version.Build != 0) ? ("." + version.Build) : "");
using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap))
{
using (System.Drawing.Brush brush = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(0x7F, System.Drawing.Color.Gray)))
{
graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit;
graphics.DrawString(s, Font, brush, 1f, 1f);
graphics.DrawString(s, Font, System.Drawing.Brushes.White, 0f, 0f);
}
}
return bitmap;
}
private void UpdateBackgroundBrush()
{
backgroundBrush = ((backgroundType == BackgroundTypes.Texture) ? new System.Drawing.TextureBrush(backgroundTexture) : ((backgroundType == BackgroundTypes.Gradient) ? new System.Drawing.Drawing2D.LinearGradientBrush(new System.Drawing.Point(0, 0), new System.Drawing.Point(0, System.Math.Max(1, base.Height)), backgroundGradientColor1, backgroundGradientColor2) : new System.Drawing.SolidBrush(backgroundColor)));
}
public System.Drawing.Brush GetBackgroundBrush(System.Drawing.Size size)
{
if (backgroundType == BackgroundTypes.Texture)
{
return new System.Drawing.TextureBrush(backgroundTexture);
}
if (backgroundType != BackgroundTypes.Gradient)
{
return new System.Drawing.SolidBrush(backgroundColor);
}
return new LinearGradientBrush(new System.Drawing.Point(0, 0), new System.Drawing.Point(0, Math.Max(1, size.Height)), backgroundGradientColor1, backgroundGradientColor2);
}
private void SetupProjection()
{
cameraZ = 2400f / Fov;
scale = Math.Min(Width, Height) * 0.01f / (float)Math.Tan((perspective ? Fov : IsometricFOV) * Math.PI / 360.0);
}
protected override void OnResize(EventArgs e)
{
SetupProjection();
UpdateBackgroundBrush();
base.OnResize(e);
}
internal void RemoveTexelsOf(TexturePlane texturePlane)
{
for (int i = 0; i < texelList.Count; i++)
{
if (texelList[i].TexturePlane == texturePlane)
{
texelList.RemoveAt(i);
i--;
}
}
}
internal void AddTexel(Texel texel)
{
texelList.Add(texel);
}
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
System.Drawing.PointF location = new System.Drawing.PointF((e.X - Width * 0.5f) / scale, -(e.Y - Height * 0.5f) / scale);
rotatingObject3D = null;
Object3D item = null;
float num = -1000f;
foreach (Object3D object3D in object3DList)
{
float num2 = object3D.HitTest(location);
if (num2 > num)
{
num = num2;
item = object3D;
}
}
if (num > -1000f && dynamicObject3DtList.Contains(item))
{
rotatingObject3D = item;
}
mouseLastLocation = e.Location;
Invalidate();
}
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
rotatingObject3D = null;
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (e.Button != MouseButtons.Left)
{
return;
}
if (rotatingObject3D != null)
{
rotatingObject3D.RotateByMouse((e.X - mouseLastLocation.X) * 400f / Height, (e.Y - mouseLastLocation.Y) * 400f / Height);
mouseLastLocation = e.Location;
Invalidate();
return;
}
RotationY += (e.X - mouseLastLocation.X) * 400f / Height;
RotationX += (e.Y - mouseLastLocation.Y) * 400f / Height;
mouseLastLocation = e.Location;
Matrix3D globalTransformation = Matrix3D.CreateRotationX(RotationX * 3.14159274f / 180f) * Matrix3D.CreateRotationY(RotationY * 3.14159274f / 180f);
foreach (Object3D object3D in object3DList)
{
object3D.GlobalTransformation = globalTransformation;
}
Invalidate();
}
public void AddStatic(Object3D object3D)
{
object3D.Viewport = this;
object3DList.Add(object3D);
foreach (Object3D object3D2 in object3DList)
{
object3D2.Update();
}
}
public void AddDynamic(Object3D object3D)
{
AddStatic(object3D);
dynamicObject3DtList.Add(object3D);
}
internal System.Drawing.PointF Point3DTo2D(Point3D point3D)
{
if (perspective)
{
return new System.Drawing.PointF(point3D.X * (-50f / (point3D.Z - cameraZ)), point3D.Y * (-50f / (point3D.Z - cameraZ)));
}
return new System.Drawing.PointF(point3D.X, point3D.Y);
}
internal float GetZOrder(Point3D point3D)
{
if (perspective)
{
return point3D.X * point3D.X + point3D.Y * point3D.Y + (cameraZ - point3D.Z) * (cameraZ - point3D.Z);
}
return -point3D.Z;
}
public MinecraftModelView()
{
SetStyle(ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
InitializeComponent();
texelComparer = new TexelComparer();
}
public MinecraftModelView(IContainer container) : this()
{
container.Add(this);
}
}
}

View File

@@ -1,461 +0,0 @@
using System;
using System.Drawing;
namespace PckStudio.Models
{
public abstract class Object3D
{
public abstract Image Image { set; }
public float Angle1
{
get
{
return angle1;
}
set
{
angle1 = value;
OnUpdateRotation();
}
}
public float Angle2
{
get
{
return angle2;
}
set
{
angle2 = value;
OnUpdateRotation();
}
}
public float MinAngle1
{
get
{
return minAngle1;
}
set
{
minAngle1 = value;
}
}
public float MinAngle2
{
get
{
return minAngle2;
}
set
{
minAngle2 = value;
}
}
public float MaxAngle1
{
get
{
return maxAngle1;
}
set
{
maxAngle1 = value;
}
}
public float MaxAngle2
{
get
{
return maxAngle2;
}
set
{
maxAngle2 = value;
}
}
public float AngleRange1
{
get
{
return maxAngle1 - minAngle1;
}
set
{
minAngle1 = angle1 - value / 2f;
maxAngle1 = angle1 + value / 2f;
}
}
public float AngleRange2
{
get
{
return maxAngle2 - minAngle2;
}
set
{
minAngle2 = angle2 - value / 2f;
maxAngle2 = angle2 + value / 2f;
}
}
public float MinDegrees1
{
get
{
return minAngle1 / PIby180;
}
set
{
minAngle1 = value * PIby180;
}
}
public float MinDegrees2
{
get
{
return minAngle2 / PIby180;
}
set
{
minAngle2 = value * PIby180;
}
}
public float MaxDegrees1
{
get
{
return maxAngle1 / PIby180;
}
set
{
maxAngle1 = value * PIby180;
}
}
public float MaxDegrees2
{
get
{
return maxAngle2 / PIby180;
}
set
{
maxAngle2 = value * PIby180;
}
}
public float DegreesRange1
{
get
{
return AngleRange1 / PIby180;
}
set
{
AngleRange1 = value * PIby180;
}
}
public float DegreesRange2
{
get
{
return AngleRange2 / PIby180;
}
set
{
AngleRange2 = value * PIby180;
}
}
public float Scale
{
get
{
return scaleTransformation.M11;
}
set
{
scaleTransformation = Matrix3D.CreateScale(value);
UpdateRotation();
}
}
public RotationOrders RotationOrder
{
get
{
return order;
}
set
{
order = value;
switch (order)
{
case RotationOrders.XY:
Rotate = new RotateMethod(RotateXY);
OnUpdateRotation = UpdateRotationXY;
return;
case RotationOrders.YX:
Rotate = new RotateMethod(RotateYX);
OnUpdateRotation = UpdateRotationYX;
return;
case RotationOrders.XZ:
Rotate = new RotateMethod(RotateXZ);
OnUpdateRotation = UpdateRotationXZ;
return;
case RotationOrders.ZX:
Rotate = new RotateMethod(RotateZX);
OnUpdateRotation = UpdateRotationZX;
return;
case RotationOrders.YZ:
Rotate = new RotateMethod(RotateYZ);
OnUpdateRotation = UpdateRotationYZ;
return;
case RotationOrders.ZY:
Rotate = new RotateMethod(RotateZY);
OnUpdateRotation = UpdateRotationZY;
return;
default:
return;
}
}
}
internal virtual MinecraftModelView Viewport
{
set
{
viewport = value;
}
}
public Point3D Origin
{
get
{
return new Point3D(-originTranslation.M14, -originTranslation.M24, -originTranslation.M34);
}
set
{
originTranslation = Matrix3D.CreateTranslation(-value.X, -value.Y, -value.Z);
UpdateRotation();
}
}
public Point3D Position
{
get
{
return new Point3D(positionTranslation.M14, positionTranslation.M24, positionTranslation.M34);
}
set
{
positionTranslation = Matrix3D.CreateTranslation(value);
UpdateRotation();
Update();
}
}
internal abstract void Update();
public Matrix3D GlobalTransformation
{
get
{
return globalTransformation;
}
set
{
globalTransformation = value;
Update();
}
}
public Matrix3D LocalTransformation
{
get
{
return localTransformation;
}
set
{
localTransformation = value;
Update();
}
}
public void SetRotation(float angle1, float angle2)
{
this.angle1 = angle1;
this.angle2 = angle2;
OnUpdateRotation();
}
public void RotateByMouse(float deltaX, float deltaY)
{
if (Rotate != null)
{
Rotate(deltaX, deltaY);
Update();
}
}
private void CorrectAngles()
{
if (angle1 > maxAngle1)
{
angle1 = maxAngle1;
}
else if (angle1 < minAngle1)
{
angle1 = minAngle1;
}
if (angle2 > maxAngle2)
{
angle2 = maxAngle2;
return;
}
if (angle2 < minAngle2)
{
angle2 = minAngle2;
}
}
public abstract float HitTest(PointF location);
private void RotateXY(float delta1, float delta2)
{
angle1 += delta1 * PIby180;
angle2 += delta2 * PIby180 * (float)Math.Cos((double)(viewport.RotationY * PIby180));
UpdateRotationXY();
}
private void RotateYX(float delta1, float delta2)
{
angle1 += delta1 * PIby180;
angle2 += delta2 * PIby180 * (float)Math.Cos(viewport.RotationY * 3.1415926535897931 / 180.0);
UpdateRotationYX();
}
private void RotateXZ(float delta1, float delta2)
{
angle1 += delta1 * PIby180 * (float)Math.Cos((double)(viewport.RotationY * PIby180)) + delta2 * PIby180 * (float)Math.Sin((double)(viewport.RotationY * PIby180));
angle2 += delta2 * PIby180 * (float)Math.Cos((double)(viewport.RotationY * PIby180)) - delta1 * PIby180 * (float)Math.Sin((double)(viewport.RotationY * PIby180));
UpdateRotationXZ();
}
private void RotateZX(float delta1, float delta2)
{
angle1 += delta1 * PIby180 * (float)Math.Cos((double)(viewport.RotationY * PIby180)) + delta2 * PIby180 * (float)Math.Sin((double)(viewport.RotationY * PIby180));
angle2 += delta2 * PIby180 * (float)Math.Cos((double)(viewport.RotationY * PIby180)) - delta1 * PIby180 * (float)Math.Sin((double)(viewport.RotationY * PIby180));
UpdateRotationZX();
}
private void RotateZY(float delta1, float delta2)
{
angle1 -= delta2 * PIby180;
angle2 += delta1 * PIby180;
UpdateRotationZY();
}
private void RotateYZ(float delta1, float delta2)
{
angle1 += delta1 * PIby180;
angle2 += delta2 * PIby180 * (float)Math.Sin((double)(viewport.RotationY * PIby180));
UpdateRotationYZ();
}
private void UpdateRotationXY()
{
CorrectAngles();
localRotation = Matrix3D.CreateRotationY(angle1) * Matrix3D.CreateRotationX(angle2);
UpdateRotation();
}
private void UpdateRotationYX()
{
CorrectAngles();
localRotation = Matrix3D.CreateRotationX(angle2) * Matrix3D.CreateRotationY(angle1);
UpdateRotation();
}
private void UpdateRotationXZ()
{
CorrectAngles();
localRotation = Matrix3D.CreateRotationZ(angle1) * Matrix3D.CreateRotationX(angle2);
UpdateRotation();
}
private void UpdateRotationZX()
{
CorrectAngles();
localRotation = Matrix3D.CreateRotationX(angle2) * Matrix3D.CreateRotationZ(angle1);
UpdateRotation();
}
private void UpdateRotationZY()
{
CorrectAngles();
localRotation = Matrix3D.CreateRotationY(angle2) * Matrix3D.CreateRotationZ(angle1);
UpdateRotation();
}
private void UpdateRotationYZ()
{
CorrectAngles();
localRotation = Matrix3D.CreateRotationZ(angle2) * Matrix3D.CreateRotationY(angle1);
UpdateRotation();
}
private void UpdateRotation()
{
localTransformation = positionTranslation * localRotation * originTranslation * scaleTransformation;
}
public const float PIby180 = 0.0174532924f;
protected Matrix3D originTranslation = Matrix3D.Identity;
protected Matrix3D positionTranslation = Matrix3D.Identity;
protected Matrix3D scaleTransformation = Matrix3D.Identity;
protected Matrix3D localRotation = Matrix3D.Identity;
protected Matrix3D localTransformation = Matrix3D.Identity;
protected Matrix3D globalTransformation = Matrix3D.Identity;
private float angle1;
private float angle2;
private float maxAngle1 = (float)Math.PI;
private float minAngle1 = (float)-Math.PI;
private float maxAngle2 = (float)Math.PI;
private float minAngle2 = (float)-Math.PI;
private RotationOrders order;
protected MinecraftModelView viewport;
private RotateMethod Rotate;
private Action OnUpdateRotation;
private delegate void RotateMethod(float deltaX, float deltaY);
}
}

View File

@@ -1,65 +0,0 @@
using System;
using System.Collections.Generic;
namespace PckStudio.Models
{
public class Object3DGroup : Object3D
{
internal override MinecraftModelView Viewport
{
set
{
base.Viewport = value;
foreach (Object3D object3D in objects)
{
object3D.Viewport = value;
}
}
}
public override System.Drawing.Image Image
{
set
{
foreach (Object3D object3D in objects)
{
object3D.Image = value;
}
}
}
internal override void Update()
{
Matrix3D globalTransformation = this.globalTransformation * localTransformation;
for (int i = 0; i < objects.Count; i++)
{
objects[i].GlobalTransformation = globalTransformation;
}
}
public override float HitTest(System.Drawing.PointF location)
{
float num = -1000f;
foreach (Object3D object3D in objects)
{
float num2 = object3D.HitTest(location);
if (num2 > num)
{
num = num2;
}
}
return num;
}
public void Add(Object3D object3D)
{
if (object3D == this)
{
throw new ArgumentException("Cannot add Object3D into itself.");
}
objects.Add(object3D);
}
private List<Object3D> objects = new List<Object3D>();
}
}

View File

@@ -1,31 +0,0 @@
using System;
namespace PckStudio.Models
{
public struct Point3D
{
public float X;
public float Y;
public float Z;
public Point3D(float x, float y, float z)
{
(X, Y, Z) = (x, y, z);
}
public static Point3D Zero => default(Point3D);
public override string ToString()
{
return string.Format("({0};{1};{2})", X, Y, Z);
}
public static Point3D operator +(Point3D a, Point3D b) => new Point3D(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
public static Point3D operator -(Point3D a, Point3D b) => new Point3D(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
public static Point3D operator *(Point3D p, float s) => new Point3D(p.X * s, p.Y * s, p.Z * s);
public static Point3D operator /(Point3D p, float s) => new Point3D(p.X / s, p.Y / s, p.Z / s);
}
}

View File

@@ -1,14 +0,0 @@
using System;
namespace PckStudio.Models
{
public enum Positions
{
Default,
Outstretched,
Walking,
Running,
Sitting,
Zombie
}
}

View File

@@ -1,10 +0,0 @@
using System;
namespace PckStudio.Models
{
public enum ProjectionTypes : byte
{
Perspective,
Isometric
}
}

View File

@@ -1,14 +0,0 @@
using System;
namespace PckStudio.Models
{
public enum RotationOrders : byte
{
XY,
YX,
XZ,
ZX,
YZ,
ZY
}
}

View File

@@ -1,49 +0,0 @@
using System;
namespace PckStudio.Models
{
internal struct Texel
{
internal Texel(TexturePlane texturePlane, int x, int y, System.Drawing.Color color)
{
TexturePlane = texturePlane;
X = x;
Y = y;
this.color = color;
brush = new System.Drawing.SolidBrush(color);
pen = new System.Drawing.Pen(System.Drawing.Color.White, 0.01f);
}
internal double Z
{
get
{
return TexturePlane.ZOrder[X + 1, Y + 1];
}
}
internal void Draw(System.Drawing.Graphics g)
{
System.Drawing.PointF[] points = new System.Drawing.PointF[]
{
TexturePlane.Points[X, Y],
TexturePlane.Points[X + 1, Y],
TexturePlane.Points[X + 1, Y + 1],
TexturePlane.Points[X, Y + 1]
};
g.FillPolygon(brush, points);
}
internal TexturePlane TexturePlane;
internal int X;
internal int Y;
private System.Drawing.Color color;
private System.Drawing.Brush brush;
private System.Drawing.Pen pen;
}
}

View File

@@ -1,17 +0,0 @@
using System;
using System.Collections.Generic;
namespace PckStudio.Models
{
internal class TexelComparer : IComparer<Texel>
{
public int Compare(Texel x, Texel y)
{
return -x.Z.CompareTo(y.Z);
}
public TexelComparer()
{
}
}
}

View File

@@ -1,189 +0,0 @@
using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing;
namespace PckStudio.Models
{
public class TexturePlane : Object3D
{
public override Image Image
{
set
{
Bitmap = (Bitmap)value;
}
}
internal override MinecraftModelView Viewport
{
set
{
base.Viewport = value;
if (bitmap != null && value != null)
{
UpdateBitmap();
}
}
}
internal override void Update()
{
if (Points == null || viewport == null)
{
return;
}
Matrix3D m = globalTransformation * localTransformation * originTranslation;
for (int i = 0; i <= width; i++)
{
for (int j = 0; j <= height; j++)
{
Point3D point3D = m * new Point3D(i, j, 0f);
Points[i, j] = viewport.Point3DTo2D(point3D);
double num = (double)viewport.GetZOrder(point3D);
ZOrder[i, j] += num;
ZOrder[i + 1, j] += num;
ZOrder[i, j + 1] += num;
ZOrder[i + 1, j + 1] = num;
}
}
}
private Bitmap Bitmap
{
set
{
if (viewport == null)
{
bitmap = value;
return;
}
texelList.Clear();
if (bitmap != null)
{
viewport.RemoveTexelsOf(this);
Points = null;
}
bitmap = value;
if (bitmap != null)
{
UpdateBitmap();
Update();
}
}
}
private void UpdateBitmap()
{
width = bitmap.Width;
height = bitmap.Height;
visibility = new bool[width, height];
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
Color pixel = bitmap.GetPixel(i, j);
int num = flipHorizontally ? (width - i - 1) : i;
int num2 = flipVertically ? j : (height - j - 1);
if (pixel.A == 0)
{
visibility[num, num2] = false;
}
else
{
visibility[num, num2] = true;
Texel texel = new Texel(this, num, num2, pixel);
viewport.AddTexel(texel);
texelList.Add(texel);
}
}
}
Points = new PointF[width + 1, height + 1];
ZOrder = new double[width + 2, height + 2];
}
public TexturePlane(Image bitmap, Rectangle srcRect, Point3D origin, Point3D normal, Effects effects)
{
Origin = origin;
this.normal = normal;
if (bitmap == null)
{
Bitmap = null;
return;
}
Bitmap bitmap2 = new Bitmap(srcRect.Width, srcRect.Height);
using (Graphics graphics = Graphics.FromImage(bitmap2))
{
graphics.DrawImage(bitmap, new Rectangle(0, 0, bitmap2.Width, bitmap2.Height), srcRect, GraphicsUnit.Pixel);
}
flipHorizontally = (byte)(effects & Effects.FlipHorizontally) == 1;
flipVertically = (byte)(effects & Effects.FlipVertically) == 2;
Bitmap = bitmap2;
}
public override float HitTest(PointF location)
{
if (Points == null)
{
return -1000f;
}
GraphicsPath graphicsPath = new GraphicsPath();
graphicsPath.AddPolygon(new PointF[]
{
Points[0, 0],
Points[Points.GetLength(0) - 1, 0],
Points[Points.GetLength(0) - 1, Points.GetLength(1) - 1],
Points[0, Points.GetLength(1) - 1]
});
Region region = new Region(graphicsPath);
if (region.IsVisible(location))
{
for (int i = 0; i < Points.GetLength(0) - 1; i++)
{
for (int j = 0; j < Points.GetLength(1) - 1; j++)
{
if (visibility[i, j])
{
graphicsPath.Reset();
graphicsPath.AddPolygon(new PointF[]
{
Points[i, j],
Points[i + 1, j],
Points[i + 1, j + 1],
Points[i, j + 1]
});
if (graphicsPath.IsVisible(location))
{
return (globalTransformation * localTransformation * originTranslation * new Point3D(i, j, 0f)).Z;
}
}
}
}
}
return -1000f;
}
private List<Texel> texelList = new List<Texel>();
internal PointF[,] Points;
internal double[,] ZOrder;
internal bool IsVisible = true;
private bool[,] visibility;
private Bitmap bitmap;
private bool flipHorizontally;
private bool flipVertically;
private int width;
private int height;
private Point3D normal;
}
}

View File

@@ -2,18 +2,16 @@
using System.Collections.Generic;
using System.Drawing;
using OpenTK;
using PckStudio.ToolboxItems;
using PckStudio.Rendering;
namespace PckStudio.Classes.Utils
{
public class MouseRay
public class Ray
{
public Vector3 CurrentRay { get; set; } = new Vector3();
public Matrix4 ViewMatrix { get; set; }
public Matrix4 projectionMatrix { get; set; }
public Matrix4 ProjectionMatrix { get; set; }
public Vector3 CamPos { get; set; }
@@ -21,9 +19,10 @@ namespace PckStudio.Classes.Utils
public Point Pos { get; set; }
// TODO: remove Renderer3D from Ray
public Renderer3D Renderer { get; set; }
public struct ResultDistance
public struct RayResult
{
public float Distance { get; set; }
@@ -36,7 +35,7 @@ namespace PckStudio.Classes.Utils
public Is IsWhat { get; set; }
public ResultDistance(float Distance, Is IsWhat)
public RayResult(float Distance, Is IsWhat)
{
this.Distance = Distance;
this.IsWhat = IsWhat;
@@ -87,7 +86,7 @@ namespace PckStudio.Classes.Utils
LegYIndex[0] = (-4 - CamPos.Y) / CurrentRay.Y;
LegYIndex[1] = (-16 - CamPos.Y) / CurrentRay.Y;
var PointsDis = new List<ResultDistance>();
var PointsDis = new List<RayResult>();
Vector3 HeadPoint, BodyPoint, HeadXPoint, BodyXPoint, LegXPoint, HeadYPoint, BodyYPoint, LegYPoint;
@@ -96,7 +95,7 @@ namespace PckStudio.Classes.Utils
if (!(I > 1))
{
HeadPoint = getPointOnRay(CurrentRay, HeadIndex[I]);
HeadPoint = GetPointOnRay(CurrentRay, HeadIndex[I]);
}
else
{
@@ -104,7 +103,7 @@ namespace PckStudio.Classes.Utils
}
if (!(I > 1))
{
BodyPoint = getPointOnRay(CurrentRay, BodyIndex[I]);
BodyPoint = GetPointOnRay(CurrentRay, BodyIndex[I]);
}
else
{
@@ -113,16 +112,16 @@ namespace PckStudio.Classes.Utils
if (!(I > 1))
{
HeadXPoint = getPointOnRay(CurrentRay, HeadXIndex[I]);
HeadXPoint = GetPointOnRay(CurrentRay, HeadXIndex[I]);
}
else
{
HeadXPoint = new Vector3(20f, 20f, 20f);
}
BodyXPoint = getPointOnRay(CurrentRay, BodyXIndex[I]);
BodyXPoint = GetPointOnRay(CurrentRay, BodyXIndex[I]);
if (!(I > 2))
{
LegXPoint = getPointOnRay(CurrentRay, LegXIndex[I]);
LegXPoint = GetPointOnRay(CurrentRay, LegXIndex[I]);
}
else
{
@@ -131,7 +130,7 @@ namespace PckStudio.Classes.Utils
if (!(I > 1))
{
HeadYPoint = getPointOnRay(CurrentRay, HeadYIndex[I]);
HeadYPoint = GetPointOnRay(CurrentRay, HeadYIndex[I]);
}
else
{
@@ -139,7 +138,7 @@ namespace PckStudio.Classes.Utils
}
if (!(I > 1))
{
BodyYPoint = getPointOnRay(CurrentRay, BodyYIndex[I]);
BodyYPoint = GetPointOnRay(CurrentRay, BodyYIndex[I]);
}
else
{
@@ -147,7 +146,7 @@ namespace PckStudio.Classes.Utils
}
if (!(I > 1))
{
LegYPoint = getPointOnRay(CurrentRay, LegYIndex[I]);
LegYPoint = GetPointOnRay(CurrentRay, LegYIndex[I]);
}
else
{
@@ -156,95 +155,95 @@ namespace PckStudio.Classes.Utils
if (Renderer.ShowHead && HeadPoint.X < 4f && HeadPoint.X > -4 && HeadPoint.Y < 16f && HeadPoint.Y > 8f)
{
PointsDis.Add(new ResultDistance(HeadIndex[I], ResultDistance.Is.Z));
PointsDis.Add(new RayResult(HeadIndex[I], RayResult.Is.Z));
}
if (Renderer.ShowBody && BodyPoint.X < 4f && BodyPoint.X > -4 && BodyPoint.Y < 8f && BodyPoint.Y > -4)
{
PointsDis.Add(new ResultDistance(BodyIndex[I], ResultDistance.Is.Z));
PointsDis.Add(new RayResult(BodyIndex[I], RayResult.Is.Z));
}
if (Renderer.ShowRightArm && BodyPoint.Y > -4 && BodyPoint.Y < 8f)
{
if (Renderer.Model == Renderer3D.Models.Steve && BodyPoint.X > -8 && BodyPoint.X < -4 || Renderer.Model == Renderer3D.Models.Alex && BodyPoint.X > -7 && BodyPoint.X < -4)
{
PointsDis.Add(new ResultDistance(BodyIndex[I], ResultDistance.Is.Z));
PointsDis.Add(new RayResult(BodyIndex[I], RayResult.Is.Z));
}
}
if (Renderer.ShowLeftArm && BodyPoint.Y < 8f && BodyPoint.Y > -4)
{
if (Renderer.Model == Renderer3D.Models.Steve && BodyPoint.X < 8f && BodyPoint.X > 4f || Renderer.Model == Renderer3D.Models.Alex && BodyPoint.X < 7f && BodyPoint.X > 4f)
{
PointsDis.Add(new ResultDistance(BodyIndex[I], ResultDistance.Is.Z));
PointsDis.Add(new RayResult(BodyIndex[I], RayResult.Is.Z));
}
}
if (Renderer.ShowRightLeg && BodyPoint.X < 0f && BodyPoint.X > -4 && BodyPoint.Y < -4 && BodyPoint.Y > -16)
{
PointsDis.Add(new ResultDistance(BodyIndex[I], ResultDistance.Is.Z));
PointsDis.Add(new RayResult(BodyIndex[I], RayResult.Is.Z));
}
if (Renderer.ShowLeftLeg && BodyPoint.X < 4f && BodyPoint.X > 0f && BodyPoint.Y < -4 && BodyPoint.Y > -16)
{
PointsDis.Add(new ResultDistance(BodyIndex[I], ResultDistance.Is.Z));
PointsDis.Add(new RayResult(BodyIndex[I], RayResult.Is.Z));
}
if (Renderer.ShowHead && HeadXPoint.Z < 4f && HeadXPoint.Z > -4 && HeadXPoint.Y < 16f && HeadXPoint.Y > 8f)
{
PointsDis.Add(new ResultDistance(HeadXIndex[I], ResultDistance.Is.X));
PointsDis.Add(new RayResult(HeadXIndex[I], RayResult.Is.X));
}
if (Renderer.ShowRightArm && (Convert.ToInt32(BodyXPoint.X) == -8 || Convert.ToInt32(BodyXPoint.X) == -7) && BodyXPoint.Z < 2f && BodyXPoint.Z > -2 && BodyXPoint.Y < 8f && BodyXPoint.Y > -4)
{
PointsDis.Add(new ResultDistance(BodyXIndex[I], ResultDistance.Is.X));
PointsDis.Add(new RayResult(BodyXIndex[I], RayResult.Is.X));
}
if (Renderer.ShowLeftArm && (Convert.ToInt32(BodyXPoint.X) == 8 || Convert.ToInt32(BodyXPoint.X) == 7) && BodyXPoint.Z < 2f && BodyXPoint.Z > -2 && BodyXPoint.Y < 8f && BodyXPoint.Y > -4)
{
PointsDis.Add(new ResultDistance(BodyXIndex[I], ResultDistance.Is.X));
PointsDis.Add(new RayResult(BodyXIndex[I], RayResult.Is.X));
}
if (Renderer.ShowRightArm ^ Renderer.ShowBody && Convert.ToInt32(BodyXPoint.X) == -4 && BodyXPoint.Z < 2f && BodyXPoint.Z > -2 && BodyXPoint.Y < 8f && BodyXPoint.Y > -4)
{
PointsDis.Add(new ResultDistance(BodyXIndex[I], ResultDistance.Is.X));
PointsDis.Add(new RayResult(BodyXIndex[I], RayResult.Is.X));
}
if (Renderer.ShowLeftArm ^ Renderer.ShowBody && Convert.ToInt32(BodyXPoint.X) == 4 && BodyXPoint.Z < 2f && BodyXPoint.Z > -2 && BodyXPoint.Y < 8f && BodyXPoint.Y > -4)
{
PointsDis.Add(new ResultDistance(BodyXIndex[I], ResultDistance.Is.X));
PointsDis.Add(new RayResult(BodyXIndex[I], RayResult.Is.X));
}
if (Renderer.ShowRightLeg && Convert.ToInt32(LegXPoint.X) == -4 && LegXPoint.Z < 2f && LegXPoint.Z > -2 && LegXPoint.Y < -4 && LegXPoint.Y > -16)
{
PointsDis.Add(new ResultDistance(LegXIndex[I], ResultDistance.Is.X));
PointsDis.Add(new RayResult(LegXIndex[I], RayResult.Is.X));
}
if (Renderer.ShowLeftLeg && Convert.ToInt32(LegXPoint.X) == 4 && LegXPoint.Z < 2f && LegXPoint.Z > -2 && LegXPoint.Y < -4 && LegXPoint.Y > -16)
{
PointsDis.Add(new ResultDistance(LegXIndex[I], ResultDistance.Is.X));
PointsDis.Add(new RayResult(LegXIndex[I], RayResult.Is.X));
}
if (Renderer.ShowRightLeg ^ Renderer.ShowLeftLeg && Convert.ToInt32(LegXPoint.X) == 0 && LegXPoint.Z < 2f && LegXPoint.Z > -2 && LegXPoint.Y < -4 && LegXPoint.Y > -16)
{
PointsDis.Add(new ResultDistance(LegXIndex[I], ResultDistance.Is.X));
PointsDis.Add(new RayResult(LegXIndex[I], RayResult.Is.X));
}
if (Renderer.ShowHead && HeadYPoint.Z < 4f && HeadYPoint.Z > -4 && HeadYPoint.X < 4f && HeadYPoint.X > -4)
{
PointsDis.Add(new ResultDistance(HeadYIndex[I], ResultDistance.Is.Y));
PointsDis.Add(new RayResult(HeadYIndex[I], RayResult.Is.Y));
}
if (Renderer.ShowBody && BodyYPoint.Z < 2f && BodyYPoint.Z > -2 && BodyYPoint.X < 4f && BodyYPoint.X > -4)
{
PointsDis.Add(new ResultDistance(BodyYIndex[I], ResultDistance.Is.Y));
PointsDis.Add(new RayResult(BodyYIndex[I], RayResult.Is.Y));
}
if (Renderer.ShowRightArm && BodyYPoint.Z < 2f && BodyYPoint.Z > -2)
{
if (Renderer.Model == Renderer3D.Models.Steve && BodyYPoint.X > -8 && BodyYPoint.X < -4 || Renderer.Model == Renderer3D.Models.Alex && BodyYPoint.X > -7 && BodyYPoint.X < -4)
{
PointsDis.Add(new ResultDistance(BodyYIndex[I], ResultDistance.Is.Y));
PointsDis.Add(new RayResult(BodyYIndex[I], RayResult.Is.Y));
}
}
if (Renderer.ShowLeftArm && BodyYPoint.Z < 2f && BodyYPoint.Z > -2)
{
if (Renderer.Model == Renderer3D.Models.Steve && BodyYPoint.X < 8f && BodyYPoint.X > 4f || Renderer.Model == Renderer3D.Models.Alex && BodyYPoint.X < 7f && BodyYPoint.X > 4f)
{
PointsDis.Add(new ResultDistance(BodyYIndex[I], ResultDistance.Is.Y));
PointsDis.Add(new RayResult(BodyYIndex[I], RayResult.Is.Y));
}
}
if (Renderer.ShowRightLeg && LegYPoint.Z < 2f && LegYPoint.Z > -2 && LegYPoint.X < 0f && LegYPoint.X > -4)
{
PointsDis.Add(new ResultDistance(LegYIndex[I], ResultDistance.Is.Y));
PointsDis.Add(new RayResult(LegYIndex[I], RayResult.Is.Y));
}
if (Renderer.ShowLeftLeg && LegYPoint.Z < 2f && LegYPoint.Z > -2 && LegYPoint.X < 4f && LegYPoint.X > 0f)
{
PointsDis.Add(new ResultDistance(LegYIndex[I], ResultDistance.Is.Y));
PointsDis.Add(new RayResult(LegYIndex[I], RayResult.Is.Y));
}
}
@@ -252,24 +251,24 @@ namespace PckStudio.Classes.Utils
if (PointsDis.Count == 0)
return default;
var Smallest = new ResultDistance(1000f, ResultDistance.Is.X);
var Smallest = new RayResult(1000f, RayResult.Is.X);
foreach (ResultDistance value in PointsDis)
foreach (RayResult value in PointsDis)
{
if (value.Distance < Smallest.Distance)
Smallest = value;
}
var Result = getPointOnRay(CurrentRay, Smallest.Distance);
if (Smallest.IsWhat == ResultDistance.Is.X)
var Result = GetPointOnRay(CurrentRay, Smallest.Distance);
if (Smallest.IsWhat == RayResult.Is.X)
{
Result.X = (int)Math.Round(Result.X);
}
else if (Smallest.IsWhat == ResultDistance.Is.Y)
else if (Smallest.IsWhat == RayResult.Is.Y)
{
Result.Y = (int)Math.Round(Result.Y);
}
else if (Smallest.IsWhat == ResultDistance.Is.Z)
else if (Smallest.IsWhat == RayResult.Is.Z)
{
Result.Z = (int)Math.Round(Result.Z);
}
@@ -329,110 +328,110 @@ namespace PckStudio.Classes.Utils
LegYIndex[0] = (float)((-3.64d - CamPos.Y) / CurrentRay.Y);
LegYIndex[1] = (float)((-16.36d - CamPos.Y) / CurrentRay.Y);
var PointsDis = new List<ResultDistance>();
var PointsDis = new List<RayResult>();
Vector3 HeadPoint, BodyPoint, HeadXPoint, BodyXPoint, LArmXPoint, RArmXPoint, LLegXPoint, RLegXPoint, HeadYPoint, BodyYPoint, LegYPoint;
for (byte I = 0; I <= 1; I++)
{
HeadPoint = getPointOnRay(CurrentRay, HeadIndex[I]);
BodyPoint = getPointOnRay(CurrentRay, BodyIndex[I]);
HeadPoint = GetPointOnRay(CurrentRay, HeadIndex[I]);
BodyPoint = GetPointOnRay(CurrentRay, BodyIndex[I]);
HeadXPoint = getPointOnRay(CurrentRay, HeadXIndex[I]);
BodyXPoint = getPointOnRay(CurrentRay, BodyXIndex[I]);
RArmXPoint = getPointOnRay(CurrentRay, RArmXIndex[I]);
LArmXPoint = getPointOnRay(CurrentRay, LArmXIndex[I]);
RLegXPoint = getPointOnRay(CurrentRay, RLegXIndex[I]);
LLegXPoint = getPointOnRay(CurrentRay, LLegXIndex[I]);
HeadXPoint = GetPointOnRay(CurrentRay, HeadXIndex[I]);
BodyXPoint = GetPointOnRay(CurrentRay, BodyXIndex[I]);
RArmXPoint = GetPointOnRay(CurrentRay, RArmXIndex[I]);
LArmXPoint = GetPointOnRay(CurrentRay, LArmXIndex[I]);
RLegXPoint = GetPointOnRay(CurrentRay, RLegXIndex[I]);
LLegXPoint = GetPointOnRay(CurrentRay, LLegXIndex[I]);
HeadYPoint = getPointOnRay(CurrentRay, HeadYIndex[I]);
BodyYPoint = getPointOnRay(CurrentRay, BodyYIndex[I]);
LegYPoint = getPointOnRay(CurrentRay, LegYIndex[I]);
HeadYPoint = GetPointOnRay(CurrentRay, HeadYIndex[I]);
BodyYPoint = GetPointOnRay(CurrentRay, BodyYIndex[I]);
LegYPoint = GetPointOnRay(CurrentRay, LegYIndex[I]);
if (Renderer.Show2ndHead && HeadPoint.X < 4.24d && HeadPoint.X > -4.24d && HeadPoint.Y < 16.24d && HeadPoint.Y > 7.76d)
if (Renderer.ShowHeadOverlay && HeadPoint.X < 4.24d && HeadPoint.X > -4.24d && HeadPoint.Y < 16.24d && HeadPoint.Y > 7.76d)
{
PointsDis.Add(new ResultDistance(HeadIndex[I], ResultDistance.Is.Z));
PointsDis.Add(new RayResult(HeadIndex[I], RayResult.Is.Z));
}
if (Renderer.Show2ndBody && BodyPoint.X < 4.24d && BodyPoint.X > -4.24d && BodyPoint.Y < 8.36d && BodyPoint.Y > -4.36d)
if (Renderer.ShowBodyOverlay && BodyPoint.X < 4.24d && BodyPoint.X > -4.24d && BodyPoint.Y < 8.36d && BodyPoint.Y > -4.36d)
{
PointsDis.Add(new ResultDistance(BodyIndex[I], ResultDistance.Is.Z));
PointsDis.Add(new RayResult(BodyIndex[I], RayResult.Is.Z));
}
if (Renderer.Show2ndRightArm && BodyPoint.Y < 8.36d && BodyPoint.Y > -4.36d)
if (Renderer.ShowRightArmOverlay && BodyPoint.Y < 8.36d && BodyPoint.Y > -4.36d)
{
if (Renderer.Model == Renderer3D.Models.Steve && BodyPoint.X < -3.88d && BodyPoint.X > -8.12d || Renderer.Model == Renderer3D.Models.Alex && BodyPoint.X < -3.91d && BodyPoint.X > -7.09d)
{
PointsDis.Add(new ResultDistance(BodyIndex[I], ResultDistance.Is.Z));
PointsDis.Add(new RayResult(BodyIndex[I], RayResult.Is.Z));
}
}
if (Renderer.Show2ndLeftArm && BodyPoint.Y < 8.36d && BodyPoint.Y > -4.36d)
if (Renderer.ShowLeftArmOverlay && BodyPoint.Y < 8.36d && BodyPoint.Y > -4.36d)
{
if (Renderer.Model == Renderer3D.Models.Steve && BodyPoint.X < 8.12d && BodyPoint.X > 3.88d || Renderer.Model == Renderer3D.Models.Alex && BodyPoint.X < 7.09d && BodyPoint.X > 3.91d)
{
PointsDis.Add(new ResultDistance(BodyIndex[I], ResultDistance.Is.Z));
PointsDis.Add(new RayResult(BodyIndex[I], RayResult.Is.Z));
}
}
if (Renderer.Show2ndRightLeg && BodyPoint.X < 0.12d && BodyPoint.X > -4.12d && BodyPoint.Y < -3.64d && BodyPoint.Y > -16.36d)
if (Renderer.ShowRightLegOverlay && BodyPoint.X < 0.12d && BodyPoint.X > -4.12d && BodyPoint.Y < -3.64d && BodyPoint.Y > -16.36d)
{
PointsDis.Add(new ResultDistance(BodyIndex[I], ResultDistance.Is.Z));
PointsDis.Add(new RayResult(BodyIndex[I], RayResult.Is.Z));
}
if (Renderer.Show2ndLeftLeg && BodyPoint.X < 4.12d && BodyPoint.X > -0.12d && BodyPoint.Y < -3.64d && BodyPoint.Y > -16.36d)
if (Renderer.ShowLeftLegOverlay && BodyPoint.X < 4.12d && BodyPoint.X > -0.12d && BodyPoint.Y < -3.64d && BodyPoint.Y > -16.36d)
{
PointsDis.Add(new ResultDistance(BodyIndex[I], ResultDistance.Is.Z));
PointsDis.Add(new RayResult(BodyIndex[I], RayResult.Is.Z));
}
if (Renderer.Show2ndHead && HeadXPoint.Z < 4.24d && HeadXPoint.Z > -4.24d && HeadXPoint.Y < 16.24d && HeadXPoint.Y > 7.76d)
if (Renderer.ShowHeadOverlay && HeadXPoint.Z < 4.24d && HeadXPoint.Z > -4.24d && HeadXPoint.Y < 16.24d && HeadXPoint.Y > 7.76d)
{
PointsDis.Add(new ResultDistance(HeadXIndex[I], ResultDistance.Is.X));
PointsDis.Add(new RayResult(HeadXIndex[I], RayResult.Is.X));
}
if (Renderer.Show2ndBody && BodyXPoint.Z < 2.12d && BodyXPoint.Z > -2.12d && BodyXPoint.Y < 8.36d && BodyXPoint.Y > -4.36d)
if (Renderer.ShowBodyOverlay && BodyXPoint.Z < 2.12d && BodyXPoint.Z > -2.12d && BodyXPoint.Y < 8.36d && BodyXPoint.Y > -4.36d)
{
PointsDis.Add(new ResultDistance(BodyXIndex[I], ResultDistance.Is.X));
PointsDis.Add(new RayResult(BodyXIndex[I], RayResult.Is.X));
}
if (Renderer.Show2ndRightArm && RArmXPoint.Z < 2.12d && RArmXPoint.Z > -2.12d && RArmXPoint.Y < 8.36d && RArmXPoint.Y > -4.36d)
if (Renderer.ShowRightArmOverlay && RArmXPoint.Z < 2.12d && RArmXPoint.Z > -2.12d && RArmXPoint.Y < 8.36d && RArmXPoint.Y > -4.36d)
{
PointsDis.Add(new ResultDistance(RArmXIndex[I], ResultDistance.Is.X));
PointsDis.Add(new RayResult(RArmXIndex[I], RayResult.Is.X));
}
if (Renderer.Show2ndLeftArm && LArmXPoint.Z < 2.12d && LArmXPoint.Z > -2.12d && LArmXPoint.Y < 8.36d && LArmXPoint.Y > -4.36d)
if (Renderer.ShowLeftArmOverlay && LArmXPoint.Z < 2.12d && LArmXPoint.Z > -2.12d && LArmXPoint.Y < 8.36d && LArmXPoint.Y > -4.36d)
{
PointsDis.Add(new ResultDistance(LArmXIndex[I], ResultDistance.Is.X));
PointsDis.Add(new RayResult(LArmXIndex[I], RayResult.Is.X));
}
if (Renderer.Show2ndRightLeg && RLegXPoint.Z < 2.12d && RLegXPoint.Z > -2.12d && RLegXPoint.Y < -3.64d && RLegXPoint.Y > -16.36d)
if (Renderer.ShowRightLegOverlay && RLegXPoint.Z < 2.12d && RLegXPoint.Z > -2.12d && RLegXPoint.Y < -3.64d && RLegXPoint.Y > -16.36d)
{
PointsDis.Add(new ResultDistance(RLegXIndex[I], ResultDistance.Is.X));
PointsDis.Add(new RayResult(RLegXIndex[I], RayResult.Is.X));
}
if (Renderer.Show2ndLeftLeg && LLegXPoint.Z < 2.12d && LLegXPoint.Z > -2.12d && LLegXPoint.Y < -3.64d && LLegXPoint.Y > -16.36d)
if (Renderer.ShowLeftLegOverlay && LLegXPoint.Z < 2.12d && LLegXPoint.Z > -2.12d && LLegXPoint.Y < -3.64d && LLegXPoint.Y > -16.36d)
{
PointsDis.Add(new ResultDistance(LLegXIndex[I], ResultDistance.Is.X));
PointsDis.Add(new RayResult(LLegXIndex[I], RayResult.Is.X));
}
if (Renderer.Show2ndHead && HeadYPoint.Z < 4.24d && HeadYPoint.Z > -4.24d && HeadYPoint.X < 4.24d && HeadYPoint.X > -4.24d)
if (Renderer.ShowHeadOverlay && HeadYPoint.Z < 4.24d && HeadYPoint.Z > -4.24d && HeadYPoint.X < 4.24d && HeadYPoint.X > -4.24d)
{
PointsDis.Add(new ResultDistance(HeadYIndex[I], ResultDistance.Is.Y));
PointsDis.Add(new RayResult(HeadYIndex[I], RayResult.Is.Y));
}
if (Renderer.Show2ndBody && BodyYPoint.Z < 2.12d && BodyYPoint.Z > -2.12d && BodyYPoint.X < 4.24d && BodyYPoint.X > -4.24d)
if (Renderer.ShowBodyOverlay && BodyYPoint.Z < 2.12d && BodyYPoint.Z > -2.12d && BodyYPoint.X < 4.24d && BodyYPoint.X > -4.24d)
{
PointsDis.Add(new ResultDistance(BodyYIndex[I], ResultDistance.Is.Y));
PointsDis.Add(new RayResult(BodyYIndex[I], RayResult.Is.Y));
}
if (Renderer.Show2ndRightArm && BodyYPoint.Z < 2.12d && BodyYPoint.Z > -2.12d)
if (Renderer.ShowRightArmOverlay && BodyYPoint.Z < 2.12d && BodyYPoint.Z > -2.12d)
{
if (Renderer.Model == Renderer3D.Models.Steve && BodyYPoint.X < -3.88d && BodyYPoint.X > -8.12d || Renderer.Model == Renderer3D.Models.Alex && BodyYPoint.X < -3.91d && BodyYPoint.X > -7.09d)
{
PointsDis.Add(new ResultDistance(BodyYIndex[I], ResultDistance.Is.Y));
PointsDis.Add(new RayResult(BodyYIndex[I], RayResult.Is.Y));
}
}
if (Renderer.Show2ndLeftArm && BodyYPoint.Z < 2.12d && BodyYPoint.Z > -2.12d)
if (Renderer.ShowLeftArmOverlay && BodyYPoint.Z < 2.12d && BodyYPoint.Z > -2.12d)
{
if (Renderer.Model == Renderer3D.Models.Steve && BodyYPoint.X < 8.12d && BodyYPoint.X > 3.88d || Renderer.Model == Renderer3D.Models.Alex && BodyYPoint.X < 7.09d && BodyYPoint.X > 3.91d)
{
PointsDis.Add(new ResultDistance(BodyYIndex[I], ResultDistance.Is.Y));
PointsDis.Add(new RayResult(BodyYIndex[I], RayResult.Is.Y));
}
}
if (Renderer.Show2ndRightLeg && LegYPoint.Z < 2.12d && LegYPoint.Z > -2.12d && LegYPoint.X < 0.12d && LegYPoint.X > -4.12d)
if (Renderer.ShowRightLegOverlay && LegYPoint.Z < 2.12d && LegYPoint.Z > -2.12d && LegYPoint.X < 0.12d && LegYPoint.X > -4.12d)
{
PointsDis.Add(new ResultDistance(LegYIndex[I], ResultDistance.Is.Y));
PointsDis.Add(new RayResult(LegYIndex[I], RayResult.Is.Y));
}
if (Renderer.Show2ndLeftLeg && LegYPoint.Z < 2.12d && LegYPoint.Z > -2.12d && LegYPoint.X < 4.12d && LegYPoint.X > -0.12d)
if (Renderer.ShowLeftLegOverlay && LegYPoint.Z < 2.12d && LegYPoint.Z > -2.12d && LegYPoint.X < 4.12d && LegYPoint.X > -0.12d)
{
PointsDis.Add(new ResultDistance(LegYIndex[I], ResultDistance.Is.Y));
PointsDis.Add(new RayResult(LegYIndex[I], RayResult.Is.Y));
}
}
@@ -440,15 +439,15 @@ namespace PckStudio.Classes.Utils
if (PointsDis.Count == 0)
return new Vector3(100f, 100f, 100f);
var Smallest = new ResultDistance(1000f, ResultDistance.Is.Z);
var Smallest = new RayResult(1000f, RayResult.Is.Z);
foreach (ResultDistance value in PointsDis)
foreach (RayResult value in PointsDis)
{
if (value.Distance < Smallest.Distance)
Smallest = value;
}
var Result = getPointOnRay(CurrentRay, Smallest.Distance);
var Result = GetPointOnRay(CurrentRay, Smallest.Distance);
float[] ZIndex = new[] { 4.24f, 2.12f, (float)-4.24d, (float)-2.12d };
float[] XIndex;
@@ -464,7 +463,7 @@ namespace PckStudio.Classes.Utils
float AResult = 20f;
if (Smallest.IsWhat == ResultDistance.Is.X)
if (Smallest.IsWhat == RayResult.Is.X)
{
foreach (float value in XIndex)
{
@@ -475,7 +474,7 @@ namespace PckStudio.Classes.Utils
}
Result.X = AResult;
}
else if (Smallest.IsWhat == ResultDistance.Is.Y)
else if (Smallest.IsWhat == RayResult.Is.Y)
{
foreach (float value in YIndex)
{
@@ -486,7 +485,7 @@ namespace PckStudio.Classes.Utils
}
Result.Y = AResult;
}
else if (Smallest.IsWhat == ResultDistance.Is.Z)
else if (Smallest.IsWhat == RayResult.Is.Z)
{
foreach (float value in ZIndex)
{
@@ -502,56 +501,55 @@ namespace PckStudio.Classes.Utils
}
}
public MouseRay(ref Matrix4 View, ref Matrix4 Projection, Size TheSize, Vector3 Camera, Renderer3D TheRenderer)
public Ray(ref Matrix4 viewMatrix, ref Matrix4 projectionMatrix, Size size, Vector3 cameraPosition, Renderer3D renderer)
{
projectionMatrix = Projection;
ViewMatrix = View;
Size = TheSize;
CamPos = Camera;
Renderer = TheRenderer;
ProjectionMatrix = projectionMatrix;
ViewMatrix = viewMatrix;
Size = size;
CamPos = cameraPosition;
Renderer = renderer;
}
private void Update(int X, int Y)
{
CurrentRay = calculateMouseRay(X, Y);
CurrentRay = CalculateRay(X, Y);
}
private Vector3 calculateMouseRay(int X, int Y)
private Vector3 CalculateRay(int x, int y)
{
var normalizedCoords = getNormalisedDeviceCoordinates(X, Y);
var normalizedCoords = GetNormalisedDeviceCoordinates(x, y);
var clipCoords = new Vector4(normalizedCoords.X, normalizedCoords.Y, -1.0f, 1.0f);
var eyeCoords = toEyeCoords(clipCoords);
var worldRay = toWorldCoords(eyeCoords);
var eyeCoords = ToEyeCoords(clipCoords);
var worldRay = ToWorldCoords(eyeCoords);
return worldRay;
}
private Vector4 toEyeCoords(Vector4 clipCoords)
private Vector4 ToEyeCoords(Vector4 clipCoords)
{
var invertedProjection = Matrix4.Invert(projectionMatrix);
var invertedProjection = Matrix4.Invert(ProjectionMatrix);
var eyeCoords = Vector4.Transform(clipCoords, invertedProjection);
return new Vector4(eyeCoords.X, eyeCoords.Y, -1.0f, 0f);
}
private Vector3 toWorldCoords(Vector4 eyeCoords)
private Vector3 ToWorldCoords(Vector4 eyeCoords)
{
var invertedView = Matrix4.Invert(ViewMatrix);
var rayWorld = Vector4.Transform(eyeCoords, invertedView);
var TheMouseRay = new Vector3(rayWorld.X, rayWorld.Y, rayWorld.Z);
TheMouseRay.Normalize();
return TheMouseRay;
var ray = new Vector3(rayWorld);
ray.Normalize();
return ray;
}
private Vector2 getNormalisedDeviceCoordinates(int x, int y)
private Vector2 GetNormalisedDeviceCoordinates(int x, int y)
{
float x2 = 2.0f * x / Size.Width - 1.0f;
float y2 = -(2.0f * y / Size.Height - 1.0f);
return new Vector2(x2, y2);
}
private Vector3 getPointOnRay(Vector3 ray, float distance)
private Vector3 GetPointOnRay(Vector3 ray, float distance)
{
var start = new Vector3(CamPos.X, CamPos.Y, CamPos.Z);
var start = new Vector3(CamPos);
var scaledRay = new Vector3(ray.X * distance, ray.Y * distance, ray.Z * distance);
return start + scaledRay;
}

View File

@@ -31,24 +31,17 @@ namespace PckStudio.Forms
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SkinPreview));
this.ModelView = new PckStudio.Models.MinecraftModelView(this.components);
this.ModelView = new PckStudio.Rendering.Renderer3D();
this.SuspendLayout();
//
// ModelView
//
this.ModelView.BackColor = System.Drawing.Color.DarkGray;
this.ModelView.BackGradientColor1 = System.Drawing.SystemColors.ActiveCaptionText;
this.ModelView.BackGradientColor2 = System.Drawing.SystemColors.ActiveCaptionText;
this.ModelView.BackgroundType = PckStudio.Models.BackgroundTypes.Color;
this.ModelView.DegreesX = 0;
this.ModelView.DegreesY = 0;
this.ModelView.Dock = System.Windows.Forms.DockStyle.Fill;
this.ModelView.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.ModelView.ForeColor = System.Drawing.Color.Black;
this.ModelView.FOV = 90;
this.ModelView.Location = new System.Drawing.Point(0, 0);
this.ModelView.Name = "ModelView";
this.ModelView.Projection = PckStudio.Models.ProjectionTypes.Perspective;
this.ModelView.Size = new System.Drawing.Size(418, 568);
this.ModelView.TabIndex = 1;
this.ModelView.Text = "PCK Model View";
@@ -70,6 +63,6 @@ namespace PckStudio.Forms
#endregion
private PckStudio.Models.MinecraftModelView ModelView;
private PckStudio.Rendering.Renderer3D ModelView;
}
}

View File

@@ -1,34 +1,42 @@
using System;
using System.Drawing;
using System.Windows.Forms;
using PckStudio.Classes.Models.DefaultModels;
using PckStudio.Internal;
using PckStudio.Models;
using PckStudio.Rendering;
namespace PckStudio.Forms
{
public partial class SkinPreview : Form
{
Image Texture;
ModelBase Model;
public SkinPreview(Image img, SkinANIM anim, ModelBase model = null)
public SkinPreview(Image texture, SkinANIM anim)
{
InitializeComponent();
Texture = img;
Texture = texture;
ModelView.Model = anim.GetFlag(SkinAnimFlag.SLIM_MODEL) ? Renderer3D.Models.Alex : Renderer3D.Models.Steve;
Model = model ?? new Steve64x32Model(Texture);
if (img.Width == 64 && img.Height == 64)
{
Model = model ?? new Steve64x64Model(Texture, anim);
}
ModelView.ShowHead = !anim.GetFlag(SkinAnimFlag.HEAD_DISABLED);
ModelView.ShowHeadOverlay = !anim.GetFlag(SkinAnimFlag.HEAD_OVERLAY_DISABLED);
ModelView.ShowBody = !anim.GetFlag(SkinAnimFlag.BODY_DISABLED);
ModelView.ShowBodyOverlay = !anim.GetFlag(SkinAnimFlag.BODY_OVERLAY_DISABLED);
ModelView.ShowLeftArm = !anim.GetFlag(SkinAnimFlag.LEFT_ARM_DISABLED);
ModelView.ShowLeftArmOverlay = !anim.GetFlag(SkinAnimFlag.LEFT_ARM_OVERLAY_DISABLED);
ModelView.ShowRightArm = !anim.GetFlag(SkinAnimFlag.RIGHT_ARM_DISABLED);
ModelView.ShowRightArmOverlay = !anim.GetFlag(SkinAnimFlag.RIGHT_ARM_OVERLAY_DISABLED);
ModelView.ShowLeftLeg = !anim.GetFlag(SkinAnimFlag.LEFT_LEG_DISABLED);
ModelView.ShowLeftLegOverlay = !anim.GetFlag(SkinAnimFlag.LEFT_LEG_OVERLAY_DISABLED);
ModelView.ShowRightLeg = !anim.GetFlag(SkinAnimFlag.RIGHT_LEG_DISABLED);
ModelView.ShowRightLegOverlay = !anim.GetFlag(SkinAnimFlag.RIGHT_LEG_OVERLAY_DISABLED);
}
private void SkinPreview_Load(object sender, EventArgs e) => RenderModel(Texture);
public void RenderModel(Image source)
{
Model.AddToModelView(ModelView);
ModelView.Texture = source as Bitmap;
}
}
}

View File

@@ -28,28 +28,24 @@
/// </summary>
private void InitializeComponent()
{
this.renderer3D1 = new PckStudio.ToolboxItems.Renderer3D();
this.renderer3D1 = new PckStudio.Rendering.Renderer3D();
this.SuspendLayout();
//
// renderer3D1
//
this.renderer3D1.BackColor = System.Drawing.Color.Gray;
this.renderer3D1.Dock = System.Windows.Forms.DockStyle.Fill;
this.renderer3D1.InDesignMode = true;
this.renderer3D1.Location = new System.Drawing.Point(0, 0);
this.renderer3D1.LookX = 0D;
this.renderer3D1.LookY = 0D;
this.renderer3D1.Model = PckStudio.ToolboxItems.Renderer3D.Models.Steve;
this.renderer3D1.Model = PckStudio.Rendering.Renderer3D.Models.Steve;
this.renderer3D1.Name = "renderer3D1";
this.renderer3D1.Paintable = true;
this.renderer3D1.RotationX = 0;
this.renderer3D1.RotationY = 0;
this.renderer3D1.Show2ndBody = true;
this.renderer3D1.Show2ndHead = true;
this.renderer3D1.Show2ndLeftArm = true;
this.renderer3D1.Show2ndLeftLeg = true;
this.renderer3D1.Show2ndRightArm = true;
this.renderer3D1.Show2ndRightLeg = true;
this.renderer3D1.ShowBodyOverlay = true;
this.renderer3D1.ShowHeadOverlay = true;
this.renderer3D1.ShowLeftArmOverlay = true;
this.renderer3D1.ShowLeftLegOverlay = true;
this.renderer3D1.ShowRightArmOverlay = true;
this.renderer3D1.ShowRightLegOverlay = true;
this.renderer3D1.ShowBody = true;
this.renderer3D1.ShowHead = true;
this.renderer3D1.ShowLeftArm = true;
@@ -57,7 +53,7 @@
this.renderer3D1.ShowRightArm = true;
this.renderer3D1.ShowRightLeg = true;
this.renderer3D1.Size = new System.Drawing.Size(426, 428);
this.renderer3D1.Skin = global::PckStudio.Properties.Resources.steve;
this.renderer3D1.Texture = global::PckStudio.Properties.Resources.classic_template;
this.renderer3D1.TabIndex = 8;
this.renderer3D1.Zoom = 1D;
//
@@ -76,6 +72,6 @@
#endregion
private ToolboxItems.Renderer3D renderer3D1;
private PckStudio.Rendering.Renderer3D renderer3D1;
}
}

View File

@@ -1,5 +1,4 @@
using PckStudio.ToolboxItems;
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@@ -8,8 +7,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using PckStudio.ToolboxItems;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using PckStudio.Properties;
namespace PckStudio.Forms
{
@@ -20,7 +18,7 @@ namespace PckStudio.Forms
InitializeComponent();
}
internal Bitmap Skin = Properties.Resources.steve;
internal Bitmap Skin = Resources.classic_template;
internal void UpdateImage()
{
var Image = new Bitmap(Skin.Width, Skin.Height); // Create the skin preview bitmao
@@ -36,12 +34,11 @@ namespace PckStudio.Forms
Image.SetPixel(X, Y, Skin.GetPixel(X / 2, Y / 2));
}
// *************************************************************
renderer3D1.Skin = Skin;
renderer3D1.Texture = Skin;
renderer3D1.Refresh(); // Render
}
private void TestGL_Load(object sender, EventArgs e)
{
renderer3D1.InDesignMode = false;
UpdateImage(); // Load preview
}
}

View File

@@ -2270,7 +2270,7 @@ namespace PckStudio
private void skinRenderer3DToolStripMenuItem_Click(object sender, EventArgs e)
{
TestGL gl = new TestGL();
var gl = new TestGL();
gl.Show();
}
}

View File

@@ -133,7 +133,7 @@
<Reference Include="WindowsFormsIntegration" />
</ItemGroup>
<ItemGroup>
<Compile Include="Classes\Utils\MouseRay.cs" />
<Compile Include="Classes\Utils\Ray.cs" />
<Compile Include="Extensions\PckFileDataExtensions.cs" />
<Compile Include="Extensions\TreeNodeExtensions.cs" />
<Compile Include="Forms\TestGL.cs">
@@ -146,16 +146,21 @@
<Compile Include="Internal\AnimationCategory.cs" />
<Compile Include="Internal\SkinAnimFlag.cs" />
<Compile Include="Internal\SkinAnimMask.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="ToolboxItems\BlendPictureBox.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="ToolboxItems\InterpolationPictureBox.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="ToolboxItems\Renderer3D.cs">
<Compile Include="Rendering\Renderer3D.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="ToolboxItems\Renderer3D.Designer.cs">
<Compile Include="Rendering\Renderer3D.Designer.cs">
<DependentUpon>Renderer3D.cs</DependentUpon>
</Compile>
<Compile Include="ToolboxItems\ToolStripRadioButtonMenuItem.cs">
@@ -207,7 +212,6 @@
<Compile Include="Classes\Misc\FTPClient.cs" />
<Compile Include="Classes\Misc\FileCacher.cs" />
<Compile Include="Classes\Misc\OpenFolderDialog.cs" />
<Compile Include="Classes\Models\DefaultModels\Steve64x64Model.cs" />
<Compile Include="Internal\ApplicationScope.cs" />
<Compile Include="Internal\Json\ColorEntry.cs" />
<Compile Include="Internal\Json\TileInfo.cs" />
@@ -217,28 +221,6 @@
<Compile Include="Internal\SkinBOX.cs" />
<Compile Include="Extensions\ImageExtensions.cs" />
<Compile Include="Internal\SkinANIM.cs" />
<Compile Include="Classes\Models\DefaultModels\Steve64x32Model.cs" />
<Compile Include="Classes\Models\DefaultModels\ModelBase.cs" />
<Compile Include="Classes\Models\Backgrounds.cs" />
<Compile Include="Classes\Models\BackgroundTypes.cs" />
<Compile Include="Classes\Models\Box.cs" />
<Compile Include="Classes\Models\Effects.cs" />
<Compile Include="Classes\Models\Matrix3D.cs" />
<Compile Include="Classes\Models\ModelView.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Classes\Models\ModelView.Designer.cs">
<DependentUpon>ModelView.cs</DependentUpon>
</Compile>
<Compile Include="Classes\Models\Object3D.cs" />
<Compile Include="Classes\Models\Object3DGroup.cs" />
<Compile Include="Classes\Models\Point3D.cs" />
<Compile Include="Classes\Models\Positions.cs" />
<Compile Include="Classes\Models\ProjectionTypes.cs" />
<Compile Include="Classes\Models\RotationOrders.cs" />
<Compile Include="Classes\Models\Texel.cs" />
<Compile Include="Classes\Models\TexelComparer.cs" />
<Compile Include="Classes\Models\TexturePlane.cs" />
<Compile Include="Classes\Networking\Network.cs" />
<Compile Include="Classes\Misc\RichPresenceClient.cs" />
<Compile Include="Classes\Networking\Update.cs" />
@@ -629,11 +611,6 @@
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>

View File

@@ -3,12 +3,10 @@ using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
namespace PckStudio.ToolboxItems
namespace PckStudio.Rendering
{
public partial class Renderer3D : UserControl
public partial class Renderer3D
{
// UserControl overrides dispose to clean up the component list.
[DebuggerNonUserCode()]
protected override void Dispose(bool disposing)
{
@@ -35,50 +33,46 @@ namespace PckStudio.ToolboxItems
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
GlControl = new OpenTK.GLControl();
GlControl.Paint += new PaintEventHandler(GlControl_Paint);
GlControl.MouseDown += new MouseEventHandler(GlControl_MouseDown);
GlControl.MouseUp += new MouseEventHandler(GlControl_MouseUp);
timMove = new Timer(components);
timMove.Tick += new EventHandler(Move_Tick);
timPaint = new Timer(components);
timPaint.Tick += new EventHandler(Paint_Tick);
SuspendLayout();
//
// GlControl
//
GlControl.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
GlControl.BackColor = Color.Black;
GlControl.Location = new Point(0, 0);
GlControl.Name = "GlControl";
GlControl.Size = new Size(150, 150);
GlControl.TabIndex = 0;
GlControl.VSync = true;
//
// timMove
//
timMove.Enabled = true;
timMove.Interval = 20;
#if DEBUG
//
// timPaint
// debugLabel
//
timPaint.Enabled = true;
timPaint.Interval = 1;
debugLabel = new System.Windows.Forms.Label();
debugLabel.Enabled = true;
debugLabel.Visible = true;
debugLabel.AutoSize = true;
debugLabel.Location = new Point(0, 0);
debugLabel.BackColor = Color.Transparent;
Controls.Add(debugLabel);
#endif
//
// Renderer3D
//
Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
BackColor = Color.Transparent;
Location = new Point(0, 0);
Size = new Size(150, 150);
TabIndex = 0;
VSync = true;
AutoScaleDimensions = new SizeF(6.0f, 13.0f);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(GlControl);
Name = "Renderer3D";
MouseWheel += new MouseEventHandler(Renderer3D_MouseWheel);
ResumeLayout(false);
}
internal OpenTK.GLControl GlControl;
internal Timer timMove;
internal Timer timPaint;
private Timer timMove;
#if DEBUG
private System.Windows.Forms.Label debugLabel;
#endif
}
}