winform也想做三维模拟?我都帮你试过啦!

准备

Unity 5.3.8f VisualStudio2008 ,webPlayerControl插件

1.Unity处理

1.创建Scene场景,给cube添加移动脚本Move.cs

在这里插入图片描述在这里插入图片描述

2.Scene场景打包,注意发布webPlayer版本,Offline Depleyment离线也可运行

在这里插入图片描述打包出来的文件如下,tt.unity3d的路径就是webplayercontrol所需的路径
在这里插入图片描述

2.VisualStudio处理

1.新建winform项目,并引入UnityWebPlayer Control控件

工具箱下选择常规并右键,点击选择项,出现如下图,COM组件勾选UnityWebPlayer Control即可
在这里插入图片描述

2.搭建界面,添加按钮和文本分别用于发送消息和接收,添加UnityWebPlayerControl组件,

在这里插入图片描述查看属性src,填入刚才的路径。
在这里插入图片描述

3.双击按钮和webPlayercontro组件,进入代码页,并添加代码

方法1.点击按钮,给Unity发送消息,该方法会找到unity里的名为“Cube”的物体,调用他本身的Down方法,(并传参数,根据方法有无均可)
方法2. 在Label上显示接收的Unity消息
在这里插入图片描述

3.运行查看。

点击SendToWinform按钮,可以看到winform接收到消息并显示出“SendToWindows”
点击SendToUnity按钮,可以看到Unity场景里的cube物体上升

如此一来,实现了winform与Unity3d 的消息互通。
在这里插入图片描述

  • 3
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在WinForm绘制三维曲线,你可以使用OpenGL或DirectX等图形渲染库。这些库可以让你在三维空间中绘制对象和曲线。下面是一个使用OpenGL进行三维曲线绘制的示例代码: 1. 首先,你需要在WinForm中添加一个OpenGL控件。可以使用OpenTK库来实现: ``` using OpenTK.Graphics.OpenGL; using OpenTK; public partial class Form1 : Form { private GLControl glControl; public Form1() { InitializeComponent(); glControl = new GLControl(); this.Controls.Add(glControl); } } ``` 2. 然后,你需要在OpenGL控件的Paint事件中绘制三维曲线。使用glBegin(GL_LINE_STRIP)函数启动绘制线段的过程,使用glVertex3f(x, y, z)函数指定每个点的坐标,使用glEnd()函数结束绘制。 ``` private void glControl_Paint(object sender, PaintEventArgs e) { GL.ClearColor(Color.Black); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.Viewport(0, 0, glControl.Width, glControl.Height); GL.Perspective(45.0f, (float)glControl.Width / (float)glControl.Height, 0.1f, 100.0f); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); GL.Translate(0.0f, 0.0f, -6.0f); GL.Begin(BeginMode.LineStrip); for (float x = -1.0f; x <= 1.0f; x += 0.01f) { float y = (float)Math.Sin(x * 10.0f) * 0.5f; float z = x; GL.Vertex3(x, y, z); } GL.End(); glControl.SwapBuffers(); } ``` 这个例子绘制了一条沿着x轴的三维正弦曲线。你可以修改顶点的坐标来绘制其他曲线。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值