gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 05:56:30 26 4
gpt4 key购买 nike

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

//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,这样你就会得到正确的顶点位置。

关于ios - 错误的顶点在视网膜显示器上移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14722691/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com