2012-01-03 126 views
0

我试图在iOS中使用glTranslatef在OGLES中绘制图像。我知道我可以使用UIPanGestureRecognizer获得泛数量,但我不确定如何将变量应用于x和y变量。任何想法如何做到这一点或知道更好的方法来平移OpenGL ES 1.1中的图像?如何平移2D OpenGL ES场景

如何IM设置了我的观点:这

CGRect rect = view.bounds; 
glViewport(0, 0,rect.size.width,rect.size.height); 
glMatrixMode(GL_PROJECTION); 
glLoadIdentity(); 
glOrthof(0,rect.size.width,-rect.size.height, 0, -1, 1) ; 
glMatrixMode(GL_MODELVIEW); 
glLoadIdentity();  
+0

取决于你想如何做到这一点。我通常会改变相机所在的位置。根据您使用的旋转,如果您在渲染开始时执行glTranslatef,则所有内容都可能出现重击。你如何设置你的相机? – nmjohn 2012-01-03 04:30:38

+0

其2D视图,即时消息不做任何旋转。 glTranslatef(0,0,0)将焦点放在图像的中心 – jfisk 2012-01-03 04:38:41

+0

如果您只想在X平面中平移,可以使用glTranslate(xVal,0,0);你是否希望在这架飞机外面转转?你用什么来设置你的视图矩阵? – nmjohn 2012-01-03 04:42:28

回答

1
CGRect rect = view.bounds; 
glViewport(0, 0,rect.size.width,rect.size.height); 
glMatrixMode(GL_PROJECTION); 
glLoadIdentity(); 
glOrthof(xPan,rect.size.width + xPan,-rect.size.height + yPan, yPan, -1, 1) ; 
glMatrixMode(GL_MODELVIEW); 
glLoadIdentity();