Unity3D 四元数旋转使用 Quaternion
来源:互联网 发布:西语记单词软件 编辑:程序博客网 时间:2024/06/04 10:52
//增量a是180度的百分比
//debug
if (Input.GetKeyDown(KeyCode.D))
{
Debug.Log(gameObject.transform.right.ToString() + " x");
Debug.Log(gameObject.transform.up.ToString() + " y");
Debug.Log(gameObject.transform.forward.ToString() + " z");
}
//打印当前Quaternion的值
if (Input.GetKeyDown(KeyCode.Q))
{
Debug.Log(gameObject.transform.rotation.ToString() + " q");
}
//调试增量
if (Input.GetKeyDown(KeyCode.O))
{
a += 0.1f;
Debug.Log(a.ToString());
}
//调试增量
if (Input.GetKeyDown(KeyCode.P))
{
a -= 0.1f;
Debug.Log(a.ToString());
}
//输出调试增量
if (Input.GetKeyDown(KeyCode.S))
{
Debug.Log(a.ToString());
}
//清空调试增量
if (Input.GetKeyDown(KeyCode.B))
{
a = 0.0f;
Debug.Log(a.ToString());
}
/*绕单一轴旋转
if (Input.GetKeyDown(KeyCode.X))
{
gameObject.transform.rotation = new Quaternion(1,0,0, (Mathf.PI - Mathf.PI * a));
}
*/
//绕三个轴旋转一个调用周期只能执行一个操作
if (Input.GetKeyDown(KeyCode.X))
{
gameObject.transform.rotation = new Quaternion(gameObject.transform.up.x, gameObject.transform.up.y, gameObject.transform.up.z, (Mathf.PI - Mathf.PI * a));
}
//绕三个轴旋转一个调用周期只能执行一个操作
if (Input.GetKeyDown(KeyCode.Y))
{
gameObject.transform.rotation = new Quaternion(gameObject.transform.right.x, gameObject.transform.right.y,gameObject.transform.right.z, (Mathf.PI - Mathf.PI * a));
}
//绕三个轴旋转一个调用周期只能执行一个操作
if (Input.GetKeyDown(KeyCode.Z))
{
gameObject.transform.rotation = new Quaternion(gameObject.transform.forward.x, gameObject.transform.forward.y, gameObject.transform.forward.z, (Mathf.PI - Mathf.PI * a));
}
//移动一个轴到指定位置
if (Input.GetKeyDown(KeyCode.T))
{
Quaternion q;
q.x = q.y = q.z = 0.0f;
q.w = 1.0f;
q.SetFromToRotation(gameObject.transform.forward, gameObject.transform.up);
gameObject.transform.rotation = q;
Debug.Log("ttttt");
//SetFromToRotation(gameObject.transform.forward, gameObject.transform.up);
}
//debug
if (Input.GetKeyDown(KeyCode.D))
{
Debug.Log(gameObject.transform.right.ToString() + " x");
Debug.Log(gameObject.transform.up.ToString() + " y");
Debug.Log(gameObject.transform.forward.ToString() + " z");
}
//打印当前Quaternion的值
if (Input.GetKeyDown(KeyCode.Q))
{
Debug.Log(gameObject.transform.rotation.ToString() + " q");
}
//调试增量
if (Input.GetKeyDown(KeyCode.O))
{
a += 0.1f;
Debug.Log(a.ToString());
}
//调试增量
if (Input.GetKeyDown(KeyCode.P))
{
a -= 0.1f;
Debug.Log(a.ToString());
}
//输出调试增量
if (Input.GetKeyDown(KeyCode.S))
{
Debug.Log(a.ToString());
}
//清空调试增量
if (Input.GetKeyDown(KeyCode.B))
{
a = 0.0f;
Debug.Log(a.ToString());
}
/*绕单一轴旋转
if (Input.GetKeyDown(KeyCode.X))
{
gameObject.transform.rotation = new Quaternion(1,0,0, (Mathf.PI - Mathf.PI * a));
}
*/
//绕三个轴旋转一个调用周期只能执行一个操作
if (Input.GetKeyDown(KeyCode.X))
{
gameObject.transform.rotation = new Quaternion(gameObject.transform.up.x, gameObject.transform.up.y, gameObject.transform.up.z, (Mathf.PI - Mathf.PI * a));
}
//绕三个轴旋转一个调用周期只能执行一个操作
if (Input.GetKeyDown(KeyCode.Y))
{
gameObject.transform.rotation = new Quaternion(gameObject.transform.right.x, gameObject.transform.right.y,gameObject.transform.right.z, (Mathf.PI - Mathf.PI * a));
}
//绕三个轴旋转一个调用周期只能执行一个操作
if (Input.GetKeyDown(KeyCode.Z))
{
gameObject.transform.rotation = new Quaternion(gameObject.transform.forward.x, gameObject.transform.forward.y, gameObject.transform.forward.z, (Mathf.PI - Mathf.PI * a));
}
//移动一个轴到指定位置
if (Input.GetKeyDown(KeyCode.T))
{
Quaternion q;
q.x = q.y = q.z = 0.0f;
q.w = 1.0f;
q.SetFromToRotation(gameObject.transform.forward, gameObject.transform.up);
gameObject.transform.rotation = q;
Debug.Log("ttttt");
//SetFromToRotation(gameObject.transform.forward, gameObject.transform.up);
}
0 0
- Unity3D 四元数旋转使用 Quaternion
- [unity3D基础知识]之Quaternion(四元数)和旋转
- Unity3d-旋转Quaternion、Matrix4x4、 Euler
- Quaternion(四元数)和旋转
- Quaternion四元数与旋转
- Quaternion(四元数)和旋转
- Quaternion(四元数)和旋转
- Quaternion(四元数)和旋转
- Unity3D的四元数 Quaternion
- Unity3D的四元数 Quaternion
- unity3d的四元数 Quaternion
- unity3d的四元数 Quaternion
- unity3d的四元数 Quaternion
- unity3d的四元数 Quaternion
- Unity3D 物体旋转之Quaternion.Slerp
- Unity3D 物体旋转之Quaternion.Slerp
- Unity3D:详解注视旋转(Quaternion.LookRotation)
- 四元数(Quaternion)和旋转
- Spring MVC 学习指南学习,学习笔记。
- perl
- JavaScript实现原生ajax
- Perl 模块 Getopt::Std 和 Getopt::Long
- perl模块Getopt::Std用法及实例-从命令行读取参数模块
- Unity3D 四元数旋转使用 Quaternion
- 第一天来认识认识指针与const
- PYTHON中的语法元素(续)--Python(8)
- JavaScript取数组数据动态生成下拉列表
- VMware Workstation 12 Pro
- Github全面详解-12Pull Request
- bzoj 2275 Fibonacci博弈 齐肯多夫定理
- 录入学生信息排序fwrite fread 冒泡
- GDOI2017酱油记+题解+关于oi的一些总结