我從https://github.com/antonholmquist/rend-ios下載了該項目。手觸動移動對象模型在撕裂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;
}
移動茶壺它不會移動,只顯示黑色屏幕。 如何顯示移動的茶壺模型?
謝謝Sabs .... – prabu