Note that there are some explanatory texts on larger screens.

plurals
  1. PORetina & non-retina device when we move say in the center of the device, some point on left bottom also gets moved
    primarykey
    data
    text
    <p>We have created a grid on texture by directly dividing the texture using gridsize. We have divided the texture into 10x10. The goal is to modify the texture image using finger. We are facing issues on the non-retina as well as Retina device when we move say in the center of the device, some point on left bottom also gets moved. Not sure why this happens.</p> <pre><code>- (id)init { // Apple recommends to re-assign "self" with the "super" return value if( (self=[super init])) { [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES]; [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888]; if ([CocosDistort isRetinaDisplay]) originalImage = [UIImage imageNamed:@"IMG_1968-hd.PNG"]; else originalImage = [UIImage imageNamed:@"IMG_1968.PNG"]; texture2D = [[CCTexture2D alloc] initWithImage:originalImage]; [self body_init]; self.isTouchEnabled = YES; } return self; } - (void)draw { glDisableClientState(GL_COLOR_ARRAY); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4ub(224,224,244,200); [self body_redraw]; glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST); glEnableClientState(GL_COLOR_ARRAY); } - (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event { isFirstTouch=YES; CGPoint location = [self convertTouchToNodeSpace: touch]; if ([CocosDistort isRetinaDisplay]) { mousex = (location.x * 2); mousey = (location.y * 2); } else { mousex = location.x ; mousey = location.y ; } firstPoint=location; grab = [self body_grab:mousex:mousey]; return YES; } - (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event { isFirstTouch=NO; CGPoint location = [self convertTouchToNodeSpace: touch]; mousex1 = 0.0; mousey1 = 0.0; if ([CocosDistort isRetinaDisplay]) { mousex1 = (location.x * 2) - mousex; mousey1 = (location.y * 2) - mousey ; } else { mousex1 = location.x - mousex; mousey1 = location.y - mousey ; } if ([CocosDistort isRetinaDisplay]) { mousex = (location.x * 2); mousey = (location.y * 2); } else { mousex = location.x ; mousey = location.y ; } [self body_dynamics:mousex:mousey]; } - (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event { grab = -1; } - (void)body_dynamics:(int)x:(int)y { if (mass[grab].x[0] &gt; x &amp;&amp; mass[grab].x[1] &gt; y) { grab2 = grab - GRID_SIZE_X; grab3 = grab2 - 1; grab4 = grab - 1; } if (mass[grab].x[0] &gt; x &amp;&amp; mass[grab].x[1] &lt; y) { grab2 = grab - GRID_SIZE_X; grab3 = grab2 + 1; grab4 = grab + 1; } if (mass[grab].x[0] &lt; x &amp;&amp; mass[grab].x[1] &lt; y) { grab2 = grab + GRID_SIZE_X; grab3 = grab2 + 1; grab4 = grab + 1; } if (mass[grab].x[0] &lt; x &amp;&amp; mass[grab].x[0] &gt; y) { grab2 = grab + GRID_SIZE_X; grab3 = grab2 - 1; grab4 = grab - 1; } if (grab != -1 &amp;&amp; !mass[grab].nail &amp;&amp;!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; } } - (int)body_grab:(int)x:(int)y { float dx[2]; float d; float min_d; float min_i; int i; for (i = 0; i &lt; 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 &lt; min_d) { min_i = i; min_d = d; } } return min_i; } - (void)body_redraw { int k; int i, j; if(mass == NULL) return; glBindTexture(GL_TEXTURE_2D, [texture2D name]); k = 0; for (i = 0; i &lt; GRID_SIZE_X - 1; i++) { for (j = 0; j &lt; GRID_SIZE_Y - 1; j++) { GLfloat vertices[]= { mass[k].x[0],mass[k].x[1],mass[k].x[2], mass[k + 1].x[0],mass[k + 1].x[1],mass[k + 1].x[2], mass[k + GRID_SIZE_Y + 1].x[0],mass[k + GRID_SIZE_Y + 1].x[1], mass[k + GRID_SIZE_Y + 1].x[2], mass[k + GRID_SIZE_Y].x[0],mass[k + GRID_SIZE_Y].x[1],mass[k + GRID_SIZE_Y].x[2] }; GLfloat tex[]={ mass[k].t[0], mass[k].t[1], mass[k + 1].t[0], mass[k + 1].t[1], mass[k + GRID_SIZE_Y + 1].t[0], mass[k + GRID_SIZE_Y + 1].t[1], mass[k + GRID_SIZE_Y].t[0], mass[k + GRID_SIZE_Y].t[1] }; glVertexPointer(3, GL_FLOAT, 0, vertices); glTexCoordPointer(2, GL_FLOAT, 0, tex); glDrawArrays(GL_LINE_STRIP, 0,4); k++; } k++; } } - (void)body_init { GLint width = texture2D.contentSizeInPixels.width; GLint height = texture2D.contentSizeInPixels.height; int i, j, 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 &lt; GRID_SIZE_X; i++) for (j = 0; j &lt; GRID_SIZE_Y; j++) { 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++; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload