资源简介
它画了一个手脚能动的机器人, 场景做360度旋转, 可以观察到机器人每个面.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SharpGL;
namespace SharpGLWinformsApplication1
{
public partial class SharpGLForm : Form
{
public float angle; // 机器人绕视点旋转的角度
float[] legAngle = new float[2]; // 腿的当前旋转角度
float[] armAngle = new float[2]; // 胳膊的当前旋转角度
bool leg1 = true; // 机器人腿的状态,true向前,flase向后
bool leg2 = false;
bool arm1 = true;
bool arm2 = false;
private float rotation = 0.0f;
public SharpGLForm()
{
InitializeComponent();
angle = 0.0f; // 设置初始角度为0
legAngle[0] = legAngle[1] = 0.0f;
armAngle[0] = armAngle[1] = 0.0f;
}
private void openGLControl_OpenGLDraw(object sender, PaintEventArgs e)
{
OpenGL gl = openGLControl.OpenGL;
gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
gl.LoadIdentity();
gl.Rotate(rotation, 0.0f, 1.0f, 0.0f);
drawGrid(gl);
DrawRobot(ref gl, 0, 0, 0);
//rtest(ref gl, 0, 0, 0);
rotation = 1.0f;
}
private void openGLControl_OpenGLInitialized(object sender, EventArgs e)
{
OpenGL gl = openGLControl.OpenGL;
gl.ClearColor(0, 0, 0, 0);
}
private void openGLControl_Resized(object sender, EventArgs e)
{
OpenGL gl = openGLControl.OpenGL;
gl.MatrixMode(OpenGL.GL_PROJECTION);
gl.LoadIdentity();
gl.Perspective(60.0f, (double)Width / (double)Height, 0.01, 100.0);
gl.LookAt(-5, 5, 15, 0, 0, 0, 0, 1, 0);
gl.MatrixMode(OpenGL.GL_MODELVIEW);
}
//测试例子
public void rtest(ref OpenGL gl, float xPos, float yPos, float zPos)
{
gl.PushMatrix();
{
gl.Color(1f, 0f, 0f);
gl.Translate(xPos, yPos, zPos);
gl.Scale(2f, 1f, 1f);
gl.Rotate(45, 1f, 0f, 0f);
DrawCube(ref gl, 0, 0, 0, true);
}
gl.PopMatrix();
gl.PushMatrix();
{
gl.Color(0f, 1f, 0f);
gl.Translate(xPos - 2f, yPos, zPos);
DrawCube(ref gl, 0, 0, 0, true);
}
gl.PopMatrix();
}
public void DrawRobot(ref OpenGL Gl, float xPos, float yPos, float zPos)
{
Gl.PushMatrix();
{
Gl.Translate(xPos, yPos, zPos);
///绘制各个部分
//Gl.LoadIdentity();
DrawHead(ref Gl, 1f, 2f, 0f); // 绘制头部 2*2*2
DrawTorso(ref Gl, 1.5f, 0.0f, 0.0f); //躯干, 3*5*2
Gl.PushMatrix();
{
//如果胳膊正在向前运动,则递增角度,否则递减角度
if (arm1)
armAngle[0] = armAngle[0] 1f;
else
armAngle[0] = armAngle[0] - 1f;
///如果胳膊达到其最大角度则改变其状态
if (armAngle[0] >= 15.0f)
arm1 = false;
if (armAngle[0] <= -15.0f)
arm1 = true;
//平移并旋转后绘制胳膊
Gl.Translate(0.0f, -0.5f, 0.0f);
Gl.Rotate(armAngle[0], 1.0f, 0.0f, 0.0f);
DrawArm(ref Gl, 2.5f, 0.0f, -0.5f); //胳膊1, 1*4*1
}
Gl.PopMatrix();
Gl.PushMatrix();
{
if (arm2)
armAngle[1] = armAngle[1] 1f;
else
armAngle[1] = armAngle[1] - 1f;
if (armAngle[1] >= 15.0f)
arm2 = false;
if (armAngle[1] <= -15.0f)
arm2 = true;
Gl.Translate(0.0f, -0.5f, 0.0f);
Gl.Rotate(armAngle[1], 1.0f, 0.0f, 0.0f);
DrawArm(ref Gl, -1.5f, 0.0f, -0.5f); //胳膊2, 1*4*1
}
Gl.PopMatrix();
Gl.PushMatrix();
{
///如果腿正在向前运动,则递增角度,否则递减角度
if (leg1)
legAngle[0] = legAngle[0] 1f;
else
legAngle[0] = legAngle[0] - 1f;
///如果腿达到其最大角度则改变其状态
if (legAngle[0] >= 15.0f)
leg1 = false;
if (legAngle[0] <= -15.0f)
leg1 = true;
///平移并旋转后绘制胳膊
Gl.Translate(0.0f, -0.5f, 0.0f);
Gl.Rotate(legAngle[0], 1.0f, 0.0f, 0.0f);
DrawLeg(ref Gl, -0.5f, -5.0f, -0.5f); //腿部1,1*5*1
}
Gl.PopMatrix();
Gl.PushMatrix();
{
if (leg2)
legAngle[1] = legAngle[1] 1f;
else
legAngle[1] = legAngle[1] - 1f;
if (legAngle[1] >= 15.0f)
leg2 = false;
if (legAngle[1] <= -15.0f)
leg2 = true;
Gl.Translate(0.0f, -0.5f, 0.0f);
Gl.Rotate(legAngle[1], 1.0f, 0.0f, 0.0f);
DrawLeg(ref Gl, 1.5f, -5.0f, -0.5f); //腿部2, 1*5*1
}
Gl.PopMatrix();
}
Gl.PopMatrix();
}
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace SharpGLWinformsApplication1
{
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.EnableVisualstyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new SharpGLForm());
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-08-23 08:39 robot\
目录 0 2020-11-23 21:33 robot\SharpGLWinformsApplication1\
目录 0 2020-11-23 21:33 robot\SharpGLWinformsApplication1\.vs\
目录 0 2020-11-23 21:33 robot\SharpGLWinformsApplication1\.vs\SharpGLWinformsApplication1\
目录 0 2020-11-23 21:33 robot\SharpGLWinformsApplication1\.vs\SharpGLWinformsApplication1\v15\
文件 46080 2020-11-26 10:38 robot\SharpGLWinformsApplication1\.vs\SharpGLWinformsApplication1\v15\.suo
目录 0 2020-11-23 21:33 robot\SharpGLWinformsApplication1\.vs\SharpGLWinformsApplication1\v15\Server\
目录 0 2020-11-23 21:33 robot\SharpGLWinformsApplication1\.vs\SharpGLWinformsApplication1\v15\Server\sqlite3\
文件 0 2020-11-23 21:33 robot\SharpGLWinformsApplication1\.vs\SharpGLWinformsApplication1\v15\Server\sqlite3\db.lock
文件 589824 2020-11-26 10:27 robot\SharpGLWinformsApplication1\.vs\SharpGLWinformsApplication1\v15\Server\sqlite3\storage.ide
文件 32768 2020-11-25 21:31 robot\SharpGLWinformsApplication1\.vs\SharpGLWinformsApplication1\v15\Server\sqlite3\storage.ide-shm
文件 4120032 2020-11-26 10:31 robot\SharpGLWinformsApplication1\.vs\SharpGLWinformsApplication1\v15\Server\sqlite3\storage.ide-wal
目录 0 2020-11-26 10:31 robot\SharpGLWinformsApplication1\SharpGLWinformsApplication1\
文件 923 2016-08-23 08:39 robot\SharpGLWinformsApplication1\SharpGLWinformsApplication1.sln
文件 20992 2016-08-23 11:04 robot\SharpGLWinformsApplication1\SharpGLWinformsApplication1.suo
文件 144 2016-08-23 08:39 robot\SharpGLWinformsApplication1\SharpGLWinformsApplication1\app.config
目录 0 2016-08-23 08:39 robot\SharpGLWinformsApplication1\SharpGLWinformsApplication1\bin\
目录 0 2020-11-23 21:36 robot\SharpGLWinformsApplication1\SharpGLWinformsApplication1\bin\Debug\
文件 357888 2012-02-21 16:19 robot\SharpGLWinformsApplication1\SharpGLWinformsApplication1\bin\Debug\SharpGL.dll
文件 141824 2012-02-21 16:19 robot\SharpGLWinformsApplication1\SharpGLWinformsApplication1\bin\Debug\SharpGL.SceneGraph.dll
文件 19456 2012-02-21 16:19 robot\SharpGLWinformsApplication1\SharpGLWinformsApplication1\bin\Debug\SharpGL.WinForms.dll
文件 14848 2020-11-26 10:31 robot\SharpGLWinformsApplication1\SharpGLWinformsApplication1\bin\Debug\SharpGLWinformsApplication1.exe
文件 144 2016-08-23 08:39 robot\SharpGLWinformsApplication1\SharpGLWinformsApplication1\bin\Debug\SharpGLWinformsApplication1.exe.config
文件 28160 2020-11-26 10:31 robot\SharpGLWinformsApplication1\SharpGLWinformsApplication1\bin\Debug\SharpGLWinformsApplication1.pdb
文件 11600 2016-08-23 11:04 robot\SharpGLWinformsApplication1\SharpGLWinformsApplication1\bin\Debug\SharpGLWinformsApplication1.vshost.exe
文件 144 2016-08-23 08:39 robot\SharpGLWinformsApplication1\SharpGLWinformsApplication1\bin\Debug\SharpGLWinformsApplication1.vshost.exe.config
文件 490 2010-03-17 22:39 robot\SharpGLWinformsApplication1\SharpGLWinformsApplication1\bin\Debug\SharpGLWinformsApplication1.vshost.exe.manifest
目录 0 2020-11-23 21:36 robot\SharpGLWinformsApplication1\SharpGLWinformsApplication1\Dependencies\
文件 357888 2012-02-21 16:19 robot\SharpGLWinformsApplication1\SharpGLWinformsApplication1\Dependencies\SharpGL.dll
文件 141824 2012-02-21 16:19 robot\SharpGLWinformsApplication1\SharpGLWinformsApplication1\Dependencies\SharpGL.SceneGraph.dll
文件 18944 2012-02-21 16:19 robot\SharpGLWinformsApplication1\SharpGLWinformsApplication1\Dependencies\SharpGL.Serialization.dll
............此处省略31个文件信息
- 上一篇:手机聊天程序(xamarin开发案例)
- 下一篇:OAUS源码
相关资源
- 手机聊天程序(xamarin开发案例)
- Winform图表(MSChart)
- bartender二次开发
- C# 8 Code sample:Using declarations(ef-cor
- Eslaticsearch 操作(EasyElasticSearch)
- 桔园施肥计算(ESRI.ArcGIS)
- 计算不规则格网土方量计算 Calculati
- HMI-with-WPF-part-3-Communication-with-multipl
- 空间拓扑查询(ArcEngine)
- C# 调用BarTender打印条码DEMO
- 试题库管理系统毕业论文(C#)源程序
- 亮剑ASP.NET项目开发案例导航-part03共三
- C#自定义控件案例--美化GroupBox.rar
- ASP.net MVC vcard名片二维码自动生成
- C#车牌识别系统.rar
- c# 完全参考手册大全.rar
- asp.net 在线聊天室系统源代码.rar
- Bunifu_Ui_WinForms_v1.10.0.0_Downloadly.ir.rar
-
cef_binary_32_64双版包和pepflashpla
yer. - delta机器人运动学算法正向逆向求解
- C#远程控制软件TwoCare完美无错源代码
- 华视CVR100开发SDK说明+C#案例.rar
- Mqttnet.rar
-
Pro C# 5.0 and the .NET 4.5 fr
amework - Csharp 网上商城代码
- ASP.NET网站建设实战--人民邮电出版社
- 电子病历系统.rar
- HelixToolkitWPF中文手册.rar
- Winform通用经典快速开发CS框架-outloo
- [Csharp高级编程(第6版)].美内格尔
评论
共有 条评论