关键词:
using UnityEngine;
public class TrackTargets : MonoBehaviour
[SerializeField]
Transform[] targets;
[SerializeField]
float boundingBoxPadding = 2f;
[SerializeField]
float minimumOrthographicSize = 8f;
[SerializeField]
float zoomSpeed = 20f;
Camera camera;
void Awake ()
camera = GetComponent<Camera>();
camera.orthographic = true;
void LateUpdate()
Rect boundingBox = CalculateTargetsBoundingBox();
transform.position = CalculateCameraPosition(boundingBox);
camera.orthographicSize = CalculateOrthographicSize(boundingBox);
/// <summary>
/// Calculates a bounding box that contains all the targets.
/// </summary>
/// <returns>A Rect containing all the targets.</returns>
Rect CalculateTargetsBoundingBox()
float minX = Mathf.Infinity;
float maxX = Mathf.NegativeInfinity;
float minY = Mathf.Infinity;
float maxY = Mathf.NegativeInfinity;
foreach (Transform target in targets)
Vector3 position = target.position;
minX = Mathf.Min(minX, position.x);
minY = Mathf.Min(minY, position.y);
maxX = Mathf.Max(maxX, position.x);
maxY = Mathf.Max(maxY, position.y);
return Rect.MinMaxRect(minX - boundingBoxPadding, maxY + boundingBoxPadding, maxX + boundingBoxPadding, minY - boundingBoxPadding);
/// <summary>
/// Calculates a camera position given the a bounding box containing all the targets.
/// </summary>
/// <param name="boundingBox">A Rect bounding box containg all targets.</param>
/// <returns>A Vector3 in the center of the bounding box.</returns>
Vector3 CalculateCameraPosition(Rect boundingBox)
Vector2 boundingBoxCenter = boundingBox.center;
return new Vector3(boundingBoxCenter.x, boundingBoxCenter.y, camera.transform.position.z);
/// <summary>
/// Calculates a new orthographic size for the camera based on the target bounding box.
/// </summary>
/// <param name="boundingBox">A Rect bounding box containg all targets.</param>
/// <returns>A float for the orthographic size.</returns>
float CalculateOrthographicSize(Rect boundingBox)
float orthographicSize = camera.orthographicSize;
Vector3 topRight = new Vector3(boundingBox.x + boundingBox.width, boundingBox.y, 0f);
Vector3 topRightAsViewport = camera.WorldToViewportPoint(topRight);
if (topRightAsViewport.x >= topRightAsViewport.y)
orthographicSize = Mathf.Abs(boundingBox.width) / camera.aspect / 2f;
else
orthographicSize = Mathf.Abs(boundingBox.height) / 2f;
return Mathf.Clamp(Mathf.Lerp(camera.orthographicSize, orthographicSize, Time.deltaTime * zoomSpeed), minimumOrthographicSize, Mathf.Infinity);
csharp把相机朝向的物体的面向相机面剔除(代码片段)
查看详情
csharp用于创建像素锁定正交相机的统一脚本(代码片段)
查看详情
csharp适用于unity3d的超级银河战士风格相机。(代码片段)
查看详情
csharp令人敬畏的2d相机(unity2dc#脚本)(代码片段)
查看详情
csharp将文件从源移动到目标(代码片段)
查看详情
csharp多线程样本(代码片段)
查看详情
csharp多字段断言非空(代码片段)
查看详情
csharp用于cli的多线程记录器(代码片段)
查看详情
相机跟随目标及跟随目标背后(u3d)(代码片段)
学习siki学院关于Animation的内容,顺便记录一下相机跟随目标的移动而移动的脚本:privateTransformplayer; privateVector3offset; privatefloatsmoothing=3; //Usethisforinitialization voidStart() player=GameObject.Find 查看详情
相机跟随目标及跟随目标背后(u3d)(代码片段)
学习siki学院关于Animation的内容,顺便记录一下相机跟随目标的移动而移动的脚本:privateTransformplayer; privateVector3offset; privatefloatsmoothing=3; //Usethisforinitialization voidStart() player=GameObject.Fin 查看详情
双目相机同目标追踪
多摄像头多目标定位追踪相关原理:1.多摄像头多目标追踪指标(Multi-TargetMulti-CameraTracking,MTMCTracking)2.多相机系统视觉定位中的高效2D-3D点匹配方法3.多摄像头实时目标追踪和计数4.多目标多相机追踪5.双目视觉的运动目标跟踪... 查看详情
camera-radar基于ros的多传感器融合感知系统实现(雷达+相机)(代码片段)
实现功能:代码下载地址:下载地址1)基于深度学习的目标检测;2)基于雷达的距离估计和预测;3)多传感器感知结果融合模块。相机感知模块解析4.Runnodes:python3fusion_node/main.pypython3gps_node/main.pypython3radar_node/main 查看详情
csharp使用stringbuilder对象连接,比使用+=进行字符串连接要好得多(代码片段)
查看详情
autoware使用相机和深度学习进行目标检测(代码片段)
autoware使用相机和深度学习进行目标检测(六)安装yolo进入对应的vision_darknet_detect/darknet/data/目录下对应目录位置:autoware.ai/install/vision_darknet_detect/share/vision_darknet_detect/darknet或通过命令进入roscdvision_darknet_detect/darknet 查看详情
smoke单目相机3d目标检测训练模型(代码片段)
前言本文基于SMOKE模型,使用kitti 3D目标检测数据集进行训练,记录一下过程。如果发现有错误,欢迎指出。关于原理和搭建开发环境,可以参考之前的博客:【论文解读】SMOKE单目相机3D目标检测(CVPR2020&... 查看详情
smoke单目相机3d目标检测训练模型(代码片段)
前言本文基于SMOKE模型,使用kitti 3D目标检测数据集进行训练,记录一下过程。如果发现有错误,欢迎指出。关于原理和搭建开发环境,可以参考之前的博客:【论文解读】SMOKE单目相机3D目标检测(CVPR2020&... 查看详情
camera-radar基于ros的多传感器融合感知系统实现(雷达+相机)(代码片段)
实现功能:代码下载地址:下载地址1)基于深度学习的目标检测;2)基于雷达的距离估计和预测;3)多传感器感知结果融合模块。环境配置、数据下载、节点启动1.InstallROSmelodic:Instructionsareavailableat:http://wiki.ros.org/melodic/Installat... 查看详情
基于pylon嵌入式目标应用(basler相机)(代码片段)
基于pylon嵌入式目标应用(Basler相机)1简介pylonCamera软件套件(简称“pylon”)是Basler的软件包,它包含易于使用的SDK、驱动程序和工具,使您能够将Basler相机集成到自己的应用程序中。pylon提供以下组件... 查看详情