iPhone でのタッチの追跡に関して簡単な質問がありますが、これについて結論を出すことができないようです。そのため、提案やアイデアは大歓迎です。
iPhoneのタッチを追跡して識別できるようにしたいです。基本的に、すべてのタッチには開始位置と現在/移動した位置があります。タッチは std::vector に保存され、終了するとコンテナーから削除されます。彼らの位置は移動すると更新されますが、最初に開始した場所 (ジェスチャー認識) を追跡したいと考えています。
[event allTouches] からタッチを取得しています。つまり、NSSet はソートされておらず、std::vector に既に格納されているタッチを識別できず、NSSet 内のタッチを参照できないようです (したがって、どれが終了し、削除されるか、または移動されたかなどがわかります)
もちろん、タッチスクリーン上で1本の指だけで完全に機能しますが、複数の指で予測できない結果が得られます...
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
[self handleTouches:[event allTouches]];
}
- (void) touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
{
[self handleTouches:[event allTouches]];
}
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
[self handleTouches:[event allTouches]];
}
- (void) touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event
{
[self handleTouches:[event allTouches]];
}
- (void) handleTouches:(NSSet*)allTouches
{
for(int i = 0; i < (int)[allTouches count]; ++i)
{
UITouch* touch = [[allTouches allObjects] objectAtIndex:i];
NSTimeInterval timestamp = [touch timestamp];
CGPoint currentLocation = [touch locationInView:self];
CGPoint previousLocation = [touch previousLocationInView:self];
if([touch phase] == UITouchPhaseBegan)
{
Finger finger;
finger.start.x = currentLocation.x;
finger.start.y = currentLocation.y;
finger.end = finger.start;
finger.hasMoved = false;
finger.hasEnded = false;
touchScreen->AddFinger(finger);
}
else if([touch phase] == UITouchPhaseEnded || [touch phase] == UITouchPhaseCancelled)
{
Finger& finger = touchScreen->GetFingerHandle(i);
finger.hasEnded = true;
}
else if([touch phase] == UITouchPhaseMoved)
{
Finger& finger = touchScreen->GetFingerHandle(i);
finger.end.x = currentLocation.x;
finger.end.y = currentLocation.y;
finger.hasMoved = true;
}
}
touchScreen->RemoveEnded();
}
ありがとう!