Handle all rotations from matrix in shaders so they render accurate.
This commit is contained in:
parent
3be9e0c9de
commit
0da677980f
@ -71,6 +71,13 @@ namespace LayoutBXLYT
|
||||
}
|
||||
}
|
||||
|
||||
//For non material panes
|
||||
public void SetBasic(BasePane pane)
|
||||
{
|
||||
var rotationMatrix = pane.GetRotationMatrix();
|
||||
SetMatrix("rotationMatrix", ref rotationMatrix);
|
||||
}
|
||||
|
||||
public void SetVec4(string name, Vector4 value)
|
||||
{
|
||||
if (uniforms.ContainsKey(name))
|
||||
|
@ -47,26 +47,7 @@ namespace LayoutBXLYT
|
||||
|
||||
public void SetMaterials(BasePane pane, Dictionary<string, STGenericTexture> textures)
|
||||
{
|
||||
var paneRotate = pane.GetRotation();
|
||||
|
||||
Matrix4 rotationX = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(paneRotate.X));
|
||||
Matrix4 rotationY = Matrix4.CreateRotationY(MathHelper.DegreesToRadians(paneRotate.Y));
|
||||
Matrix4 rotationZ = Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(paneRotate.Z));
|
||||
var rotationMatrix = rotationX * rotationY * rotationZ;
|
||||
|
||||
//Get parent rotation if using material rotation transforms
|
||||
//If it's a null pane, it would rotate automatically with GL.Rotate
|
||||
if (pane.Parent is IPicturePane || pane.Parent is IWindowPane)
|
||||
{
|
||||
var parentRotate = pane.Parent.GetRotation();
|
||||
|
||||
Matrix4 parentRotationX = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(parentRotate.X));
|
||||
Matrix4 parentRotationY = Matrix4.CreateRotationY(MathHelper.DegreesToRadians(parentRotate.Y));
|
||||
Matrix4 parentRotationZ = Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(parentRotate.Z));
|
||||
var parentRotationMatrix = parentRotationX * parentRotationY * parentRotationZ;
|
||||
rotationMatrix = parentRotationMatrix * rotationMatrix;
|
||||
}
|
||||
|
||||
var rotationMatrix = pane.GetRotationMatrix();
|
||||
SetMatrix("rotationMatrix", ref rotationMatrix);
|
||||
|
||||
STColor8 WhiteColor = material.WhiteColor;
|
||||
|
@ -131,6 +131,19 @@ namespace LayoutBXLYT
|
||||
get { return Childern.Count > 0; }
|
||||
}
|
||||
|
||||
public OpenTK.Matrix4 GetRotationMatrix()
|
||||
{
|
||||
var paneRotate = GetRotation();
|
||||
OpenTK.Matrix4 rotationX = OpenTK.Matrix4.CreateRotationX(OpenTK.MathHelper.DegreesToRadians(paneRotate.X));
|
||||
OpenTK.Matrix4 rotationY = OpenTK.Matrix4.CreateRotationY(OpenTK.MathHelper.DegreesToRadians(paneRotate.Y));
|
||||
OpenTK.Matrix4 rotationZ = OpenTK.Matrix4.CreateRotationZ(OpenTK.MathHelper.DegreesToRadians(paneRotate.Z));
|
||||
var rotationMatrix = rotationX * rotationY * rotationZ;
|
||||
|
||||
if (Parent != null)
|
||||
rotationMatrix = Parent.GetRotationMatrix() * rotationMatrix;
|
||||
return rotationMatrix;
|
||||
}
|
||||
|
||||
public Vector3F GetTranslation()
|
||||
{
|
||||
var posX = Translate.X;
|
||||
|
@ -443,19 +443,9 @@ namespace LayoutBXLYT
|
||||
}
|
||||
|
||||
|
||||
//Note rotation matrix done by shaders
|
||||
|
||||
GL.Translate(translate.X, translate.Y, 0);
|
||||
|
||||
//Rotate normally unless the object uses shaders/materials
|
||||
//Rotation matrix + shaders works accurately with X/Y rotation axis
|
||||
//Todo, do everything by shaders
|
||||
bool HasMaterials = pane is IWindowPane || pane is IPicturePane;
|
||||
if (!HasMaterials)
|
||||
{
|
||||
GL.Rotate(rotate.X, 1, 0, 0);
|
||||
GL.Rotate(rotate.Y, 0, 1, 0);
|
||||
GL.Rotate(rotate.Z, 0, 0, 1);
|
||||
}
|
||||
|
||||
GL.Scale(scale.X, scale.Y, 1);
|
||||
|
||||
byte alpha = pane.Alpha;
|
||||
@ -479,7 +469,12 @@ namespace LayoutBXLYT
|
||||
else if (pane is IWindowPane)
|
||||
BxlytToGL.DrawWindowPane(pane, GameWindow, effectiveAlpha, Textures, isSelected);
|
||||
else if (pane is IBoundryPane)
|
||||
{
|
||||
shader.Enable();
|
||||
shader.SetBasic(pane);
|
||||
BxlytToGL.DrawBoundryPane(pane, GameWindow, effectiveAlpha, isSelected);
|
||||
shader.Disable();
|
||||
}
|
||||
else if (pane is ITextPane && Runtime.LayoutEditor.DisplayTextPane)
|
||||
{
|
||||
var textPane = (ITextPane)pane;
|
||||
@ -553,6 +548,9 @@ namespace LayoutBXLYT
|
||||
if (!Runtime.LayoutEditor.DisplayNullPane || GameWindow || Runtime.LayoutEditor.IsGamePreview)
|
||||
return;
|
||||
|
||||
shader.Enable();
|
||||
shader.SetBasic(pane);
|
||||
|
||||
Vector2[] TexCoords = new Vector2[] {
|
||||
new Vector2(1,1),
|
||||
new Vector2(0,1),
|
||||
@ -572,6 +570,8 @@ namespace LayoutBXLYT
|
||||
};
|
||||
|
||||
BxlytToGL.DrawRectangle(pane, GameWindow, pane.Rectangle, TexCoords, Colors, true, 255, isSelectionBox);
|
||||
|
||||
shader.Disable();
|
||||
}
|
||||
|
||||
private void DrawPartsPane(BxlytShader shader, BFLYT.PRT1 pane, byte effectiveAlpha,bool isSelected, bool parentInfluenceAlpha)
|
||||
|
@ -247,7 +247,7 @@ namespace Toolbox.Library
|
||||
{
|
||||
animationTimer = new Timer
|
||||
{
|
||||
Interval = 1000 / 60
|
||||
Interval = (int)(1000.0f / 60.0f)
|
||||
};
|
||||
animationTimer.Tick += new EventHandler(animationTimer_Tick);
|
||||
}
|
||||
@ -434,8 +434,9 @@ namespace Toolbox.Library
|
||||
}
|
||||
|
||||
private void frameSpeedUD_ValueChanged(object sender, EventArgs e) {
|
||||
|
||||
if (animationTimer != null)
|
||||
animationTimer.Interval = (int)(1000 / frameSpeedUD.Value);
|
||||
animationTimer.Interval = (int)(1000.0f / (float)frameSpeedUD.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user