相机旋转算法
更多的是一个数学问题,而不是一个编程问题,但我需要编写相机旋转代码,但我不知道如何做。对于我来说,突然做的数学有点抽象。 相机的旋转是用四元数完成的,我真正想要的是一个研究样本或者只是一篇关于该主题的文章,但我找不到任何东西。
More a maths question then a programming one, but I need to code camera rotation and I have no idea how. The maths are a bit to abstract for me to do out of the blue.
The camera's rotation is done with quaternions, all I really want is a sample to study or just an article about the subject but I can't find anything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我用 opengl 写的东西。任何语言的基本算法都应该是相同的。你需要的东西是:
单位长度的向上向量(如果你看着中心,则向上定义):(upx,upy,upz)
原点(你正在看的地方):(ox,oy,oz)
相机位置(你的相机所在的位置):(cx,cy,cz)
假设“del”是你想要移动的量,
之后,你可以计算“前向”向量。也就是说,单位长度的向量通过以下方式从你指向中心:
然后你可以计算单位“左”向量,即如果你看着中心,则指向单位长度左侧的向量
:然后可以编写以下例程(每个原始的“//”左对齐表示一个新例程)
here is something i wrote in opengl. the basic algorithm should be the same in any language. the things you need are:
the up vector of unit length (where up is defined if you are looking at the center): (upx, upy, upz)
origin (the place you are looking at): (ox,oy,oz)
camera position (where your camera is): (cx, cy, cz)
assume "del" is the amount you want to move, and that
after that, you can calculate the "forward" vector. that is, the vector which is unit length and points from you to the center via:
you can then calculate the unit "left" vector, that is, the vector pointing to the left of unit length if you are looking at the center:
you can then write the following routines (each original '//' justified left signifies a new routine)