views:

31

answers:

0

Hi guys

I have drawn a 2D triangle on the my EAGLView using openGL coding. Now my requirement is like, user can rotate this triangle 360 degree by his finger's motion.

My code is working pretty well but still not perfect. My triange is getting stucks for few pixels at some edges.

Here is sample of my rotation code :

    GLfloat totalRotation = sqrt(xRotation*xRotation + yRotation*yRotation);

    /* EAGLView's size is 600 x 860
       That's why currentX and currentY is compared to 300 and 430 respectivelly (half      
       point of EAGLView)  */

    // Region 1
    if (currentX >= 300.0f && currentY < 430.0f) {
        // NSLog(@"Region 1");
        if(xRotation >= 0.0f && yRotation >= 0.0f) {
            totalRotation = -totalRotation;
        } else if(xRotation > 0.0f && yRotation < 0.0f) {
            totalRotation = -totalRotation;
        }
    }

    // Region 2
    if(currentX < 300.0f && currentY < 430.0f) {
        // NSLog(@"Region 2");
        if(xRotation > 0.0f && yRotation >= 0.0f) {
            totalRotation = -totalRotation;
        } else if (xRotation >= 0.0f && yRotation < 0.0f) {
            totalRotation = -totalRotation;
        }
    }

    // Region 3
    if(currentX < 300.0f && currentY >= 430.0f) {
        // NSLog(@"Region 3");
        if(xRotation < 0.0f && yRotation <= 0.0f) {
            totalRotation = -totalRotation;
        } else if (xRotation >= 0.0f && yRotation < 0.0f) {
            totalRotation = -totalRotation;
        }
    }

    // Region 4
    if (currentX >= 300.0f && currentY >= 430.0f) {
        // NSLog(@"Region 4");
        if(xRotation < 0.0f && yRotation <= 0.0f) {
            totalRotation = -totalRotation;
        } else if(xRotation <= 0.0f && yRotation >= 0.0f) {
            totalRotation = -totalRotation;
        }
    }

    NSLog(@"totalRotation : %f", totalRotation);
    CATransform3D temporaryMatrix = CATransform3DRotate(currentCalculatedMatrix, totalRotation * M_PI / 180.0, 0.0f, 0.0f, 1.0f);

is my above logic is correct? or please help me to understand what's wrong with above code ?

Thanks in advance