博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
根据模型大小,限定摄像头旋转角度(上,下,左,右)
阅读量:7107 次
发布时间:2019-06-28

本文共 3393 字,大约阅读时间需要 11 分钟。

hot3.png

思路:

  1. 首先确定Sensor上报数据控制的是摄像头角度旋转

  2. 所以限定摄像头旋转角度的脚本要挂在摄像头上

  3. 确定视角边界

  4. 查看效果

using UnityEngine;using System.Collections;public class cameraControl : MonoBehaviour {	private Vector3 euler;	private Vector2 startPos;	private Vector2 startPospa;	private string uilog;	private bool displayUI;	private float timer;	private Quaternion originalRotation;	private Quaternion yLeftBorderRotation;	private Quaternion yRightBorderRotation;	private Quaternion xDownBorderRotation;	private Quaternion xUptBorderRotation;	// Use this for initialization	void Start () {		displayUI = false;		originalRotation=transform.rotation;		yLeftBorderRotation = Quaternion.Euler (0.25f, 336.5f, 0f);		yRightBorderRotation = Quaternion.Euler (359.25f, 28f,0f);		xDownBorderRotation = Quaternion.Euler (13f, 359.75f,0f);		xUptBorderRotation = Quaternion.Euler (342.25f, 1.5f,0f);		Debug.Log ("Martin "+originalRotation.x+","+originalRotation.y+","+originalRotation.z+",");	}		// Update is called once per frame	void Update () {		//update rotate		rotateUpdate ();			//timer		if ((Time.time - timer) > 2.0f) {			displayUI = false;				}	}		//rotate update	void rotateUpdate()	{		float x=transform.rotation.eulerAngles.x;		float y=transform.rotation.eulerAngles.y;		Vector3 m= transform.eulerAngles;		Debug.Log("Martin Vector eulerAngles m.x :"+m.x);		Debug.Log("Martin Vector eulerAngles m.x :"+m.y);		Debug.Log("Martin Vector eulerAngles m.x :"+m.z);		Debug.Log("Martin x :"+x);		Debug.Log("Martin y :"+y);		if(y<336.5f && x>0.26f){			transform.rotation=yLeftBorderRotation;		}else if(y>28f && x<360f){			transform.rotation=yRightBorderRotation;		}else if(x>13f && y<360f){			transform.rotation=xDownBorderRotation;		}else if(x<343f && y>1.5f){			transform.rotation=xUptBorderRotation;		}#if !UNITY_ANDROID || UNITY_EDITOR		if(Input.GetMouseButton(0))		{			euler.x -= Input.GetAxis ("Mouse Y") * 5;			euler.y += Input.GetAxis ("Mouse X") * 5;			Quaternion qua = Quaternion.Euler (euler.x, euler.y,0f);			transform.rotation = qua;			//Quaternion originalRotation=transform.rotation;			//	float m=transform.Rotate.x						}#else		if (Input.touchCount > 0) {			var touch = Input.GetTouch(0);						// Handle finger movements based on touch phase.			switch (touch.phase) {				// Record initial touch position.			case TouchPhase.Began:				startPos = touch.position;				startPospa = touch.position;				break;								// Determine direction by comparing the current touch position with the initial one.			case TouchPhase.Moved:				Vector2 delta = touch.position - startPos;				euler.x -= delta.y*0.1f;				euler.y += delta.x*0.1f;				Debug.Log("tclogposition " + delta.x + " " + delta.y);				Quaternion qua = Quaternion.Euler (euler.x, euler.y,0f);				transform.rotation = qua;				startPos = touch.position;				break;								// Report that a direction has been chosen when the finger is lifted.			case TouchPhase.Ended:				Vector2 deltaa = touch.position - startPospa;				if(deltaa.magnitude < 0.01f)				{					doclick();					displayUI = true;					timer = Time.time;				}				break;			}		}#endif	}	private bool isVisible = true;	void doclick()	{		uilog = "pa pa pa ...";		Debug.Log ("pa pa pa ...");		OVRManager.eventFromSensor = keyEvent.Enter;	//	OVRManager.eventFromSensor = keyEvent.Enter;	}//	void OnGUI()//	{//		if (displayUI) {//			GUI.Label (new Rect(300f,200f,200f,100f), uilog);//		}////	}	}

102845_IV1p_2611390.png

102845_hH02_2611390.jpg

103056_fZiw_2611390.png

转载于:https://my.oschina.net/martindudu/blog/602722

你可能感兴趣的文章
Android Design
查看>>
使用pure-ftpd搭建ftp服务
查看>>
交换机相关
查看>>
RSA的数学及算法实现
查看>>
Spark中narrow dependency和wide dependency
查看>>
【尖端干货】H.264编码下直播视频添加水印的优化
查看>>
maildir 邮件文件名 记录
查看>>
在线模拟HTTP请求
查看>>
如何对压缩文件设置解压密码
查看>>
Linux运维学习之LNMP搭建"小米商城"
查看>>
#if #ifdef使用小记
查看>>
2.1/2.2系统目录结构 2.3 ls命令 2.4文件类型 2.5 alias命令
查看>>
KVM虚拟机管理程序(转)
查看>>
android中用Spannable在TextView中设置超链接、颜色、字体
查看>>
自定义BeanUtils的populate方法实现
查看>>
部署Nginx+Tomcat负载均衡集群
查看>>
Unable to instantiate default tuplizer [org.hib...
查看>>
Django模板--反向解析
查看>>
linux搭建grafana
查看>>
tomcat环境变量
查看>>