https://github.com/antonholmquist/rend-iosからプロジェクトをダウンロードしました。
私はこのプロジェクトを実行し、ティーポットを 360 度完全に回転させますが、回転を停止せず、タッチしてもティーポットを回転させません。したがって、回転を停止して正常に機能し、回転が停止してティーポットを移動した後、次のコードを試します。
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
{
CGPoint currentMovementPosition = [[touches anyObject] locationInView:glView_];
[self renderByRotatingAroundX:(lastMovementPosition.x - currentMovementPosition.x)
rotatingAroundY: (lastMovementPosition.y - currentMovementPosition.y) scaling:1.0f translationInX:0.0f translationInY:0.0f];
lastMovementPosition = currentMovementPosition;
}
- (void)renderByRotatingAroundX:(float)xRotation rotatingAroundY:(float)yRotation scaling:(float)scaleF translationInX:(float)xTranslation translationInY:(float)yTranslation{
currentCalculatedMatrix = CATransform3DIdentity;
currentCalculatedMatrix = CATransform3DTranslate(currentCalculatedMatrix, 0.0, -0.2, 0.0);
currentCalculatedMatrix = CATransform3DScale(currentCalculatedMatrix, 4.5, 4.5 * (320.0/480.0), 4.5);
glClearColor(0.0f,0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GLfloat currentModelViewMatrix[16];
// Perform incremental rotation based on current angles in X and Y
if ((xRotation != 0.0) || (yRotation != 0.0))
{
GLfloat totalRotation = sqrt(xRotation*xRotation + yRotation*yRotation);
CATransform3D temporaryMatrix = CATransform3DRotate(currentCalculatedMatrix, totalRotation * M_PI / 180.0,
((xRotation/totalRotation) * currentCalculatedMatrix.m12 + (yRotation/totalRotation) * currentCalculatedMatrix.m11),
((xRotation/totalRotation) * currentCalculatedMatrix.m22 + (yRotation/totalRotation) * currentCalculatedMatrix.m21),
((xRotation/totalRotation) * currentCalculatedMatrix.m32 + (yRotation/totalRotation) * currentCalculatedMatrix.m31));
if ((temporaryMatrix.m11 >= -100.0) && (temporaryMatrix.m11 <= 100.0))
currentCalculatedMatrix = temporaryMatrix;
}
else
{
}
// Draw the teapot model
[self convert3DTransform:¤tCalculatedMatrix toMatrix:currentModelViewMatrix];
[plainDisplayProgram use];
glUniformMatrix4fv(plainDisplayModelViewMatrix, 1, 0, currentModelViewMatrix);
glVertexAttribPointer(plainDisplayPositionAttribute, 3, GL_FLOAT, 0, 0, cube_vertices);
glEnableVertexAttribArray(plainDisplayPositionAttribute);
NSLog(@"posit:%d,matrix=%d",plainDisplayPositionAttribute,plainDisplayModelViewMatrix);
//Draw teapot. The new_teapot_indicies array is an RLE (run-length encoded) version of the teapot_indices array in teapot.h
for(int i = 0; i < num_cube_indices; i += cube_indices[i] + 1)
{
NSLog(@"count:%d,i=%d",num_cube_indices,i);
glDrawElements(GL_TRIANGLES, cube_indices[i], GL_UNSIGNED_SHORT, &cube_indices[i + 1]);
}
[glView_ presentFramebuffer];
}
- (BOOL)presentFramebuffer
{
BOOL success = FALSE;
if ([EAGLContext currentContext])
{
#ifdef MSAA
glBindFramebuffer(GL_READ_FRAMEBUFFER_APPLE, multisampleFramebuffer);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER_APPLE,framebuffer);
glResolveMultisampleFramebufferAPPLE();
#endif
glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer);
success = [[EAGLContext currentContext] presentRenderbuffer:GL_RENDERBUFFER];
#ifdef MSAA
glBindFramebuffer(GL_FRAMEBUFFER, multisampleFramebuffer);
#endif
}
return success;
}
ティーポットを動かしても動かず、黒い画面だけが表示されます。移動したタッチのティーポット モデルを表示する方法は?