Unity3D的四种坐标系
2015-10-27 17:06
381 查看
【Unity3D的四种坐标系】
1、World Space(世界坐标):我们在场景中添加物体(如:Cube),他们都是以世界坐标显示在场景中的。transform.position可以获得该位置坐标。
2、Screen Space(屏幕坐标):以像素来定义的,以屏幕的左下角为(0,0)点,右上角为(Screen.width,Screen.height),Z的位置是以相机的世界单位来衡量的。注:鼠标位置坐标属于屏幕坐标,Input.mousePosition可以获得该位置坐标,手指触摸屏幕也为屏幕坐标,Input.GetTouch(0).position可以获得单个手指触摸屏幕坐标。
Screen.width = Camera.pixelWidth
Screen.height = Camera.pixelHeigth
3、ViewPort Space(视口坐标):视口坐标是标准的和相对于相机的。相机的左下角为(0,0)点,右上角为(1,1)点,Z的位置是以相机的世界单位来衡量的。
4、绘制GUI界面的坐标系:这个坐标系与屏幕坐标系相似,不同的是该坐标系以屏幕的左上角为(0,0)点,右下角为(Screen.width,Screen.height)。
【四种坐标系的转换】
1、世界坐标→屏幕坐标:camera.WorldToScreenPoint(transform.position);这样可以将世界坐标转换为屏幕坐标。其中camera为场景中的camera对象。
2、屏幕坐标→视口坐标:camera.ScreenToViewportPoint(Input.GetTouch(0).position);这样可以将屏幕坐标转换为视口坐标。其中camera为场景中的camera对象。
3、视口坐标→屏幕坐标:camera.ViewportToScreenPoint();
4、视口坐标→世界坐标:camera.ViewportToWorldPoint();
问题
1.Screen VS Viewport What is the difference
Screen and Viewport represent same area - on screen, but they have different coordinate systems (IIRC):
Screen: from [0,0] to [Screen.width, Screen.height]
Viewport: from [-1,-1] to [1,1]
World point is a point in world space.
noflyzone · 2011年09月19日
09:19 0
In unity3d, why this design? Viewport In what circumstances is used?
Paulius
Liekis · 2011年09月19日
11:29 1
I don't think it's Unity specific design - these are common terms in 3d graphics. Viewport might be useful if you want to check if something is on-screen (you don't care about Screen size), but I'm sure there are
better exampled.
syclamoth · 2011年09月19日
11:49 1
Viewport is used when you need to be sure something will show up the same on all different screen sizes and shapes. It is independent of the pixel width and height of the exact screen in question.
noflyzone · 2011年09月19日
12:36 0
Thank syclamoth and Paulius
RedRival · 2012年12月19日
03:44 3
Correction Viewport: from [0,0] to [1,1] Quote: Viewport space is normalized and relative to the camera. The bottom-left of the camera is (0,0); the top-right is (1,1). The z position is in world units from the
camera.http://docs.unity3d.com/Documentation/ScriptReference/Camera.ViewportToWorldPoint.html
1、World Space(世界坐标):我们在场景中添加物体(如:Cube),他们都是以世界坐标显示在场景中的。transform.position可以获得该位置坐标。
2、Screen Space(屏幕坐标):以像素来定义的,以屏幕的左下角为(0,0)点,右上角为(Screen.width,Screen.height),Z的位置是以相机的世界单位来衡量的。注:鼠标位置坐标属于屏幕坐标,Input.mousePosition可以获得该位置坐标,手指触摸屏幕也为屏幕坐标,Input.GetTouch(0).position可以获得单个手指触摸屏幕坐标。
Screen.width = Camera.pixelWidth
Screen.height = Camera.pixelHeigth
3、ViewPort Space(视口坐标):视口坐标是标准的和相对于相机的。相机的左下角为(0,0)点,右上角为(1,1)点,Z的位置是以相机的世界单位来衡量的。
4、绘制GUI界面的坐标系:这个坐标系与屏幕坐标系相似,不同的是该坐标系以屏幕的左上角为(0,0)点,右下角为(Screen.width,Screen.height)。
【四种坐标系的转换】
1、世界坐标→屏幕坐标:camera.WorldToScreenPoint(transform.position);这样可以将世界坐标转换为屏幕坐标。其中camera为场景中的camera对象。
2、屏幕坐标→视口坐标:camera.ScreenToViewportPoint(Input.GetTouch(0).position);这样可以将屏幕坐标转换为视口坐标。其中camera为场景中的camera对象。
3、视口坐标→屏幕坐标:camera.ViewportToScreenPoint();
4、视口坐标→世界坐标:camera.ViewportToWorldPoint();
问题
1.Screen VS Viewport What is the difference
Screen and Viewport represent same area - on screen, but they have different coordinate systems (IIRC):
Screen: from [0,0] to [Screen.width, Screen.height]
Viewport: from [-1,-1] to [1,1]
World point is a point in world space.
noflyzone · 2011年09月19日
09:19 0
In unity3d, why this design? Viewport In what circumstances is used?
Paulius
Liekis · 2011年09月19日
11:29 1
I don't think it's Unity specific design - these are common terms in 3d graphics. Viewport might be useful if you want to check if something is on-screen (you don't care about Screen size), but I'm sure there are
better exampled.
syclamoth · 2011年09月19日
11:49 1
Viewport is used when you need to be sure something will show up the same on all different screen sizes and shapes. It is independent of the pixel width and height of the exact screen in question.
noflyzone · 2011年09月19日
12:36 0
Thank syclamoth and Paulius
RedRival · 2012年12月19日
03:44 3
Correction Viewport: from [0,0] to [1,1] Quote: Viewport space is normalized and relative to the camera. The bottom-left of the camera is (0,0); the top-right is (1,1). The z position is in world units from the
camera.http://docs.unity3d.com/Documentation/ScriptReference/Camera.ViewportToWorldPoint.html
相关文章推荐
- unity 关于模型的边界框bounds
- Unity3D加载4种机制
- Unity Network 使用小结
- Unity3D 多种播放音效的方式
- Unity 音乐播放全局类
- 自学Unity之做一个MOBA游戏2——镜头移动
- unity目录结构--三分天下,一主一副一酱油
- Unity 二战中加飞机
- 自学Unity之做一个MOBA游戏1——Terrain(地形)
- 王立平--Unity中间GUI Skin
- unity中的坐标转换
- unity图片打包
- unity5.X 中的全局光照技术详解(建议收藏)
- Unity学习笔记
- Unity鼠标设置
- Unity中使用Json解析字符串
- Unity 下载
- Unity3D——MonoBehaviour api函数 调用时序剖析(From 圣典)
- unity生成android release 版本的apk性能比较好
- unity set texture offset