向量 旋转 3D 相机倾斜
希望简单的答案,但我无法得到它。
我有一个自己编写的 3D 渲染引擎。
我有相机位置、观察位置和向上向量。
我希望能够向左、向右、向上、向下“倾斜”相机。就像固定三脚架上的相机一样,你可以抓住手柄并将其向上、向下、向左、向右等倾斜。
数学难倒了我。我已经能够进行向前/向后移动和上/下/左/右平移,但无法计算出矢量数学以使其倾斜。
对于左右倾斜,我想围绕相机位置旋转观察位置,但我需要考虑向上向量,否则旋转不知道要绕哪个轴转动。
我需要的数学/算法是沿着...
Camera=(cx,cy,cz) 看=(lx,ly,lz) Up=(ux,uy,uz)
RotatePointAroundVector(lx,ly,lz,ux,uy,uz,amount)
任何人都可以帮助解决所涉及的数学问题吗?
非常感谢。
Hopefully easy answer, but I cannot get it.
I have a 3D render engine I have written.
I have the camera position, the lookat position and the up vector.
I want to be able to "tilt" the camera left, right, up and down. Like a camera on a fixed tripod that you can grab the handle and tilt it it up, down, left right etc.
The maths stumps me. I have been able to do forwards/backwards dolly and up/down/left/right panning, but cannot work out the vector math to get it to tilt.
For left and right tilt I want to rotate the lookat position around the camera position, but I need to take into account the up vector, otherwise the rotation doesn't know which axis to to turn around.
The maths/algorithm I need is along the lines of...
Camera=(cx,cy,cz)
Lookat=(lx,ly,lz)
Up=(ux,uy,uz)
RotatePointAroundVector(lx,ly,lz,ux,uy,uz,amount)
Can anyone assist with the maths involved?
Many thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在相机前面确定一个点,然后围绕相机旋转该点(使用三角函数)并使用 Lookat() 来旋转相机。
一旦你必须开始使用滚动(绕 Z 轴旋转),这将不起作用。所以你可能想创建一个基于四元数的相机类。此链接帮助了我:gpwiki.org/Quaternion...
You could make a point infront of the camera, then rotate that around the camera (using trig) and use your lookat() to rotate the camera.
This wont work once you have to start using roll (rotation around the Z). So you might wanna create a quaternion based camera class. This link helped me: gpwiki.org/Quaternion...
它可能不是数学上最优的,但您可以将相机观察向量分解为三个向量 - 两个定义水平面,一个向上向量。
要获得水平面,您可以得到一个向量作为向上向量和摄像机观察向量的叉积。然后,您可以通过取 up 和刚刚找到的向量的点积来获得另一个正交向量。不要忘记标准化你的三个向量。
接下来,用相机的点积来观察向量与三个向量,然后绕水平面旋转(将向量视为坐标轴)。
抱歉用文字表达了一切。我希望这有帮助。
It may not be mathematically optimal, but you could de-compose the camera to look-at vector into three vectors - two that define the horizontal plane, and the up vector.
To get the horizontal plane, you can get one vector as the cross product of the up vector and the camer to look-at vector. You can then get the other orthogonal vector by taking the dot product of up and the vector just found. Don't forget to normalize your three vectors.
Next take the dot product of your camera to look-at vector with your three vectors, and now do the rotation about the horizontal plane (treating your vectors as though they were the coordinate axis).
Sorry for putting it all in words. I hope this helps.
基本上,您可以可视化相机的本地坐标系。
局部 Z 是观察向量(从相机中心到观察点)并且“进入屏幕”。 本地 Y 将位于屏幕上方。如果保持相机向上向量垂直于相机注视向量,则向上向量也是局部 Y。局部 X 将垂直于其他两个轴(这是它们在它们之后的叉积)正常化)。
左右旋转是围绕局部 Y 轴(偏航)旋转观察向量。 上下旋转是围绕局部 X 轴(俯仰)旋转向上向量和观察向量。 “左右倾斜头部”是围绕局部 Z 轴(倾斜)向上旋转向量。
每次更改观察向量或向上向量时,都需要重新计算局部轴。
Basically you visualize a local coordinate system for your camera.
The local Z is the lookat vector (from the camera center to the lookat point) and is "into the screen". The local Y will be toward the up of the screen. If you maintain your camera up vector perpendicular to the camera lookat vector, then the up vector is also the local Y. The local X will be normal to the two other axes (it is their cross product after their normalization).
Rotating left-right is a matter of rotating the lookat vector about the local Y axis (yaw). Rotating up-down is a matter of rotating the up vector and the lookat vector about the local X axis (pitch). "Tilting the head" left-right is a matter of rotating up vector about the local Z axis (bank).
Each time you change the lookat vector or the up vector, you need to recompute the local axes.