原地址:http://www.cnblogs.com/88999660/p/3262656.html

using UnityEngine;
using System.Collections; public class PlayerScript : MonoBehaviour { public GameObject cameraObject;
public float cameraDistance;//the distance the camera should be palced from the palyer
public float cameraHeight;//how heigh the camera should be
private float cameraAngleToPlayer;// the current angle the camera is to the palyer
private Vector3 tempVector; // the temporary vector we shall use for calcuations
// Use this for initialization
void Start () { } // Update is called once per frame
void Update () {
tempVector = Vector3.left;
if(Input.GetKey ("left")) //rotation the angle based on input
{
cameraAngleToPlayer = cameraAngleToPlayer - (Time.deltaTime * 50f);
}else if(Input.GetKey("right")){
cameraAngleToPlayer = cameraAngleToPlayer +(Time.deltaTime *50f);
}
Debug.Log("Quaternion:"+Quaternion.AngleAxis(90f,Vector3.up)+";tempVector:"+tempVector); tempVector = Quaternion.AngleAxis(cameraAngleToPlayer,Vector3.up)*tempVector;//We are now rotating the Vector around the vertical(y) axis by an angle specificed in the variable 'cameraAngleToPlayer'
Debug.Log("tempVector after calculate:"+tempVector);
Debug.DrawLine(transform.position,tempVector*10f,Color.yellow);
cameraObject.transform.position = transform.position + (tempVector.normalized * cameraDistance) + new Vector3(,cameraHeight,);
cameraObject.transform.rotation = Quaternion.LookRotation(transform.position - cameraObject.transform.position);
}
}
以上是绕cube旋转摄像机的示例代码,这段代码拖到cube上。
Quaternion*Vector3的几何意义

例如

Quaternion.AngleAxis(90f,Vector3.up)*Vector3.left

Quaternion:(0.0, 0.7, 0.0, 0.7);Vector3.left:(-1.0, 0.0, 0.0)

calculated:(0.0, 0.0, 1.0)

这样我们得到了从(-1.0, 0.0, 0.0)绕y轴旋转90°的新坐标。

quaternion*Vector3的新理解的更多相关文章

  1. catalan数的新理解

    catalan数的新理解h[5]==h[4][0]+h[3][1]+h[2][2]+h[1][3]+h[0][4];对于这种递推式就是catalan数

  2. unity, 由Matrix4x4提取Quaternion和Vector3 及 由Quaternion,Vector3构造Matrix4x4

    一,由Matrix4x4提取Quaternion和Vector3 Quaternion getRotationFromMatrix(Matrix4x4 m) {         return Quat ...

  3. JavaScript——对this指针的新理解

    一直以来对this的理解只在可以用,会用,却没有去深究其本质.这次,借着<JavaScript The Good Parts>,作了一次深刻的理解.(所有调试都可以在控制台中看到,浏览器F ...

  4. 对Delphi控件作用的新理解(控件本身的源代码就是一个很强的工业级源码)

    最近几天,对Delphi控件的含义有了一个新的理解.其实它不仅仅是给程序员提供功能的一个表层调用,控件本身的源代码就是一个很强的工业级源码.而且它的Main例子,往往就已经是半成品.而别的语言里没有那 ...

  5. springMVC新理解

    springmvc 中@Controller和@RestController的区别 1. Controller, RestController的共同点 都是用来表示spring某个类的是否可以接收HT ...

  6. let 、const 、var、function声明关键字的新理解

    今天在群里看到大佬们讨论let .const 的提升问题,有个大佬问  三种声明都在什么阶段提升?  什么阶段?这个真不清楚,以前是只知道let.const存在死区,没有变量提升,一下子就懵了 后经手 ...

  7. 关于js参数传递矛盾新理解

    之前看了很多人的解释,说js中,函数的参数传递都是值传递中不理解. 他们无非举了两个例子 在这两个例子中,第二个例子可以看出参数是由值传递的.因为函数内对象的变化没有影响到函数外对象的变化.但是在第一 ...

  8. Adaboost新理解

    Adaboost有几个难点: 1.弱分类器的权重怎么理解? 误差大的弱分类器权重小,误差小的弱分类器权重大.这很好理解.在台湾大学林轩田老师的视频中,推导说,这个权值实际上貌似梯度下降,权值定义成1/ ...

  9. SVM的新理解

    svm导出的原始问题然后利用KKT条件,为何还需要对偶空间? 一方面,实际上KKT条件怎么得到的?KKT条件的推导是:svm原始问题->极大极小问题(先算极小这步,但极小这步中α是有约束的,不好 ...

随机推荐

  1. Provider 错误 '80004005' 未指定的错误 /conn.asp,行 23

    网站本来正常,由于网站修改了title标签的内容,想要百度快照快点更新. 就自己提交快照.在下面网站: http://zhanzhang.baidu.com/sitesubmit/index 提交UR ...

  2. datepicker自定义 -- iOS

    /** * 创建时间选择器 */ - (void)createPickerView { self.datePicker = [[UIDatePicker alloc] init]; _datePick ...

  3. Red Hat Linux9命令行--修改补充中

    1.使用rpm工具安装应用软件:rpm   [选项]  [软件包名] 常用的参数及含义如下图所示: 2.编译安装应用软件 (1).tar.gz和.tgz使用如下的命令: [root@myhost ro ...

  4. Struts2 数据校验流程

  5. hdu3746 KMP

    这题琢磨了挺长的时间.需要理解next[]表示了什么; next[i]代表了前缀和后缀的最大匹配的值,也就是个数. len-next[len]表示循环节的长度; 比如abcab   int fl=le ...

  6. Java 并发-任务执行.

    首先来看一下,任务的定义: 所谓的任务,就是抽象,离散的工作单位.你可以简单理解为代码级别的 (Runnable接口) 大多数并发应用程序都是围绕着任务进行管理的. 看一小段代码: package c ...

  7. Linux文件权限;ACL;Setuid、Setgid、Stick bit特殊权限;sudo提权

    相关学习资料 http://blog.sina.com.cn/s/blog_4e2e6d6a0100g47o.html http://blog.csdn.net/aegoose/article/det ...

  8. Linux mount/unmount命令(转)

    格式:mount [-参数] [设备名称] [挂载点] 其中常用的参数有:-a 安装在/etc/fstab文件中类出的所有文件系统.-f 伪装mount,作出检查设备和目录的样子,但并不真正挂载文件系 ...

  9. Nutch的配置以及动态网站的抓取

    http://blog.csdn.net/jimanyu/article/details/5619949 一:配置Nutch: 1.解压缩的nutch后,以抓取http://www.163.com/为 ...

  10. 创建,增加,删除mysql表分区

    1.测试添加分区和删除分区 ###添加删除range分区 (1)创建一个分区: CREATE TABLE titles (     emp_no      INT NOT NULL,     titl ...