2013-05-22 75 views
0

我從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:&currentCalculatedMatrix 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; 
} 

移動茶壺它不會移動,只顯示黑色屏幕。 如何顯示移動的茶壺模型?

回答

1

使用觸摸移動,它將在各個方向上清晰地旋轉。嘗試這個。

xangle和yangle全局聲明並初始化爲0.0。

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    UITouch * touch = [touches anyObject]; 


    NSLog(@"Touch Returns : %@",touches); 
    CGPoint location = [touch locationInView:glView_]; 
    CGPoint lastLoc = [touch previousLocationInView:glView_]; 
    CGPoint diff = CGPointMake(lastLoc.x - location.x, lastLoc.y - location.y); 

    float rotX = 1 * DegreesToRadians(diff.y/0.2); 
    float rotY = 1 * DegreesToRadians(diff.x/0.2); 

    xAngle += rotX; 
    yAngle += rotY; 

    teapotNode_.rotation = CC3VectorMake(xAngle, yAngle, 0); 
    director_.running = YES; 

} 
+0

謝謝Sabs .... – prabu

1

我發現回答自己在此雷德-IOS https://github.com/antonholmquist/rend-ios項目中的每個按鈕的觸摸使用下面的代碼移動對象模型:

- (無效)rightButtonPressed {

float angle;  
angle = teapotNode_.rotationAngle;  
angle +=0.4;   
director_.running = YES;//Redirector object  
if (director_.frameInterval == 2) 
{ 
    director_.running = NO; 

}   

} 其做工精細。