Results 1 to 2 of 2

Thread: Opengl es 2.0 touch rotation problem

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    2

    Opengl es 2.0 touch rotation problem

    I am currently creating a 3D cube in open gl es 2.0 and wish to rotate it by touch movements. Initially the cube is rendered well as a 3D cube and it appears fine like http://imageshack.us/photo/my-images/64/originalnw.png/.

    However when i rotate it, it gets elongated sometimes and doesnt really appear well. It gets flattened out and after sometime, it disappears after some rotations. Like this http://imageshack.us/photo/my-images/24/56821607.png/.


    Can some one help me with this problem?

    This is what I am doing.

    Code :
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    NSSet *allTouches = [event allTouches];
     
    if([allTouches count] == 1) {
        lastTouchPosition = [[touches anyObject] locationInView:self];
    } else if([allTouches count] == 2) {
        UITouch *t1 = [[allTouches allObjects] objectAtIndex:0];
        UITouch *t2 = [[allTouches allObjects] objectAtIndex:1];
     
        CGPoint p1 = [t1 locationInView:self];
        CGPoint p2 = [t2 locationInView:self];
     
        float x = p1.x - p2.x;
        float y = p1.y - p2.y;
     
        lastPinchDistance = sqrtf(x * x + y * y);
    }
    }
     
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
    {    
    CGPoint currentTouchPosition = [[touches anyObject] locationInView:self];    
            NSSet *allTouches = [event allTouches];
            if([allTouches count] == 1) 
            {        
                float xMovement = lastTouchPosition.x - currentTouchPosition.x;
                float yMovement = lastTouchPosition.y - currentTouchPosition.y;
                lastTouchPosition = currentTouchPosition;
                [self rotateCubeAroundX:yMovement andY:xMovement];
            }
            else if([allTouches count] == 2) 
            {
                UITouch *t1 = [[allTouches allObjects] objectAtIndex:0];
                UITouch *t2 = [[allTouches allObjects] objectAtIndex:1];
                CGPoint p1 = [t1 locationInView:self];
                CGPoint p2 = [t2 locationInView:self];
                float x = p1.x - p2.x;
                float y = p1.y - p2.y;
     
                float currPinchDistance = sqrtf(x * x + y * y);
     
                float zoomDistance = lastPinchDistance - currPinchDistance;
     
                lastZoomDistance = lastZoomDistance - (zoomDistance / 100);
     
                lastPinchDistance = currPinchDistance;
            }
    }

    Code :
    - (void)rotateCubeAroundX:(float)x andY:(float)y {
    GLfloat totalXRotation = x * M_PI / 180.0f;
    GLfloat totalYRotation = y * M_PI / 180.0f;
     Matrix4x4Utils:: applyRotation(rotationMatrix, totalXRotation, totalYRotation, 0.0);
    }

    In the initwithframe function, I set the rotation and projection matrix to identity initially and then set the projection of the scene.

    In my drawFrame function, I set my cube vertices and its normals. Then i set the mvp matrix to identity. Then I multiply the mvp matrix with the rotation and projection matrices and I pass it to the shader. The inital drawing is fine, but on rotation using touch, it gets flattened out. Could someone help me, as to why is this happening?

  2. #2
    Junior Member
    Join Date
    Jul 2011
    Posts
    2

    Re: Opengl es 2.0 touch rotation problem

    This is another screen shot of what i am getting after performing rotation by gestures. Pl help me to solve this problem. http://imageshack.us/photo/my-images/718/screengm.jpg/

Similar Threads

  1. 3D Cube rotationg unexpectedly on touch
    By innova in forum OpenGL ES general technical discussions
    Replies: 1
    Last Post: 09-07-2010, 11:42 PM
  2. problem with rotation
    By himanshu405 in forum OpenGL ES general technical discussions
    Replies: 4
    Last Post: 07-15-2009, 06:14 AM
  3. EGL supporting touch input
    By dilip_devaraj in forum Cross API and window system integration
    Replies: 2
    Last Post: 06-05-2008, 12:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •