大佬教程收集整理的这篇文章主要介绍了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",mass[k].x[1]); mass[k].x[2] = -(CLIP_FAR - CLIP_NEAR)/4.0; NSLog(@"mass[%d].x[2]:: %f",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; } }
以上是大佬教程为你收集整理的ios – 在视网膜显示器上移动错误的顶点全部内容,希望文章能够帮你解决ios – 在视网膜显示器上移动错误的顶点所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。