RegularTetrahedron3D.cs 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  1. using System;
  2. using System.ComponentModel;
  3. using System.Windows.Forms;
  4. using System.Diagnostics;
  5. using System.Runtime.InteropServices;
  6. using Tao.OpenGl;
  7. using Tao.Platform.Windows;
  8. using OpenCvSharp;
  9. using System.Collections.Generic;
  10. using System.Drawing;
  11. namespace PaintDotNet.Instrument
  12. {
  13. public partial class RegularTetrahedron3D : PdnBaseForm
  14. {
  15. private GroupBox groupBox1;
  16. //以下是所有接口变量
  17. public static int[] m_aiSquareRGB = new int[3] { 255, 0, 0 };//正方面颜色
  18. public static int[] m_aiTriangleRGB = new int[3] { 255, 0, 50 };//三角面颜色
  19. public static int[] m_aiEdgeRGB = new int[3] { 0, 0, 0 };//棱的颜色
  20. //public static double m_dEdgeLength = 100.0;//正十四面体的棱长
  21. public static double m_dScale = 1.0;//实际显示时的放大比例
  22. /*需要最大棱长的原因是:要建立一个不变的视场,保证每次显示时观察点远近方向都一样,
  23. 这样才能体现不同棱长十四面体的区别,也可设置为一个比较大的经验值。*/
  24. public static double m_dMaxLength = 200.0;//可能存在的最大棱长
  25. //以下是内部参数
  26. private static double m_dHalfCubeLength = 100.0;
  27. private static float[] m_afRealSRGB = new float[3] { 1.0f, 0, 0 };
  28. private static float[] m_afRealTRGB = new float[3] { 1.0f, 0, 0.5f };
  29. private static float[] m_afRealERGB = new float[3] { 0, 0, 0 };
  30. // --- Fields ---
  31. private static IntPtr hDC; // Private GDI Device Context
  32. private static IntPtr hRC; // Permanent Rendering Context
  33. private static RegularTetrahedron3D form; // Our Current Windows Form
  34. private static bool done = false; // Bool Variable To Exit Main Loop
  35. int m_iMusMod = 0;// 1;//0;
  36. public System.Windows.Forms.PictureBox pictureBox1;
  37. int m_iMusDown = 1;//##0;
  38. int m_iLastmouseX, m_iLastmouseY;
  39. int m_iLastMusDown = 0;
  40. float[] m_fR_xyz = new float[3] { 10.0F, 0.0F, 0.0F };
  41. float[] m_fT_xyz = new float[3] { 0.0F, 0.0F, 0.0F };
  42. public static double m1_dEdgeLength = 100.0;//正十四面体的棱长
  43. //private AppWorkspace appWorkspace;
  44. /// <summary>
  45. /// 三维数据
  46. /// </summary>
  47. private Base.SettingModel.ThreeDataDemoModel threeDataDemo;
  48. ////new platform
  49. //private System.Windows.Forms.PictureBox pictureBox1;
  50. //int m_iMusDown = 0;
  51. //zzz
  52. public static/* const*/ int LINE_PNTS = 100;
  53. ////Glfw.GLFWkeyfun m_funKeyCallBak;
  54. ////Glfw.GLFWmousebuttonfun m_funMsBtnCallBak;
  55. ////Glfw.GLFWmouseposfun m_funMsPosCallBak;
  56. //int m_iMusMod = 1;//0;
  57. //int m_iLastmouseX, m_iLastmouseY;
  58. //int m_iLastMusDown = 0;
  59. //float[] m_fR_xyz = new float[3] { 0.0F, 0.0F, 0.0F };
  60. //float[] m_fT_xyz = new float[3] { 0.0F, 0.0F, 0.0F };
  61. bool m_bOverTurn = false;
  62. float[] m_afPonitA = new float[2] { 1.0F, 1.0F };
  63. float[] m_afPonitB = new float[2] { 1.0F, 1.0F };
  64. float[] m_afLineStep = new float[2] { 0.0F, 0.0F };
  65. float[,] m_afLineXY = new float[/*LINE_PNTS - 2*/98, 2];
  66. double[] m_adLineZV = new double[/*LINE_PNTS*/100];
  67. double[] m_adLineOverTurnZV = new double[/*LINE_PNTS*/100];
  68. //SRLinesForm m_fmLine;
  69. internal RegularTetrahedron3D(double m0_dEdgeLength)
  70. {
  71. m1_dEdgeLength = m0_dEdgeLength;
  72. InitializeComponent();
  73. InitializeLanguageText();
  74. m_dHalfCubeLength = m1_dEdgeLength * m_dScale * 0.7071/*sqrt(1/2)*/;
  75. m_afRealSRGB[0] = (float)(Math.Min(Math.Max(m_aiSquareRGB[0] / 255.0, 0.0), 1.0));
  76. m_afRealSRGB[1] = (float)(Math.Min(Math.Max(m_aiSquareRGB[1] / 255.0, 0.0), 1.0));
  77. m_afRealSRGB[2] = (float)(Math.Min(Math.Max(m_aiSquareRGB[2] / 255.0, 0.0), 1.0));
  78. m_afRealTRGB[0] = (float)(Math.Min(Math.Max(m_aiTriangleRGB[0] / 255.0, 0.0), 1.0));
  79. m_afRealTRGB[1] = (float)(Math.Min(Math.Max(m_aiTriangleRGB[1] / 255.0, 0.0), 1.0));
  80. m_afRealTRGB[2] = (float)(Math.Min(Math.Max(m_aiTriangleRGB[2] / 255.0, 0.0), 1.0));
  81. m_afRealERGB[0] = (float)(Math.Min(Math.Max(m_aiEdgeRGB[0] / 255.0, 0.0), 1.0));
  82. m_afRealERGB[1] = (float)(Math.Min(Math.Max(m_aiEdgeRGB[1] / 255.0, 0.0), 1.0));
  83. m_afRealERGB[2] = (float)(Math.Min(Math.Max(m_aiEdgeRGB[2] / 255.0, 0.0), 1.0));
  84. this.CreateParams.ClassStyle = this.CreateParams.ClassStyle | // Redraw On Size, And Own DC For Window.
  85. User.CS_HREDRAW | User.CS_VREDRAW | User.CS_OWNDC;
  86. this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); // No Need To Erase Form Background
  87. this.SetStyle(ControlStyles.DoubleBuffer, true); // Buffer Control
  88. //zzz this.SetStyle(ControlStyles.Opaque, true); // No Need To Draw Form Background
  89. this.SetStyle(ControlStyles.ResizeRedraw, true); // Redraw On Resize
  90. this.SetStyle(ControlStyles.UserPaint, true); // We'll Handle Painting Ourselves
  91. //this.Activated += new EventHandler(this.Form_Activated); // On Activate Event Call Form_Activated
  92. this.Closing += new CancelEventHandler(this.Form_Closing); // On Closing Event Call Form_Closing
  93. //this.Deactivate += new EventHandler(this.Form_Deactivate); // On Deactivate Event Call Form_Deactivate
  94. //this.KeyUp += new KeyEventHandler(this.Form_KeyUp); // On KeyUp Event Call Form_KeyUp
  95. this.Resize += new EventHandler(this.Form_Resize);
  96. //this.Close();
  97. //ReadPar();
  98. }
  99. private void InitializeLanguageText()
  100. {
  101. this.groupBox1.Text = "";// "三维图像";
  102. this.Text = PdnResources.GetString("Menu.Tools.SurfacePlot.Text");
  103. }
  104. /// <summary>
  105. /// 初始化基础控件
  106. /// </summary>
  107. public void InitializeComponent()
  108. {
  109. this.groupBox1 = new System.Windows.Forms.GroupBox();
  110. this.SuspendLayout();
  111. //
  112. // groupBox1
  113. //
  114. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  115. | System.Windows.Forms.AnchorStyles.Left)));
  116. this.groupBox1.Location = new System.Drawing.Point(20, 20);
  117. this.groupBox1.Margin = new System.Windows.Forms.Padding(4);
  118. this.groupBox1.Name = "groupBox1";
  119. this.groupBox1.Padding = new System.Windows.Forms.Padding(4);
  120. this.groupBox1.Size = new System.Drawing.Size(588, 424);
  121. this.groupBox1.TabIndex = 1;
  122. this.groupBox1.TabStop = false;
  123. //
  124. // RegularTetrahedron3D
  125. //
  126. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  127. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  128. this.ClientSize = new System.Drawing.Size(632, 465);
  129. this.Controls.Add(this.groupBox1);
  130. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  131. this.Margin = new System.Windows.Forms.Padding(4);
  132. this.MaximizeBox = false;
  133. this.MaximumSize = new System.Drawing.Size(648, 504);
  134. this.MinimizeBox = false;
  135. this.MinimumSize = new System.Drawing.Size(648, 504);
  136. this.Name = "RegularTetrahedron3D";
  137. this.Text = "RegularTetrahedron3D";
  138. this.Load += new System.EventHandler(this.RegularTetrahedron3D_Load);
  139. this.Controls.SetChildIndex(this.groupBox1, 0);
  140. this.ResumeLayout(false);
  141. }
  142. private static void PictureBox1_Paint(object sender, PaintEventArgs e)
  143. {
  144. //Application.DoEvents(); // Process Events
  145. //// Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene()
  146. //if ((active && (form != null) && !DrawGLScene()) /*|| keys[(int) Keys.Escape]*/)
  147. //{ // Active? Was There A Quit Received?
  148. // done = true; // ESC Or DrawGLScene Signalled A Quit
  149. //}
  150. //else
  151. //{ // Not Time To Quit, Update Screen
  152. // Gdi.SwapBuffers(hDC); // Swap Buffers (Double Buffering)
  153. //}
  154. }
  155. internal static int GetStatus()
  156. {
  157. if (form != null)
  158. { // Do We Have A Windows Form?
  159. //form.Hide(); // Hide The Window
  160. //form.Close(); // Close The Form
  161. //form = null; // Set form To Null
  162. return 1;
  163. }
  164. return -1;
  165. }
  166. /// <summary>
  167. /// 更新正十四面体的棱长
  168. /// </summary>
  169. /// <param name="m0_dEdgeLength"></param>
  170. internal static void UpdateRun(double m0_dEdgeLength)
  171. {
  172. m1_dEdgeLength = m0_dEdgeLength;
  173. m_dHalfCubeLength = m1_dEdgeLength * m_dScale * 0.7071/*sqrt(1/2)*/;
  174. //m_afRealSRGB[0] = (float)(Math.Min(Math.Max(m_aiSquareRGB[0] / 255.0, 0.0), 1.0));
  175. //m_afRealSRGB[1] = (float)(Math.Min(Math.Max(m_aiSquareRGB[1] / 255.0, 0.0), 1.0));
  176. //m_afRealSRGB[2] = (float)(Math.Min(Math.Max(m_aiSquareRGB[2] / 255.0, 0.0), 1.0));
  177. //m_afRealTRGB[0] = (float)(Math.Min(Math.Max(m_aiTriangleRGB[0] / 255.0, 0.0), 1.0));
  178. //m_afRealTRGB[1] = (float)(Math.Min(Math.Max(m_aiTriangleRGB[1] / 255.0, 0.0), 1.0));
  179. //m_afRealTRGB[2] = (float)(Math.Min(Math.Max(m_aiTriangleRGB[2] / 255.0, 0.0), 1.0));
  180. //m_afRealERGB[0] = (float)(Math.Min(Math.Max(m_aiEdgeRGB[0] / 255.0, 0.0), 1.0));
  181. //m_afRealERGB[1] = (float)(Math.Min(Math.Max(m_aiEdgeRGB[1] / 255.0, 0.0), 1.0));
  182. //m_afRealERGB[2] = (float)(Math.Min(Math.Max(m_aiEdgeRGB[2] / 255.0, 0.0), 1.0));
  183. }
  184. internal static void Run(double m0_dEdgeLength) {
  185. done = false;
  186. // Create Our OpenGL Window //# 640, 480, 16
  187. if (!CreateGLWindow(m0_dEdgeLength, "3D效果"/*PdnResources.GetString("Menu.Tools.SurfacePlot.Text")*/, 990, 690, 16)) {
  188. return; // Quit If Window Was Not Created
  189. }
  190. while (!done)
  191. { // Loop That Runs While done = false
  192. Application.DoEvents(); // Process Events
  193. // Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene()
  194. if ((/* //# active && */(form != null) && !DrawGLScene()) /*|| keys[(int) Keys.Escape]*/)
  195. { // Active? Was There A Quit Received?
  196. done = true; // ESC Or DrawGLScene Signalled A Quit
  197. }
  198. else
  199. { // Not Time To Quit, Update Screen
  200. Gdi.SwapBuffers(hDC); // Swap Buffers (Double Buffering)
  201. }
  202. /*
  203. if(keys[(int) Keys.F1]) { // Is F1 Being Pressed?
  204. keys[(int) Keys.F1] = false; // If So Make Key false
  205. KillGLWindow(); // Kill Our Current Window
  206. // Recreate Our OpenGL Window
  207. if(!CreateGLWindow("三维面绘制", 640, 480, 16)) {
  208. return; // Quit If Window Was Not Created
  209. }
  210. done = false; // We're Not Done Yet
  211. }
  212. */
  213. }
  214. // Shutdown
  215. KillGLWindow(); // Kill The Window
  216. return; // Exit The Program
  217. }
  218. private static bool CreateGLWindow(double m0_dEdgeLength, string title, int width, int height, int bits)
  219. {
  220. int pixelFormat; // Holds The Results After Searching For A Match
  221. form = null; // Null The Form
  222. GC.Collect(); // Request A Collection
  223. // This Forces A Swap
  224. Kernel.SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
  225. form = new RegularTetrahedron3D(m0_dEdgeLength); // Create The Window
  226. form.FormBorderStyle = FormBorderStyle.Sizable; // Sizable
  227. Cursor.Show(); // Show Mouse Pointer
  228. form.Width = width; // Set Window Width
  229. form.Height = height; // Set Window Height
  230. form.Text = title; // Set Window Title
  231. Gdi.PIXELFORMATDESCRIPTOR pfd = new Gdi.PIXELFORMATDESCRIPTOR(); // pfd Tells Windows How We Want Things To Be
  232. pfd.nSize = (short) Marshal.SizeOf(pfd); // Size Of This Pixel Format Descriptor
  233. pfd.nVersion = 1; // Version Number
  234. pfd.dwFlags = Gdi.PFD_DRAW_TO_WINDOW | // Format Must Support Window
  235. Gdi.PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
  236. Gdi.PFD_DOUBLEBUFFER; // Format Must Support Double Buffering
  237. pfd.iPixelType = (byte) Gdi.PFD_TYPE_RGBA; // Request An RGBA Format
  238. pfd.cColorBits = (byte) bits; // Select Our Color Depth
  239. pfd.cRedBits = 0; // Color Bits Ignored
  240. pfd.cRedShift = 0;
  241. pfd.cGreenBits = 0;
  242. pfd.cGreenShift = 0;
  243. pfd.cBlueBits = 0;
  244. pfd.cBlueShift = 0;
  245. pfd.cAlphaBits = 0; // No Alpha Buffer
  246. pfd.cAlphaShift = 0; // Shift Bit Ignored
  247. pfd.cAccumBits = 0; // No Accumulation Buffer
  248. pfd.cAccumRedBits = 0; // Accumulation Bits Ignored
  249. pfd.cAccumGreenBits = 0;
  250. pfd.cAccumBlueBits = 0;
  251. pfd.cAccumAlphaBits = 0;
  252. pfd.cDepthBits = 16; // 16Bit Z-Buffer (Depth Buffer)
  253. pfd.cStencilBits = 0; // No Stencil Buffer
  254. pfd.cAuxBuffers = 0; // No Auxiliary Buffer
  255. pfd.iLayerType = (byte) Gdi.PFD_MAIN_PLANE; // Main Drawing Layer
  256. pfd.bReserved = 0; // Reserved
  257. pfd.dwLayerMask = 0; // Layer Masks Ignored
  258. pfd.dwVisibleMask = 0;
  259. pfd.dwDamageMask = 0;
  260. //hDC = User.GetDC(form.Handle); // Attempt To Get A Device Context
  261. form.pictureBox1 = new PictureBox();
  262. ((System.ComponentModel.ISupportInitialize)(form.pictureBox1)).BeginInit();
  263. //form.pictureBox1.Location = new System.Drawing.Point(22, 40);
  264. //form.pictureBox1.Location = new System.Drawing.Point(20, 180);
  265. form.pictureBox1.Location = new System.Drawing.Point(15, 18);
  266. form.pictureBox1.Name = "pictureBox1";
  267. form.pictureBox1.Size = new System.Drawing.Size(560, 400);
  268. //# form.pictureBox1.Size = new System.Drawing.Size(1272, 651);
  269. form.pictureBox1.TabIndex = 0;
  270. form.pictureBox1.TabStop = false;
  271. /*form*/form.groupBox1.Controls.Add(form.pictureBox1);
  272. ((System.ComponentModel.ISupportInitialize)(form.pictureBox1)).EndInit();
  273. form.pictureBox1.Paint += PictureBox1_Paint;
  274. form.pictureBox1.MouseMove += new MouseEventHandler(form.pictureBox1_MouseMove);
  275. form.pictureBox1.MouseDown += new MouseEventHandler(form.pictureBox1_MouseDown);
  276. form.pictureBox1.MouseUp += new MouseEventHandler(form.pictureBox1_MouseUp);
  277. form.pictureBox1.MouseLeave += new EventHandler(form.pictureBox1_MouseLeave);
  278. hDC = User.GetDC(form.pictureBox1.Handle);
  279. if(hDC == IntPtr.Zero) { // Did We Get A Device Context?
  280. KillGLWindow(); // Reset The Display
  281. MessageBox.Show("Can't Create A GL Device Context.", "ERROR",
  282. MessageBoxButtons.OK, MessageBoxIcon.Error);
  283. return false;
  284. }
  285. pixelFormat = Gdi.ChoosePixelFormat(hDC, ref pfd); // Attempt To Find An Appropriate Pixel Format
  286. if(pixelFormat == 0) { // Did Windows Find A Matching Pixel Format?
  287. KillGLWindow(); // Reset The Display
  288. MessageBox.Show("Can't Find A Suitable PixelFormat.", "ERROR",
  289. MessageBoxButtons.OK, MessageBoxIcon.Error);
  290. return false;
  291. }
  292. if(!Gdi.SetPixelFormat(hDC, pixelFormat, ref pfd)) { // Are We Able To Set The Pixel Format?
  293. KillGLWindow(); // Reset The Display
  294. MessageBox.Show("Can't Set The PixelFormat.", "ERROR",
  295. MessageBoxButtons.OK, MessageBoxIcon.Error);
  296. return false;
  297. }
  298. hRC = Wgl.wglCreateContext(hDC); // Attempt To Get The Rendering Context
  299. if(hRC == IntPtr.Zero) { // Are We Able To Get A Rendering Context?
  300. KillGLWindow(); // Reset The Display
  301. MessageBox.Show("Can't Create A GL Rendering Context.", "ERROR",
  302. MessageBoxButtons.OK, MessageBoxIcon.Error);
  303. return false;
  304. }
  305. if(!Wgl.wglMakeCurrent(hDC, hRC)) { // Try To Activate The Rendering Context
  306. KillGLWindow(); // Reset The Display
  307. MessageBox.Show("Can't Activate The GL Rendering Context.", "ERROR",
  308. MessageBoxButtons.OK, MessageBoxIcon.Error);
  309. return false;
  310. }
  311. form.Show(); // Show The Window
  312. //zzz form.TopMost = true; // Topmost Window
  313. form.Focus(); // Focus The Window
  314. //# form.BackColor = Color.Gray;
  315. //# //# form.WindowState = FormWindowState.Maximized;
  316. ReSizeGLScene(width, height); // Set Up Our Perspective GL Screen
  317. if (!InitGL())
  318. { // Initialize Our Newly Created GL Window
  319. KillGLWindow(); // Reset The Display
  320. MessageBox.Show("Initialization Failed.", "ERROR",
  321. MessageBoxButtons.OK, MessageBoxIcon.Error);
  322. return false;
  323. }
  324. return true; // Success
  325. }
  326. private static bool DrawGLScene()
  327. {
  328. //new platform
  329. iniView();
  330. Gl.glTranslatef(0, 0, 0);
  331. myRotate();
  332. ////错了 Gl.glTranslatef(m_fT_xyz[0],m_fT_xyz[1],0);
  333. //for (int i = 0; i < form.m_iWidth - 1; i++)
  334. //{
  335. // Gl.glBegin(Gl.GL_TRIANGLE_STRIP);
  336. // for (int j = 0; j < form.m_iHeight; j++)
  337. // {
  338. // DrowOnePnt(i, j);
  339. // DrowOnePnt(i + 1, j);
  340. // }
  341. // Gl.glEnd();
  342. //}
  343. ////if ((form.m_iMusMod >= 5) && (form.m_iMusMod <= 7) || true)
  344. ////{
  345. //// Gl.glBegin(Gl.GL_QUADS);
  346. //// Gl.glColor3f(1.0F, 1.0F, 0.0F);
  347. //// Gl.glVertex3d(form.m_afPonitA[0] - 10 - form.m_iWidth / 2.0, form.m_afPonitA[1] - 10 - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[0] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
  348. //// Gl.glVertex3d(form.m_afPonitA[0] + 10 - form.m_iWidth / 2.0, form.m_afPonitA[1] - 10 - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[0] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
  349. //// Gl.glVertex3d(form.m_afPonitA[0] + 10 - form.m_iWidth / 2.0, form.m_afPonitA[1] + 10 - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[0] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
  350. //// Gl.glVertex3d(form.m_afPonitA[0] - 10 - form.m_iWidth / 2.0, form.m_afPonitA[1] + 10 - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[0] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
  351. //// Gl.glEnd();
  352. //// Gl.glBegin(Gl.GL_LINE_STRIP);
  353. //// Gl.glColor3f(0.0F, 1.0F, 0.0F);
  354. //// Gl.glVertex3d(form.m_afPonitA[0] - form.m_iWidth / 2.0, form.m_afPonitA[1] - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[0] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
  355. //// for (int i = 0; i < (LINE_PNTS - 2); i++)
  356. //// {
  357. //// Gl.glVertex3d(form.m_afLineXY[i, 0] - form.m_iWidth / 2.0, form.m_afLineXY[i, 1] - form.m_iHeight / 2.0, 1.0 + /*form.m_adThisZV[(int)form.m_afLineXY[i, 0], (int)form.m_afLineXY[i, 1]]*/form.m_adThisLineZV[i + 1] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
  358. //// }
  359. //// Gl.glVertex3d(form.m_afPonitB[0] - form.m_iWidth / 2.0, form.m_afPonitB[1] - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[LINE_PNTS - 1] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
  360. //// Gl.glEnd();
  361. //// Gl.glBegin(Gl.GL_QUADS);
  362. //// Gl.glColor3f(0.0F, 1.0F, 01.0F);
  363. //// Gl.glVertex3d(form.m_afPonitB[0] - 10 - form.m_iWidth / 2.0, form.m_afPonitB[1] - 10 - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[LINE_PNTS - 1] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
  364. //// Gl.glVertex3d(form.m_afPonitB[0] + 10 - form.m_iWidth / 2.0, form.m_afPonitB[1] - 10 - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[LINE_PNTS - 1] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
  365. //// Gl.glVertex3d(form.m_afPonitB[0] + 10 - form.m_iWidth / 2.0, form.m_afPonitB[1] + 10 - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[LINE_PNTS - 1] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
  366. //// Gl.glVertex3d(form.m_afPonitB[0] - 10 - form.m_iWidth / 2.0, form.m_afPonitB[1] + 10 - form.m_iHeight / 2.0, 1.0 + form.m_adThisLineZV[LINE_PNTS - 1] - (form.m_dMaxZV + form.m_dMinZV) / 2.0);
  367. //// Gl.glEnd();
  368. ////}
  369. ///
  370. Gl.glBegin(Gl.GL_QUADS);
  371. Gl.glColor3f(m_afRealSRGB[0], m_afRealSRGB[1], m_afRealSRGB[2]);
  372. Gl.glVertex3d(m_dHalfCubeLength, 0, m_dHalfCubeLength);
  373. Gl.glVertex3d(0, m_dHalfCubeLength, m_dHalfCubeLength);
  374. Gl.glVertex3d(-m_dHalfCubeLength, 0, m_dHalfCubeLength);
  375. Gl.glVertex3d(0, -m_dHalfCubeLength, m_dHalfCubeLength);
  376. Gl.glVertex3d(m_dHalfCubeLength, 0, -m_dHalfCubeLength);
  377. Gl.glVertex3d(0, m_dHalfCubeLength, -m_dHalfCubeLength);
  378. Gl.glVertex3d(-m_dHalfCubeLength, 0, -m_dHalfCubeLength);
  379. Gl.glVertex3d(0, -m_dHalfCubeLength, -m_dHalfCubeLength);
  380. Gl.glVertex3d(m_dHalfCubeLength, 0, m_dHalfCubeLength);
  381. Gl.glVertex3d(m_dHalfCubeLength, m_dHalfCubeLength, 0);
  382. Gl.glVertex3d(m_dHalfCubeLength, 0, -m_dHalfCubeLength);
  383. Gl.glVertex3d(m_dHalfCubeLength, -m_dHalfCubeLength, 0);
  384. Gl.glVertex3d(-m_dHalfCubeLength, 0, m_dHalfCubeLength);
  385. Gl.glVertex3d(-m_dHalfCubeLength, m_dHalfCubeLength, 0);
  386. Gl.glVertex3d(-m_dHalfCubeLength, 0, -m_dHalfCubeLength);
  387. Gl.glVertex3d(-m_dHalfCubeLength, -m_dHalfCubeLength, 0);
  388. Gl.glVertex3d(0, m_dHalfCubeLength, m_dHalfCubeLength);
  389. Gl.glVertex3d(m_dHalfCubeLength, m_dHalfCubeLength, 0);
  390. Gl.glVertex3d(0, m_dHalfCubeLength, -m_dHalfCubeLength);
  391. Gl.glVertex3d(-m_dHalfCubeLength, m_dHalfCubeLength, 0);
  392. Gl.glVertex3d(0, -m_dHalfCubeLength, m_dHalfCubeLength);
  393. Gl.glVertex3d(m_dHalfCubeLength, -m_dHalfCubeLength, 0);
  394. Gl.glVertex3d(0, -m_dHalfCubeLength, -m_dHalfCubeLength);
  395. Gl.glVertex3d(-m_dHalfCubeLength, -m_dHalfCubeLength, 0);
  396. Gl.glEnd();
  397. Gl.glBegin(Gl.GL_TRIANGLES);
  398. Gl.glColor3f(m_afRealTRGB[0], m_afRealTRGB[1], m_afRealTRGB[2]);
  399. Gl.glVertex3d(m_dHalfCubeLength, 0, m_dHalfCubeLength);
  400. Gl.glVertex3d(m_dHalfCubeLength, m_dHalfCubeLength, 0);
  401. Gl.glVertex3d(0, m_dHalfCubeLength, m_dHalfCubeLength);
  402. Gl.glVertex3d(-m_dHalfCubeLength, 0, -m_dHalfCubeLength);
  403. Gl.glVertex3d(-m_dHalfCubeLength, -m_dHalfCubeLength, 0);
  404. Gl.glVertex3d(0, -m_dHalfCubeLength, -m_dHalfCubeLength);
  405. Gl.glVertex3d(0, m_dHalfCubeLength, m_dHalfCubeLength);
  406. Gl.glVertex3d(-m_dHalfCubeLength, m_dHalfCubeLength, 0);
  407. Gl.glVertex3d(-m_dHalfCubeLength, 0, m_dHalfCubeLength);
  408. Gl.glVertex3d(0, -m_dHalfCubeLength, -m_dHalfCubeLength);
  409. Gl.glVertex3d(m_dHalfCubeLength, -m_dHalfCubeLength, 0);
  410. Gl.glVertex3d(m_dHalfCubeLength, 0, -m_dHalfCubeLength);
  411. Gl.glVertex3d(-m_dHalfCubeLength, 0, m_dHalfCubeLength);
  412. Gl.glVertex3d(-m_dHalfCubeLength, -m_dHalfCubeLength, 0);
  413. Gl.glVertex3d(0, -m_dHalfCubeLength, m_dHalfCubeLength);
  414. Gl.glVertex3d(m_dHalfCubeLength, 0, -m_dHalfCubeLength);
  415. Gl.glVertex3d(m_dHalfCubeLength, m_dHalfCubeLength, 0);
  416. Gl.glVertex3d(0, m_dHalfCubeLength, -m_dHalfCubeLength);
  417. Gl.glVertex3d(0, -m_dHalfCubeLength, m_dHalfCubeLength);
  418. Gl.glVertex3d(m_dHalfCubeLength, -m_dHalfCubeLength, 0);
  419. Gl.glVertex3d(m_dHalfCubeLength, 0, m_dHalfCubeLength);
  420. Gl.glVertex3d(0, m_dHalfCubeLength, -m_dHalfCubeLength);
  421. Gl.glVertex3d(-m_dHalfCubeLength, m_dHalfCubeLength, 0);
  422. Gl.glVertex3d(-m_dHalfCubeLength, 0, -m_dHalfCubeLength);
  423. Gl.glEnd();
  424. Gl.glLineWidth(2);
  425. Gl.glColor3f(m_afRealERGB[0], m_afRealERGB[1], m_afRealERGB[2]);
  426. Gl.glBegin(Gl.GL_LINE_STRIP);
  427. Gl.glVertex3d(m_dHalfCubeLength, 0, m_dHalfCubeLength);
  428. Gl.glVertex3d(0, m_dHalfCubeLength, m_dHalfCubeLength);
  429. Gl.glVertex3d(-m_dHalfCubeLength, 0, m_dHalfCubeLength);
  430. Gl.glVertex3d(0, -m_dHalfCubeLength, m_dHalfCubeLength);
  431. Gl.glVertex3d(m_dHalfCubeLength, 0, m_dHalfCubeLength);
  432. Gl.glEnd();
  433. Gl.glBegin(Gl.GL_LINE_STRIP);
  434. Gl.glVertex3d(m_dHalfCubeLength, 0, -m_dHalfCubeLength);
  435. Gl.glVertex3d(0, m_dHalfCubeLength, -m_dHalfCubeLength);
  436. Gl.glVertex3d(-m_dHalfCubeLength, 0, -m_dHalfCubeLength);
  437. Gl.glVertex3d(0, -m_dHalfCubeLength, -m_dHalfCubeLength);
  438. Gl.glVertex3d(m_dHalfCubeLength, 0, -m_dHalfCubeLength);
  439. Gl.glEnd();
  440. Gl.glBegin(Gl.GL_LINE_STRIP);
  441. Gl.glVertex3d(m_dHalfCubeLength, 0, m_dHalfCubeLength);
  442. Gl.glVertex3d(m_dHalfCubeLength, m_dHalfCubeLength, 0);
  443. Gl.glVertex3d(m_dHalfCubeLength, 0, -m_dHalfCubeLength);
  444. Gl.glVertex3d(m_dHalfCubeLength, -m_dHalfCubeLength, 0);
  445. Gl.glVertex3d(m_dHalfCubeLength, 0, m_dHalfCubeLength);
  446. Gl.glEnd();
  447. Gl.glBegin(Gl.GL_LINE_STRIP);
  448. Gl.glVertex3d(-m_dHalfCubeLength, 0, m_dHalfCubeLength);
  449. Gl.glVertex3d(-m_dHalfCubeLength, m_dHalfCubeLength, 0);
  450. Gl.glVertex3d(-m_dHalfCubeLength, 0, -m_dHalfCubeLength);
  451. Gl.glVertex3d(-m_dHalfCubeLength, -m_dHalfCubeLength, 0);
  452. Gl.glVertex3d(-m_dHalfCubeLength, 0, m_dHalfCubeLength);
  453. Gl.glEnd();
  454. Gl.glBegin(Gl.GL_LINE_STRIP);
  455. Gl.glVertex3d(0, m_dHalfCubeLength, m_dHalfCubeLength);
  456. Gl.glVertex3d(m_dHalfCubeLength, m_dHalfCubeLength, 0);
  457. Gl.glVertex3d(0, m_dHalfCubeLength, -m_dHalfCubeLength);
  458. Gl.glVertex3d(-m_dHalfCubeLength, m_dHalfCubeLength, 0);
  459. Gl.glVertex3d(0, m_dHalfCubeLength, m_dHalfCubeLength);
  460. Gl.glEnd();
  461. Gl.glBegin(Gl.GL_LINE_STRIP);
  462. Gl.glVertex3d(0, -m_dHalfCubeLength, m_dHalfCubeLength);
  463. Gl.glVertex3d(m_dHalfCubeLength, -m_dHalfCubeLength, 0);
  464. Gl.glVertex3d(0, -m_dHalfCubeLength, -m_dHalfCubeLength);
  465. Gl.glVertex3d(-m_dHalfCubeLength, -m_dHalfCubeLength, 0);
  466. Gl.glVertex3d(0, -m_dHalfCubeLength, m_dHalfCubeLength);
  467. Gl.glEnd();
  468. Gl.glBegin(Gl.GL_LINE_STRIP);
  469. Gl.glVertex3d(m_dHalfCubeLength, 0, m_dHalfCubeLength);
  470. Gl.glVertex3d(m_dHalfCubeLength, m_dHalfCubeLength, 0);
  471. Gl.glVertex3d(0, m_dHalfCubeLength, m_dHalfCubeLength);
  472. Gl.glVertex3d(m_dHalfCubeLength, 0, m_dHalfCubeLength);
  473. Gl.glEnd();
  474. Gl.glBegin(Gl.GL_LINE_STRIP);
  475. Gl.glVertex3d(-m_dHalfCubeLength, 0, -m_dHalfCubeLength);
  476. Gl.glVertex3d(-m_dHalfCubeLength, -m_dHalfCubeLength, 0);
  477. Gl.glVertex3d(0, -m_dHalfCubeLength, -m_dHalfCubeLength);
  478. Gl.glVertex3d(-m_dHalfCubeLength, 0, -m_dHalfCubeLength);
  479. Gl.glEnd();
  480. Gl.glBegin(Gl.GL_LINE_STRIP);
  481. Gl.glVertex3d(0, m_dHalfCubeLength, m_dHalfCubeLength);
  482. Gl.glVertex3d(-m_dHalfCubeLength, m_dHalfCubeLength, 0);
  483. Gl.glVertex3d(-m_dHalfCubeLength, 0, m_dHalfCubeLength);
  484. Gl.glVertex3d(0, m_dHalfCubeLength, m_dHalfCubeLength);
  485. Gl.glEnd();
  486. Gl.glBegin(Gl.GL_LINE_STRIP);
  487. Gl.glVertex3d(0, -m_dHalfCubeLength, -m_dHalfCubeLength);
  488. Gl.glVertex3d(m_dHalfCubeLength, -m_dHalfCubeLength, 0);
  489. Gl.glVertex3d(m_dHalfCubeLength, 0, -m_dHalfCubeLength);
  490. Gl.glVertex3d(0, -m_dHalfCubeLength, -m_dHalfCubeLength);
  491. Gl.glEnd();
  492. Gl.glBegin(Gl.GL_LINE_STRIP);
  493. Gl.glVertex3d(-m_dHalfCubeLength, 0, m_dHalfCubeLength);
  494. Gl.glVertex3d(-m_dHalfCubeLength, -m_dHalfCubeLength, 0);
  495. Gl.glVertex3d(0, -m_dHalfCubeLength, m_dHalfCubeLength);
  496. Gl.glVertex3d(-m_dHalfCubeLength, 0, m_dHalfCubeLength);
  497. Gl.glEnd();
  498. Gl.glBegin(Gl.GL_LINE_STRIP);
  499. Gl.glVertex3d(m_dHalfCubeLength, 0, -m_dHalfCubeLength);
  500. Gl.glVertex3d(m_dHalfCubeLength, m_dHalfCubeLength, 0);
  501. Gl.glVertex3d(0, m_dHalfCubeLength, -m_dHalfCubeLength);
  502. Gl.glVertex3d(m_dHalfCubeLength, 0, -m_dHalfCubeLength);
  503. Gl.glEnd();
  504. Gl.glBegin(Gl.GL_LINE_STRIP);
  505. Gl.glVertex3d(0, -m_dHalfCubeLength, m_dHalfCubeLength);
  506. Gl.glVertex3d(m_dHalfCubeLength, -m_dHalfCubeLength, 0);
  507. Gl.glVertex3d(m_dHalfCubeLength, 0, m_dHalfCubeLength);
  508. Gl.glVertex3d(0, -m_dHalfCubeLength, m_dHalfCubeLength);
  509. Gl.glEnd();
  510. Gl.glBegin(Gl.GL_LINE_STRIP);
  511. Gl.glVertex3d(0, m_dHalfCubeLength, -m_dHalfCubeLength);
  512. Gl.glVertex3d(-m_dHalfCubeLength, m_dHalfCubeLength, 0);
  513. Gl.glVertex3d(-m_dHalfCubeLength, 0, -m_dHalfCubeLength);
  514. Gl.glVertex3d(0, m_dHalfCubeLength, -m_dHalfCubeLength);
  515. Gl.glEnd();
  516. Gl.glLoadIdentity();
  517. return true;
  518. }
  519. private static void myRotate()
  520. {
  521. int[,] vec = new int[3, 3] { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
  522. for (int i = 0; i <= 2; i++)
  523. {
  524. Gl.glRotatef(form.m_fR_xyz[i], vec[i, 0], vec[i, 1], vec[i, 2]);
  525. }
  526. }
  527. private static bool InitGL()
  528. {
  529. ////Gl.glShadeModel(Gl.GL_SMOOTH); // Enable Smooth Shading
  530. ////Gl.glClearColor(0, 0, 0, 0.5f); // Black Background
  531. ////Gl.glClearDepth(1); // Depth Buffer Setup
  532. //Gl.glEnable(Gl.GL_DEPTH_TEST); //# // Enables Depth Testing
  533. ////Gl.glDepthFunc(Gl.GL_LEQUAL); // The Type Of Depth Testing To Do
  534. ////Gl.glHint(Gl.GL_PERSPECTIVE_CORRECTION_HINT, Gl.GL_NICEST); // Really Nice Perspective Calculations
  535. // 设置视口 viewport
  536. Gl.glViewport(0, 0, form.pictureBox1.Width, form.pictureBox1.Height);
  537. //启用阴影平滑
  538. Gl.glShadeModel(Gl.GL_SMOOTH);
  539. //启用反走样
  540. Gl.glHint(Gl.GL_PERSPECTIVE_CORRECTION_HINT, Gl.GL_NICEST);
  541. //21.01.25 启动深度测试
  542. Gl.glEnable(Gl.GL_DEPTH_TEST);
  543. // 设置投影模式 projection matrix
  544. Gl.glMatrixMode(Gl.GL_PROJECTION);
  545. Gl.glLoadIdentity();
  546. iniView();
  547. return true;
  548. }
  549. public static void iniView(bool clearColor = true)
  550. {
  551. //// 重置黑色背景
  552. //if (clearColor)
  553. //{
  554. // Gl.glClearColor((float)(0 / 255.0), (float)(0 / 255.0), (float)(0 / 255.0), (float)(255 / 255.0));
  555. // Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
  556. //}
  557. //else
  558. // return;
  559. // 重置黑色背景
  560. Gl.glClearColor(0, 0, 0, 0);
  561. //21.01.25 启动深度测试 Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
  562. Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
  563. //form.m_fT_xyz[2] = (float)Math.Max(form.m_dMaxZV, Math.Abs(form.m_dMinZV));
  564. //form.m_fT_xyz[2] = (float)(-1.0 * Math.Max(Math.Max(form.m_iWidth * 0.98, form.m_iHeight * 0.98), form.m_fT_xyz[2]));
  565. //////form.m_fT_xyz[2] = (float)(1.2 * form.m_fT_xyz[2]);
  566. //////Glu.gluPerspective(85, form.pictureBox1.Width / (double)form.pictureBox1.Height, 1, -4.0/*-2.0*/ * form.m_fT_xyz[2]);//距离裁减
  567. ////Gl.glOrtho(0, form.pictureBox1.Width, form.pictureBox1.Height, 0, 1, -4.0/*-2.0*/ * form.m_fT_xyz[2]);
  568. //double size1 = form.m_iHeight / 1.0;
  569. //Gl.glOrtho(-size1 * form.pictureBox1.Width / (double)form.pictureBox1.Height, size1 * form.pictureBox1.Width / (double)form.pictureBox1.Height, -size1, size1, 2.4 * form.m_fT_xyz[2], -2.4 * form.m_fT_xyz[2]);
  570. //// 选择模型观察矩阵 modelview matrix
  571. //Gl.glMatrixMode(Gl.GL_MODELVIEW);
  572. ////重置模型观察矩阵
  573. //Gl.glLoadIdentity();
  574. //Glu.gluLookAt(-1.0 * form.m_fT_xyz[0], -1.0 * form.m_fT_xyz[1], -1.0/*-1.0*/ * form.m_fT_xyz[2], // 眼睛位置
  575. // -1.0 * form.m_fT_xyz[0], -1.0 * form.m_fT_xyz[1], 0, // 观察点
  576. // 0, 1, 0);
  577. //###
  578. form.m_fT_xyz[2] = (float)(m_dMaxLength * 1.225/*sqrt(3/2)*/ * m_dScale);
  579. Glu.gluPerspective(65, form.pictureBox1.Width / (double)form.pictureBox1.Height, 1, -2.0 * form.m_fT_xyz[2]);//距离裁减
  580. // 选择模型观察矩阵 modelview matrix
  581. Gl.glMatrixMode(Gl.GL_MODELVIEW);
  582. //重置模型观察矩阵
  583. Gl.glLoadIdentity();
  584. Glu.gluLookAt(-1.0 * form.m_fT_xyz[0], -1.0 * form.m_fT_xyz[1], -1.0 * form.m_fT_xyz[2], // 眼睛位置
  585. -1.0 * form.m_fT_xyz[0], -1.0 * form.m_fT_xyz[1], 0, // 观察点
  586. 0, 1, 0);
  587. }
  588. private static void KillGLWindow() {
  589. if(hRC != IntPtr.Zero) { // Do We Have A Rendering Context?
  590. if(!Wgl.wglMakeCurrent(IntPtr.Zero, IntPtr.Zero)) { // Are We Able To Release The DC and RC Contexts?
  591. MessageBox.Show("Release Of DC And RC Failed.", "SHUTDOWN ERROR",
  592. MessageBoxButtons.OK, MessageBoxIcon.Error);
  593. }
  594. if(!Wgl.wglDeleteContext(hRC)) { // Are We Able To Delete The RC?
  595. MessageBox.Show("Release Rendering Context Failed.", "SHUTDOWN ERROR",
  596. MessageBoxButtons.OK, MessageBoxIcon.Error);
  597. }
  598. hRC = IntPtr.Zero; // Set RC To Null
  599. }
  600. if(hDC != IntPtr.Zero) { // Do We Have A Device Context?
  601. if(form != null && !form.IsDisposed) { // Do We Have A Window?
  602. if(form.Handle != IntPtr.Zero) { // Do We Have A Window Handle?
  603. if(!User.ReleaseDC(form.Handle, hDC)) { // Are We Able To Release The DC?
  604. MessageBox.Show("Release Device Context Failed.", "SHUTDOWN ERROR",
  605. MessageBoxButtons.OK, MessageBoxIcon.Error);
  606. }
  607. }
  608. }
  609. hDC = IntPtr.Zero; // Set DC To Null
  610. }
  611. if(form != null) { // Do We Have A Windows Form?
  612. form.Hide(); // Hide The Window
  613. form.Close(); // Close The Form
  614. form = null; // Set form To Null
  615. }
  616. }
  617. //#
  618. private static void ReSizeGLScene(int width, int height) {
  619. if(height == 0) { // Prevent A Divide By Zero...
  620. height = 1; // By Making Height Equal To One
  621. }
  622. Gl.glViewport(0, 0, width, height); // Reset The Current Viewport
  623. Gl.glMatrixMode(Gl.GL_PROJECTION); // Select The Projection Matrix
  624. Gl.glLoadIdentity(); // Reset The Projection Matrix
  625. Glu.gluPerspective(45, width / (double) height, 0.1, 100); // Calculate The Aspect Ratio Of The Window
  626. Gl.glMatrixMode(Gl.GL_MODELVIEW); // Select The Modelview Matrix
  627. Gl.glLoadIdentity(); // Reset The Modelview Matrix
  628. }
  629. private void Form_Closing(object sender, CancelEventArgs e)
  630. {
  631. done = true; // Send A Quit Message
  632. }
  633. //zzz
  634. public int m_iYVCount = 10;
  635. public double m_dYVMax = 51;
  636. public double m_dYVMin = -51;
  637. public int m_iYPixelMax = 350;
  638. public int m_iYPixelMin = 40;
  639. public int m_iXPixelMax = 1100;
  640. public int m_iXPixelMin = 60;
  641. /*
  642. private void Form_KeyUp(object sender, KeyEventArgs e) {
  643. keys[e.KeyValue] = false; // Key Has Been Released, Mark It As false
  644. }
  645. */
  646. private void Form_Resize(object sender, EventArgs e)
  647. {
  648. ReSizeGLScene(form.Width, form.Height); // Resize The OpenGL Window
  649. }
  650. private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
  651. {
  652. if ((m_iMusMod <= 0) || (m_iMusMod >= 3/* //# 7*/))
  653. {
  654. return;
  655. }
  656. //int iBtnDwn = Glfw.glfwGetMouseButton(Glfw.GLFW_MOUSE_BUTTON_LEFT);
  657. if (0 == m_iMusDown)
  658. {
  659. m_iLastMusDown = 0;
  660. return;
  661. }
  662. else if (0 == m_iLastMusDown)
  663. {
  664. m_iLastMusDown = 1;
  665. m_iLastmouseX = e.X;
  666. m_iLastmouseY = e.Y;
  667. return;
  668. }
  669. float fXChange = e.X - m_iLastmouseX;
  670. float fYChange = e.Y - m_iLastmouseY;
  671. m_fR_xyz[0] = AngleNormalization(m_fR_xyz[0]);
  672. m_fR_xyz[1] = AngleNormalization(m_fR_xyz[1]);
  673. if (1 == m_iMusMod)
  674. {
  675. if ((m_fR_xyz[0] > 90.0) && (m_fR_xyz[0] < 270.0))//先绕X轴转完了
  676. {
  677. fXChange *= -1.0F;
  678. }
  679. m_fR_xyz[0] -= fYChange;//21.01.25
  680. m_fR_xyz[1] += fXChange;
  681. //m_fR_xyz[2] = 0.0F;
  682. }
  683. else if (2 == m_iMusMod)
  684. {
  685. m_fT_xyz[0] += fXChange * 0.91F;
  686. m_fT_xyz[1] += fYChange * -0.91F;
  687. }
  688. m_iLastmouseX = e.X;
  689. m_iLastmouseY = e.Y;
  690. }
  691. private float AngleNormalization(float fOldAngle)
  692. {
  693. float fNewAngle = fOldAngle % 360.0F;
  694. if (fNewAngle < 0)
  695. {
  696. fNewAngle += 360.0F;
  697. }
  698. return fNewAngle;
  699. }
  700. private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
  701. {
  702. if (e.Button == MouseButtons.Left)
  703. {
  704. m_iMusDown = 1;
  705. }
  706. }
  707. private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
  708. {
  709. if (e.Button == MouseButtons.Left)
  710. {
  711. m_iMusDown = 0;
  712. }
  713. }
  714. private void RegularTetrahedron3D_Load(object sender, EventArgs e)
  715. {
  716. m_iMusMod = 1;
  717. ReSizeGLScene(form.Width, form.Height); // Resize The OpenGL Window
  718. }
  719. private void pictureBox1_MouseLeave(object sender, EventArgs e)
  720. {
  721. m_iMusDown = 0;
  722. }
  723. }
  724. }