根据模型大小,限定摄像头旋转角度(上,下,左,右)

思路:

  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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值