Ios6 手动触摸是否在rend ios中移动对象模型?

Ios6 手动触摸是否在rend ios中移动对象模型?,ios6,rendering,opengl-es-2.0,uitouch,Ios6,Rendering,Opengl Es 2.0,Uitouch,我从网站下载了这个项目 我运行此项目使茶壶旋转360度全旋转,但不停止旋转,触摸不旋转茶壶,因此我为停止旋转而工作,它工作正常,旋转停止后触摸移动茶壶,我将尝试以下代码: - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; { CGPoint currentMovementPosition = [[touches anyObject] locationInView:glView_]; [self

我从网站下载了这个项目

我运行此项目使茶壶旋转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;
}
-(void)touchsmoved:(NSSet*)touchsevent:(UIEvent*)event;
{  
CGPoint currentMovementPosition=[[Touchs anyObject]locationInView:glView_2;];
[self-renderByRotatingAroundX:(lastMovementPosition.x-currentMovementPosition.x)
旋转圆:(lastMovementPosition.y-currentMovementPosition.y)缩放:1.0f平移X:0.0f平移:0.0f];
lastMovementPosition=currentMovementPosition;
}
-(void)renderByRotatingRoundX:(float)X旋转旋转RoundY:(float)旋转缩放:(float)scaleF translationX:(float)xtransation translationY:(float)ytransation{
currentCalculatedMatrix=CATTransformM3DidEntity;
currentCalculatedMatrix=CATTransformM3dTranslate(currentCalculatedMatrix,0.0,-0.2,0.0);
currentCalculatedMatrix=CATTransformM3DScale(currentCalculatedMatrix,4.5,4.5*(320.0/480.0),4.5);
glClearColor(0.0f、0.0f、0.0f、1.0f);
glClear(GL_颜色_缓冲_位| GL_深度_缓冲_位);
GLfloat currentModelViewMatrix[16];
//基于X和Y方向的当前角度执行增量旋转
如果((X旋转!=0.0)| |(旋转!=0.0))
{
GLfloat totalRotation=sqrt(X旋转*X旋转+旋转*旋转);
CATTransformM3D时间矩阵=CATTransformM3Drotate(当前计算矩阵,总旋转*M_PI/180.0,
((X旋转/总旋转)*currentCalculatedMatrix.m12+(旋转/总旋转)*currentCalculatedMatrix.m11),
((X旋转/总旋转)*currentCalculatedMatrix.m22+(旋转/总旋转)*currentCalculatedMatrix.m21),
((X旋转/总旋转)*currentCalculatedMatrix.m32+(旋转/总旋转)*currentCalculatedMatrix.m31));
如果((temporaryMatrix.m11>=-100.0)和(&(temporaryMatrix.m11我在这个rend ios项目中找到了答案,每次按按钮都会使用下面的代码移动对象模型:

-(无效)右按钮按下 {

}
它的工作很好。

使用移动的触控,它将在所有方向上清晰地旋转。试试这个

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;

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

}