首页
壁纸
直播
留言板
更多
视频
统计
友情链接
实用工具
Search
1
给孙小姐的一封情书
98 阅读
2
armUbuntu系统构建
47 阅读
3
armUbuntu | uboot常用指令
47 阅读
4
Linux | Linux通过stty命令操作串口设备(linux串口操作命令)
47 阅读
5
编译 openwrt 及初始配置-及部分排错
45 阅读
取次花丛懒回顾
默认分类
C#
MySQL
LabVIEW
Java
Android
PHP
Python
handsome
相册
百度地图
嵌入式
嵌入式Ubuntu
linux
Unity
Golang
Rust
Search
标签搜索
C#
handsome
Git
动态壁纸
开源
Unity3d
Unity
csharp
魔傲手记
累计撰写
115
篇文章
累计收到
18
条评论
首页
栏目
取次花丛懒回顾
默认分类
C#
MySQL
LabVIEW
Java
Android
PHP
Python
handsome
相册
百度地图
嵌入式
嵌入式Ubuntu
linux
Unity
Golang
Rust
页面
壁纸
直播
留言板
视频
统计
友情链接
实用工具
搜索到
2
篇与
的结果
2024-06-06
Unity 脚本 | Unity相机控制脚本(鼠标键盘控制,简单实用)
unity相机控制脚本,思路是仿照Unity Scene 里面控制的逻辑鼠标滚轮 上滚 拉近视野(放大),下滚 推远视野(缩小)鼠标滚轮 按下并拖动,调整相机位置鼠标右键 按下并拖动,调整相机视角左键留空w a s d 类似于 fps 游戏一样前后左右移动ctrl 向下移动空格 向上移动该脚本直接挂载在相机上就可以用using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class MouseOperationCameraRotationFovMove : MonoBehaviour { public enum MouseState { None, MidMouseBtn, LeftMouseBtn } private MouseState mMouseState = MouseState.None; private Camera mCamera; private void Awake() { mCamera = GetComponent<Camera>(); if (mCamera==null) { UnityEngine.Debug.LogError(GetType()+"camera Get Error ……"); } GetDefaultFov(); } private void LateUpdate() { CameraRotate(); CameraFOV(); CameraMove(); } #region Camera Rotation //旋转最大角度 public int yRotationMinLimit = -90; public int yRotationMaxLimit = 0; //旋转速度 public float xRotationSpeed = 250.0f; public float yRotationSpeed = 120.0f; //旋转角度 private float xRotation = 0.0f; private float yRotation = 0.0f; /// <summary> /// 鼠标右间点下移动进行旋转 /// </summary> void CameraRotate() { if (Input.GetMouseButton(1)) // 0:鼠标左键;1:鼠标右键;2:鼠标中键 { if (mMouseState == MouseState.None) { // 保存当前的旋转角度,默认为0,0的时候代表第一次,获取一下 Vector3 currentRotation = transform.rotation.eulerAngles; if (xRotation == 0.0f && yRotation == 0.0f) { // 暂时不知道为啥X和Y要反过来 yRotation = -currentRotation.x; xRotation = 360 - currentRotation.y; } //Input.GetAxis("MouseX")获取鼠标移动的X轴的距离 xRotation -= Input.GetAxis("Mouse X") * xRotationSpeed * 0.02f; yRotation += Input.GetAxis("Mouse Y") * yRotationSpeed * 0.02f; yRotation = ClampValue(yRotation, yRotationMinLimit, yRotationMaxLimit);//这个函数在结尾 //欧拉角转化为四元数 Quaternion rotation = Quaternion.Euler(-yRotation, -xRotation, 0); transform.rotation = rotation; } } } #endregion #region Camera fov //fov 最大最小角度 public int fovMinLimit = 25; public int fovMaxLimit = 75; //fov 变化速度 public float fovSpeed = 50.0f; //fov 角度 private float fov = 0.0f; void GetDefaultFov() { fov = mCamera.fieldOfView; } /// <summary> /// 滚轮控制相机视角缩放 /// </summary> public void CameraFOV() { //获取鼠标滚轮的滑动量 fov -= Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime * 100 * fovSpeed; // fov 限制修正 fov = ClampValue(fov,fovMinLimit, fovMaxLimit); //改变相机的 fov mCamera.fieldOfView = (fov); } #endregion #region Camera Move float _mouseX = 0; float _mouseY = 0; public float moveSpeed = 10; /// <summary> /// 中键控制拖动 /// </summary> public void CameraMove() { if (Input.GetMouseButton(2)) // 0:鼠标左键;1:鼠标右键;2:鼠标中键 { _mouseX = Input.GetAxis("Mouse X"); _mouseY = Input.GetAxis("Mouse Y"); //相机位置的偏移量(Vector3类型,实现原理是:向量的加法) Vector3 moveDir = (_mouseX * - transform.right + _mouseY * - transform.forward); //限制y轴的偏移量 moveDir.y = 0; transform.position += moveDir * 0.5f * moveSpeed; } else if (Input.GetMouseButtonDown(2)) { mMouseState = MouseState.MidMouseBtn; UnityEngine.Debug.Log(GetType() + "mMouseState = " + mMouseState.ToString()); } else if (Input.GetMouseButtonUp(2)) { mMouseState = MouseState.None; UnityEngine.Debug.Log(GetType() + "mMouseState = " + mMouseState.ToString()); } // WASD控制相机的前后左右移动 float horizontalInput = Input.GetAxis("Horizontal"); float verticalInput = Input.GetAxis("Vertical"); Vector3 direction = new Vector3(horizontalInput, 0, verticalInput).normalized; transform.Translate(direction * moveSpeed * Time.deltaTime); // Ctrl键控制相机向下移动 if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) { transform.Translate(Vector3.down * moveSpeed * Time.deltaTime); } // 空格键控制相机向上移动 if (Input.GetKey(KeyCode.Space)) { transform.Translate(Vector3.up * moveSpeed * Time.deltaTime); } } #endregion #region tools ClampValue //值范围值限定 float ClampValue(float value, float min, float max)//控制旋转的角度 { if (value < -360) value += 360; if (value > 360) value -= 360; return Mathf.Clamp(value, min, max);//限制value的值在min和max之间, 如果value小于min,返回min。 如果value大于max,返回max,否则返回value } #endregion }
2024年06月06日
24 阅读
0 评论
0 点赞
2018-05-20
C#,Aforge调用摄像头,实时处理图像,灰度化/二值化
https://img-blog.csdn.net/20180520180903818?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dhbmd5dTIzMw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70//声明全局函数private FilterInfoCollection videoDevices; private VideoCaptureDevice videoSource; private static int jj; //Aforge调用摄像头private void Form1_Load(object sender, EventArgs e) { videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); if (videoDevices.Count == 0) { throw new ApplicationException(); } foreach(FilterInfo device in videoDevices) { comboBox1.Items.Add(device.Name); } comboBox1.SelectedIndex = 0; } //链接摄像头private void button1_Click(object sender, EventArgs e) { CameraConn(); } private void CameraConn() { VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[comboBox1.SelectedIndex].MonikerString); videoSourcePlayer1.VideoSource = videoSource; videoSourcePlayer1.Start(); } //捕获摄像头当前画面,生成灰度化图片private void button2_Click_1(object sender, EventArgs e) { pictureBox1.Image= videoSourcePlayer1.GetCurrentVideoFrame(); } //捕获摄像头当前画面,生成成二值化图片private void button2_Click(object sender, EventArgs e) { Bitmap b = videoSourcePlayer1.GetCurrentVideoFrame(); pictureBox1.Image = ConvertTo1Bpp1(b); } --------------------------------------------------------灰度化,二值化函数操作方法-------------------------------------------// 图像灰度化操作函数public static Bitmap ToGray(Bitmap bmp){ for (int i = 0; i < bmp.Width; i++) { for (int j = 0; j < bmp.Height; j++) { //获取该点的像素的RGB的颜色 Color color = bmp.GetPixel(i, j); //利用公式计算灰度值 int gray = (int)(color.R * 0.3 + color.G * 0.59 + color.B * 0.11); Color newColor = Color.FromArgb(gray, gray, gray); bmp.SetPixel(i, j, newColor); } } return bmp; } // 图像二值化1:取图片的平均灰度作为阈值,低于该值的全都为0,高于该值的全都为255public static Bitmap ConvertTo1Bpp1(Bitmap bmp){ int average = 0; average = 122; jj = average; //将阈值传递出来 for (int i = 0; i < bmp.Width; i++) { for (int j = 0; j < bmp.Height; j++) { //获取该点的像素的RGB的颜色 Color color = bmp.GetPixel(i, j); int value = 255 - color.B; Color newColor = value > average ? Color.FromArgb(0, 0, 0) : Color.FromArgb(255, 255, 255); bmp.SetPixel(i, j, newColor); } } return bmp; } //用到的指令集using AForge.Video.DirectShow; using System; using System.Drawing; using System.IO; using System.Windows.Forms;
2018年05月20日
16 阅读
1 评论
0 点赞