- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个比例为 (64,1,36) 且旋转为 (90,-180,0) 的平面,并且需要 2d 坐标格式的光线转换的局部坐标:
(0,0)-------(64,0)
| |
| |
| |
(0,36)------(64,36)
使用我当前的代码:
RaycastHit hit;
Vector3 coords = new Vector3();
if (Physics.Raycast(GazeOriginCombinedLocal, GazeDirectionCombined, out hit, Mathf.Infinity))
{
if (!hit.transform.Equals("Cube"))
{
Pointer.transform.position = hit.point; //Green cube for visualization of hit in worldspace
// coords = RectTransformUtility.ScreenPointToLocalPointInRectangle(Plane, hit.point, Camera.main, out coords);// no result at all
}
}
试试这个:
hit.transform.InverseTransformPoint(hit.point)
给我这个
(5,-5)---(-5,-5)
| |
| (0,0) |
| |
(5,5)----(-5,5)
有人知道如何获得所需的格式吗?
最佳答案
我想你可以使用 Transform.InverseTransformPoint
哪个
Transforms position from world space to local space.
然后,由于这也受到比例的影响,它再次受到平面比例的影响,使用 Vector3.Scale
.
所以你的坐标可能应该是这样的
coords = hit.transform.localScale / 2f + Vector3.Scale(hit.transform.InverseTransformPoint(hit.point), hit.transform.localScale);
现在不能测试它,因为在智能手机上打字。你可能例如需要根据您的需要和平面的旋转方式等来反转 y/z 分量。但我希望这能给您一个想法
为了调试错误,您可能应该逐步打印出这些值
var scale = hit.transform.localScale; // 64, 1, 36
var halfScale = scale / 2f; // 32, 0.5, 18
var localHitPoint = hit.transform.InverseTransformPoint(hit.point);
Debug.Log($"{nameof(localHitPoint)}:{localHitPoint:0.000}");
所以我最初在这里期望的值是这样的
(-0.5, 0.5, 0)----(0.5, 0.5, 0)
| |
| (0, 0, 0) |
| |
(-0.5, -0.5, 0)---(0.5, -0.5, 0)
但是 正如您现在添加的那样:您的飞机是旋转的!
X 上的 90° 实际上使 Y 和 Z 交换了位置。因此,为了获得所需的 Y 坐标,您宁愿阅读 localHitPoint.z
。
然后 Y 上的 180° 基本上反转了 X 和 Z。
所以我现在希望这些值看起来像
(0.5, 0, -0.5)----(-0.5, 0, -0.5)
| |
| (0, 0, 0) |
| |
(0.5, 0, 0.5)---(-0.5, 0, 0.5)
这看起来与您描述的值非常相似。 虽然不确定为什么因子为 10 以及为什么不需要切换 Y 和 Z。
但是,由于您实际上希望 0,0 位于左上角,因此您只需要翻转 X 轴并使用 Z 而不是 Y,所以
fixedLocalHitPoint = new Vector2(-localHitPoint.x, localHitPoint.z);
Debug.Log($"{nameof(fixedLocalHitPoint)}:{fixedLocalHitPoint:0.000}");
现在应该给你这样的值
(-0.5, -0.5)----(0.5, -0.5)
| |
| (0, 0) |
| |
(-0.5, 0.5)----(0.5, 0.5)
你仍然需要再次扩大规模
var scaledHitPoint = Vector2.Scale(fixedLocalHitPoint, new Vector2 (scale.x, scale.z));
Debug.Log($"{nameof(scaledHitPoint)}:{scaledHitPoint:0.000}");
现在应该给出如下值
(-32, -18)----(32, -18)
| |
| (0, 0) |
| |
(-32, 18)-----(32, 18)
这就是为什么你需要添加中心点作为引用
coords = new Vector2(halfScale.x, halfScale.z) + scaledHitPoint;
Debug.Log($"{nameof(coords)}:{coords:0.000}");
现在应该是
(0, 0)------(64, 0)
| |
| (32, 18) |
| |
(0, 36)-----(64, 36)
我希望这能让人们更清楚地了解这些“奇怪”值的来源。
由于您的相机按比例缩放 1,1,1
并且没有涉及任何其他内容,老实说,我很难找到 10 的因子会在何处偷偷进入计算。
关于unity3d - Raycast 获取 Plane 命中的局部坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62540444/
我刚开始使用 PyPNG。但是在元数据中有一项我不明白:飞机。所以两个文件的两个例子: 文件 1 'bitdepth': 8, 'interlace': 0, 'planes': 1, 'greysc
我正致力于确定两个 3D 对象(三角形面)之间的关系(边界/内部交叉点)并偶然发现了 Shapely ,我有兴趣使用它而不是实现我自己的点/线段/射线/三角形相交函数。 但是,我遇到了以下问题: >>
我有一个比例为 (64,1,36) 且旋转为 (90,-180,0) 的平面,并且需要 2d 坐标格式的光线转换的局部坐标: (0,0)-------(64,0) | |
Plane没有 lookAt 方法,所以我不能只执行 lookAt(camera.position)。相反,它是用 normal 定义的。 ,表示为 Vector3。如何让这架飞机始终面向相机? 最佳
使用scatterplot3d在 R 中,我试图从观察到回归平面绘制红线: wh 0 s3d$points3d(x[wh], z[wh], y[wh], pch = 19) 残差 # scatter
我已经加载了纹理,但它似乎显示纹理的单一颜色。我首先定位了纹理坐标,但似乎无法使纹理正确显示。预期的纹理如下: 256x256 纹理正在显示,但看起来是纯色。也许放大到纹理的一个像素,或者纹理坐标的扭
嗨,有人可以看看这个程序吗?我不明白为什么输出是 _c。书上的回答是“一旦s3()抛出异常给s2(),s2()抛给s1(),s2()的代码就不会再执行了”。为什么不呢? public class Pl
我有一个由模拟生成的数据点组成的大网格,与 xy 平面中的每个点相关联的是一个 z 值(模拟的结果)。 我将 x、y、z 值转储到一个纯文本文件中,我想做的是测量 xy 平面(即 z=0)和由数据点。
我尝试为内存使用拍摄图像,但 imageProxy.planes[0].remaining() 始终为 0。因此我无法从结果中获取位图。这是错误还是我做错了什么? 这是我绑定(bind)相机的方法:
我目前正在研究 1.6 版的服务网格 Istio。数据平面(Envoy 代理)由控制平面配置。尤其是 Pilot( istiod 的一部分)负责将路由规则和配置传播给特使。我想知道通信是如何工作的?
有谁知道如何在 THREEJS 中的平面图元(planemesh?/mesh)上发光?我用谷歌搜索并找到了立方体和球体的发光,但这些更像是将对象/网格封装在另一个具有透明 Material 的对象中,
我正在开发一款纸牌游戏,其中纸牌以透视方式显示在 table 上。 table 和卡片都有相同的 x 旋转 (45°)。 随着卡片离玩家越来越远(在 table 上“向上”移动),我希望它们变小。我认
在 x265 编码器 ( https://x265.readthedocs.org/en/default/api.html ) 的编码过程中,我想在新图像编码后将图像像素值(特别是 Y channel
在 openGles 中,减少平截头体近平面(如您所见 here )会使物体看起来更近。我来自 3d,例如在 Vray 中,更改近裁剪平面不会修改距离,只会裁剪一些几何体。 为什么改变平截头体的近平面
我正在尝试开发一个应用程序来渲染我手腕上 watch 的 3D 模型。但是 Sceneform SDK 只检测到一个平面。 我尝试通过增强手腕的图片来增强图像,但由于特征点太少而没有检测到我的手腕。
使用 SpriteKit,是否可以让两个节点相互碰撞,但是当引入另一个节点时,物理原理会发生变化吗? 例如,考虑以下 3 个节点: - 对象 - Object_Hole - 播放器 因此,包含一个 P
有没有办法轻松地动态改变平面的宽度和高度?下面的代码无效。 plane.geometry.parameters.width = width; plane.geometry.parameters.hei
我正在学习 ARKit 并尝试将对象放置在检测到的平面上。但它不能正常工作,并且平面和 3D 对象之间存在空间。 这是我的平面检测代码: func renderer(_ renderer: SCNSc
我对 C++ 的 GLM 库还很陌生,所以我遇到了一些问题。我有一个由一个位置和两个跨 vector 组成的平面,以及一条包含它的位置和方向的线 - 所有值都是 glm::vec3。 struct P
我可以使用 normal 和常量 w 定义一个 CSG.Plane,如下所示: CSG.Plane = function(normal, w) { this.normal = normal;
我是一名优秀的程序员,十分优秀!