Unity3d物体模型(实现旋转缩放平移自动旋转)
基本功能实现:物体通过鼠标左键上下移动,中间键缩放、右键旋转,30秒没操作,物体自动旋转
实例代码:
using UnityEngine;
using System.Collections; public class Script_07_11 : MonoBehaviour
{ public Transform target; private int MouseWheelSensitivity = 50;
private int MouseZoomMin = 20;
private int MouseZoomMax = 112;
private float normalDistance = 500; private bool flag_Roable = true;//自动旋转标志 private Vector3 normalized; private float xSpeed = 250.0f;
private float ySpeed = 120.0f; private float x = 0.0f;
private float y = 0.0f; private System.DateTime oldTime;
private System.DateTime nowTime; void Start ()
{ oldTime = System.DateTime.Now;
//transform.LookAt(target); } void Update ()
{
nowTime = System.DateTime .Now;
System.TimeSpan ts1 = new System.TimeSpan(oldTime.Ticks);
System.TimeSpan ts2 = new System.TimeSpan(nowTime.Ticks); System.TimeSpan ts = ts2.Subtract(ts1).Duration(); if(ts.Seconds>30 && !Input.anyKey)
{
flag_Roable = true;
oldTime = System.DateTime.Now;
} if(flag_Roable && Input.anyKey)
{
flag_Roable = false;
} if(flag_Roable)//自动旋转
{ x-=Time.deltaTime*30; var rotation = Quaternion.Euler(0,x,0);
transform.RotateAround(target.position,Vector3.up,0.3f);
}
else
{
if(Input.GetMouseButton(1))
{
if(Input.GetAxis("Mouse X")<0)
transform.RotateAround(target.position,Vector3.down,4);
if(Input.GetAxis("Mouse X")>0)
transform.RotateAround(target.position,Vector3.up,4);
}
else if (Input.GetAxis("Mouse ScrollWheel") != 0)
{ //normalized = (transform.position - CameraTarget).normalized; if (normalDistance >= MouseZoomMin && normalDistance <= MouseZoomMax)
{
normalDistance -= Input.GetAxis("Mouse ScrollWheel") * MouseWheelSensitivity;
}
if (normalDistance < MouseZoomMin)
{
normalDistance = MouseZoomMin;
}
if (normalDistance > MouseZoomMax)
{
normalDistance = MouseZoomMax;
}
//transform.position = normalized * normalDistance;
transform.camera.fieldOfView = normalDistance; }
else if(Input.GetMouseButton(0))
{
//print("wyz-==="+Input.GetAxis("Mouse Y"));
if(Input.GetAxis("Mouse Y")<0) //down
{
Vector3 temp=Vector3.up * 60.0f * Time.deltaTime; print("wyz==up==="+transform.localPosition.y);
if(transform.localPosition.y>300)
{
temp=Vector3.up * 5.0f * Time.deltaTime;
transform.Translate(temp);
}
else
{
transform.Translate(temp);
}
} if(Input.GetAxis("Mouse Y")>0) //up
{
print("wyz==donw==="+transform.localPosition.y);
Vector3 temp=Vector3.down * 60.0f * Time.deltaTime; if(transform.localPosition.y<-300)
{
temp=Vector3.up * 5.0f * Time.deltaTime;
transform.Translate(temp);
}
else
{
transform.Translate(temp);
}
} } } } }
Unity3d物体模型(实现旋转缩放平移自动旋转)的更多相关文章
- OpenGL绘制简单场景,实现旋转缩放平移和灯光效果
本项目实现了用OpenGL绘制一个简单场景,包括正方体.球体和网格,实现了物体的旋转.缩放.平移和灯光效果.附有项目完整代码.有具体凝视.适合刚開始学习的人熟悉opengl使用. 开发情况 开发环境V ...
- osg中使用MatrixTransform来实现模型的平移/旋转/缩放
osg中使用MatrixTransform来实现模型的平移/旋转/缩放 转自:http://www.cnblogs.com/kekec/archive/2011/08/15/2139893.html# ...
- VTK中模型的旋转与平移
当从外界读入STL等三维模型时,其会按照它内部的坐标位置进行显示.因此它的位置和大小是确定的.但是在实际应用中,有可能需要人为地对这个模型在空间中进行旋转.平移或缩放等操作.VTK中有许多和旋转.平移 ...
- 【转载】Unity3D研究院之IOS触摸屏手势控制镜头旋转与缩放
前几篇文章介绍了很多Unity3D引擎自身的一些问题, 今天我们在回到IOS设备上讨论一些触摸屏幕手势,本章的目标是通过触摸iPhone屏幕手势 实现模型左右的旋转,与模型的缩放. 大家想一想模型的旋 ...
- threeJS创建mesh,创建平面,设置mesh的平移,旋转、缩放、自传、透明度、拉伸
这个小案例是当初我在学习的时候,小的一个小案例,代码还需要进一步优化:还请谅解~~:主要用到了threeJS创建mesh,创建平面,设置mesh的平移,旋转.缩放.自传.透明度.拉伸等这些小功能: 采 ...
- 【转载】Unity中矩阵的平移、旋转、缩放
By:克森 简介 在这篇文章中,我们将会学到几个概念:平移矩阵.旋转矩阵.缩放矩阵.在学这几个基本概念的同时,我们会用到 Mesh(网格).数学运算.4x4矩阵的一些简单的操作.但由于克森也是新手,文 ...
- osg矩阵变换节点-----平移旋转缩放
osg矩阵变换节点-----平移旋转缩放 转自:http://www.cnblogs.com/ylwn817/articles/1973396.html 平移旋转缩放这个三个是osg矩阵操作中,最常见 ...
- Blender模型导入进Unity,旋转缩放的调整
Blender跟Unity的XYZ轴不同的原因,导致Blender模型导入Unity之后会发生模型朝向不对. 请先看看下边这个情况: 首先,Blender物体模式下,对模型进行 旋转 缩放,将会在右边 ...
- OpenCV计算机视觉学习(11)——图像空间几何变换(图像缩放,图像旋转,图像翻转,图像平移,仿射变换,镜像变换)
如果需要处理的原图及代码,请移步小编的GitHub地址 传送门:请点击我 如果点击有误:https://github.com/LeBron-Jian/ComputerVisionPractice 图像 ...
随机推荐
- C#关于HttpClient的应用(一):获取IP所在的地理位置信息
public class IpHttpClient:BaseHttpClient { private String appKey; private const string HOST_PATH = & ...
- api接口对于客户端的身份认证方式以及安全措施
转载 基于http协议的api接口对于客户端的身份认证方式以及安全措施 由于http是无状态的,所以正常情况下在浏览器浏览网页,服务器都是通过访问者的cookie(cookie中存储的jsession ...
- Oracle\MS SQL Server Update多表关联更新
原文:Oracle\MS SQL Server Update多表关联更新 一条Update更新语句是不能更新多张表的,除非使用触发器隐含更新.而表的更新操作中,在很多情况下需要在表达式中引用要更新的表 ...
- linux_解压缩详解
.tar 解包:tar xvf FileName.tar打包:tar cvf FileName.tar DirName(注:tar是打包,不是压缩!)———————————————.gz解压1:gun ...
- BIZTALK项目中WEB引用WEBSERVICES服务时候报错
近期工作中须要完毕通过BIZTALK完毕调用WEBLOGIC公布的WebServices服务,环境搭建好后,打开VS开发工具新建一个BIZTALK项目,加入WEB引用将对方公布的地址拷贝上去,能够正常 ...
- GitFlow使用说明
———————安装--------------- $ git clone --recursive git://github.com/nvie/gitflow.git $ cd gitflow $ [s ...
- Java笔试题集锦
Java笔试题集锦 1.MVC的各个部分都有那些技术来实现?怎样实现? 答:MVC是Model-View-Controller的简写."Model" 代表的是应用的业务逻辑(通过J ...
- 顶级jQuery树插件
顶级jQuery树插件 顶级jQuery树插件 2013-03-05 17:20 139人阅读 评论(0) 收藏 举报 jsTree JsTree是一个基于jQuery的Tree控件.支持HTML.J ...
- location将地址栏参数拆分成键值对的对象
window.location可获取地址栏的一系列信息,并且每个浏览器都支持该属性,非常方便.而获取到的问号后面的参数可以进行加工转变成我们所想要的键值对. location的属性: 属性名 例子 说 ...
- leetcode第39题--Combination Sum II
题目: Given a collection of candidate numbers (C) and a target number (T), find all unique combination ...