XCodeのOpenGlESサンプルが機能する理由を説明してください。drawFrameメソッドを開始するために次のことを行います(blablaViewController.m内-名前はプロジェクトの名前に依存します):
//sets up a CADisplayLink to do a regular (draw & update) call like this
CADisplayLink *aDisplayLink = [[UIScreen mainScreen] displayLinkWithTarget:self
selector:@selector(drawFrame)];
[aDisplayLink setFrameInterval:animationFrameInterval];
[aDisplayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
そして、drawFrameメソッド内で次のことを行います。
//start of method
...
static float transY = 0.0f;
...
//Quite a lot of OpenGl code, I am showing only parts of the OpenGL ES1 version:
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, (GLfloat)(sinf(transY)/2.0f), 0.0f);
transY += 0.075f;
...
//end of method
私はまだObjectiveCの多くを知りませんが、このtransY変数がリセットされ、同じ方法でインクリメントされる方法は非常に奇妙です。GL_MODELVIEWマトリックスは、シフトされる前にIDにリセットされるため、openglのどこかに累積値を保持できるとは思いません。
staticキーワードはここでのトリックですか?何かが一度静的であると宣言された後、Objective Cは将来のすべての変数宣言を無視しますか?
助けてくれてありがとう!