資源簡介
3D直角坐標系演示控件,使用C#和OpenTK(基于OpenGL)編寫,具有如下特點:
1.帶有一個空間方位指針。指針指向可由方向角和俯仰角確定。
2.實現了鼠標軌跡球(ArcBall)功能。可以用鼠標拖動直角坐標系任意旋轉,運行流暢,查看靈活。

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Drawing;
using?System.Data;
using?System.Text;
using?System.Windows.Forms;
using?OpenTK;
using?OpenTK.Graphics;
namespace?AxlesGL
{
public?partial?class?Axles3D?:?GLControl
{
bool?_loaded?=?false;
double?_azi?_ele;
double?_angleX?_angleY?_angleZ;
//?旋轉角度
float?theta?=?0.0f;
//?旋轉軸
float[]?axis?=?{?1.0f?0.0f?0.0f?};
//?鼠標上次和當前坐標(映射到單位半球面)
float[]?lastPos?=?{?0.0f?0.0f?0.0f?};
float[]?curPos?=?{?0.0f?0.0f?0.0f?};
//?上一次轉換矩陣
float[]?lastMatrix?=
{
1.0f?0.0f?0.0f?0.0f
0.0f?1.0f?0.0f?0.0f
0.0f?0.0f?1.0f?0.0f
0.0f?0.0f?0.0f?1.0f
};
public?double?Azimuth
{
get
{
return?_azi;
}
set
{
_azi?=?value;
if?(_loaded)
DrawAll();
}
}
public?double?Elevation
{
get
{
return?_ele;
}
set
{
_ele?=?value;
if?(_loaded)
DrawAll();
}
}
public?double?AngleX
{
get
{
return?_angleX;
}
set
{
_angleX?=?value;
if?(_loaded)
DrawAll();
}
}
public?double?AngleY
{
get
{
return?_angleY;
}
set
{
_angleY?=?value;
if?(_loaded)
DrawAll();
}
}
public?double?AngleZ
{
get
{
return?_angleZ;
}
set
{
_angleZ?=?value;
if?(_loaded)
DrawAll();
}
}
public?Axles3D()
{
InitializeComponent();
AngleY?=?30;
AngleZ?=?-30;
}
private?void?Axles3D_Resize(object?sender?EventArgs?e)
{
if?(_loaded)
{
DrawAll();
}
}
private?void?Axles3D_Paint(object?sender?PaintEventArgs?e)
{
if?(_loaded)
{
DrawAll();
}
}
private?void?DrawAll()
{
//SETGL
GL.Enable(EnableCap.Blend);
GL.Enable(EnableCap.DepthTest);
GL.ShadeModel(ShadingModel.Smooth);
GL.ClearColor(Color.Black);
GL.ClearColor(1.0f?1.0f?0.5f?0.7f);
GL.BlendFunc(BlendingFactorSrc.SrcAlpha?BlendingFactorDest.OneMinusSrcAlpha);
//SETVIEW
GL.Viewport(0?0?this.Bounds.Width?this.Bounds.Height);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
Glu.Perspective(45.0f?(float)this.Bounds.Width?/?(float)this.Bounds.Height?1.0?10.0);
Glu.LookAt(0.0?0.0?4.0?0.0?0.0?3.0?0.0?1.0?0.0);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
GL.Clear(ClearBufferMask.ColorBufferBit?|?ClearBufferMask.DepthBufferBit);
//?計算新的旋轉矩陣,即:M?=?E?·?R?=?R
GL.Rotate(theta?axis[0]?axis[1]?axis[2]);
//?左乘上前一次的矩陣,即:M?=?R?·?L
GL.MultMatrix(lastMatrix);
//?保存此次處理結果,即:L?=?M
GL.GetFloat(GetPName.ModelviewMatrix?lastMatrix);
theta?=?0.0f;
//?畫坐標軸
DrawOLineInGL(0?0?1.1f?2.0f?Color.Red?true);
DrawOLineInGL(Math.PI?0?1.1f?2.0f?Color.Red?false);
DrawOLineInGL(Math.PI?/?2?0?1.1f?2.0f?Color.Lime?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1392??2018-05-11?10:01??3D坐標系演示\3D坐標系演示.sln
????..A..H.?????30720??2011-07-05?01:13??3D坐標系演示\3D坐標系演示.suo
????..A..H.?????30720??2011-07-05?01:13??3D坐標系演示\3D坐標系演示.v11.suo
?????文件???????8259??2011-07-05?01:11??3D坐標系演示\AxlesGL\Axles3D.cs
?????文件???????1442??2011-07-04?19:31??3D坐標系演示\AxlesGL\Axles3D.Designer.cs
?????文件???????5814??2011-07-04?19:31??3D坐標系演示\AxlesGL\Axles3D.resx
?????文件???????3515??2018-05-11?10:01??3D坐標系演示\AxlesGL\AxlesGL.csproj
?????文件??????11264??2018-05-11?10:01??3D坐標系演示\AxlesGL\bin\Debug\AxlesGL.dll
?????文件??????24064??2018-05-11?10:01??3D坐標系演示\AxlesGL\bin\Debug\AxlesGL.pdb
?????文件????3223552??2010-10-07?00:48??3D坐標系演示\AxlesGL\bin\Debug\OpenTK.Compatibility.dll
?????文件????2719744??2010-10-07?00:47??3D坐標系演示\AxlesGL\bin\Debug\OpenTK.dll
?????文件??????24576??2010-10-07?00:47??3D坐標系演示\AxlesGL\bin\Debug\OpenTK.GLControl.dll
?????文件???????5904??2010-10-07?00:47??3D坐標系演示\AxlesGL\bin\Debug\OpenTK.GLControl.xm
?????文件????3843235??2010-10-07?00:47??3D坐標系演示\AxlesGL\bin\Debug\OpenTK.xm
?????文件????????180??2018-05-11?10:01??3D坐標系演示\AxlesGL\obj\Debug\AxlesGL.Axles3D.resources
?????文件???????1254??2018-05-11?10:01??3D坐標系演示\AxlesGL\obj\Debug\AxlesGL.csproj.FileListAbsolute.txt
?????文件????????776??2018-05-11?10:01??3D坐標系演示\AxlesGL\obj\Debug\AxlesGL.csproj.GenerateResource.Cache
?????文件??????17214??2018-05-11?10:01??3D坐標系演示\AxlesGL\obj\Debug\AxlesGL.csprojResolveAssemblyReference.cache
?????文件??????11264??2018-05-11?10:01??3D坐標系演示\AxlesGL\obj\Debug\AxlesGL.dll
?????文件??????24064??2018-05-11?10:01??3D坐標系演示\AxlesGL\obj\Debug\AxlesGL.pdb
?????文件???????6854??2018-05-11?10:01??3D坐標系演示\AxlesGL\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件???????4575??2018-05-11?10:01??3D坐標系演示\AxlesView\AxlesView.csproj
?????文件??????11264??2018-05-11?10:01??3D坐標系演示\AxlesView\bin\Debug\AxlesGL.dll
?????文件??????24064??2018-05-11?10:01??3D坐標系演示\AxlesView\bin\Debug\AxlesGL.pdb
?????文件???????9216??2018-05-11?10:01??3D坐標系演示\AxlesView\bin\Debug\AxlesView.exe
?????文件??????22016??2018-05-11?10:01??3D坐標系演示\AxlesView\bin\Debug\AxlesView.pdb
?????文件??????21464??2018-05-11?10:02??3D坐標系演示\AxlesView\bin\Debug\AxlesView.vshost.exe
?????文件????????490??2012-06-06?02:06??3D坐標系演示\AxlesView\bin\Debug\AxlesView.vshost.exe.manifest
?????文件????3223552??2010-10-07?00:48??3D坐標系演示\AxlesView\bin\Debug\OpenTK.Compatibility.dll
?????文件????2719744??2010-10-07?00:47??3D坐標系演示\AxlesView\bin\Debug\OpenTK.dll
............此處省略60個文件信息
- 上一篇:基于RFID的RSSI測距
- 下一篇:c#工資管理系統+文檔只供參考
評論
共有 條評論