2

触れられているすべてのピクセルを検出することは可能ですか?より具体的には、ユーザーが画面に触れたときに、ユーザーが触れた点のクラスターのすべてのxy座標を追跡することは可能ですか?ユーザーが親指で描いているときと指先で描いているときの違いをどのように見分けることができますか?ユーザーが画面に触れる方法によるブラシの違いを反映し、触れられているすべてのピクセルを追跡したいと思います。

私は現在、AppleデベロッパサイトのGLPaintサンプルから次のコードを使用しています。

http://developer.apple.com/library/ios/#samplecode/GLPaint/Introduction/Intro.html

サンプルコードを使用すると、事前定義されたブラシサイズで描画し、途中でxy座標を追跡できます。ユーザーが画面に触れる方法に応じてブラシを変更し、時間の経過とともに触れられているすべてのピクセルを追跡するにはどうすればよいですか?

// Drawings a line onscreen based on where the user touches

- (void) renderLineFromPoint:(CGPoint)start toPoint:(CGPoint)end

{
     NSLog(@"x:%f   y:%f",start.x, start.y);

     static GLfloat*          vertexBuffer = NULL;

     static NSUInteger     vertexMax = 64;

     NSUInteger               vertexCount = 0,

                    count,

                    i;



     [EAGLContext setCurrentContext:context];

     glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);



     // Convert locations from Points to Pixels

     CGFloat scale = self.contentScaleFactor;

     start.x *= scale;

     start.y *= scale;

     end.x *= scale;

     end.y *= scale;



     // Allocate vertex array buffer

     if(vertexBuffer == NULL)

          vertexBuffer = malloc(vertexMax * 2 * sizeof(GLfloat));



     // Add points to the buffer so there are drawing points every X pixels

     count = MAX(ceilf(sqrtf((end.x - start.x) * (end.x - start.x) + (end.y - start.y) * (end.y - start.y)) / kBrushPixelStep), 1);

     for(i = 0; i < count; ++i) {

          if(vertexCount == vertexMax) {

               vertexMax = 2 * vertexMax;

               vertexBuffer = realloc(vertexBuffer, vertexMax * 2 * sizeof(GLfloat));

          }



          vertexBuffer[2 * vertexCount + 0] = start.x + (end.x - start.x) * ((GLfloat)i / (GLfloat)count);

          vertexBuffer[2 * vertexCount + 1] = start.y + (end.y - start.y) * ((GLfloat)i / (GLfloat)count);

          vertexCount += 1;

     }



     // Render the vertex array

     glVertexPointer(2, GL_FLOAT, 0, vertexBuffer);

     glDrawArrays(GL_POINTS, 0, vertexCount);



     // Display the buffer

     glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);

     [context presentRenderbuffer:GL_RENDERBUFFER_OES];

}


// Handles the start of a touch

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

     CGRect                    bounds = [self bounds];

     UITouch*     touch = [[event touchesForView:self] anyObject];

     firstTouch = YES;

     // Convert touch point from UIView referential to OpenGL one (upside-down flip)

     location = [touch locationInView:self];

     location.y = bounds.size.height - location.y;

}

// Handles the continuation of a touch.

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

{  

     CGRect                    bounds = [self bounds];

     UITouch*               touch = [[event touchesForView:self] anyObject];



     // Convert touch point from UIView referential to OpenGL one (upside-down flip)

     if (firstTouch) {

          firstTouch = NO;

          previousLocation = [touch previousLocationInView:self];

          previousLocation.y = bounds.size.height - previousLocation.y;

     } else {

          location = [touch locationInView:self];

         location.y = bounds.size.height - location.y;

          previousLocation = [touch previousLocationInView:self];

          previousLocation.y = bounds.size.height - previousLocation.y;

     }



     // Render the stroke

     [self renderLineFromPoint:previousLocation toPoint:location];

}



// Handles the end of a touch event when the touch is a tap.

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

{

     CGRect                    bounds = [self bounds];

    UITouch*     touch = [[event touchesForView:self] anyObject];

     if (firstTouch) {

          firstTouch = NO;

          previousLocation = [touch previousLocationInView:self];

          previousLocation.y = bounds.size.height - previousLocation.y;

          [self renderLineFromPoint:previousLocation toPoint:location];

     }

}


// Handles the end of a touch event.

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event

{

     // If appropriate, add code necessary to save the state of the application.

     // This application is not saving state.

}
4

2 に答える 2

1

私の知る限り、タッチのためにタッチゾーンにアクセスするための API はありません。容量性タッチスクリーンの限界を考えると、あなたが望むことが物理的に可能かどうかさえわかりません. 最近の Cocoa Heads でのプレゼンテーションで、OS X では (プライベート API を介して) トラックパッド用に一部の情報を利用できるが、iOS 用では利用できないことが示されたプレゼンテーションを思い出します。

これが、グラフィック タブレットに独自のセンサー技術が組み込まれた特別なスタイラスが採用されている理由の 1 つだと思います。

描画アプリケーションの場合の部分的な回避策は、一部のデスクトップ アプリケーションが行うように、「インク」をシミュレートすることです。ユーザーのタッチが特定の場所に残っている場合、インクが「ペン」から出て徐々に拡散するように描画します。紙。"

于 2012-04-04T16:59:29.123 に答える