mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-06-17 10:31:53 +00:00
[WIP] Added Vertex struct for better data management, Updated shaders and renderer
This commit is contained in:
@@ -19,495 +19,32 @@ namespace PckStudio.Classes.Utils
|
||||
|
||||
public Point Pos { get; set; }
|
||||
|
||||
// TODO: remove Renderer3D from Ray
|
||||
public Renderer3D Renderer { get; set; }
|
||||
|
||||
public struct RayResult
|
||||
{
|
||||
public float Distance { get; set; }
|
||||
|
||||
public enum Is
|
||||
public enum eAxis
|
||||
{
|
||||
X,
|
||||
Y,
|
||||
Z
|
||||
}
|
||||
|
||||
public Is IsWhat { get; set; }
|
||||
public eAxis Axis { get; set; }
|
||||
|
||||
public RayResult(float Distance, Is IsWhat)
|
||||
public RayResult(float distance, eAxis axis)
|
||||
{
|
||||
this.Distance = Distance;
|
||||
this.IsWhat = IsWhat;
|
||||
Distance = distance;
|
||||
Axis = axis;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3 MouseHit
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
Update(Pos.X, Pos.Y);
|
||||
var HeadIndex = new float[2];
|
||||
var BodyIndex = new float[2];
|
||||
HeadIndex[0] = (4f - CamPos.Z) / CurrentRay.Z;
|
||||
BodyIndex[0] = (2f - CamPos.Z) / CurrentRay.Z;
|
||||
HeadIndex[1] = (-4 - CamPos.Z) / CurrentRay.Z;
|
||||
BodyIndex[1] = (-2 - CamPos.Z) / CurrentRay.Z;
|
||||
|
||||
var HeadXIndex = new float[2];
|
||||
var BodyXIndex = new float[4];
|
||||
var LegXIndex = new float[3];
|
||||
HeadXIndex[0] = (4f - CamPos.X) / CurrentRay.X;
|
||||
if (Renderer.Model == Renderer3D.Models.Steve)
|
||||
{
|
||||
BodyXIndex[0] = (8f - CamPos.X) / CurrentRay.X;
|
||||
BodyXIndex[1] = (-8 - CamPos.X) / CurrentRay.X;
|
||||
}
|
||||
else
|
||||
{
|
||||
BodyXIndex[0] = (7f - CamPos.X) / CurrentRay.X;
|
||||
BodyXIndex[1] = (-7 - CamPos.X) / CurrentRay.X;
|
||||
}
|
||||
HeadXIndex[1] = (-4 - CamPos.X) / CurrentRay.X;
|
||||
BodyXIndex[2] = (-4 - CamPos.X) / CurrentRay.X;
|
||||
BodyXIndex[3] = (4f - CamPos.X) / CurrentRay.X;
|
||||
LegXIndex[0] = (4f - CamPos.X) / CurrentRay.X;
|
||||
LegXIndex[1] = (-4 - CamPos.X) / CurrentRay.X;
|
||||
LegXIndex[2] = -CamPos.X / CurrentRay.X;
|
||||
|
||||
var HeadYIndex = new float[2];
|
||||
var BodyYIndex = new float[2];
|
||||
var LegYIndex = new float[2];
|
||||
HeadYIndex[0] = (16f - CamPos.Y) / CurrentRay.Y;
|
||||
BodyYIndex[0] = (8f - CamPos.Y) / CurrentRay.Y;
|
||||
HeadYIndex[1] = (8f - CamPos.Y) / CurrentRay.Y;
|
||||
BodyYIndex[1] = (-4 - CamPos.Y) / CurrentRay.Y;
|
||||
LegYIndex[0] = (-4 - CamPos.Y) / CurrentRay.Y;
|
||||
LegYIndex[1] = (-16 - CamPos.Y) / CurrentRay.Y;
|
||||
|
||||
var PointsDis = new List<RayResult>();
|
||||
|
||||
Vector3 HeadPoint, BodyPoint, HeadXPoint, BodyXPoint, LegXPoint, HeadYPoint, BodyYPoint, LegYPoint;
|
||||
|
||||
for (byte I = 0; I <= 3; I++)
|
||||
{
|
||||
|
||||
if (!(I > 1))
|
||||
{
|
||||
HeadPoint = GetPointOnRay(CurrentRay, HeadIndex[I]);
|
||||
}
|
||||
else
|
||||
{
|
||||
HeadPoint = new Vector3(20f, 20f, 20f);
|
||||
}
|
||||
if (!(I > 1))
|
||||
{
|
||||
BodyPoint = GetPointOnRay(CurrentRay, BodyIndex[I]);
|
||||
}
|
||||
else
|
||||
{
|
||||
BodyPoint = new Vector3(20f, 20f, 20f);
|
||||
}
|
||||
|
||||
if (!(I > 1))
|
||||
{
|
||||
HeadXPoint = GetPointOnRay(CurrentRay, HeadXIndex[I]);
|
||||
}
|
||||
else
|
||||
{
|
||||
HeadXPoint = new Vector3(20f, 20f, 20f);
|
||||
}
|
||||
BodyXPoint = GetPointOnRay(CurrentRay, BodyXIndex[I]);
|
||||
if (!(I > 2))
|
||||
{
|
||||
LegXPoint = GetPointOnRay(CurrentRay, LegXIndex[I]);
|
||||
}
|
||||
else
|
||||
{
|
||||
LegXPoint = new Vector3(20f, 20f, 20f);
|
||||
}
|
||||
|
||||
if (!(I > 1))
|
||||
{
|
||||
HeadYPoint = GetPointOnRay(CurrentRay, HeadYIndex[I]);
|
||||
}
|
||||
else
|
||||
{
|
||||
HeadYPoint = new Vector3(20f, 20f, 20f);
|
||||
}
|
||||
if (!(I > 1))
|
||||
{
|
||||
BodyYPoint = GetPointOnRay(CurrentRay, BodyYIndex[I]);
|
||||
}
|
||||
else
|
||||
{
|
||||
BodyYPoint = new Vector3(20f, 20f, 20f);
|
||||
}
|
||||
if (!(I > 1))
|
||||
{
|
||||
LegYPoint = GetPointOnRay(CurrentRay, LegYIndex[I]);
|
||||
}
|
||||
else
|
||||
{
|
||||
LegYPoint = new Vector3(20f, 20f, 20f);
|
||||
}
|
||||
|
||||
if (Renderer.ShowHead && HeadPoint.X < 4f && HeadPoint.X > -4 && HeadPoint.Y < 16f && HeadPoint.Y > 8f)
|
||||
{
|
||||
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 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 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 RayResult(BodyIndex[I], RayResult.Is.Z));
|
||||
}
|
||||
}
|
||||
if (Renderer.ShowRightLeg && BodyPoint.X < 0f && BodyPoint.X > -4 && BodyPoint.Y < -4 && BodyPoint.Y > -16)
|
||||
{
|
||||
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 RayResult(BodyIndex[I], RayResult.Is.Z));
|
||||
}
|
||||
if (Renderer.ShowHead && HeadXPoint.Z < 4f && HeadXPoint.Z > -4 && HeadXPoint.Y < 16f && HeadXPoint.Y > 8f)
|
||||
{
|
||||
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 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 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 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 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 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 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 RayResult(LegXIndex[I], RayResult.Is.X));
|
||||
}
|
||||
if (Renderer.ShowHead && HeadYPoint.Z < 4f && HeadYPoint.Z > -4 && HeadYPoint.X < 4f && HeadYPoint.X > -4)
|
||||
{
|
||||
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 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 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 RayResult(BodyYIndex[I], RayResult.Is.Y));
|
||||
}
|
||||
}
|
||||
if (Renderer.ShowRightLeg && LegYPoint.Z < 2f && LegYPoint.Z > -2 && LegYPoint.X < 0f && LegYPoint.X > -4)
|
||||
{
|
||||
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 RayResult(LegYIndex[I], RayResult.Is.Y));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (PointsDis.Count == 0)
|
||||
return default;
|
||||
|
||||
var Smallest = new RayResult(1000f, RayResult.Is.X);
|
||||
|
||||
foreach (RayResult value in PointsDis)
|
||||
{
|
||||
if (value.Distance < Smallest.Distance)
|
||||
Smallest = value;
|
||||
}
|
||||
|
||||
var Result = GetPointOnRay(CurrentRay, Smallest.Distance);
|
||||
if (Smallest.IsWhat == RayResult.Is.X)
|
||||
{
|
||||
Result.X = (int)Math.Round(Result.X);
|
||||
}
|
||||
else if (Smallest.IsWhat == RayResult.Is.Y)
|
||||
{
|
||||
Result.Y = (int)Math.Round(Result.Y);
|
||||
}
|
||||
else if (Smallest.IsWhat == RayResult.Is.Z)
|
||||
{
|
||||
Result.Z = (int)Math.Round(Result.Z);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3 Mouse2ndHit
|
||||
{
|
||||
get
|
||||
{
|
||||
Update(Pos.X, Pos.Y);
|
||||
var HeadIndex = new float[2];
|
||||
var BodyIndex = new float[2];
|
||||
HeadIndex[0] = (float)((4.24d - CamPos.Z) / CurrentRay.Z);
|
||||
BodyIndex[0] = (float)((2.12d - CamPos.Z) / CurrentRay.Z);
|
||||
HeadIndex[1] = (float)((-4.24d - CamPos.Z) / CurrentRay.Z);
|
||||
BodyIndex[1] = (float)((-2.12d - CamPos.Z) / CurrentRay.Z);
|
||||
|
||||
var HeadXIndex = new float[2];
|
||||
var BodyXIndex = new float[2];
|
||||
var RArmXIndex = new float[2];
|
||||
var LArmXIndex = new float[2];
|
||||
var RLegXIndex = new float[2];
|
||||
var LLegXIndex = new float[2];
|
||||
HeadXIndex[0] = (float)((4.24d - CamPos.X) / CurrentRay.X);
|
||||
HeadXIndex[1] = (float)((-4.24d - CamPos.X) / CurrentRay.X);
|
||||
BodyXIndex[0] = (float)((-4.24d - CamPos.X) / CurrentRay.X);
|
||||
BodyXIndex[1] = (float)((4.24d - CamPos.X) / CurrentRay.X);
|
||||
if (Renderer.Model == Renderer3D.Models.Steve)
|
||||
{
|
||||
RArmXIndex[0] = (float)((-3.88d - CamPos.X) / CurrentRay.X);
|
||||
RArmXIndex[1] = (float)((-8.12d - CamPos.X) / CurrentRay.X);
|
||||
LArmXIndex[0] = (float)((3.88d - CamPos.X) / CurrentRay.X);
|
||||
LArmXIndex[1] = (float)((8.12d - CamPos.X) / CurrentRay.X);
|
||||
}
|
||||
else
|
||||
{
|
||||
RArmXIndex[0] = (float)((-3.91d - CamPos.X) / CurrentRay.X);
|
||||
RArmXIndex[1] = (float)((-7.09d - CamPos.X) / CurrentRay.X);
|
||||
LArmXIndex[0] = (float)((3.91d - CamPos.X) / CurrentRay.X);
|
||||
LArmXIndex[1] = (float)((7.09d - CamPos.X) / CurrentRay.X);
|
||||
}
|
||||
LLegXIndex[0] = (float)((4.24d - CamPos.X) / CurrentRay.X);
|
||||
RLegXIndex[0] = (float)((-4.24d - CamPos.X) / CurrentRay.X);
|
||||
RLegXIndex[1] = (float)((0.12d - CamPos.X) / CurrentRay.X);
|
||||
LLegXIndex[1] = (float)((-0.12d - CamPos.X) / CurrentRay.X);
|
||||
|
||||
var HeadYIndex = new float[2];
|
||||
var BodyYIndex = new float[2];
|
||||
var LegYIndex = new float[2];
|
||||
HeadYIndex[0] = (float)((16.24d - CamPos.Y) / CurrentRay.Y);
|
||||
BodyYIndex[0] = (float)((8.36d - CamPos.Y) / CurrentRay.Y);
|
||||
HeadYIndex[1] = (float)((7.76d - CamPos.Y) / CurrentRay.Y);
|
||||
BodyYIndex[1] = (float)((-4.36d - CamPos.Y) / CurrentRay.Y);
|
||||
LegYIndex[0] = (float)((-3.64d - CamPos.Y) / CurrentRay.Y);
|
||||
LegYIndex[1] = (float)((-16.36d - CamPos.Y) / CurrentRay.Y);
|
||||
|
||||
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]);
|
||||
|
||||
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]);
|
||||
|
||||
if (Renderer.ShowHeadOverlay && HeadPoint.X < 4.24d && HeadPoint.X > -4.24d && HeadPoint.Y < 16.24d && HeadPoint.Y > 7.76d)
|
||||
{
|
||||
PointsDis.Add(new RayResult(HeadIndex[I], RayResult.Is.Z));
|
||||
}
|
||||
if (Renderer.ShowBodyOverlay && BodyPoint.X < 4.24d && BodyPoint.X > -4.24d && BodyPoint.Y < 8.36d && BodyPoint.Y > -4.36d)
|
||||
{
|
||||
PointsDis.Add(new RayResult(BodyIndex[I], RayResult.Is.Z));
|
||||
}
|
||||
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 RayResult(BodyIndex[I], RayResult.Is.Z));
|
||||
}
|
||||
}
|
||||
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 RayResult(BodyIndex[I], RayResult.Is.Z));
|
||||
}
|
||||
}
|
||||
if (Renderer.ShowRightLegOverlay && BodyPoint.X < 0.12d && BodyPoint.X > -4.12d && BodyPoint.Y < -3.64d && BodyPoint.Y > -16.36d)
|
||||
{
|
||||
PointsDis.Add(new RayResult(BodyIndex[I], RayResult.Is.Z));
|
||||
}
|
||||
if (Renderer.ShowLeftLegOverlay && BodyPoint.X < 4.12d && BodyPoint.X > -0.12d && BodyPoint.Y < -3.64d && BodyPoint.Y > -16.36d)
|
||||
{
|
||||
PointsDis.Add(new RayResult(BodyIndex[I], RayResult.Is.Z));
|
||||
}
|
||||
if (Renderer.ShowHeadOverlay && HeadXPoint.Z < 4.24d && HeadXPoint.Z > -4.24d && HeadXPoint.Y < 16.24d && HeadXPoint.Y > 7.76d)
|
||||
{
|
||||
PointsDis.Add(new RayResult(HeadXIndex[I], RayResult.Is.X));
|
||||
}
|
||||
if (Renderer.ShowBodyOverlay && BodyXPoint.Z < 2.12d && BodyXPoint.Z > -2.12d && BodyXPoint.Y < 8.36d && BodyXPoint.Y > -4.36d)
|
||||
{
|
||||
PointsDis.Add(new RayResult(BodyXIndex[I], RayResult.Is.X));
|
||||
}
|
||||
if (Renderer.ShowRightArmOverlay && RArmXPoint.Z < 2.12d && RArmXPoint.Z > -2.12d && RArmXPoint.Y < 8.36d && RArmXPoint.Y > -4.36d)
|
||||
{
|
||||
PointsDis.Add(new RayResult(RArmXIndex[I], RayResult.Is.X));
|
||||
}
|
||||
if (Renderer.ShowLeftArmOverlay && LArmXPoint.Z < 2.12d && LArmXPoint.Z > -2.12d && LArmXPoint.Y < 8.36d && LArmXPoint.Y > -4.36d)
|
||||
{
|
||||
PointsDis.Add(new RayResult(LArmXIndex[I], RayResult.Is.X));
|
||||
}
|
||||
if (Renderer.ShowRightLegOverlay && RLegXPoint.Z < 2.12d && RLegXPoint.Z > -2.12d && RLegXPoint.Y < -3.64d && RLegXPoint.Y > -16.36d)
|
||||
{
|
||||
PointsDis.Add(new RayResult(RLegXIndex[I], RayResult.Is.X));
|
||||
}
|
||||
if (Renderer.ShowLeftLegOverlay && LLegXPoint.Z < 2.12d && LLegXPoint.Z > -2.12d && LLegXPoint.Y < -3.64d && LLegXPoint.Y > -16.36d)
|
||||
{
|
||||
PointsDis.Add(new RayResult(LLegXIndex[I], RayResult.Is.X));
|
||||
}
|
||||
if (Renderer.ShowHeadOverlay && HeadYPoint.Z < 4.24d && HeadYPoint.Z > -4.24d && HeadYPoint.X < 4.24d && HeadYPoint.X > -4.24d)
|
||||
{
|
||||
PointsDis.Add(new RayResult(HeadYIndex[I], RayResult.Is.Y));
|
||||
}
|
||||
if (Renderer.ShowBodyOverlay && BodyYPoint.Z < 2.12d && BodyYPoint.Z > -2.12d && BodyYPoint.X < 4.24d && BodyYPoint.X > -4.24d)
|
||||
{
|
||||
PointsDis.Add(new RayResult(BodyYIndex[I], RayResult.Is.Y));
|
||||
}
|
||||
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 RayResult(BodyYIndex[I], RayResult.Is.Y));
|
||||
}
|
||||
}
|
||||
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 RayResult(BodyYIndex[I], RayResult.Is.Y));
|
||||
}
|
||||
}
|
||||
if (Renderer.ShowRightLegOverlay && LegYPoint.Z < 2.12d && LegYPoint.Z > -2.12d && LegYPoint.X < 0.12d && LegYPoint.X > -4.12d)
|
||||
{
|
||||
PointsDis.Add(new RayResult(LegYIndex[I], RayResult.Is.Y));
|
||||
}
|
||||
if (Renderer.ShowLeftLegOverlay && LegYPoint.Z < 2.12d && LegYPoint.Z > -2.12d && LegYPoint.X < 4.12d && LegYPoint.X > -0.12d)
|
||||
{
|
||||
PointsDis.Add(new RayResult(LegYIndex[I], RayResult.Is.Y));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (PointsDis.Count == 0)
|
||||
return new Vector3(100f, 100f, 100f);
|
||||
|
||||
var Smallest = new RayResult(1000f, RayResult.Is.Z);
|
||||
|
||||
foreach (RayResult value in PointsDis)
|
||||
{
|
||||
if (value.Distance < Smallest.Distance)
|
||||
Smallest = value;
|
||||
}
|
||||
|
||||
var Result = GetPointOnRay(CurrentRay, Smallest.Distance);
|
||||
|
||||
float[] ZIndex = new[] { 4.24f, 2.12f, (float)-4.24d, (float)-2.12d };
|
||||
float[] XIndex;
|
||||
if (Renderer.Model == Renderer3D.Models.Steve)
|
||||
{
|
||||
XIndex = new[] { 4.24f, 8.12f, (float)-4.24d, (float)-8.12d, (float)-3.88d, 3.88f, 0.12f, (float)-0.12d };
|
||||
}
|
||||
else
|
||||
{
|
||||
XIndex = new[] { 4.24f, 7.09f, (float)-4.24d, (float)-7.09d, (float)-3.91d, 3.91f, 0.12f, (float)-0.12d };
|
||||
}
|
||||
float[] YIndex = new[] { 16.24f, 8.36f, 7.76f, (float)-4.36d, (float)-3.64d, (float)-16.36d };
|
||||
|
||||
float AResult = 20f;
|
||||
|
||||
if (Smallest.IsWhat == RayResult.Is.X)
|
||||
{
|
||||
foreach (float value in XIndex)
|
||||
{
|
||||
if (Math.Abs(value - Result.X) < Math.Abs(AResult - Result.X))
|
||||
{
|
||||
AResult = value;
|
||||
}
|
||||
}
|
||||
Result.X = AResult;
|
||||
}
|
||||
else if (Smallest.IsWhat == RayResult.Is.Y)
|
||||
{
|
||||
foreach (float value in YIndex)
|
||||
{
|
||||
if (Math.Abs(value - Result.Y) < Math.Abs(AResult - Result.Y))
|
||||
{
|
||||
AResult = value;
|
||||
}
|
||||
}
|
||||
Result.Y = AResult;
|
||||
}
|
||||
else if (Smallest.IsWhat == RayResult.Is.Z)
|
||||
{
|
||||
foreach (float value in ZIndex)
|
||||
{
|
||||
if (Math.Abs(value - Result.Z) < Math.Abs(AResult - Result.Z))
|
||||
{
|
||||
AResult = value;
|
||||
}
|
||||
}
|
||||
Result.Z = AResult;
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
}
|
||||
|
||||
public Ray(ref Matrix4 viewMatrix, ref Matrix4 projectionMatrix, Size size, Vector3 cameraPosition, Renderer3D renderer)
|
||||
public Ray(ref Matrix4 viewMatrix, ref Matrix4 projectionMatrix, Size size, Vector3 cameraPosition)
|
||||
{
|
||||
ProjectionMatrix = projectionMatrix;
|
||||
ViewMatrix = viewMatrix;
|
||||
Size = size;
|
||||
CamPos = cameraPosition;
|
||||
Renderer = renderer;
|
||||
}
|
||||
|
||||
private void Update(int X, int Y)
|
||||
@@ -542,15 +79,17 @@ namespace PckStudio.Classes.Utils
|
||||
|
||||
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);
|
||||
return new Vector2()
|
||||
{
|
||||
X = 2.0f * x / Size.Width - 1.0f,
|
||||
Y = -(2.0f * y / Size.Height - 1.0f)
|
||||
};
|
||||
}
|
||||
|
||||
private Vector3 GetPointOnRay(Vector3 ray, float distance)
|
||||
{
|
||||
var start = new Vector3(CamPos);
|
||||
var scaledRay = new Vector3(ray.X * distance, ray.Y * distance, ray.Z * distance);
|
||||
var scaledRay = ray * distance;
|
||||
return start + scaledRay;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,20 +16,20 @@ namespace PckStudio.Forms
|
||||
Texture = texture;
|
||||
ModelView.Model = anim.GetFlag(SkinAnimFlag.SLIM_MODEL) ? Renderer3D.Models.Alex : Renderer3D.Models.Steve;
|
||||
|
||||
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.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.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);
|
||||
//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);
|
||||
|
||||
@@ -547,18 +547,6 @@
|
||||
this.renderer3D1.Model = PckStudio.Rendering.Renderer3D.Models.Steve;
|
||||
this.renderer3D1.Name = "renderer3D1";
|
||||
this.renderer3D1.Rotation = ((OpenTK.Vector2)(resources.GetObject("renderer3D1.Rotation")));
|
||||
this.renderer3D1.ShowBody = true;
|
||||
this.renderer3D1.ShowBodyOverlay = true;
|
||||
this.renderer3D1.ShowHead = true;
|
||||
this.renderer3D1.ShowHeadOverlay = true;
|
||||
this.renderer3D1.ShowLeftArm = true;
|
||||
this.renderer3D1.ShowLeftArmOverlay = true;
|
||||
this.renderer3D1.ShowLeftLeg = true;
|
||||
this.renderer3D1.ShowLeftLegOverlay = true;
|
||||
this.renderer3D1.ShowRightArm = true;
|
||||
this.renderer3D1.ShowRightArmOverlay = true;
|
||||
this.renderer3D1.ShowRightLeg = true;
|
||||
this.renderer3D1.ShowRightLegOverlay = true;
|
||||
this.renderer3D1.Texture = null;
|
||||
this.renderer3D1.VSync = true;
|
||||
this.renderer3D1.FieldOfView = 1D;
|
||||
|
||||
12
PCK-Studio/Forms/TestGL.Designer.cs
generated
12
PCK-Studio/Forms/TestGL.Designer.cs
generated
@@ -38,18 +38,6 @@
|
||||
this.renderer3D1.Location = new System.Drawing.Point(0, 0);
|
||||
this.renderer3D1.Model = PckStudio.Rendering.Renderer3D.Models.Steve;
|
||||
this.renderer3D1.Name = "renderer3D1";
|
||||
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;
|
||||
this.renderer3D1.ShowLeftLeg = true;
|
||||
this.renderer3D1.ShowRightArm = true;
|
||||
this.renderer3D1.ShowRightLeg = true;
|
||||
this.renderer3D1.Size = new System.Drawing.Size(426, 428);
|
||||
this.renderer3D1.Texture = global::PckStudio.Properties.Resources.classic_template;
|
||||
this.renderer3D1.TabIndex = 8;
|
||||
|
||||
@@ -156,6 +156,7 @@
|
||||
<Compile Include="Rendering\Renderer.cs" />
|
||||
<Compile Include="Rendering\Shader.cs" />
|
||||
<Compile Include="Rendering\Texture2D.cs" />
|
||||
<Compile Include="Rendering\Vertex.cs" />
|
||||
<Compile Include="Rendering\VertexArray.cs" />
|
||||
<Compile Include="Rendering\VertexBuffer.cs" />
|
||||
<Compile Include="Rendering\VertexBufferLayout.cs" />
|
||||
|
||||
@@ -9,19 +9,12 @@ namespace PckStudio.Rendering
|
||||
{
|
||||
internal static class Renderer
|
||||
{
|
||||
public static void Draw(VertexArray va, IndexBuffer ib, Shader shader)
|
||||
public static void Draw(Shader shader, VertexArray va, IndexBuffer ib, PrimitiveType type)
|
||||
{
|
||||
shader.Bind();
|
||||
va.Bind();
|
||||
ib.Bind();
|
||||
GL.DrawElements(PrimitiveType.Triangles, ib.GetCount(), DrawElementsType.UnsignedInt, 0);
|
||||
}
|
||||
|
||||
public static void Draw(VertexArray va, Shader shader)
|
||||
{
|
||||
shader.Bind();
|
||||
va.Bind();
|
||||
GL.DrawArrays(PrimitiveType.Triangles, 0, 6);
|
||||
GL.DrawElements(type, ib.GetCount(), DrawElementsType.UnsignedInt, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
27
PCK-Studio/Rendering/Vertex.cs
Normal file
27
PCK-Studio/Rendering/Vertex.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace PckStudio.Rendering
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 4)]
|
||||
internal struct Vertex
|
||||
{
|
||||
public Vertex(Vector3 position, Color4 color, Vector2 texPosition)
|
||||
{
|
||||
Position = position;
|
||||
Color = color;
|
||||
TexPosition = texPosition;
|
||||
}
|
||||
|
||||
internal Vector3 Position { get; set; }
|
||||
internal Color4 Color { get; set; }
|
||||
internal Vector2 TexPosition { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ namespace PckStudio.Rendering
|
||||
var element = elements[i];
|
||||
GL.EnableVertexAttribArray(i);
|
||||
GL.VertexAttribPointer(i, element.Count, element.Type, element.Normalize, layout.GetStride(), offset);
|
||||
offset += layout.GetStride();
|
||||
offset += element.Count * VertexBufferElement.GetStrideSize(element.Type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,15 +10,22 @@ using OpenTK.Graphics.OpenGL;
|
||||
|
||||
namespace PckStudio.Rendering
|
||||
{
|
||||
internal class VertexBuffer<T> : IDisposable where T : struct
|
||||
internal struct VertexBuffer<T> : IDisposable where T : struct
|
||||
{
|
||||
private int _id;
|
||||
|
||||
#if DEBUG
|
||||
private T[] __data;
|
||||
#endif
|
||||
|
||||
public VertexBuffer(T[] data, int size)
|
||||
{
|
||||
_id = GL.GenBuffer();
|
||||
Bind();
|
||||
GL.BufferData(BufferTarget.ArrayBuffer, size, data, BufferUsageHint.StaticDraw);
|
||||
#if DEBUG
|
||||
__data = data;
|
||||
#endif
|
||||
}
|
||||
|
||||
public void Bind()
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace PckStudio.Rendering
|
||||
}
|
||||
}
|
||||
|
||||
internal class VertexBufferLayout
|
||||
internal struct VertexBufferLayout
|
||||
{
|
||||
private List<VertexBufferElement> elements;
|
||||
private int stride;
|
||||
|
||||
@@ -2,14 +2,18 @@
|
||||
|
||||
layout(location = 0) out vec4 color;
|
||||
|
||||
uniform vec4 u_Color;
|
||||
uniform sampler2D u_Texture;
|
||||
|
||||
in vec2 v_TexCoord;
|
||||
in vec4 v_VertexPos;
|
||||
in vec4 v_Color;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 texColor = texture(u_Texture, v_TexCoord);
|
||||
color = u_Color;
|
||||
// color = vec4(v_VertexPos.xyz, 1.0);
|
||||
// color = vec4(v_TexCoord, 0.0, 1.0) * vec4(v_VertexPos.xyz, 1.0);
|
||||
// color = v_Color;
|
||||
// color = vec4(v_TexCoord, 0.0, 1.0);
|
||||
color = texColor;
|
||||
};
|
||||
@@ -1,14 +1,19 @@
|
||||
#version 330 core
|
||||
|
||||
layout(location = 0) in vec4 vertexPosition;
|
||||
layout(location = 1) in vec2 texCoord;
|
||||
layout(location = 1) in vec4 color;
|
||||
layout(location = 2) in vec2 texCoord;
|
||||
|
||||
uniform mat4 u_MVP;
|
||||
|
||||
out vec2 v_TexCoord;
|
||||
out vec4 v_VertexPos;
|
||||
out vec4 v_Color;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = u_MVP * vertexPosition;
|
||||
v_TexCoord = texCoord;
|
||||
v_Color = color;
|
||||
v_VertexPos = vertexPosition;
|
||||
gl_Position = u_MVP * vertexPosition;
|
||||
};
|
||||
Reference in New Issue
Block a user