安卓 触屏旋转、缩放、拖拽
来源:互联网 发布:苹方字体ttf windows 编辑:程序博客网 时间:2024/05/21 17:53
公共函数,不放入任何模型上
using UnityEngine;using System.Collections;public class Globe : MonoBehaviour {public static int AugmentationObjectState = 0;//增强物体的状态:0表示没有检测到识别图; 1表示在识别图之上;2表示脱离识别图,但仍存在。// Use this for initializationvoid Start () {}// Update is called once per framevoid Update () {}}
放在需要旋转、缩放、拖拽的模型上
using UnityEngine;using System.Collections;public class GetModelScale : MonoBehaviour {public Vector3 go_modelDefaultScale;// Use this for initializationvoid Start () {}// Update is called once per framevoid Update () {go_modelDefaultScale = this.transform.localScale;}}放在需要旋转、缩放、拖拽的模型上
using UnityEngine;using System.Collections;public class TouchToRotateAndScaleModel : MonoBehaviour {public GameObject go_model;private Vector3 go_modelCurScale;private Vector3 go_modelDefaultScale; private float curScale = 1.0f; private float olddis = 0.0f;private float newdis = 0.0f; private float RoatedSpeed = 100.0F; public float y; public float z;private Transform pickedObject = null; // Use this for initialization void Start() { y = 90; } // Update is called once per frame void Update() {//旋转功能if (Input.touchCount==1) {if(Input.touches[0].phase == TouchPhase.Moved)//手指移动{ y += Input.GetAxis("Mouse X") * Time.deltaTime * RoatedSpeed;z += Input.GetAxis("Mouse Y") * Time.deltaTime * RoatedSpeed;if (z <= -90){z = Mathf.Ceil(-90);}if (z >= 90){z = Mathf.Ceil(90);}transform.eulerAngles = new Vector3(0, y, -z);} }//缩放功能if(Input.touchCount == 2){if (go_modelDefaultScale != go_model.GetComponent<GetModelScale>().go_modelDefaultScale) { go_modelDefaultScale = go_modelCurScale = go_model.GetComponent<GetModelScale>().go_modelDefaultScale; }if(Input.GetTouch(0).phase==TouchPhase.Moved||Input.GetTouch(1).phase==TouchPhase.Moved){var pos1=Input.GetTouch(0).position;var pos2=Input.GetTouch(1).position;newdis=Vector2.Distance(pos1,pos2);curScale = go_modelCurScale.x / go_modelDefaultScale.x; if(newdis < olddis){go_model.transform.localScale -= go_modelDefaultScale * Time.deltaTime;}if(newdis>olddis) {go_model.transform.localScale += go_modelDefaultScale * Time.deltaTime;}go_modelCurScale = go_model.transform.localScale; olddis=newdis;}}//拖动功能if(Input.touchCount == 3){if(Globe.AugmentationObjectState == 2 ){foreach (Touch touch in Input.touches) {Debug.Log("Touching at: " + touch.position);if (touch.phase == TouchPhase.Began) {Debug.Log("Touch phase began at: " + touch.position);pickedObject = go_model.transform;} else if (touch.phase == TouchPhase.Moved) {Debug.Log("Touch phase Moved");if (pickedObject != null) {Vector2 screenDelta = touch.deltaPosition;float halfScreenWidth = 0.5f * Screen.width;float halfScreenHeight = 0.5f * Screen.height;float dx = screenDelta.x / halfScreenWidth;float dy = screenDelta.y / halfScreenHeight;Vector3 objectToCamera = pickedObject.transform.position - Camera.main.transform.position;float distance = objectToCamera.magnitude;float fovRad = Camera.main.fieldOfView * Mathf.Deg2Rad;float motionScale = distance * Mathf.Tan(fovRad/2);Vector3 translationInCameraRef = new Vector3(motionScale * dx, motionScale * dy, 0);Vector3 translationInWorldRef =Camera.main.transform.TransformDirection(translationInCameraRef);pickedObject.position += translationInWorldRef;}} else if (touch.phase == TouchPhase.Ended) {Debug.Log("Touch phase Ended");pickedObject = null;}}}} }}
0 0
- 安卓 触屏旋转、缩放、拖拽
- 安卓开发,关于静态图显示,缩放以及旋转
- 安卓动画 移位,缩放,旋转,透明度简单实现
- 安卓动画(旋转,平移,透明,缩放,帧动画)
- 触屏控制物体旋转,缩放
- [一个星期自学安卓]使用ImageView显示图像的缩放与旋转
- 【安卓】自定义基于onDraw的任意动画(不仅仅是平移/旋转/缩放/alpha)、!
- 安卓控件使用系列16:ImageView实现图片缩放和旋转
- 安卓的各种动画(透明度,平移,旋转,缩放)以及侦听
- [安卓初学者实验]实现图片的顺逆时针旋转和缩放功能
- 安卓用手指触碰屏幕缩放和移动,三指触碰屏幕旋转图片
- 安卓智能地图开发与实施九:地图缩放与旋转
- 安卓自定义View基础07-Canvas位移,缩放,旋转操作
- 安卓-BitMap缩放
- 安卓图片缩放
- 008-实现Unity3d中使用LeanTouch插件进行触屏控制(拖拽、移动、缩放旋转...)
- unity3d 触屏多点触控(旋转与缩放)
- 旋转+缩放
- JSP2自定义标签库技术
- 兼容PC和移动页面的mobiscroll日期插件之简单使用
- 爱情智慧:1招让你搞定不愿意付出的男人
- 关于mysql5.7安装步骤
- 全志A64 android6.0系统允许第三方应用读写U盘外置sd卡修改
- 安卓 触屏旋转、缩放、拖拽
- TEC1304.值集和弹性域相关技术总结 - 第三章 键弹性域详解
- Git 命令集
- Undefined symbols for architecture x86_64:和"_OBJC_CLASS_$_xx", referenced from:问题解决方法
- 读取excel
- 微信小程序之我见
- 自己训练SVM分类器进行HOG行人检测
- GREENPLUM中使用脚本导出非外部表的表结构
- Oracle 触发器中修改字段值