Try to fix some errors
This commit is contained in:
parent
a62f1b8a07
commit
8300b0658f
@ -163,6 +163,34 @@ namespace LayoutBXLYT
|
||||
}
|
||||
}
|
||||
|
||||
public void ApplyNewParentTransform()
|
||||
{
|
||||
//Get the new transform and apply it
|
||||
var transform = GetParentTransform();
|
||||
// Translate += transform;
|
||||
}
|
||||
|
||||
public void ResetParentTransform(BasePane newParent)
|
||||
{
|
||||
//We need to get the difference in the parent transform and remove it to the current transform of this pane
|
||||
var transform = GetParentTransform();
|
||||
var newParentTransform = newParent.GetParentTransform();
|
||||
Translate -= transform;
|
||||
Translate += newParentTransform;
|
||||
}
|
||||
|
||||
private Vector3F GetParentTransform() {
|
||||
return GetParentTransform(Vector3F.Zero);
|
||||
}
|
||||
|
||||
private Vector3F GetParentTransform(Vector3F translate)
|
||||
{
|
||||
if (Parent != null)
|
||||
return translate += Parent.GetParentTransform(translate);
|
||||
else
|
||||
return translate;
|
||||
}
|
||||
|
||||
public void KeepChildrenTransform(float newTransX, float newTransY)
|
||||
{
|
||||
Vector2F distance = new Vector2F(newTransX - Translate.X, newTransY - Translate.Y);
|
||||
|
@ -410,7 +410,9 @@ namespace LayoutBXLYT
|
||||
var upperParentNode = targetNode.Parent;
|
||||
var upperParentPane = upperParentNode.Tag as BasePane;
|
||||
|
||||
draggedPane.ResetParentTransform(upperParentPane);
|
||||
draggedPane.Parent = upperParentPane;
|
||||
|
||||
upperParentPane.Childern.Add(draggedPane);
|
||||
|
||||
upperParentNode.Nodes.Add(draggedNode);
|
||||
@ -419,12 +421,16 @@ namespace LayoutBXLYT
|
||||
else //Set the target node as the parent
|
||||
{
|
||||
var parentPane = targetNode.Tag as BasePane;
|
||||
draggedPane.ResetParentTransform(parentPane);
|
||||
draggedPane.Parent = parentPane;
|
||||
|
||||
parentPane.Childern.Add(draggedPane);
|
||||
|
||||
targetNode.Nodes.Add(draggedNode);
|
||||
targetNode.Expand();
|
||||
}
|
||||
|
||||
ParentEditor.UpdateViewport();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
53
Switch_Toolbox_Library/OpenGL/OpenGLHelper.cs
Normal file
53
Switch_Toolbox_Library/OpenGL/OpenGLHelper.cs
Normal file
@ -0,0 +1,53 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
uniform vec2 uvScale0;
|
||||
uniform vec2 uvRotate0;
|
||||
uniform float uvRotate0;
|
||||
uniform vec2 uvTranslate0;
|
||||
uniform int flipTexture;
|
||||
uniform mat4 rotationMatrix;
|
||||
@ -53,7 +53,10 @@ void main()
|
||||
gl_FrontColor = gl_Color;
|
||||
vec2 texCoord0 = vec2(0.5, 0.5) + uvScale0 * (gl_MultiTexCoord0.xy + (uvTranslate0 / uvScale0 - 0.5));
|
||||
texCoord0 = SetTexCoordType(texCoords0GenType, texCoord0);
|
||||
texCoord0 = rotateUV(texCoord0, radians(-uvRotate0));
|
||||
|
||||
gl_TexCoord[0].st = SetFlip(texCoord0);
|
||||
|
||||
|
||||
gl_Position = gl_ModelViewProjectionMatrix * rotationMatrix * gl_Vertex;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user