0

I downloaded the project from https://github.com/antonholmquist/rend-ios.

I run this project the teapot rotating 360 degree full rotation,But not stop the rotation and touches not rotate the teapot,So i work for stop the rotation it worked properly and after rotation stopped touches to move the teapot i will try this below code:

- (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;
}

Move the teapot it will not move, only blackcolor screen shown. How to show the teapot model for touches moved?

4

2 回答 2

1

我在这个rend-ios项目中找到了自己的答案 https://github.com/antonholmquist/rend-ios,每个按钮触摸都使用下面的代码移动对象模型:

-(void)rightButtonPressed {

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

}        

} 它的工作正常。

于 2013-06-07T11:13:25.073 回答
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;

}
于 2013-09-10T04:10:41.503 回答