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原始问题->极大极小问题(先算极小这步,但极小这步中α是有约束的,不好 ...
随机推荐
- [BZOJ1271][WC2008]秦腾与教学评估(巧妙的二分)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1271 分析: 很巧妙的一道题 因为最多只有一个点是奇数,所以说明这个点前面的前缀和都是 ...
- [bzoj 2005][NOI 2010]能量采集(容斥原理+递推)
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2005 分析:首先易得ans=∑gcd(x,y)*2+1 然后我就布吉岛了…… 上网搜了下题解, ...
- [bzoj 1004][HNOI 2008]Cards(Burnside引理+DP)
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1004 分析: 1.确定方向:肯定是组合数学问题,不是Polya就是Burnside,然后题目上 ...
- [poj3046]Ant Counting(母函数)
题意: S<=x1+x2+...+xT<=B 0<=x1<=N1 0<=x2<=N2 ... 0<=xT<=NT 求这个不等式方程组的解的个数. 分析: ...
- 在Web Service中傳送Dictionary
有個需求,想在Web Service中傳遞Dictionary<string, string>參數,例如: 排版顯示純文字 [WebMethod] public Dictionary< ...
- JS模式:策略模式,感觉就是一个闭包存储信息,然后是加一些验证方法--还看了老半天
<!DOCTYPE html> <html> <head> <title></title> </head> <body&g ...
- Hibernate-Criteria用法
criteria 英[kraɪˈtɪərɪə] 美[kraɪˈtɪrɪə] Hibernate 设计了 CriteriaSpecification Hibernate 设计了 CriteriaSpec ...
- Spring的拦截器
<filter> <filter-name>characterEncodingFilter</filter-name> <filter-class>or ...
- ECSHOP Inject PHPCode Into \library\myship.php Via \admin\template.php && \includes\cls_template.php Vul Tag_PHP_Code Execute Getshell
目录 . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 PHP语言作为开源社区的一员,提供了各种模板引擎,如FastTemplate,Sm ...
- 使用python来调试串口
串口模块的波特率比较特别,找了几个串口工具都不支持...所以,干脆用python自己来写了,其实已经好奇好久了,别人的工具各种不顺手. 需要pyserial的支持,兼容各种平台,不需要新编译二进制文件 ...