如何使用 OpenGL 通过鼠标旋转 3D 任何对象?
如何使用 OpenGL 通过鼠标旋转 3D 对象?我该怎么做?你能告诉我这是如何完成的吗?
How can I rotate 3-D an object with through mouse by using OpenGL?How can I do that?Could you show me how this is done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此需要很多代码,而且还取决于渲染对象的方式。
您使用的是固定功能管道还是着色器?
至于鼠标部分,您需要处理表单生成的 MouseDown、MouseMove 和 MouseUp 方法/事件。尝试通过绘制可以使用鼠标移动的简单位图来感受鼠标的工作原理。一旦掌握了处理鼠标输入的窍门,就可以更改响应以根据鼠标在 x/y/z 轴上移动的量来更新对象的旋转。尽量避免使用欧拉(角度)表示法来旋转对象,而是使用矩阵并旋转矩阵。
That's a lot of code to do that and it also depends on how you're rendering the object.
Are you using the fixed function pipeline or are you using shaders?
As for the mouse part, you need to handle the MouseDown, MouseMove and MouseUp methods / events the form generates. Try getting a feel for how the mouse works by just drawing a simple bitmap that can be moved using the mouse. Once you've got the hang of handling the mouse input, change the response to update the object's rotation based on the amount the mouse moved in the x/y/z axes. Try to avoid using Euler (angle) notation for the rotation of the object, use a matrix and rotate the matrix instead.