模型的操作
来源:互联网 发布:linux mmap 编辑:程序博客网 时间:2024/06/01 10:11
using UnityEngine;
using System.Collections;
public class ModelRotate : MonoBehaviour
{
public float speed = 100.0f;
//缩放系数
float distance = 10.0f;
float yMinLimit = -20;
float yMaxLimit = 80;
//记录上一次手机触摸位置判断用户是在左放大还是缩小手势
private Vector2 oldPosition1;
private Vector2 oldPosition2;
Transform myTrans;
// Use this for initialization
void Start()
{
myTrans = this.transform;
}
// Update is called once per frame
void Update()
{
if (Input.touchCount == 1)
//if (Input.GetMouseButton(0))
{
if (Input.GetTouch(0).phase == TouchPhase.Moved)
{
float h = Input.GetAxis("Mouse X");
float v = Input.GetAxis("Mouse Y");
if (Mathf.Abs(h) >= Mathf.Abs(v))
{
if (h < 0)
{
myTrans.Rotate(Vector3.up, Time.deltaTime * speed);
}
if (h > 0)
{
myTrans.Rotate(-Vector3.up, Time.deltaTime * speed);
}
}
}
}
//判断触摸数量为多点触摸
if (Input.touchCount > 1)
{
//前两只手指触摸类型都为移动触摸
if (Input.GetTouch(0).phase == TouchPhase.Moved || Input.GetTouch(1).phase == TouchPhase.Moved)
{
//计算出当前两点触摸点的位置
Vector2 tempPosition1 = Input.GetTouch(0).position;
Vector2 tempPosition2 = Input.GetTouch(1).position;
//函数返回真为放大,返回假为缩小
if (isEnlarge(oldPosition1, oldPosition2, tempPosition1, tempPosition2))
{
//放大系数超过3以后不允许继续放大
//这里的数据是根据我项目中的模型而调节的,大家可以自己任意修改
//if (distance > 3)
{
distance -= 0.5f;
myTrans.localScale *= 1.05f;
}
}
else
{
//缩小洗漱返回18.5后不允许继续缩小
//这里的数据是根据我项目中的模型而调节的,大家可以自己任意修改
//if (distance < 18.5)
{
distance += 0.5f;
myTrans.localScale *= 0.95f;
}
}
//备份上一次触摸点的位置,用于对比
oldPosition1 = tempPosition1;
oldPosition2 = tempPosition2;
}
}
}
//函数返回真为放大,返回假为缩小
bool isEnlarge(Vector2 oP1, Vector2 oP2, Vector2 nP1, Vector2 nP2)
{
//函数传入上一次触摸两点的位置与本次触摸两点的位置计算出用户的手势
var leng1 =Mathf.Sqrt((oP1.x-oP2.x)*(oP1.x-oP2.x)+(oP1.y-oP2.y)*(oP1.y-oP2.y));
var leng2 =Mathf.Sqrt((nP1.x-nP2.x)*(nP1.x-nP2.x)+(nP1.y-nP2.y)*(nP1.y-nP2.y));
if(leng1<leng2)
{
//放大手势
return true;
}else
{
//缩小手势
return false;
}
}
}
using System.Collections;
public class ModelRotate : MonoBehaviour
{
public float speed = 100.0f;
//缩放系数
float distance = 10.0f;
float yMinLimit = -20;
float yMaxLimit = 80;
//记录上一次手机触摸位置判断用户是在左放大还是缩小手势
private Vector2 oldPosition1;
private Vector2 oldPosition2;
Transform myTrans;
// Use this for initialization
void Start()
{
myTrans = this.transform;
}
// Update is called once per frame
void Update()
{
if (Input.touchCount == 1)
//if (Input.GetMouseButton(0))
{
if (Input.GetTouch(0).phase == TouchPhase.Moved)
{
float h = Input.GetAxis("Mouse X");
float v = Input.GetAxis("Mouse Y");
if (Mathf.Abs(h) >= Mathf.Abs(v))
{
if (h < 0)
{
myTrans.Rotate(Vector3.up, Time.deltaTime * speed);
}
if (h > 0)
{
myTrans.Rotate(-Vector3.up, Time.deltaTime * speed);
}
}
}
}
//判断触摸数量为多点触摸
if (Input.touchCount > 1)
{
//前两只手指触摸类型都为移动触摸
if (Input.GetTouch(0).phase == TouchPhase.Moved || Input.GetTouch(1).phase == TouchPhase.Moved)
{
//计算出当前两点触摸点的位置
Vector2 tempPosition1 = Input.GetTouch(0).position;
Vector2 tempPosition2 = Input.GetTouch(1).position;
//函数返回真为放大,返回假为缩小
if (isEnlarge(oldPosition1, oldPosition2, tempPosition1, tempPosition2))
{
//放大系数超过3以后不允许继续放大
//这里的数据是根据我项目中的模型而调节的,大家可以自己任意修改
//if (distance > 3)
{
distance -= 0.5f;
myTrans.localScale *= 1.05f;
}
}
else
{
//缩小洗漱返回18.5后不允许继续缩小
//这里的数据是根据我项目中的模型而调节的,大家可以自己任意修改
//if (distance < 18.5)
{
distance += 0.5f;
myTrans.localScale *= 0.95f;
}
}
//备份上一次触摸点的位置,用于对比
oldPosition1 = tempPosition1;
oldPosition2 = tempPosition2;
}
}
}
//函数返回真为放大,返回假为缩小
bool isEnlarge(Vector2 oP1, Vector2 oP2, Vector2 nP1, Vector2 nP2)
{
//函数传入上一次触摸两点的位置与本次触摸两点的位置计算出用户的手势
var leng1 =Mathf.Sqrt((oP1.x-oP2.x)*(oP1.x-oP2.x)+(oP1.y-oP2.y)*(oP1.y-oP2.y));
var leng2 =Mathf.Sqrt((nP1.x-nP2.x)*(nP1.x-nP2.x)+(nP1.y-nP2.y)*(nP1.y-nP2.y));
if(leng1<leng2)
{
//放大手势
return true;
}else
{
//缩小手势
return false;
}
}
}
0 0
- 模型的常用操作
- 模型的操作
- 树状结构的操作模型
- 模型的数据库CRUD操作
- thinkphp 的关联模型 CURD操作
- Yii 登录表单模型的简单操作
- django中模型的简单操作
- ECMAScript5对DOM模型Node的操作
- 软件工程常见的五种操作模型
- select模型各个操作的总结
- Django学习之模型的操作详解
- Django 模型(数据库)操作的要点
- Elasticsearch的存储模型和读写操作
- elasticsearch的存储模型和读写操作
- 银行账户操作的简单模型
- 一个简单的本地存储操作,直接操作模型的方式操作缓存
- 在VB环境中操作三维模型的实现方法
- 在VB环境中操作三维模型的实现方法
- 发的回复的好的方法和
- 远程管理 Remote Management
- 数据结构->树:树的深度与高度
- ECMA 操作符
- sublime编辑器如何快速输入PHP头部版本声明
- 模型的操作
- 在VFP报表中实现每页打印指定记录数
- 使用TinyXml库值得注意的几个地方
- ECMA函数参数arguments的使用
- 看懂Gradle脚本(1)- Groovy语言的Map语法糖
- struct和typedef struct
- The connection to adb is down, and a severe error has occured解决方法
- 别让PPT把你绑架了
- 巴西世界杯,程序员专业版