mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-23 04:53:09 +00:00
8939687f6a
Load vertex positions for layouts in rectangle class. This will be used for proper rotation adjusting. Add latest muunt editor files. Add somewhat functional mk8 camera bin editor. Points can be moved around. The map orientation determines the position of the icons to map over the model. Fix window content UV map for layouts. Add 2D KCL renderer for top down KCL preview for both muunt and camera editors.
55 lines
1.7 KiB
C#
55 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using OpenTK;
|
|
using OpenTK.Graphics.OpenGL;
|
|
using System.Drawing;
|
|
|
|
namespace Toolbox.Library
|
|
{
|
|
public class OpenGLHelper
|
|
{
|
|
public static Point convertScreenToWorldCoords(int x, int y)
|
|
{
|
|
int[] viewport = new int[4];
|
|
Matrix4 modelViewMatrix, projectionMatrix;
|
|
GL.GetFloat(GetPName.ModelviewMatrix, out modelViewMatrix);
|
|
GL.GetFloat(GetPName.ProjectionMatrix, out projectionMatrix);
|
|
GL.GetInteger(GetPName.Viewport, viewport);
|
|
Vector2 mouse;
|
|
mouse.X = x;
|
|
mouse.Y = y;
|
|
Vector4 vector = UnProject(ref projectionMatrix, modelViewMatrix, new Size(viewport[2], viewport[3]), mouse);
|
|
Point coords = new Point((int)vector.X, (int)vector.Y);
|
|
|
|
return coords;
|
|
}
|
|
|
|
public static Vector4 UnProject(ref Matrix4 projection, Matrix4 view, Size viewport, Vector2 mouse)
|
|
{
|
|
Vector4 vec;
|
|
|
|
vec.X = (2.0f * mouse.X / (float)viewport.Width - 1);
|
|
vec.Y = -(2.0f * mouse.Y / (float)viewport.Height - 1);
|
|
vec.Z = 0;
|
|
vec.W = 1.0f;
|
|
|
|
Matrix4 viewInv = Matrix4.Invert(view);
|
|
Matrix4 projInv = Matrix4.Invert(projection);
|
|
|
|
Vector4.Transform(ref vec, ref projInv, out vec);
|
|
Vector4.Transform(ref vec, ref viewInv, out vec);
|
|
|
|
if (vec.W > float.Epsilon || vec.W < float.Epsilon)
|
|
{
|
|
vec.X /= vec.W;
|
|
vec.Y /= vec.W;
|
|
vec.Z /= vec.W;
|
|
}
|
|
|
|
return vec;
|
|
}
|
|
}
|
|
}
|