📄 main_form.cs
字号:
}
Animate = true;
break;
case Api.VK_PGDN:
ZoomIs = GI.GetGLzoom(hGLcontrol);
if (ZoomIs < 100)
{
GI.SetGLzoom(hGLcontrol, ZoomIs + 1);
GI.ResizeGLWindow(hGLcontrol);
}
Animate = true;
break;
}
}
// Free up resources
private void DisposeGL()
{
for (int T = 0; T < TIMER_MAX; T++)
{
Api.KillTimer(hFORM_Main, T + 1);
}
// Delete OpenGL font.
GI.DeleteGLFont(ref UseFont);
}
private void RenderOpenGL(IntPtr hContainer)
{
// Save the active planet zoom,
// then switch to a fixed zoom for the stellar background
int ZoomIs = GI.GetGLzoom(hGLcontrol);
SetZoom(45);
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
GL.glLoadIdentity();
// ***********************
// Draw the Sky background
// ***********************
GL.glDisable(GL.GL_LIGHT0); // Disable Light ZERO
GL.glDisable(GL.GL_LIGHTING); // Disable Lighting
GL.glDisable(GL.GL_COLOR_MATERIAL); // Disable Coloring Of Material
GL.glBindTexture(GL.GL_TEXTURE_2D, mt[STARS].Texture);
// Disable Depth Test
GL.glDisable(GL.GL_DEPTH_TEST);
GL.glBegin(GL.GL_QUADS);
GL.glTexCoord2f(0.0f, 0.0f); GL.glVertex3f(-60.0f, -50.0f, -80.0f); // Bottom left of texture and quad
GL.glTexCoord2f(1.0f, 0.0f); GL.glVertex3f(60.0f, -50.0f, -80.0f); // Bottom right
GL.glTexCoord2f(1.0f, 1.0f); GL.glVertex3f(60.0f, 50.0f, -80.0f); // Top right
GL.glTexCoord2f(0.0f, 1.0f); GL.glVertex3f(-60.0f, 50.0f, -80.0f); // Top left
GL.glEnd();
// ***********************
// Restore the previously saved Zoom to display the planet
SetZoom(ZoomIs);
// ***********************
// Draw the Globe texture
// ***********************
GL.glBindTexture(GL.GL_TEXTURE_2D, mt[0].Texture);
// Enable Depth Test
GL.glEnable(GL.GL_DEPTH_TEST);
GL.glEnable(GL.GL_LIGHT0); // Enable Light ZERO
GL.glEnable(GL.GL_LIGHTING); // Enable Lighting
GL.glEnable(GL.GL_COLOR_MATERIAL); // Enable Coloring Of Material
GL.glPushMatrix();
double Radius = 4.5;
double Twist = 0.0;
GI.UseGLPolarView(Radius, Twist, grSpinY, grSpinX);
int quadObj = GL.gluNewQuadric(); // Pointer to the Quadric Object (Return 0 If No Memory))
if (quadObj != 0)
{
GL.gluQuadricNormals(quadObj, GL.GLU_SMOOTH); // Create Smooth Normals
GL.gluQuadricTexture(quadObj, GL.GL_TRUE); // Create Texture Coords
GL.gluSphere(quadObj, 1.5, 48, 48);
GL.gluDeleteQuadric(quadObj);
}
GL.glPopMatrix();
// ***********************
// ***********************
// Display coordinates
// ***********************
if (OnOff.Checked)
{
int UseColor = Api.ARGB(255, 128, 0, 0);
int V = (int)grSpinY % 360;
int H = Math.Abs((int)grSpinX % 360); if (H > 180) H = 360 - H;
string MyStr = "Longitude " + H.ToString();
GI.DrawGLText(hContainer, ref UseFont, 10, 10, MyStr, UseColor);
int aLat = Math.Abs(V); V = 90 - (aLat % 90); if ((aLat % 180) > 90) V = (aLat % 180) - 90;
MyStr = "Latitude " + V.ToString();
GI.DrawGLText(hContainer, ref UseFont, 22, 10 + UseFont.fontHeight, MyStr, UseColor);
MyStr = "Zoom " + ((int)ZOOM_Track.Value).ToString();
GI.DrawGLText(hContainer, ref UseFont, 39, 10 + UseFont.fontHeight * 2, MyStr, UseColor);
}
// ***********************
// ***********************
// Draw the scene
// ***********************
GI.UpdateGLWindow(hContainer);
// ***********************
if (Animate)
{
grSpinY += grYincr;
grSpinX += grXincr;
}
}
private void ResetGlobe()
{
grSpinY = 75;
grSpinX = 0;
grYincr = 0f;
grXincr = 0f;
ZOOM_Track.Value = 50;
}
// ****************************************
private void FORM_Close(object sender, EventArgs e)
{
}
//***********************************************************
// We use the .NET template to resize the GDImage control
private void FORM_Resize(object sender, EventArgs e)
{
// Use the template to resize the GDImage OpenGL control
Api.MoveWindow(hGLcontrol, GL_Template.Location.X, GL_Template.Location.Y, GL_Template.Width, GL_Template.Height, true);
GI.ResizeGLWindow(hGLcontrol);
RenderOpenGL(hGLcontrol);
}
private void BTN_Start_Click(object sender, EventArgs e)
{
Animate = true;
grXincr = 0.05f;
}
private void BTN_Select_Click(object sender, EventArgs e)
{
GI.LoadSavePath(Api.ExePath(), true);
string sFileName = GI.LoadDialog(hFORM_Main);
if (sFileName != null)
{
GI.DoNotSquareTexture();
int NamedTexture = mt[GLOBE].Texture;
GI.UpdateNamedGLTextureFromFile(sFileName, NamedTexture);
}
}
private void BTN_Pause_Click(object sender, EventArgs e)
{
Animate = false;
}
private void BTN_Reset_Click(object sender, EventArgs e)
{
Animate = false;
ResetGlobe();
GI.SetGLzoom(hGLcontrol, 0); GI.ResizeGLWindow(hGLcontrol);
RenderOpenGL(hGLcontrol);
}
private void BTN_Up_Click(object sender, EventArgs e)
{
Animate = true; grYincr -= 0.05f;
}
private void BTN_Down_Click(object sender, EventArgs e)
{
Animate = true; grYincr += 0.05f;
}
private void BTN_Left_Click(object sender, EventArgs e)
{
Animate = true; grXincr -= 0.05f;
}
private void BTN_Right_Click(object sender, EventArgs e)
{
Animate = true; grXincr += 0.05f;
}
private void BTN_MouseEnter(object sender, EventArgs e)
{
Button btn = ((Button)sender);
SK.USE_BTN_Image(btn, 5);
}
private void BTN_MouseLeave(object sender, EventArgs e)
{
Button btn = ((Button)sender);
SK.USE_BTN_Image(btn, 1);
}
private void BTN_MouseUp(object sender, MouseEventArgs e)
{
Button btn = ((Button)sender);
SK.USE_BTN_Image(btn, 1);
}
private void BTN_MouseDown(object sender, MouseEventArgs e)
{
Button btn = ((Button)sender);
SK.USE_BTN_Image(btn, 2);
}
private void BTN_EnabledChanged(object sender, EventArgs e)
{
Button btn = ((Button)sender);
SK.InitButton(btn);
}
//Version 1.01
//_________________________________________________________________________
public static int glWndProc(IntPtr hWnd, int wMsg, uint wParam, uint lParam)
{
int x, y;
switch (wMsg)
{
case Api.WM_LBUTTONDOWN:
if (bMousing == false)
{
x = Api.LoWrd(lParam); y = Api.HiWrd(lParam);
ptLastMousePositX = x;
ptCurrentMousePositX = x;
ptLastMousePositY = y;
ptCurrentMousePositY = y;
bMousing = true;
}
if (Api.GetFocus() != hWnd) Api.SetFocus(hWnd);
break;
case Api.WM_LBUTTONUP:
bMousing = false;
break;
case Api.WM_MOUSEMOVE:
x = Api.LoWrd(lParam); y = Api.HiWrd(lParam);
if (GI.IsLButtonDown() == false)
{
bMousing = false;
}
else
{
if ((GLwasX != x) || (GLwasY != y))
{
ptCurrentMousePositX = x;
ptCurrentMousePositY = y;
if (bMousing)
{
grSpinX += (ptCurrentMousePositX - ptLastMousePositX);
grSpinY -= (ptCurrentMousePositY - ptLastMousePositY);
}
ptLastMousePositX = ptCurrentMousePositX;
ptLastMousePositY = ptCurrentMousePositY;
}
GLwasX = x; GLwasY = y;
}
break;
}
return Api.CallWindowProc(ghGLproc, hWnd, wMsg, wParam, lParam);
}
//_________________________________________________________________________
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -