31#define SPLINE_POINT_MIN_SPACING 0.02
44- (id) initWithData: (NSPoint) left right: (NSPoint) right;
47- (id) initWithData: (NSPoint) left right: (NSPoint) right gradientleft: (
double) gradientleft;
50- (id) initWithData: (NSPoint) left right: (NSPoint) right gradientright: (
double) gradientright;
53- (id) initWithData: (NSPoint) left right: (NSPoint) right gradientleft: (
double) gradientleft gradientright: (
double) gradientright;
56+ (id) segmentWithData: (NSPoint) left right: (NSPoint) right;
59+ (id) segmentWithData: (NSPoint) left right: (NSPoint) right gradientleft: (
double) gradientleft;
62+ (id) segmentWithData: (NSPoint) left right: (NSPoint) right gradientright: (
double) gradientright;
65+ (id) segmentWithData: (NSPoint) left right: (NSPoint) right gradientleft: (
double) gradientleft gradientright: (
double) gradientright;
67- (id) copyWithZone: (NSZone *) zone;
70- (double) value: (
double) t;
71- (double) gradient: (
double) t;
75@interface OOJoystickSplineAxisProfile (Private)
88 if ((
self = [super init]))
95- (id) copyWithZone: (NSZone *) zone
102- (double) rawValue: (
double) x
107- (double) value: (
double) x
109 if (fabs(
x) < deadzone)
113 return x < 0 ? -[
self rawValue: (-
x-deadzone)/(1.0-deadzone)] : [self rawValue: (
x-deadzone)/(1.0-deadzone)];
121- (void) setDeadzone: (
double) newValue
132 if ((
self = [super init]))
140- (id) copyWithZone: (NSZone *) zone
144 copy->parameter = parameter;
148- (void) setPower: (
double) newValue
171- (void) setParameter: (
double) newValue
173 parameter = OOClamp_0_1_d(newValue);
183- (double) rawValue: (
double) x
187 return -OOClamp_0_1_d(parameter * pow(-
x,power)-(parameter - 1.0)*(-
x));
189 return OOClamp_0_1_d(parameter * pow(
x,power)-(parameter - 1.0)*(
x));
198 if ((
self = [super init]))
210- (id) copyWithZone: (NSZone *) zone
222- (id) initWithData: (NSPoint) left right: (NSPoint) right
224 double dx = right.x - left.
x;
229 if ((
self = [super init]))
233 a[1] = (right.y - left.
y)/dx;
234 a[0] = left.y-a[1]*left.
x;
241- (id) initWithData:(NSPoint) left right: (NSPoint) right gradientleft: (
double) gradientleft
243 double dx = right.x - left.
x;
248 if ((
self = [super init]))
252 a[0] = left.y*right.x*(right.x - 2*left.
x)/(dx*dx) + right.
y*left.
x*left.
x/(dx*dx) - gradientleft*left.
x*right.
x/dx;
253 a[1] = 2*left.x*(left.y-right.
y)/(dx*dx) + gradientleft*(left.
x+right.
x)/dx;
254 a[2] = (right.y-left.
y)/(dx*dx) - gradientleft/dx;
259- (id) initWithData: (NSPoint) left right: (NSPoint) right gradientright: (
double) gradientright
261 double dx = right.x - left.
x;
266 if ((
self = [super init]))
270 a[0] = (left.y*right.x*right.x + right.
y*left.
x*(left.
x-2*right.
x))/(dx*dx) + gradientright*left.
x*right.
x/dx;
271 a[1] = 2*right.x*(right.y-left.
y)/(dx*dx) - gradientright*(left.
x+right.
x)/dx;
272 a[2] = (left.y-right.
y)/(dx*dx) + gradientright/dx;
277- (id) initWithData: (NSPoint) left right: (NSPoint) right gradientleft: (
double) gradientleft gradientright: (
double) gradientright
279 double dx = right.x - left.
x;
284 if ((
self = [super init]))
288 a[0] = (left.y*right.x*right.x*(right.x-3*left.
x) - right.
y*left.
x*left.
x*(left.
x-3*right.
x))/(dx*dx*dx) - (gradientleft*right.
x + gradientright*left.
x)*left.
x*right.
x/(dx*dx);
289 a[1] = 6*left.x*right.x*(left.y-right.
y)/(dx*dx*dx) + (gradientleft*right.
x*(right.
x+2*left.
x) + gradientright*left.
x*(left.
x+2*right.
x))/(dx*dx);
290 a[2] = 3*(left.x+right.
x)*(right.
y-left.
y)/(dx*dx*dx) - (gradientleft*(2*right.
x+left.
x)+gradientright*(2*left.
x+right.
x))/(dx*dx);
291 a[3] = 2*(left.y-right.
y)/(dx*dx*dx) + (gradientleft+gradientright)/(dx*dx);
296+ (id) segmentWithData: (NSPoint) left right: (NSPoint) right
299 return [segment autorelease];
303+ (id) segmentWithData: (NSPoint) left right: (NSPoint) right gradientleft: (
double) gradientleft
306 return [segment autorelease];
310+ (id) segmentWithData: (NSPoint) left right: (NSPoint) right gradientright: (
double) gradientright
313 return [segment autorelease];
317+ (id) segmentWithData: (NSPoint) left right: (NSPoint) right gradientleft: (
double) gradientleft gradientright: (
double) gradientright
320 return [segment autorelease];
335- (double) value: (
double) x
337 return a[0] + (a[1] + (a[2] + a[3]*
x)*
x)*
x;
340- (double) gradient: (
double) x
342 return a[1]+(2*a[2] + 3*a[3]*
x)*
x;
352 if ((
self = [super init]))
354 controlPoints = [[NSMutableArray alloc] initWithCapacity: 2];
363 [controlPoints release];
369- (id) copyWithZone: (NSZone *) zone
372 copy->controlPoints = [controlPoints copyWithZone: zone];
373 copy->segments = [segments copyWithZone: zone];
378- (
int) addControl: (NSPoint) point
390 for (i = 0; i <= [controlPoints count]; i++ )
392 if (i < [controlPoints
count])
394 right = [[controlPoints objectAtIndex: i] pointValue];
398 right = NSMakePoint(1.0,1.0);
406 [controlPoints replaceObjectAtIndex: i - 1 withObject: [NSValue valueWithPoint: point]];
412 [controlPoints insertObject: [NSValue valueWithPoint: point] atIndex: i];
421- (NSPoint) pointAtIndex: (NSInteger) index
436 point = [[controlPoints objectAtIndex: index] pointValue];
443 return [controlPoints count];
449 return [NSArray arrayWithArray: controlPoints];
456 NSPoint left, right, next;
457 double gradientleft, gradientright;
459 BOOL first_segment = YES;
460 NSMutableArray *new_segments = [NSMutableArray arrayWithCapacity: ([controlPoints count] + 1)];
469 [new_segments addObject:segment];
474 right = [[controlPoints objectAtIndex: 0] pointValue];
475 for (i = 0; i < [controlPoints count]; i++)
477 next = [
self pointAtIndex: i + 1];
478 if (next.x - left.x > 0.0)
481 gradientright = (next.y - left.y)/(next.x - left.x);
484 segment = [OOJoystickSplineSegment segmentWithData: left right: right gradientright: gradientright];
488 segment = [OOJoystickSplineSegment segmentWithData: left right: right gradientleft: gradientleft gradientright: gradientright];
496 [new_segments addObject: segment];
497 gradientleft = gradientright;
511 [new_segments addObject: segment];
514 segments = [[NSArray arrayWithArray: new_segments] retain];
518- (void) removeControl: (NSInteger) index
522 [controlPoints removeObjectAtIndex: index];
530 [controlPoints removeAllObjects];
534- (void) moveControl: (NSInteger) index point: (NSPoint) point
538 point.x = OOClamp_0_1_d(point.x);
539 point.y = OOClamp_0_1_d(point.y);
551 left = [[controlPoints objectAtIndex: (index-1)] pointValue];
560 right = [[controlPoints objectAtIndex: (index+1)] pointValue];
569 point.x = (left.x + right.
x)/2;
577 point.x = (left.x + right.
x)/2;
580 [controlPoints replaceObjectAtIndex: index withObject: [NSValue valueWithPoint: point]];
585- (double) rawValue: (
double) x
600 for (i = 0; i < [segments count]; i++)
602 segment = [segments objectAtIndex: i];
603 if ([segment end] >
x)
605 return sign * OOClamp_0_1_d([segment value:
x]);
611- (double) gradient: (
double) x
615 for (i = 0; i < [segments count]; i++)
617 segment = [segments objectAtIndex: i];
618 if ([segment end] >
x)
#define STICK_MAX_DEADZONE
#define STICKPROFILE_MAX_POWER
#define SPLINE_POINT_MIN_SPACING
NSMutableArray * controlPoints
void clearControlPoints()
id segmentWithData:right:(NSPoint left,[right] NSPoint right)
double gradient:(double t)
id segmentWithData:right:gradientleft:(NSPoint left,[right] NSPoint right,[gradientleft] double gradientleft)
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque