码迷,mamicode.com
首页 > 其他好文 > 详细

Unity3D-数学相关

时间:2014-07-11 18:23:35      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:style   os   cti   for   io   re   

1. Transform.rotation:对象在世界坐标系下的旋转;Transform.localRotation:对象在父对象的局部坐标系下的旋转。两个变量的类型均为四元素。

(1)得到游戏对象当前旋转的角-轴表示

  transform.rotation.ToAngleAxis(angle, axis);

(2)旋转归零,局部坐标系的坐标轴与世界坐标系的坐标轴平行

  transform.rotation = Quaternion.identity;

(3)使对象朝向target

  relativePos = target.position - transform.position;

  rotation = Quaternion.LookRotation(relativePos);

  transform.rotation = rotation;

(4)将对象的旋转从from平滑差值到to,可以用来模拟相机的观察方向从物体a过渡到物体b的效果。

  transform.rotation = Quaternion.Slerp(from.rotation, to.rotation, Time.deltaTime*speed)

2. 坐标系:常用的坐标系有世界坐标系、局部坐标系、相机坐标系、屏幕坐标系。Transform.TransformPoint可以将坐标点从局部坐标系转换到世界坐标系,Transform.InverseTransformPoint可以将坐标点从世界坐标系转换到局部坐标系;Transform.TransformDirection和Transform.InverseTransformDirection对向量在世界坐标系和局部坐标系之间转换。例如,将对象位置转换为相机坐标系下的坐标:

  cam = Camera.main.transform;

  CameraRelative = cam.InverseTransformPoint(transform.position)

  if (CameraRelative.z > 0)

    Debug.log("The object is in front of Camera");

 

 

Unity3D-数学相关,布布扣,bubuko.com

Unity3D-数学相关

标签:style   os   cti   for   io   re   

原文地址:http://www.cnblogs.com/shihui142857/p/3833452.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!