mirror of
https://github.com/Leonmmcoset/CMLeonOS.git
synced 2026-04-21 10:53:59 +00:00
OSGraphicDraw
This commit is contained in:
38
OSGraphicDraw/Renderer3D.cs
Normal file
38
OSGraphicDraw/Renderer3D.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using CMLeonOS.Gui;
|
||||
using System.Drawing;
|
||||
|
||||
namespace CMLeonOS.OSGraphicDraw
|
||||
{
|
||||
internal static class Renderer3D
|
||||
{
|
||||
internal static bool Project(Vec3 p, int width, int height, double fovScale, double cameraDistance, out int sx, out int sy)
|
||||
{
|
||||
double z = p.Z + cameraDistance;
|
||||
if (z <= 0.05d)
|
||||
{
|
||||
sx = 0;
|
||||
sy = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
double inv = fovScale / z;
|
||||
sx = (int)((p.X * inv) + (width / 2.0));
|
||||
sy = (int)((-p.Y * inv) + (height / 2.0));
|
||||
return true;
|
||||
}
|
||||
|
||||
internal static void DrawLine3D(Window target, Vec3 a, Vec3 b, Color color, double fovScale, double cameraDistance)
|
||||
{
|
||||
if (!Project(a, target.Width, target.Height, fovScale, cameraDistance, out int ax, out int ay))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!Project(b, target.Width, target.Height, fovScale, cameraDistance, out int bx, out int by))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
target.DrawLine(ax, ay, bx, by, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
39
OSGraphicDraw/Vec3.cs
Normal file
39
OSGraphicDraw/Vec3.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
|
||||
namespace CMLeonOS.OSGraphicDraw
|
||||
{
|
||||
internal struct Vec3
|
||||
{
|
||||
internal double X;
|
||||
internal double Y;
|
||||
internal double Z;
|
||||
|
||||
internal Vec3(double x, double y, double z)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
internal static Vec3 RotateX(Vec3 v, double radians)
|
||||
{
|
||||
double c = Math.Cos(radians);
|
||||
double s = Math.Sin(radians);
|
||||
return new Vec3(v.X, (v.Y * c) - (v.Z * s), (v.Y * s) + (v.Z * c));
|
||||
}
|
||||
|
||||
internal static Vec3 RotateY(Vec3 v, double radians)
|
||||
{
|
||||
double c = Math.Cos(radians);
|
||||
double s = Math.Sin(radians);
|
||||
return new Vec3((v.X * c) + (v.Z * s), v.Y, (-v.X * s) + (v.Z * c));
|
||||
}
|
||||
|
||||
internal static Vec3 RotateZ(Vec3 v, double radians)
|
||||
{
|
||||
double c = Math.Cos(radians);
|
||||
double s = Math.Sin(radians);
|
||||
return new Vec3((v.X * c) - (v.Y * s), (v.X * s) + (v.Y * c), v.Z);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user