add model preview mouse control

This commit is contained in:
Perfare 2018-08-15 08:40:46 +08:00
parent cb3cf2a5ea
commit eb302be569
3 changed files with 90 additions and 103 deletions

View File

@ -105,7 +105,6 @@
this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.timer = new System.Windows.Forms.Timer(this.components);
this.timerOpenTK = new System.Windows.Forms.Timer(this.components);
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
@ -383,12 +382,12 @@
this.exportAnimatorWithSelectedAnimationClipToolStripMenuItem.Text = "Export Animator with selected AnimationClip";
this.exportAnimatorWithSelectedAnimationClipToolStripMenuItem.Click += new System.EventHandler(this.exportAnimatorwithAnimationClipMenuItem_Click);
//
// showTypeToolStripMenuItem
// filterTypeToolStripMenuItem
//
this.filterTypeToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.allToolStripMenuItem});
this.filterTypeToolStripMenuItem.Name = "showTypeToolStripMenuItem";
this.filterTypeToolStripMenuItem.Size = new System.Drawing.Size(83, 21);
this.filterTypeToolStripMenuItem.Name = "filterTypeToolStripMenuItem";
this.filterTypeToolStripMenuItem.Size = new System.Drawing.Size(80, 21);
this.filterTypeToolStripMenuItem.Text = "Filter Type";
//
// allToolStripMenuItem
@ -791,11 +790,14 @@
this.glControl1.Name = "glControl1";
this.glControl1.Size = new System.Drawing.Size(838, 632);
this.glControl1.TabIndex = 4;
this.glControl1.VSync = false;
this.glControl1.Visible = false;
this.glControl1.Paint += new System.Windows.Forms.PaintEventHandler(this.glControl1_Paint);
this.glControl1.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.glControl1_MouseWheel);
this.glControl1.VSync = false;
this.glControl1.Load += new System.EventHandler(this.glControl1_Load);
this.glControl1.Paint += new System.Windows.Forms.PaintEventHandler(this.glControl1_Paint);
this.glControl1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.glControl1_MouseDown);
this.glControl1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.glControl1_MouseMove);
this.glControl1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.glControl1_MouseUp);
this.glControl1.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.glControl1_MouseWheel);
//
// classPreviewPanel
//
@ -880,11 +882,6 @@
this.timer.Interval = 10;
this.timer.Tick += new System.EventHandler(this.timer_Tick);
//
// timerOpenTK
//
this.timerOpenTK.Interval = 166;
this.timerOpenTK.Tick += new System.EventHandler(this.timerOpenTK_Tick);
//
// openFileDialog1
//
this.openFileDialog1.AddExtension = false;
@ -1033,7 +1030,6 @@
private System.Windows.Forms.Label FMODtimerLabel;
private System.Windows.Forms.Label FMODinfoLabel;
private System.Windows.Forms.Timer timer;
private System.Windows.Forms.Timer timerOpenTK;
private System.Windows.Forms.ToolStripMenuItem optionsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem displayAll;
private System.Windows.Forms.ToolStripMenuItem displayOriginalName;

View File

@ -33,8 +33,10 @@ namespace AssetStudio
private Bitmap imageTexture;
#region OpenTK
#region GLControl
private bool glControlLoaded;
private int mdx, mdy;
private bool lmdown, rmdown;
private int pgmID, pgmColorID, pgmBlackID;
private int attributeVertexPosition;
private int attributeNormalDirection;
@ -267,82 +269,33 @@ namespace AssetStudio
if (glControl1.Visible)
{
switch (e.KeyCode)
if (e.Control)
{
case Keys.D: // --> Right
if (e.Shift) //Move
{
viewMatrixData *= Matrix4.CreateTranslation(0.1f, 0, 0);
}
else //Rotate
{
viewMatrixData *= Matrix4.CreateRotationY(0.1f);
}
glControl1.Invalidate();
break;
case Keys.A: // <-- Left
if (e.Shift) //Move
{
viewMatrixData *= Matrix4.CreateTranslation(-0.1f, 0, 0);
}
else //Rotate
{
viewMatrixData *= Matrix4.CreateRotationY(-0.1f);
}
glControl1.Invalidate();
break;
case Keys.W: // Up
if (e.Control) //Toggle WireFrame
{
wireFrameMode = (wireFrameMode + 1) % 3;
glControl1.Invalidate();
}
else if (e.Shift) //Move
{
viewMatrixData *= Matrix4.CreateTranslation(0, 0.1f, 0);
}
else //Rotate
{
viewMatrixData *= Matrix4.CreateRotationX(0.1f);
}
glControl1.Invalidate();
break;
case Keys.S: // Down
if (e.Control) //Toggle Shade
{
shadeMode = (shadeMode + 1) % 2;
glControl1.Invalidate();
}
else if (e.Shift) //Move
{
viewMatrixData *= Matrix4.CreateTranslation(0, -0.1f, 0);
}
else //Rotate
{
viewMatrixData *= Matrix4.CreateRotationX(-0.1f);
}
glControl1.Invalidate();
break;
case Keys.Q: // Zoom Out
viewMatrixData *= Matrix4.CreateScale(0.9f);
glControl1.Invalidate();
break;
case Keys.E: // Zoom In
viewMatrixData *= Matrix4.CreateScale(1.1f);
glControl1.Invalidate();
break;
}
// Normal mode
if (e.Control && e.KeyCode == Keys.N)
{
normalMode = (normalMode + 1) % 2;
createVAO();
glControl1.Invalidate();
}
// Toggle Timer
if (e.KeyCode == Keys.T)
{
timerOpenTK.Enabled = !timerOpenTK.Enabled;
switch (e.KeyCode)
{
case Keys.W:
if (e.Control) //Toggle WireFrame
{
wireFrameMode = (wireFrameMode + 1) % 3;
glControl1.Invalidate();
}
break;
case Keys.S:
if (e.Control) //Toggle Shade
{
shadeMode = (shadeMode + 1) % 2;
glControl1.Invalidate();
}
break;
case Keys.N:
if (e.Control) //Normal mode
{
normalMode = (normalMode + 1) % 2;
createVAO();
glControl1.Invalidate();
}
break;
}
}
}
}
@ -988,7 +941,7 @@ namespace AssetStudio
createVAO();
}
StatusStripUpdate("Using OpenGL Version: " + GL.GetString(StringName.Version) + "\n"
+ "'T'=Start/Stop Rotation | 'WASD'=Manual Rotate | 'Shift WASD'=Move | 'Q/E'=Zoom \n"
+ "'Mouse Left'=Rotate | 'Mouse Right'=Move | 'Mouse Wheel'=Zoom \n"
+ "'Ctrl W'=Wireframe | 'Ctrl S'=Shade | 'Ctrl N'=ReNormal ");
}
break;
@ -1488,15 +1441,6 @@ namespace AssetStudio
Studio.ProgressBarMaximumAdd = ProgressBarMaximumAdd;
}
private void timerOpenTK_Tick(object sender, EventArgs e)
{
if (glControl1.Visible)
{
viewMatrixData *= Matrix4.CreateRotationY(-0.1f);
glControl1.Invalidate();
}
}
private void initOpenTK()
{
changeGLSize(glControl1.Size);
@ -1576,7 +1520,6 @@ namespace AssetStudio
private void createVAO()
{
timerOpenTK.Stop();
GL.DeleteVertexArray(vao);
GL.GenVertexArrays(1, out vao);
GL.BindVertexArray(vao);
@ -1673,6 +1616,57 @@ namespace AssetStudio
}
}
private void glControl1_MouseDown(object sender, MouseEventArgs e)
{
mdx = e.X;
mdy = e.Y;
if (e.Button == MouseButtons.Left)
{
lmdown = true;
}
if (e.Button == MouseButtons.Right)
{
rmdown = true;
}
}
private void glControl1_MouseMove(object sender, MouseEventArgs e)
{
if (lmdown || rmdown)
{
float dx = mdx - e.X;
float dy = mdy - e.Y;
mdx = e.X;
mdy = e.Y;
if (lmdown)
{
dx *= 0.01f;
dy *= 0.01f;
viewMatrixData *= Matrix4.CreateRotationX(dy);
viewMatrixData *= Matrix4.CreateRotationY(dx);
}
if (rmdown)
{
dx *= 0.003f;
dy *= 0.003f;
viewMatrixData *= Matrix4.CreateTranslation(-dx, dy, 0);
}
glControl1.Invalidate();
}
}
private void glControl1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
lmdown = false;
}
if (e.Button == MouseButtons.Right)
{
rmdown = false;
}
}
private void resetForm()
{
Text = "AssetStudio";

View File

@ -144,9 +144,6 @@ The quick brown fox jumps over the lazy dog. 1234567890</value>
<metadata name="timer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>553, 17</value>
</metadata>
<metadata name="timerOpenTK.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>636, 17</value>
</metadata>