ios – 在视网膜显示器上移动错误的顶点

我正在研究改变形状的图像效果,当我触摸并移动顶点进行正常显示时,它会正确移动到顶点,但在视网膜显示中它会移动到错误的顶点.这意味着它不会在触摸位置移动顶点.

//Here I'm implementing grid on texture, storing each vertex point in array.

    GLint width = texture2D.contentSizeInPixels.width;
GLint height = texture2D.contentSizeInPixels.height;
int i, j;
int k;

if (mass == NULL)
{
    mass = (MASS *) malloc(sizeof(MASS)*GRID_SIZE_X*GRID_SIZE_Y);
    if (mass == NULL)
    {
        fprintf(stderr, "body: Can't allocate memory.\n");
        exit(-1);
    }
}

k = 0;
for (i = 0; i < GRID_SIZE_X; i++)
    for (j = 0; j < GRID_SIZE_Y; j++)
    {
        //this code implements grid on texture2D, gets vertex & side vertex in array 
        mass[k].nail = (i == 0 || j == 0 || i == GRID_SIZE_X - 1
                        || j == GRID_SIZE_Y - 1);//value is 0/1

        mass[k].x[0] = i/(GRID_SIZE_X - 1.0)*width;
        NSLog(@"mass[%d].x[0]:: %f",k,mass[k].x[0]);

        mass[k].x[1] = j/(GRID_SIZE_Y - 1.0)*height;
        NSLog(@"mass[%d].x[1]:: %f",k,mass[k].x[1]);

        mass[k].x[2] = -(CLIP_FAR - CLIP_NEAR)/4.0;
        NSLog(@"mass[%d].x[2]:: %f",k,mass[k].x[2]);

        mass[k].v[0] = 0.0;
        mass[k].v[1] = 0.0;
        mass[k].v[2] = 0.0;

        mass[k].t[0] = i/(GRID_SIZE_X - 1.0);
        mass[k].t[1] = j/(GRID_SIZE_Y - 1.0);

        k++;
    }
}

//Here I am returning index position of stored vertex in array near by touch point.

- (int)body_grab:(int)x:(int)y {

float dx[2];
float d;
float min_d;
float min_i;
int i;

for (i = 0; i < GRID_SIZE_X*GRID_SIZE_Y; i++)
{
    dx[0] = mass[i].x[0] - x;
    dx[1] = mass[i].x[1] - y;
    d = sqrt(dx[0]*dx[0] + dx[1]*dx[1]);
    if (i == 0 || d < min_d)
    {
        min_i = i;
        min_d = d;
    }
}

return min_i;
}


//Here I am getting other 3 vertex of cell where touch point exists and moving these vertex in a touch direction.

- (void)body_dynamics:(int)x:(int)y {

if (mass[grab].x[0] > x && mass[grab].x[1] > y) {

    grab2 = grab - GRID_SIZE_X;
    grab3 = grab2 - 1;
    grab4 = grab  - 1;
}
if (mass[grab].x[0] > x && mass[grab].x[1] < y) {

    grab2 = grab - GRID_SIZE_X;
    grab3 = grab2 + 1;
    grab4 = grab  + 1;
}
if (mass[grab].x[0] < x && mass[grab].x[1] < y) {

    grab2 = grab + GRID_SIZE_X;
    grab3 = grab2 + 1;
    grab4 = grab  + 1;
}
if (mass[grab].x[0] < x && mass[grab].x[0] > y) {

    grab2 = grab + GRID_SIZE_X;
    grab3 = grab2 - 1;
    grab4 = grab  - 1;

}



if (grab != -1 && !mass[grab].nail &&!isFirstTouch)
{
    mass[grab].x[0]  =  mass[grab].x[0] + mousex1;
    mass[grab].x[1]  =  mass[grab].x[1] + mousey1;
    mass[grab].x[2]  = -(CLIP_FAR - CLIP_NEAR)/4.0;

    mass[grab2].x[0] =  mass[grab2].x[0] + mousex1;
    mass[grab2].x[1] =  mass[grab2].x[1] + mousey1;
    mass[grab2].x[2] = -(CLIP_FAR - CLIP_NEAR)/4.0;

    mass[grab3].x[0] =  mass[grab3].x[0] + mousex1;
    mass[grab3].x[1] =  mass[grab3].x[1] + mousey1;
    mass[grab3].x[2] = -(CLIP_FAR - CLIP_NEAR)/4.0;

    mass[grab4].x[0] =  mass[grab4].x[0] + mousex1;
    mass[grab4].x[1] =  mass[grab4].x[1] + mousey1;
    mass[grab4].x[2] = -(CLIP_FAR - CLIP_NEAR)/4.0;
}
}

最佳答案 我解决了这个问题

你只需要将触摸点乘以2即可
意味着你得到X pos 123和y 342你必须将这些值乘以2:123 * 2,这样你才能获得正确的顶点位置.

点赞