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原始问题->极大极小问题(先算极小这步,但极小这步中α是有约束的,不好 ...
随机推荐
- 开源搜索引擎Iveely 0.8.0发布,终见天日
这是一篇博客,不是,这是一篇开源人的心酸和喜悦,没有人可以理解我们的心情,一路的辛酸一路的艰辛,不过还好,在大家的支持下,总算是终见天日,谢谢那些给予我们无私帮助的朋友.您的支持,依然是我们无限的动力 ...
- [BZOJ 3143][HNOI2013]游走(数学期望)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3143 分析: 易得如果知道了每条边经过的数学期望,那就可以贪心着按每条边的期望的大小赋 ...
- JavaScript基础---语言基础(4)
函数,对象和数组 学习要点: 1.函数声明 2.return返回值 3.arguments对象 4.Object类型 5.Array类型 6.对象中的方法 函数是定义一次但却可以调用或执行任意多次的一 ...
- Moqui学习之代码分析mantle priceServices.xml
<?xml version="1.0" encoding="UTF-8"?> <!-- This software is in the pub ...
- 0505-NABCD模型、视频
1.确定选题. 应用NABCD模型,分析你们初步选定的项目,充分说明你们选题的理由. 录制为演说视频,上传到视频网站,并把链接发到团队博客上. 截止日期:2016.5.6日晚10点 NABCD模型: ...
- 使用background和background-image对CSS优先级造成影响
在写一个关于背景图的CSS时候发现一个奇怪的现象, 原图: 如下代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitiona ...
- javaee添加验证码
package com.zh.code; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import j ...
- maven中Rhino classes (js.jar) not found - Javascript disabled的处理
想使用单元测试 来测一下服务请求,于是想到了使用Junit,查了一下,决定使用 HttpUnit 来发送请求 于是在maven中引入了 <dependency> <groupId&g ...
- 【USACO1.1】Broken Necklace
题意 一个环形项链,有rbw三种珠子,r代表red,b代表blue,w代表white,从任意一个位置断开,两端分别取珠子,同一端取的珠子要相同颜色,w可以染成想要的颜色,即既可当作r也可以当作b,求最 ...
- Cocos2d-X3.0 刨根问底(七)----- 事件机制Event源码分析
这一章,我们来分析Cocos2d-x 事件机制相关的源码, 根据Cocos2d-x的工程目录,我们可以找到所有关于事件的源码都存在放在下图所示的目录中. 从这个event_dispatcher目录中的 ...