所以,我正在尝试将我的 openGLES 1.0 代码移植到 OpenGLES 2.0 (GLKit)。基本概念是您可以在 3D 空间中四处走动。
我正在苦苦挣扎的是根据我的相机位置在物体周围移动(连接了控件等)
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect {
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
self.baseEffect.transform.modelviewMatrix = GLKMatrix4MakeLookAt(eye[0], eye[1], eye[2],center[0], center[1], center[2], 0.0, 1, 0.0);
[self.baseEffect prepareToDraw];
self.cube.effect.transform.modelviewMatrix = self.baseEffect.transform.modelviewMatrix;
self.cube.effect.transform.projectionMatrix = self.baseEffect.transform.projectionMatrix;
// Used to scale stuff based on screen res
static float roation = 0;
self.cube.rotation = GLKVector3Make(0, roation, 0);
[self.cube drawWithRotationWithRenderMode:RenderTexture];
[self handleTouches];
}
我坚持的一点是基于相机的立方体渲染(我相信我需要像 setIdentyM 这样的东西
- (void)drawWithRotationWithRenderMode:(RenderMode)renderMode
{
[EAGLContext setCurrentContext:APP_DELEGATE.context];
float alpha = 1;
float doNotRender = NO;
GLKMatrix4 current = GLKMatrix4Identity;
current = GLKMatrix4Translate(current, position.x, position.y, position.z);
current = GLKMatrix4Scale(current, scale.x, scale.y, scale.z);
self.effect.transform.modelviewMatrix = current;