旋转缩放代码


using UnityEngine;
using System.Collections;
// 直接放在相机上,控制相机的旋转和缩放 //
public class CameraContro : MonoBehaviour {

public Transform target;
public float xSpeed=200, ySpeed=200, mSpeed=10;
public float yMinLimit=-50, yMaxLimit=50;
public float distance=7, minDistance=2, maxDistance=30;

//bool needDamping = false;
public bool needDamping =true;
float damping = 5.0f;

public float x = 0.0f;
public float y = 0.0f;

public void SetTarget( GameObject go )

{
target = go.transform;
}
// Use this for initialization
void Start () {
Vector3 angles = transform.eulerAngles;
x = angles.y;
y = angles.x;
}

// Update is called once per frame
void LateUpdate ()
{

if (target)
{
//use the light button of mouse to rotate the camera
if( Input.GetMouseButton(0) )
{
x += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;

y = ClampAngle(y, yMinLimit, yMaxLimit);

//print(Input.GetAxis("Mouse X"));
//print( Input.GetAxis("Mouse Y"));
//print(x);
//print(y);

}

distance -= Input.GetAxis("Mouse ScrollWheel")*mSpeed;
distance = Mathf.Clamp(distance, minDistance, maxDistance);

Quaternion rotation = Quaternion.Euler(y, x, 0.0f);
Vector3 disVector = new Vector3( 0.0f, 0.0f, -distance );
Vector3 position = rotation * disVector + target.position;
//adjust the camera
if( needDamping )
{
transform.rotation = Quaternion.Lerp(transform.rotation, rotation, Time.deltaTime*damping);
transform.position = Vector3.Lerp(transform.position, position, Time.deltaTime*damping);
}
else
{
transform.rotation = rotation;
transform.position = position;
}

}
}

static float ClampAngle (float angle, float min, float max)
{
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return Mathf.Clamp (angle, min, max);
}
}

旋转缩放代码

时间: 2024-08-02 11:43:30

旋转缩放代码的相关文章

[WebGL入门]十七,递归处理和移动?旋转?缩放

注:文章译自http://wgld.org/,原作者杉本雅広(doxas),文章中如果有我的额外说明,我会加上[lufy:],另外,鄙人webgl研究还不够深入,一些专业词语,如果翻译有误,欢迎大家指正. 本次的demo的运行结果 模型坐标变换矩阵的好处 上次,通过操作模型坐标变换矩阵,绘制了多个模型.这次,继续在此基础上,给多个模型再添加上旋转和放大缩小等处理.看过上一篇文章的人应该知道,在3D渲染的世界里,利用VBO和一部分坐标变换矩阵,只需要少量修改,就可以绘制出大量的模型.当然,计算量也

Android图片旋转,缩放,位移,倾斜,对称完整示例(一)——imageView.setImageMatrix(matrix)和Matrix

MainActivity如下: import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.widget.ImageView; import android.app.Activity; import android.graphics.Matrix; /** * Demo描述:

讲解一下iOS图片单指旋转缩放实现方法

最近做一个项目,里边要做图片处理功能,其中就有图片单指旋转,缩放.由于之前还没做过这样的功能,于是乎找了下相关的资料,终于找到了一种好的实现方案.于是就仿照美图秀秀里边贴纸的功能做了一个demo...以下贴一些主要实现代码.... /*****头文件*********/ #import <UIKit/UIKit.h> @interface ImageEditView : UIView // 背景图片 @property (nonatomic, weak, readonly) UIImageVi

【安卓】自定义基于onDraw的任意动画(不仅仅是平移/旋转/缩放/alpha)、!

思路: 1.基于时间的显示映射.如:给定度数,显示圆弧,加上时序,即可有圆弧动画的效果 2.给定时序.用于驱动动画的一帧帧绘制 方案一.基于ObjectAnimator.动画运作时会调用degree对应set函数(基于放射调用),即setDegree. ObjectAnimator ani=ObjectAnimator.ofInt(myView, "degree", 0,300); ani.start(); 注:1>混编后,默认会将setDegree混掉,导致找不到函数,故混编后

osg中使用MatrixTransform来实现模型的平移/旋转/缩放

osg中使用MatrixTransform来实现模型的平移/旋转/缩放 转自:http://www.cnblogs.com/kekec/archive/2011/08/15/2139893.html#undefined MatrixTransform是从Transform - Group继承而来,因此可以在它的下面挂接Node对象. 通过设置其矩阵,来实现其下子节点的模型变换. -- 用局部坐标系来理解(局部坐标系又称惯性坐标系,其与模型的相对位置在变换的过程中始终不变) 如下代码: // 创建

IOS开发UI篇—手势识别器(拖拽+旋转+缩放)

IOS开发UI篇—手势识别器(拖拽+旋转+缩放) 一.拖拽 示例代码: 1 // 2 // YYViewController.m 3 // 06-拖拽事件 4 // 5 // Created by apple on 14-6-19. 6 // Copyright (c) 2014年 itcase. All rights reserved. 7 // 8 9 #import "YYViewController.h" 10 11 @interface YYViewController ()

iOS 开发----CGAffineTransform平移,旋转,缩放

在做平移,旋转,缩放的时候一定要记住三个步骤: 获取值(获取当前控件的 transform 属性值) 修改值(修改需要设置的 transform 属性值) 赋值   (将修改的 transform 属性的值赋给原来的值) /**   *  平移   *   *  @param transform 获取当前的形变 transform   *  @param tx        沿着 x 水平方向的平移   *  @param ty        沿着 y 垂直方向的平移   *   *  @ret

图片旋转js代码

function rotateImage(imgId) { imageToRotate = document.getElementById(imgId); imageToRotate.style.filter= "progid:DXImageTransform.Microsoft.Matrix(sizingMethod='auto expand')"; rotate(); } var imageToRotate; var degreeToRotate=0; function rotat

编程算法 - 左旋转字符串 代码(C)

左旋转字符串 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 字符串的左旋转操作是把字符串前面的若干个字符转移到字符串的尾部. 请定义一个函数实现字符串左旋转操作的功能. 编程珠玑, 首先翻转前部分, 再翻转后部分, 最后全部翻转. 代码: /* * main.cpp * * Created on: 2014.6.12 * Author: Spike */ /*eclipse cdt, gcc 4.8.1*/ #include <stdio