加工& OpenGL - 改变相机位置?
我正在做一个小项目,将数据集绘制到一个世界上。我已经完成了策划。现在我想实现相机移动。
我有一些代码,如果用户按住 c 并拖动鼠标,相机位置就会改变。问题是,我不确定如何根据鼠标移动来计算相机移动。
这是默认位置的相机代码:camera(width/2.0, height/2.0, (height/2.0) / tan(PI*60.0 / 360.0), width/2.0, height/2.0, 0, 0, 1, 0 );
如何更改与鼠标拖动相关的相机位置? (我尝试过使用 mouseX 和 mouseY 来偏移相机眼睛位置,但效果不佳。)
I'm doing a small project where I plot data sets onto a world. I've got the plotting done. Now I want to implement camera movement.
I have some code where if a user holds down c and drags the mouse, the camera position is changed. The thing is, I'm not sure how to calculate the camera movement from the mouse movement.
This is the camera code for the default position: camera(width/2.0, height/2.0, (height/2.0) / tan(PI*60.0 / 360.0), width/2.0, height/2.0, 0, 0, 1, 0);
How can I change the camera position in relation to the mouse dragging? (I've tried using mouseX and mouseY to offset the camera eye position, but it doesn't work well.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你有方向向量,你可以设置你的相机的位置如下(抽象代码):
这是为了前进。如果你想向后移动 - 只需将你的归一化方向向量乘以 -1 即可。对于向左和向右扫射,请使用以下内容:
以下是有关向量运算的一些注释(来自我的“HelloWorld”应用程序之一 =) ):
我的 cross_product() 版本如下所示:
希望这会有所帮助 =)
If you have got direction vector, you can set position of your camera as follow (abstract code):
That's for moving forward. If you wanna move backward - just multiply your normalized direction vertor by -1. For strafing left and right, use something this:
Here are some notes on vector operations (from one of my "HelloWorld" applications =) ):
My version of cross_product() looks like this:
Hope this will help =)
我认为到目前为止最简单的事情是使用 peasycam 库
http://mrfeinberg.com/peasycam/
该库将允许您使用鼠标访问相机,您可以通过各种方式以及各种 getter 来限制鼠标,从而可以轻松访问有关相机及其当前状态的信息。
I think by far the easiest thing to do would be to use the peasycam library
http://mrfeinberg.com/peasycam/
this library will give you access to your camera using a mouse which you can constrain in various ways as well various getters that make it easy to access information about the camera and its current state.