Guest User

Untitled

a guest
Jun 21st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. //
  2. // touchTrace.h
  3. // gestureTest
  4. //
  5. // Created by Zachry Thayer on 8/14/08.
  6. // Copyright 2008 A_Nub. All rights reserved.
  7. //
  8.  
  9. #import <UIKit/UIKit.h>
  10. #import "types.h"
  11.  
  12. @interface touchTrace : UIView {
  13. float minDist;//the minimum distance between two points to add it to the tracing
  14. int pathLen;
  15. Vert3 *path;//the recorded path
  16. @private
  17. bool update;//should this instance be checking for updates
  18. char touchIndex;//which touch from NSArray?
  19. NSArray* touchArray;
  20. CGPoint touch;
  21. }
  22.  
  23. -(void) touchEndCallback;
  24. -(id)initWithMinDist:(float)dist;
  25. -(void) startTracing; //Tracing is ended when finger is lifted
  26. -(void) endtracing; //end tracing prematurely
  27. -(void) selectTouch:(char)finger;//which object to read from NSArray of touches
  28. -(void) addPointWithX: (float) x andY:(float) y;
  29. -(void) addPoint:(Vert3)point;
  30. -(Vert3*) getPath;//get a pointer to the path of finger
  31. -(int) getPathLen;
  32.  
  33. //path recording implementation
  34. -(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event;
  35. -(void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event;
  36. -(void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event;
  37.  
  38.  
  39. @end
  40.  
  41.  
  42.  
  43. //
  44. // touchTrace.m
  45. // gestureTest
  46. //
  47. // Created by Zachry Thayer on 8/14/08.
  48. // Copyright 2008 A_Nub. All rights reserved.
  49. //
  50.  
  51. #import "touchTrace.h"
  52. #import <OpenGLES/ES1/gl.h>
  53.  
  54.  
  55. @implementation touchTrace
  56.  
  57. -(id)initWithMinDist:(float)dist{
  58. if((self = [super init])){
  59. minDist = 10.f;
  60. pathLen = 0;
  61. path = NULL;
  62. touchIndex = 0;
  63. update = FALSE;
  64. touchArray = NULL;
  65. }
  66. return self;
  67. }
  68.  
  69. -(void) startTracing{
  70. update = TRUE;
  71. if(path != NULL){
  72. free(path);
  73. path = NULL;
  74. pathLen = 0;
  75. }
  76. }
  77.  
  78. -(void) endtracing{
  79. update = FALSE;
  80. }
  81.  
  82. -(void) selectTouch:(char)finger{
  83. touchIndex = finger;
  84. }
  85.  
  86. -(void) addPointWithX: (float) x andY:(float) y{
  87. pathLen ++;
  88. if(path == NULL)
  89. path = (Vert3*)malloc(sizeof(Vert3));
  90. else
  91. path = (Vert3*)realloc(path,sizeof(Vert3)*pathLen);
  92.  
  93. path[pathLen-1].x = x;
  94. path[pathLen-1].y = y;
  95. path[pathLen-1].z = 0;
  96. }
  97.  
  98. -(void) addPoint:(Vert3)point{
  99. pathLen ++;
  100. if(path == NULL)
  101. path = (Vert3*)malloc(sizeof(Vert3));
  102. else
  103. path = (Vert3*)realloc(path,sizeof(Vert3)*pathLen);
  104.  
  105. path[pathLen-1].x = point.x;
  106. path[pathLen-1].y = point.y;
  107. path[pathLen-1].z = 0;
  108.  
  109. }
  110.  
  111. -(Vert3*) getPath{
  112. return path;
  113. }
  114.  
  115. -(int) getPathLen{
  116. return pathLen;
  117. }
  118.  
  119. -(void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
  120. {
  121. if(update){
  122. touchArray = [touches allObjects];
  123. touch = [[touchArray objectAtIndex:touchIndex] locationInView:self];
  124. [self addPointWithX:touch.x-160 andY:touch.y-240];
  125. }
  126. }
  127. #define sqr(i) ((i)*(i))
  128. -(void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
  129. {
  130. if(update){
  131. touchArray = [touches allObjects];
  132. touch = [[touchArray objectAtIndex:touchIndex] locationInView:self];
  133. //if(sqr(touch.x-path[pathLen].x)+sqr(touch.y-path[pathLen].y) > minDist*minDist)//if we mee our required distance to make a new point
  134. [self addPointWithX:touch.x-160 andY:touch.y-240];
  135. }
  136. }
  137.  
  138. -(void) touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
  139. {
  140. if(update){
  141. [self touchEndCallback];
  142. update = FALSE;
  143. }
  144. }
  145.  
  146.  
  147. -(void) touchEndCallback{
  148. //glClearColor(0,1.0f,0,1.0f);
  149. }
  150.  
  151. @end
Add Comment
Please, Sign In to add comment