quaternion*Vector3的新理解
原地址: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的新理解的更多相关文章
- catalan数的新理解
catalan数的新理解h[5]==h[4][0]+h[3][1]+h[2][2]+h[1][3]+h[0][4];对于这种递推式就是catalan数
- unity, 由Matrix4x4提取Quaternion和Vector3 及 由Quaternion,Vector3构造Matrix4x4
一,由Matrix4x4提取Quaternion和Vector3 Quaternion getRotationFromMatrix(Matrix4x4 m) { return Quat ...
- JavaScript——对this指针的新理解
一直以来对this的理解只在可以用,会用,却没有去深究其本质.这次,借着<JavaScript The Good Parts>,作了一次深刻的理解.(所有调试都可以在控制台中看到,浏览器F ...
- 对Delphi控件作用的新理解(控件本身的源代码就是一个很强的工业级源码)
最近几天,对Delphi控件的含义有了一个新的理解.其实它不仅仅是给程序员提供功能的一个表层调用,控件本身的源代码就是一个很强的工业级源码.而且它的Main例子,往往就已经是半成品.而别的语言里没有那 ...
- springMVC新理解
springmvc 中@Controller和@RestController的区别 1. Controller, RestController的共同点 都是用来表示spring某个类的是否可以接收HT ...
- let 、const 、var、function声明关键字的新理解
今天在群里看到大佬们讨论let .const 的提升问题,有个大佬问 三种声明都在什么阶段提升? 什么阶段?这个真不清楚,以前是只知道let.const存在死区,没有变量提升,一下子就懵了 后经手 ...
- 关于js参数传递矛盾新理解
之前看了很多人的解释,说js中,函数的参数传递都是值传递中不理解. 他们无非举了两个例子 在这两个例子中,第二个例子可以看出参数是由值传递的.因为函数内对象的变化没有影响到函数外对象的变化.但是在第一 ...
- Adaboost新理解
Adaboost有几个难点: 1.弱分类器的权重怎么理解? 误差大的弱分类器权重小,误差小的弱分类器权重大.这很好理解.在台湾大学林轩田老师的视频中,推导说,这个权值实际上貌似梯度下降,权值定义成1/ ...
- SVM的新理解
svm导出的原始问题然后利用KKT条件,为何还需要对偶空间? 一方面,实际上KKT条件怎么得到的?KKT条件的推导是:svm原始问题->极大极小问题(先算极小这步,但极小这步中α是有约束的,不好 ...
随机推荐
- “未能加载文件或程序集“EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”
产生原因: 使用nuget管理程序包,同一个解决方案里面有不同版本的Entity Framework,有可能在不同时间安装不同版本的Entity Framework,所以出现这个问题. 解决方案: 1 ...
- angular的工具方法笔记(equals, HashKey)
分别是angular脏值检测的工具方法equals和 类HashKey的使用方法 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transi ...
- Foix_Reader_6.0|PDF阅读器
福晰PDF阅读器,是阅读器中的精品.此版本是优化版本. 00:风格前卫 01:使用简洁 下载地址: http://yunpan.cn/cHvyUfCdMKZz6 访问密码 ead7
- “耐撕”团队2016.05.11站立会议
1. 时间 18:15--18:35 共计20分钟 2. 人员 Z 郑蕊 * 组长 (博客:http://www.cnblogs.com/zhengrui0452/), P 濮成林(博客:ht ...
- 【OpenCV入门教程之一】 安装OpenCV:OpenCV 3.0 +VS 2013 开发环境配置
图片太多,具体过程参照: [OpenCV入门教程之一] 安装OpenCV:OpenCV 3.0.OpenCV 2.4.8.OpenCV 2.4.9 +VS 开发环境配置 说下我这边的设置: 选择deb ...
- java多线程-CyclicBarrier
介绍 一个同步辅助类,它允许一组线程互相等待,直到到达某个公共屏障点 (common barrier point).在涉及一组固定大小的线程的程序中,这些线程必须不时地互相等待,此时 CyclicBa ...
- structs环境搭建
(1)<s:fielderror />放在JSP中,如果没在web.xml中配置filter相关内容,会有The Struts dispatcher cannot be found.从而显 ...
- Oracle之自定义函数
数据库中函数包含四个部分:声明.返回值.函数体和异常处理. --没有参数的函数 create or replace function get_user return varchar2 is v_use ...
- BZOJ-3231 递归数列 矩阵连乘+快速幂
题不是很难,但是啊,人很傻啊...机子也很鬼畜啊... 3231: [Sdoi2008]递归数列 Time Limit: 1 Sec Memory Limit: 256 MB Submit: 569 ...
- BZOJ-3668 起床困难综合症 位运算+贪心
faebdc学长杂题选讲中的题目...还是蛮简单的...位运算写的不熟练... 3668: [Noi2014]起床困难综合症 Time Limit: 10 Sec Memory Limit: 512 ...