从Euler角度控制正交摄影机的位置和方向 [英] Control of Orthographic camera position and orientation from Euler Angles

查看:85
本文介绍了从Euler角度控制正交摄影机的位置和方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试从欧拉角控制正交相机的位置(x,y,z)和向上矢量(相机的顶部).

Attempting to control orthorgraphic camera position (x,y,z) and up vector (top of camera) from euler angles.

我有一个带有IMU的真实设备,该设备输出沿每个轴(x,y,z)的旋转.我正在尝试将这些角度转换为相机的眼睛位置和向上的矢量方向.如果更改了物理设备,则方向的变化应反映在相机位置的变化中.

I have a real world device with an IMU that outputs rotation along each axis (x,y,z). I'm trying to translate these angles into camera eye position and up vector direction. If the physical device is altered, the change in orientation should be reflected in the change in position of the camera.

我很难理解这个映射背后的数学原理,并且在我尝试的过程中还没有碰到很多运气.我可以使单轴旋转工作,但多轴一直是个问题.将物理设备的偏航,俯仰和滚动映射到摄像机的位置和向上矢量的任何帮助都将是惊人的.数学证明对我来说是个大问题.

I'm having a hard time with the math behind this mapping, and have not had a ton of luck in what I've attempted. I can get single axis rotations to work but multiple axes has been a problem. Any help in mapping yaw,pitch and roll from physical device onto the position and up vector of camera would be amazing. The math is proving to be quite a problem for me.

相机到物体和目标点的距离应保持恒定.

The distance from camera to object and target point should remain constant.

radius = camera.target.distanceTo(camera.eye)
pos = get_data()
#convert to radians and cast to float
roll = float(pos['x'])*(math.pi/180.0)
pitch = float(pos['y'])*(math.pi/180.0)
yaw = float(pos['z'])*(math.pi/180.0)

x = camera.eye.x
y = camera.eye.y
z = camera.eye.z

x = x*math.cos(pitch)*math.sin(yaw)
y = y*math.cos(yaw)*math.cos(pitch)
z = z*math.sin(pitch)

eye = Point3D.create(x,y,z)

camera.eye = eye
camera.target = target      
camera.upVector = up

推荐答案

如果您的欧拉角表示绝对旋转,则可以计算旋转矩阵R.如何执行此操作取决于Euler角的定义,应在文档中进行描述.可能是:

If your Euler angles represent an absolute rotation, you can calculate a rotation matrix R. How you do this depends on the definition of the Euler angles, which should be described in the documentation. It might be:

R = rotateY(yaw) * rotateX(pitch) * rotateZ(roll)

同样,这只是一个例子.正确的公式取决于欧拉角的顺序及其解释.

Again, this is just an example. The correct formula depends on the order of Euler angles and their interpretation.

然后可以将相机的模型矩阵计算为:

The camera's model matrix can then be calculated as:

cam = translation(target) * R * translation(0, 0, radius)

(或对于左手坐标系为-radius). translation()计算转换矩阵.

(or -radius for left-handed coordinate systems). translation() calculates a translation matrix.

这背后的直觉是,将摄像机移至目标,然后根据R旋转它,然后再将其移回radius.

The intuition behind this is that you move your camera to the target, then rotate it according to R, and then move it back by radius.

如果具有此矩阵,则相机的向上矢量将是其第二列,眼睛矢量将是其第四列.如果只需要视图矩阵,请使用cam的逆矩阵.

If you have this matrix, the camera's up-vector will be its second column, the eye-vector will be its fourth column. If you just need a view-matrix, use cam's inverse.

注:上面的解释假定将向量视为列向量.如果将它们视为行向量(例如DirectX中的通用),则必须对计算进行相应的调整.

Note: The explanations above assume that vectors are treated as column vectors. If they are treated as row vectors (e.g. common in DirectX), the calculations have to be adapted accordingly.

这篇关于从Euler角度控制正交摄影机的位置和方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆