重新定位形状/对象-OpenGL [英] Repositioning Shapes/Objects- OpenGL
问题描述
我想重新定位圆形,三角形,直线和圆弧.我该怎么办?我已经在网上搜索了解决方案,但没有找到专门解决该问题的方法.
I would like to reposition a circle, triangles, lines and an arc. How do I go about it? I've searched the web for solutions but nothing that address the issue specifically.
任何能引导我朝正确方向发展的信息都会有所帮助.
Any input that will lead me in the right direction will be helpful.
我正在将C ++与opengl一起使用.
I'm using C++ with opengl.
推荐答案
我想重新定位一个圆,三角形,直线和圆弧.
I would like to reposition a circle, triangles, lines and an arc.
那么您已经绘制了场景,现在想更改对象的位置吗?
So you already did draw the scene and now want to change the position of the objects?
那么,您需要了解的是,OpenGL不维护各种场景图.提交绘制调用后,事物仅在目标帧缓冲区上更新,仅此而已.你想改变一些东西吗?清除屏幕,重画所有内容,但现在应用调整.
Well then, all you need to understand is, that OpenGL doesn't maintain a scene graph of sorts. After submitting a draw call, things get only updates on the target framebuffer and that's it. You want to change something? Clear the screen, redraw everything, but now with the adjustments applied.
确实,OpenGL只是绘制东西,无非就是操作系统(视口/窗口)提供的某些纸张的复杂画笔(纹理)和铅笔(基元).
Really, OpenGL just draws things, it's nothing more than sophisticated brushes (textures) and pencils (primitives) for some paper offered by the operating system (viewport/window).
由于评论需要编辑
通常的带有动画的交互式OpenGL图形程序,是用命令式编程语言编写的,其结构是这样的(伪代码)
The usual interactive OpenGL graphics program with animations, programmed in a imperative programming language, is structured like this (pseudocode)
float T = 0
float alpha = 0, beta = 0
float red = 0, green = 0, blue = 0
paused = false
on_mousemove(mousemove):
alpha += mousemove.rel_x
beta += mousemove.rel_y
on_keypress(keypress):
switch keypress.key:
case Key_ESCAPE:
queue_event(Quit)
return
case Key_PAUSE:
paused = not paused
case Key_R:
red += 0.1
case Key_r:
red -= 0.1
case Key_G:
green += 0.1
case Key_g:
green -= 0.1
case Key_B:
blue += 0.1
case Key_b:
blue -= 0.1
queue_event(Redraw)
render()
glViewport(0, 0, window.width, window.height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
apply_projection()
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
apply_modelview()
glColor3f(red, green, blue)
glRotatef(T * x_revolutions_per_second_factor, 1, 0, 0)
glRotatef(alpha, 0, 1, 0)
glRotate(beta, 0, 0, 1)
draw_object()
SwapBuffers()
main:
initialize_libraries()
load_resources()
create_window_and_OpenGL_context()
previous_loop = get_time()
loop 'eventloop':
event = peek_event()
switch event.type:
case MouseMove:
on_mousemove(event.mousemove)
case KeyPress:
on_keypress(event.keypress)
case Quit:
break 'eventloop'
case Redraw:
render()
break
case NoEvents:
fallthrough
default:
if not paused
render()
current_loop = get_time()
if not paused:
T += current_loop - previous_loop
previous_loop = current_loop
这篇关于重新定位形状/对象-OpenGL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!