[英]How to convert from world coordinates to camera coordinates
In the world coordinate system, there are objects with rotation values rx1,ry1,rz1
and position values px1,py1,pz1
.在世界坐标系中,存在旋转值为rx1,ry1,rz1
和 position 值为px1,py1,pz1
。
Similarly, there is an camera in the world coordinate system with rotation values rx2,ry2,rz2
and position values px2,py2,pz2
.类似地,世界坐标系中有一个相机,其旋转值为rx2,ry2,rz2
和 position 值为px2,py2,pz2
。
What formula can be used to convert rx1,ry1,rz1,px1,py1,pz1
to the camera coordinate system? rx1,ry1,rz1,px1,py1,pz1
可以用什么公式转换到相机坐标系?
The up vector of the camera is the Y-axis, always oriented toward the object near the world origin.相机的向上矢量是 Y 轴,始终朝向世界原点附近的 object。
The camera and the model are supposed to move within the range as shown in the following gif image.相机和 model 应该在如下 gif 图像所示的范围内移动。
I would like to use Python to do the calculations, but I am open to any other answers, including other Unity C# or mathematical statements.我想使用 Python 进行计算,但我愿意接受任何其他答案,包括其他 Unity C# 或数学陈述。
You are welcome to have commentary in quaternions or in matrices instead of euler angles.欢迎您在四元数或矩阵而不是欧拉角中进行评论。
Within Unity c# for the position you can simply use the built-in在 position 的 Unity c# 中,您可以简单地使用内置的
var localPosition = camera.transform.InverseTransformPoint(theObject.transform.position);
for the rotation you can use对于轮换,您可以使用
var localRotation = Quaternion.Inverse(camera.transform.rotation) * theObject.transform.rotation;
This should give you the localPosition
and localRotation
in the coordinate space of the camera
.这应该为您提供camera
坐标空间中的localPosition
和localRotation
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.