unity获取相机视窗口大小
using UnityEngine;
using System.Collections; public class CameraView : MonoBehaviour { private Camera theCamera; //距离摄像机8.5米 用黄色表示
public float upperDistance = 8.5f;
//距离摄像机12米 用红色表示
public float lowerDistance = 12.0f; private Transform tx; void Start (){
if ( !theCamera )
{
theCamera = Camera.main;
}
tx = theCamera.transform;
} void Update (){
FindUpperCorners();
FindLowerCorners();
} void FindUpperCorners (){
Vector3[] corners = GetCorners( upperDistance ); // for debugging
Debug.DrawLine( corners[0], corners[1], Color.yellow ); // UpperLeft -> UpperRight
Debug.DrawLine( corners[1], corners[3], Color.yellow ); // UpperRight -> LowerRight
Debug.DrawLine( corners[3], corners[2], Color.yellow ); // LowerRight -> LowerLeft
Debug.DrawLine( corners[2], corners[0], Color.yellow ); // LowerLeft -> UpperLeft
} void FindLowerCorners (){
Vector3[] corners = GetCorners( lowerDistance ); // for debugging
Debug.DrawLine( corners[0], corners[1], Color.red );
Debug.DrawLine( corners[1], corners[3], Color.red );
Debug.DrawLine( corners[3], corners[2], Color.red );
Debug.DrawLine( corners[2], corners[0], Color.red );
} Vector3[] GetCorners ( float distance ){
Vector3[] corners = new Vector3[ 4 ]; float halfFOV = ( theCamera.fieldOfView * 0.5f ) * Mathf.Deg2Rad;
float aspect = theCamera.aspect; float height = distance * Mathf.Tan( halfFOV );
float width = height * aspect; // UpperLeft
corners[ 0 ] = tx.position - ( tx.right * width );
corners[ 0 ] += tx.up * height;
corners[ 0 ] += tx.forward * distance; // UpperRight
corners[ 1 ] = tx.position + ( tx.right * width );
corners[ 1 ] += tx.up * height;
corners[ 1 ] += tx.forward * distance; // LowerLeft
corners[ 2 ] = tx.position - ( tx.right * width );
corners[ 2 ] -= tx.up * height;
corners[ 2 ] += tx.forward * distance; // LowerRight
corners[ 3 ] = tx.position + ( tx.right * width );
corners[ 3 ] -= tx.up * height;
corners[ 3 ] += tx.forward * distance; return corners;
}
}
转载自:https://www.xuanyusong.com/archives/3036
unity获取相机视窗口大小的更多相关文章
- 【转】UNITY中相机空间,投影空间的正向问题
原文链接1:https://www.cnblogs.com/wantnon/p/4570188.html 原文链接2:https://www.cnblogs.com/hefee/p/3820610.h ...
- Unity正交相机智能包围物体(组)方案
Unity正交相机智能包围物体(组)方案 目录 Unity正交相机智能包围物体(组)方案 一.技术背景 二.相关概念 2.1 正交摄像机 2.2 正交相机的Size 2.3 相机的Aspect 2.4 ...
- JS获取屏幕,浏览器窗口大小,网页高度宽度(实现代码)_javascript技巧_
JS获取屏幕,浏览器窗口大小,网页高度宽度(实现代码)_javascript技巧_--HTML5中文学习网 http://www.html5cn.com.cn/shili/javascripts/79 ...
- unity基础开发----Unity获取PC,Ios系统的mac地址等信息
在软件开发中可以会用到mac地址作为,设备的唯一标示,我们也可以通过unity获取,经测试pc,ios都可以但是安卓没有获取到. 代码如下: using UnityEngine; using Syst ...
- 介绍Unity中相机的投影矩阵与剪切图像、投影概念
这篇作为上一篇的补充介绍,主要讲Unity里面的投影矩阵的问题: 上篇的链接写给VR手游开发小白的教程:(三)UnityVR插件CardboardSDKForUnity解析(二) 关于Unity中的C ...
- JS获取各种浏览器窗口大小的方法
常用:JS 获取浏览器窗口大小复制代码 代码如下:// 获取窗口宽度if (window.innerWidth)winWidth = window.innerWidth;else if ((docum ...
- js 获取浏览器可视窗口大小,滚动条高度
// 获取窗口宽度 if (window.innerWidth) winWidth = window.innerWidth; else if ((document.body) && ( ...
- unity3d 获取相机视口四个角的坐标
功能:如标题所示,主要考虑用来做3d Plane的自适应屏幕 /// <summary> /// 获取指定距离下相机视口四个角的坐标 /// </summary> /// &l ...
- Android 从相冊获取近期拍摄的多张照片(获取相机拍照所存储的照片)
转载请标明出处:http://blog.csdn.net/android_ls/article/details/39928519 在做公司项目时.遇到的需求:自己定义显示照片的网格视图,显示用户近期採 ...
随机推荐
- 解压与压缩(把dataset转为string、、 )
/// <summary> /// 压缩 解压 /// </summary> public class ZipHelper { #region 压缩解缩 /// <sum ...
- python之函数(一)
python有很多内置函数,可以直接调用.比如type(), len(), range(),max(), min(), filter().内置函数我们就先不多提,我们主要介绍自定义函数. 1. 函数的 ...
- 使用Git向GitHub上上传代码
参考:http://www.cnblogs.com/yxhblogs/p/6130995.html 如果遇到[git无法pull仓库refusing to merge unrelated histor ...
- ASP.NET 设计模式分为三种类型
设计模式分为三种类型,共23类. 一.创建型模式:单例模式.抽象工厂模式.建造者模式.工厂模式.原型模式. 二.结构型模式:适配器模式.桥接模式.装饰模式.组合模式.外观模式.享元模式.代 ...
- git命令行使用
* git branch : 查看本地分支 * git branch -r : 查看远程分支 * git branch -a : 查看全部分支 * git branch name : 本地新建分支 * ...
- vi下搜索文本
) /user ) n 下一个匹配 ) N 上一个匹配 ) ?user 从结尾开始搜索 ) :nohlsearch 关闭高亮显示6) :100 跳转到第100行
- session.flush()与session.clear()的区别及使用环境
[From] http://blog.csdn.net/leidengyan/article/details/7514484 首先session是有一级缓存的,目的是为了减少查询数据库的时间,提高效率 ...
- mongodb的初步使用
一.mongodb简介 MongoDB是一个基于分布式文件存储的数据库.由C++语言编写.旨在为WEB应用提供可扩展的高性能数据存储解决方案. MongoDB是一个介于关系数据库和非关系数据库之间的产 ...
- mysql 数据库导入数据报错MySQL server has gone away解决办法
mysql 数据库导入数据报错MySQL server has gone away解决办法: 进入数据库执行以下命令即可: set global wait_timeout = 2880000; set ...
- List<Type> 随机排序
public List<T> GetRandomList<T>(List<T> inputList){ //Copy to a array T[] copyArra ...