Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // touchTrace.h
- // gestureTest
- //
- // Created by Zachry Thayer on 8/14/08.
- // Copyright 2008 A_Nub. All rights reserved.
- //
- #import <UIKit/UIKit.h>
- #import "types.h"
- @interface touchTrace : UIView {
- float minDist;//the minimum distance between two points to add it to the tracing
- int pathLen;
- Vert3 *path;//the recorded path
- @private
- bool update;//should this instance be checking for updates
- char touchIndex;//which touch from NSArray?
- NSArray* touchArray;
- CGPoint touch;
- }
- -(void) touchEndCallback;
- -(id)initWithMinDist:(float)dist;
- -(void) startTracing; //Tracing is ended when finger is lifted
- -(void) endtracing; //end tracing prematurely
- -(void) selectTouch:(char)finger;//which object to read from NSArray of touches
- -(void) addPointWithX: (float) x andY:(float) y;
- -(void) addPoint:(Vert3)point;
- -(Vert3*) getPath;//get a pointer to the path of finger
- -(int) getPathLen;
- //path recording implementation
- -(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event;
- -(void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event;
- -(void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event;
- @end
- //
- // touchTrace.m
- // gestureTest
- //
- // Created by Zachry Thayer on 8/14/08.
- // Copyright 2008 A_Nub. All rights reserved.
- //
- #import "touchTrace.h"
- #import <OpenGLES/ES1/gl.h>
- @implementation touchTrace
- -(id)initWithMinDist:(float)dist{
- if((self = [super init])){
- minDist = 10.f;
- pathLen = 0;
- path = NULL;
- touchIndex = 0;
- update = FALSE;
- touchArray = NULL;
- }
- return self;
- }
- -(void) startTracing{
- update = TRUE;
- if(path != NULL){
- free(path);
- path = NULL;
- pathLen = 0;
- }
- }
- -(void) endtracing{
- update = FALSE;
- }
- -(void) selectTouch:(char)finger{
- touchIndex = finger;
- }
- -(void) addPointWithX: (float) x andY:(float) y{
- pathLen ++;
- if(path == NULL)
- path = (Vert3*)malloc(sizeof(Vert3));
- else
- path = (Vert3*)realloc(path,sizeof(Vert3)*pathLen);
- path[pathLen-1].x = x;
- path[pathLen-1].y = y;
- path[pathLen-1].z = 0;
- }
- -(void) addPoint:(Vert3)point{
- pathLen ++;
- if(path == NULL)
- path = (Vert3*)malloc(sizeof(Vert3));
- else
- path = (Vert3*)realloc(path,sizeof(Vert3)*pathLen);
- path[pathLen-1].x = point.x;
- path[pathLen-1].y = point.y;
- path[pathLen-1].z = 0;
- }
- -(Vert3*) getPath{
- return path;
- }
- -(int) getPathLen{
- return pathLen;
- }
- -(void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
- {
- if(update){
- touchArray = [touches allObjects];
- touch = [[touchArray objectAtIndex:touchIndex] locationInView:self];
- [self addPointWithX:touch.x-160 andY:touch.y-240];
- }
- }
- #define sqr(i) ((i)*(i))
- -(void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
- {
- if(update){
- touchArray = [touches allObjects];
- touch = [[touchArray objectAtIndex:touchIndex] locationInView:self];
- //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
- [self addPointWithX:touch.x-160 andY:touch.y-240];
- }
- }
- -(void) touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
- {
- if(update){
- [self touchEndCallback];
- update = FALSE;
- }
- }
- -(void) touchEndCallback{
- //glClearColor(0,1.0f,0,1.0f);
- }
- @end
Add Comment
Please, Sign In to add comment