• 大小: 937KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-25
  • 语言: C#
  • 标签: c#  

资源简介

主要基于c#语言,在OpenGL绘图窗口上使用鼠标对既有的图形进行空间的缩放与旋转

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SharpGL;


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        float _x _yzs=0;
        float clickX clickY ddx ddy;
        bool clicKtf;
        public Form1()
        {
            InitializeComponent();
            this.openGLControl1.MouseWheel += new MouseEventHandler(openGLControl1_MouseWheel);
        }

        private void openGLControl1_OpenGLDraw(object sender RenderEventArgs args)
        {
            SharpGL.OpenGL gl = this.openGLControl1.OpenGL;
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.LoadIdentity(); // 重置
            gl.Translate(0 0 zs-10);    // 设置坐标,距离屏幕距离为10  
            gl.Rotate(_x 1.0f 0.0f 0.0f);
            gl.Rotate(_y 0.0f 1.0f 0.0f);
            gl.Begin(OpenGL.GL_QUADS);
            {
                gl.Color(1.0f 0.0f 1.0f);
                gl.Vertex(1f -1f 0f);
                gl.Color(0.0f 1.0f 1.0f);
                gl.Vertex(1f 1f 0f);
                gl.Color(0.0f 1.0f 0.0f);
                gl.Vertex(-1f 1f 0f);
                gl.Color(1.0f 1.0f 0.0f);
                gl.Vertex(-1f -1f 0f);
            }
            gl.End();
        }
        private void openGLControl_OpenGLInitialized(object sender EventArgs e)
        {

            OpenGL gl = openGLControl1.OpenGL;
            gl.ClearColor(1 0 1 0);
        }

        private void openGLControl1_MouseMove_1(object sender MouseEventArgs e)
        {
            if (clicKtf)
            {
                _y = ddx + e.X - clickX;
                _x = ddy + e.Y - clickY;
            }
        }

        private void openGLControl1_MouseUp_1(object sender MouseEventArgs e)
        {
            clicKtf = false;
            ddx = _y;
            ddy = _x;
        }

        private void openGLControl1_MouseDown_1(object sender MouseEventArgs e)
        {
            clicKtf = true;
            clickX = e.X;
            clickY = e.Y;
        }

        /// 
        /// Handles the Resized event of the openGLControl control.
        /// 

        /// The source of the event.
        /// The  instance containing the event data.
        private void openGLControl_Resized(object sender EventArgs e)
        {
           
            OpenGL gl = openGLControl1.OpenGL;

            gl.MatrixMode(OpenGL.GL_PROJECTION);
            gl.LoadIdentity();

            gl.Perspective(90.0f (double)Width / (double)Height 0.01 100.0);

            gl.LookAt(0 0 -5 5 5 0 0 1 0);

            gl.MatrixMode(OpenGL.GL_MODELVIEW);
  

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-11-28 17:53  鼠标控制\
     目录           0  2018-03-07 08:49  鼠标控制\WindowsFormsApplication1\
     目录           0  2017-11-28 17:53  鼠标控制\WindowsFormsApplication1\.vs\
     目录           0  2017-11-28 17:53  鼠标控制\WindowsFormsApplication1\.vs\WindowsFormsApplication1\
     目录           0  2017-11-28 17:53  鼠标控制\WindowsFormsApplication1\.vs\WindowsFormsApplication1\v14\
     文件       30720  2018-03-07 08:49  鼠标控制\WindowsFormsApplication1\.vs\WindowsFormsApplication1\v14\.suo
     文件         189  2017-11-28 17:17  鼠标控制\WindowsFormsApplication1\App.config
     文件        2886  2017-11-28 17:50  鼠标控制\WindowsFormsApplication1\Form1.Designer.cs
     文件        3337  2018-03-07 08:44  鼠标控制\WindowsFormsApplication1\Form1.cs
     文件        5817  2017-11-28 17:50  鼠标控制\WindowsFormsApplication1\Form1.resx
     文件         536  2017-11-28 17:17  鼠标控制\WindowsFormsApplication1\Program.cs
     目录           0  2017-11-28 17:53  鼠标控制\WindowsFormsApplication1\Properties\
     文件        1356  2017-11-28 17:17  鼠标控制\WindowsFormsApplication1\Properties\AssemblyInfo.cs
     文件        2861  2017-11-28 17:17  鼠标控制\WindowsFormsApplication1\Properties\Resources.Designer.cs
     文件        5612  2017-11-28 17:17  鼠标控制\WindowsFormsApplication1\Properties\Resources.resx
     文件        1111  2017-11-28 17:17  鼠标控制\WindowsFormsApplication1\Properties\Settings.Designer.cs
     文件         249  2017-11-28 17:17  鼠标控制\WindowsFormsApplication1\Properties\Settings.settings
     文件        5318  2017-11-28 17:24  鼠标控制\WindowsFormsApplication1\WindowsFormsApplication1.csproj
     文件        1368  2018-03-07 08:49  鼠标控制\WindowsFormsApplication1\WindowsFormsApplication1.sln
     目录           0  2017-11-28 17:53  鼠标控制\WindowsFormsApplication1\bin\
     目录           0  2018-03-07 08:31  鼠标控制\WindowsFormsApplication1\bin\Debug\
     文件      143872  2014-04-01 12:15  鼠标控制\WindowsFormsApplication1\bin\Debug\SharpGL.SceneGraph.dll
     文件      568832  2014-04-01 12:15  鼠标控制\WindowsFormsApplication1\bin\Debug\SharpGL.SceneGraph.pdb
     文件      260726  2014-04-01 12:15  鼠标控制\WindowsFormsApplication1\bin\Debug\SharpGL.SceneGraph.xml
     文件       21504  2014-04-01 12:15  鼠标控制\WindowsFormsApplication1\bin\Debug\SharpGL.WinForms.dll
     文件       44544  2014-04-01 12:15  鼠标控制\WindowsFormsApplication1\bin\Debug\SharpGL.WinForms.pdb
     文件       13865  2014-04-01 12:15  鼠标控制\WindowsFormsApplication1\bin\Debug\SharpGL.WinForms.xml
     文件      366592  2014-04-01 12:15  鼠标控制\WindowsFormsApplication1\bin\Debug\SharpGL.dll
     文件      441856  2014-04-01 12:15  鼠标控制\WindowsFormsApplication1\bin\Debug\SharpGL.pdb
     文件      264280  2014-04-01 12:15  鼠标控制\WindowsFormsApplication1\bin\Debug\SharpGL.xml
     文件       10752  2018-03-07 08:44  鼠标控制\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe
............此处省略53个文件信息

评论

共有 条评论