ArcGIS Maps SDK for Unity 0.3旋转

2023-11-05

​ArcGIS Maps SDK for Unity1.0版本已出
基础参考:

API:

https://developers.arcgis.com/unity-sdk/
基础

https://cloud.tencent.com/developer/news/717499

可以做什么

在这里插入图片描述

倾斜摄影 +BIM +标注 总之目的是用unity做出cesium的效果 超不超越之后再说

简单说说问题和解决办法

1.操作方式

左键移动 右键旋转相机 wsad

对于用过cesium开发的就会发现 很别扭 很难受 缺了个中键旋转
解决办法:自己写一个
如果你研究代码会发现 没有关于高程的算法 很难受
GetMouseRayCastDirection() //得到一条相机射线
Geometry.cs //用得到的射线 求与椭球的交点(对没有高程 可能是我没找到) 并返回交点与相机的距离
知道这些=》
得到鼠标点中的交点
private Vector3d getMousedownPosition(Vector3d cartesianPosition)
{
var worldRayDir = GetMouseRayCastDirection();
var ellipsoidScaling = 1.0 / (1.0 - GeoUtils.EarthFlattening);
// 缩放射线在y轴上的空间,使椭球体成为一个球体
var scaledRayOrig = new Vector3d(cartesianPosition.x, cartesianPosition.y * ellipsoidScaling, cartesianPosition.z);
var scaledRayDir = new Vector3d(worldRayDir.x, worldRayDir.y * ellipsoidScaling, worldRayDir.z);
double scaledLength;
var result = RaySphereIntersection(scaledRayOrig, scaledRayDir, Vector3d.zero, GeoUtils.EarthRadius + 750, out scaledLength);
if (result)
{
// 回到非缩放的世界坐标,计算hitPoint和rayOrig之间的真实长度
var scaledHitPoint = scaledRayOrig + scaledLength * scaledRayDir;
Vector3d hitPoint = new Vector3d(scaledHitPoint.x, scaledHitPoint.y / ellipsoidScaling, scaledHitPoint.z);
//var latLon = arcGISMapViewComponent.Scene.FromCartesianPosition(hitPoint);
return hitPoint;
}
return new Vector3d(0, 0, 0);
}
//判断射线是否与地球相交 并返回长度 (原代码有)
private bool RaySphereIntersection(Vector3d rayOrig, Vector3d rayDir, Vector3d sphereCenter, double sphereRadius, out double t)
{
double a = Vector3d.Dot(rayDir, rayDir);
Vector3d s0_r0 = rayOrig - sphereCenter;
double b = 2.0 * Vector3d.Dot(rayDir, s0_r0);
double c = Vector3d.Dot(s0_r0, s0_r0) - (sphereRadius * sphereRadius);

		if (b * b - 4.0 * a * c < 0.0)
		{
			t = 0;
			return false;
		}
		else
		{
			t = (-b - System.Math.Sqrt((b * b) - 4.0 * a * c)) / (2.0 * a);
			return true;
		}
	}

得到点后下一步旋转
原理:
我们要知道原理就不能用RotateAround 和Quaternion.AngleAxis(angle, axis)

利用 Quaternion.Euler自身旋转 Quaternion.AngleAxis 绕自定义轴旋转 得到旋转矩阵
Quaternion rotation = Quaternion.Euler(0, Input.GetAxis(“Mouse X”) * 5, 0);// 绕x y z轴的旋转
// Quaternion rotation = Quaternion.AngleAxis(Input.GetAxis(“Mouse X”) * 5, Vector3.up);
Quaternion rotation1 = Quaternion.AngleAxis(Input.GetAxis(“Mouse Y”) * 5,-transform.right);
Matrix4x4 m = Matrix4x4.TRS(new Vector3(0,0,0), rotation* rotation1, new Vector3(1,1,1));//设置 平移 大小 缩放
transform.position = m.MultiplyPoint3x4(transform.position - Model.Instance.Origin)+ Model.Instance.Origin;
//transform.rotation = m.rotation * transform.rotation;
transform.rotation = rotation* rotation1 * transform.rotation;

​然后就是:
//相机绕点旋转 ---------------------------------高度问题
void MyRotateAround(ref Vector3d cartesianPosition, ref Quaternion cartesianRotation, Vector3d center, Vector3d axis, double angle,int a)
{
Vector3d jilu = cartesianPosition;
//Quaternion rot = Quaternion.AngleAxis(angle, axis);
Vector3d dir = cartesianPosition - center; //计算从圆心指向摄像头的朝向向量
if (a==0)
{
dir = Matrix4x4d.Rotate(axis, angle).MultiplyPoint(dir);
cartesianPosition = center + dir;
cartesianRotation = Matrix4x4d.Rotate(axis, angle).ToQuaterniond().ToQuaternion() * cartesianRotation;//区别 前后位置乘的原因
}
else
{
dir = Matrix4x4d.Rotate(axis, -angle).MultiplyPoint(dir);
cartesianPosition = center + dir;
var right = Matrix4x4.Rotate(cartesianRotation).GetColumn(0);
var rotationX = Quaternion.AngleAxis(-(float)angle, right);
cartesianRotation = rotationX * cartesianRotation;
//cartesianRotation = Matrix4x4d.Rotate(axis, angle).ToQuaterniond().ToQuaternion() * cartesianRotation;
}
if (arcGISMapViewComponent.Scene.FromCartesianPosition(cartesianPosition).Altitude<700)
{
cartesianPosition = jilu;
}

	}

在DragMouseEvent()方法中插入
if (Input.GetMouseButtonDown(2))
{
RotationCenter = getMousedownPosition(cartesianPosition);
}
if (Input.GetMouseButton(2))
{
if (RotationCenter != Vector3d.Zero)
{
MyRotateAround(ref cartesianPosition, ref cartesianRotation, RotationCenter, Vector3d.Normalize(RotationCenter), Input.GetAxis(“Mouse X”) * 5, 0);
MyRotateAround(ref cartesianPosition, ref cartesianRotation, RotationCenter, (Vector3d)hpTransform.Right, Input.GetAxis(“Mouse Y”) * 5, 1);
}
}
2.相机跳转
this.transform.GetComponent().Rotation = new Rotator(356.499768212976f, 67.7412622911893f, 0.00028224651352337f);
this.transform.GetComponent().Position = newlatLon;
想要滑动跳转加个Lerp

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ArcGIS Maps SDK for Unity 0.3旋转 的相关文章

随机推荐

  • 文件包含漏洞特点和php封装伪协议

    渗透学习 文件包含漏洞 文章目录 渗透学习 前言 本文只做学习用途 严禁利用本文提到的技术进行非法攻击 否则后果自负 本人不承担任何责任 一 文件包含漏洞 二 实验步骤 1 文件包含特点 2 本地包含配合文件上传包含图片马 3 包含Apac
  • udig下载、安装及汉化,生成geoserver图层样式sld文件

    uDig是一款开源免费的桌面地理信息系统框架软件 uDig汉化版主要采用RCP技术构建 内置的多专业的水文工具 拥有复杂专业的分析能力 既可以作为独立程序运行 还可以作为插件使用 uDig是一个 open source EPL and BS
  • 【报错记录】AttributeError: ‘xxx‘ object has no attribute ‘module‘

    文章目录 问题描述 问题分析与解决 总结 参考资料 问题描述 在跑代码时 报出 AttributeError InpaintGenerator object has no attribute module 的错误 如下图所示 经过一通Deb
  • Qt 带参数的信号与槽

    1 在dialog h中定义带参数的信号函数 signals void A double level double pitch double dis double time double min spend double max spend
  • 花5分钟判断,你的Jmeter技能是大佬还是小白!

    jmeter 这个工具既可以做接口的功能测试 也可以做自动化测试 还可以做性能测试 其主要用途就是用于性能测试 但是 有些公司和个人 就想用 jmeter 来做接口自动化测试 你有没有想过呢 下面我就给大家讲讲 用 jmeter 如何做接口
  • Linux文件权限一共10位长度,分成四段

    Linux文件权限一共10位长度 分成四段 Linux文件权限 1 文件aaa的访问权限为rw r r 现要增加所有用户的执行权限和同组用户的写权限 下列哪些命令是正确的 a chmod a x g w aaa b chmod 764 aa
  • BSC 及HT 等链的NFT 创造及绑定图片教程

    我们首先打开REMIX 智能合约编程网站 下面代码是NFT合约 Submitted for verification at BscScan com on 2021 10 07 File openzeppelin contracts util
  • RxJava基本流程和lift源码分析

    http blog csdn net lzyzsd article details 50110355
  • WebStorm Debug 配置

    WebStorm 调试配置 所需工具 Chrome 浏览器 Chrome 浏览器插件 JetBrains IDE Support WebStorm 配置过程 首先 下载 Chrome 浏览器以及 JetBrains IDE Support
  • node-第三方模块之nodemailer模块

    nodemailer 模块 专门用来发邮件 下载使用
  • 利用原生js实现TodoList----最简单的待办事项列表(附详细注释)

    利用js实现TodoList 1 todoList html
  • UITableView嵌套WKWebView的那些坑

    最近项目中遇到了一个需求 TableView中需要嵌套Web页面 我的解决办法是在系统的UITableViewCell中添加WKWebView 开发的过程中 遇到了些坑 写出来分享一下 1 首先说一下WKWebView的代理方法中 页面加载
  • 锂电池充放电管理芯片和输出芯片

    锂电池充放电管理芯片 和输出芯片 锂电池充放电管理芯片 关乎锂电池供电的产品 在锂电池上 需要三个电路系统 1 锂电池保护电路 2 锂电池充电电路 3 锂电池输出电路 1 单节的锂电池保护电路 单节为 3 7V 锂电池 也叫 4 2V 和
  • springmvc

    springmvc 前景介绍 springmvc图解 环境搭建 工程起步 springmvc的配置文件 相关的注解 RequestMapping的源码 RequestMapping params PathVariable的作用 Reques
  • 【信号与系统】系统线性时不变、因果稳定性的判定

    1 线性 线性包含均匀性和叠加性 其中均匀性是指输入乘以一个常数 输出也乘一个相同的常数 叠加性是指两个输入信号相加 其对应的输出也是相加关系 判定 假设系统输入E1对应输出R1 输入E2对应输出R2 若信号C1E1 C2E2输入系统后得到
  • Kmeans聚类

    一 特征预处理 1 处理缺失 异常值 缺失值直接补0 异常值可以设置一个阈值 比喻小于数据的1分位数 或者大于95分位数 就把数据进行四舍五入 用相应的分位数赋值 这样可以减少异常值对于聚类的影响 因为聚类一般计算的是距离 有异常值影响会比
  • 谷歌瓦片的网址

    有时我们需要离线谷歌地图 最简单的办法是通过网页获取 网上有很多方法 这里介绍一种非常简单实用的 闲话少叙 先上一个网址 http mt0 google cn vt lyrs s x 0 y 0 z 0 打开后在浏览器中可以看到如下图 这张
  • [第二章 web进阶]文件上传]

    先看一下题目源码
  • dataframe先分组运算再合并输出

    dataframe先分组运算再合并输出 主要用到分组函数groupby和合并函数append concat 具体代码 比如先分组 对每组数据进行删除异常值处理 MAD 然后将处理后的数据合并成一个dataframe输出 import os
  • ArcGIS Maps SDK for Unity 0.3旋转

    ArcGIS Maps SDK for Unity1 0版本已出 基础参考 API https developers arcgis com unity sdk 基础 https cloud tencent com developer new