Oolite
Loading...
Searching...
No Matches
OOJoystickSplineAxisProfile Class Reference

#include <OOJoystickProfile.h>

Inheritance diagram for OOJoystickSplineAxisProfile:
Collaboration diagram for OOJoystickSplineAxisProfile:

Instance Methods

(id) - init
(void) - dealloc
(id) - copyWithZone:
(int) - addControl:
(NSPoint) - pointAtIndex:
(int) - countPoints
(void) - removeControl:
(void) - clearControlPoints
(void) - moveControl:point:
(double) - rawValue:
(double) - gradient:
(NSArray *) - controlPoints
(BOOL) - makeSegments [implementation]
Instance Methods inherited from OOJoystickAxisProfile
(double) - value:
(double) - deadzone
(void) - setDeadzone:

Private Attributes

NSMutableArray * controlPoints
NSArray * segments

Detailed Description

Definition at line 73 of file OOJoystickProfile.h.

Method Documentation

◆ addControl:

- (int) addControl: (NSPoint) point

Definition at line 347 of file OOJoystickProfile.m.

347 :(NSPoint)point
348{
349 NSPoint left, right;
350 NSUInteger i;
351
352 if (point.x <= SPLINE_POINT_MIN_SPACING || point.x >= 1 - SPLINE_POINT_MIN_SPACING) {
353 return -1;
354 }
355
356 left.x = 0.0;
357 left.y = 0.0;
358 for (i = 0; i <= [controlPoints count]; i++) {
359 if (i < [controlPoints count]) {
360 right = [[controlPoints objectAtIndex:i] pointValue];
361 } else {
362 right = NSMakePoint(1.0, 1.0);
363 }
364 if ((point.x - left.x) < SPLINE_POINT_MIN_SPACING) {
365 if (i == 0) {
366 return -1;
367 }
368 [controlPoints replaceObjectAtIndex:i - 1 withObject:[NSValue valueWithPoint:point]];
369 [self makeSegments];
370 return i - 1;
371 }
372 if ((right.x - point.x) >= SPLINE_POINT_MIN_SPACING) {
373 [controlPoints insertObject:[NSValue valueWithPoint:point] atIndex:i];
374 [self makeSegments];
375 return i;
376 }
377 left = right;
378 }
379 return -1;
380}
#define SPLINE_POINT_MIN_SPACING
unsigned count

References controlPoints, count, int(), makeSegments, and SPLINE_POINT_MIN_SPACING.

Referenced by OOJoystickManager::loadProfileForAxis:, and StickProfileScreen::mouseDown:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clearControlPoints

- (void) clearControlPoints

Definition at line 470 of file OOJoystickProfile.m.

471{
472 [controlPoints removeAllObjects];
473 [self makeSegments];
474}

References clearControlPoints, and makeSegments.

Referenced by clearControlPoints.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ controlPoints

- (NSArray *) controlPoints

Definition at line 402 of file OOJoystickProfile.m.

403{
404 return [NSArray arrayWithArray:controlPoints];
405}

◆ copyWithZone:

- (id) copyWithZone: (NSZone*) zone

Reimplemented from OOJoystickAxisProfile.

Definition at line 339 of file OOJoystickProfile.m.

339 :(NSZone*)zone
340{
341 OOJoystickSplineAxisProfile* copy = [[[self class] alloc] init];
342 copy->controlPoints = [controlPoints copyWithZone:zone];
343 copy->segments = [segments copyWithZone:zone];
344 return copy;
345}

◆ countPoints

- (int) countPoints

Definition at line 397 of file OOJoystickProfile.m.

398{
399 return [controlPoints count];
400}

References countPoints, and int().

Referenced by countPoints.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dealloc

- (void) dealloc

Definition at line 331 of file OOJoystickProfile.m.

332{
333 [controlPoints release];
334 [segments release];
335 [super dealloc];
336 return;
337}

References dealloc.

Referenced by dealloc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gradient:

- (double) gradient: (double) x

Definition at line 536 of file OOJoystickProfile.m.

536 :(double)x
537{
538 NSUInteger i;
539 OOJoystickSplineSegment* segment;
540 for (i = 0; i < [segments count]; i++) {
541 segment = [segments objectAtIndex:i];
542 if ([segment end] > x) {
543 return [segment gradient:x];
544 }
545 }
546 return 1.0;
547}
float x

References OOJoystickSplineSegment::gradient:, and x.

Here is the call graph for this function:

◆ init

- (id) init

Reimplemented from OOJoystickAxisProfile.

Definition at line 321 of file OOJoystickProfile.m.

322{
323 if ((self = [super init])) {
324 controlPoints = [[NSMutableArray alloc] initWithCapacity:2];
325 segments = nil;
326 [self makeSegments];
327 }
328 return self;
329}
return nil

References controlPoints, init, makeSegments, nil, and segments.

Referenced by init.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ makeSegments

- (BOOL) makeSegments
implementation

Provided by category OOJoystickSplineAxisProfile(Private).

Definition at line 408 of file OOJoystickProfile.m.

409{
410 NSUInteger i;
411 NSPoint left, right, next;
412 double gradientleft, gradientright;
413 OOJoystickSplineSegment* segment;
414 BOOL first_segment = YES;
415 NSMutableArray* new_segments = [NSMutableArray arrayWithCapacity:([controlPoints count] + 1)];
416
417 left.x = 0.0;
418 left.y = 0.0;
419 if ([controlPoints count] == 0) {
420 right.x = 1.0;
421 right.y = 1.0;
422 segment = [OOJoystickSplineSegment segmentWithData:left right:right];
423 [new_segments addObject:segment];
424 } else {
425 gradientleft = 1.0;
426 right = [[controlPoints objectAtIndex:0] pointValue];
427 for (i = 0; i < [controlPoints count]; i++) {
428 next = [self pointAtIndex:i + 1];
429 if (next.x - left.x > 0.0) {
430 // we make the gradient at right equal to the gradient of a straight line between the neighcouring points
431 gradientright = (next.y - left.y) / (next.x - left.x);
432 if (first_segment) {
433 segment = [OOJoystickSplineSegment segmentWithData:left right:right gradientright:gradientright];
434 } else {
435 segment = [OOJoystickSplineSegment segmentWithData:left right:right gradientleft:gradientleft gradientright:gradientright];
436 }
437 if (segment == nil) {
438 return NO;
439 } else {
440 [new_segments addObject:segment];
441 gradientleft = gradientright;
442 first_segment = NO;
443 left = right;
444 }
445 }
446 right = next;
447 }
448 right.x = 1.0;
449 right.y = 1.0;
450 segment = [OOJoystickSplineSegment segmentWithData:left right:right gradientleft:gradientleft];
451 if (segment == nil) {
452 return NO;
453 }
454 [new_segments addObject:segment];
455 }
456 [segments release];
457 segments = [[NSArray arrayWithArray:new_segments] retain];
458 return YES;
459}
id segmentWithData:right:(NSPoint left,[right] NSPoint right)
id segmentWithData:right:gradientleft:(NSPoint left,[right] NSPoint right,[gradientleft] double gradientleft)

References count, OOJoystickSplineAxisProfile(Private)::makeSegments, nil, pointAtIndex:, OOJoystickSplineSegment::segmentWithData:right:, OOJoystickSplineSegment::segmentWithData:right:gradientleft:, OOJoystickSplineSegment::segmentWithData:right:gradientleft:gradientright:, and OOJoystickSplineSegment::segmentWithData:right:gradientright:.

Referenced by addControl:, clearControlPoints, init, OOJoystickSplineAxisProfile(Private)::makeSegments, moveControl:point:, and removeControl:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ moveControl:point:

- (void) moveControl: (NSInteger) index
point: (NSPoint) point 

Definition at line 476 of file OOJoystickProfile.m.

476 :(NSInteger)index point:(NSPoint)point
477{
478 NSPoint left, right;
479
480 point.x = OOClamp_0_1_d(point.x);
481 point.y = OOClamp_0_1_d(point.y);
482 if (index < 0 || index >= (NSInteger)[controlPoints count]) {
483 return;
484 }
485 if (index == 0) {
486 left.x = 0.0;
487 right.x = 0.0;
488 } else {
489 left = [[controlPoints objectAtIndex:(index - 1)] pointValue];
490 }
491 if (index == (NSInteger)[controlPoints count] - 1) {
492 right.x = 1.0;
493 right.y = 1.0;
494 } else {
495 right = [[controlPoints objectAtIndex:(index + 1)] pointValue];
496 }
497 // preserve order of control points - if we attempt to move this control point beyond
498 // either of its neighbours, move it back inside. Also keep neighbours a distance of at least SPLINE_POINT_MIN_SPACING apart
499 if (point.x - left.x < SPLINE_POINT_MIN_SPACING) {
500 point.x = left.x + SPLINE_POINT_MIN_SPACING;
501 if (right.x - point.x < SPLINE_POINT_MIN_SPACING) {
502 point.x = (left.x + right.x) / 2;
503 }
504 } else if (right.x - point.x < SPLINE_POINT_MIN_SPACING) {
505 point.x = right.x - SPLINE_POINT_MIN_SPACING;
506 if (point.x - left.x < SPLINE_POINT_MIN_SPACING) {
507 point.x = (left.x + right.x) / 2;
508 }
509 }
510 [controlPoints replaceObjectAtIndex:index withObject:[NSValue valueWithPoint:point]];
511 [self makeSegments];
512 return;
513}
OOINLINE double OOClamp_0_1_d(double value) INLINE_CONST_FUNC

References controlPoints, count, makeSegments, OOClamp_0_1_d(), and SPLINE_POINT_MIN_SPACING.

Referenced by StickProfileScreen::mouseDown:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pointAtIndex:

- (NSPoint) pointAtIndex: (NSInteger) index

Definition at line 382 of file OOJoystickProfile.m.

382 :(NSInteger)index
383{
384 NSPoint point;
385 if (index < 0) {
386 point.x = 0.0;
387 point.y = 0.0;
388 } else if (index >= (NSInteger)[controlPoints count]) {
389 point.x = 1.0;
390 point.y = 1.0;
391 } else {
392 point = [[controlPoints objectAtIndex:index] pointValue];
393 }
394 return point;
395}

References controlPoints, and count.

Referenced by OOJoystickSplineAxisProfile(Private)::makeSegments.

Here is the caller graph for this function:

◆ rawValue:

- (double) rawValue: (double) x

Reimplemented from OOJoystickAxisProfile.

Definition at line 515 of file OOJoystickProfile.m.

515 :(double)x
516{
517 NSUInteger i;
518 OOJoystickSplineSegment* segment;
519 double sign;
520
521 if (x < 0) {
522 sign = -1.0;
523 x = -x;
524 } else {
525 sign = 1.0;
526 }
527 for (i = 0; i < [segments count]; i++) {
528 segment = [segments objectAtIndex:i];
529 if ([segment end] > x) {
530 return sign * OOClamp_0_1_d([segment value:x]);
531 }
532 }
533 return 1.0;
534}

References OOClamp_0_1_d(), and x.

Here is the call graph for this function:

◆ removeControl:

- (void) removeControl: (NSInteger) index

Definition at line 461 of file OOJoystickProfile.m.

461 :(NSInteger)index
462{
463 if (index >= 0 && index < (NSInteger)[controlPoints count]) {
464 [controlPoints removeObjectAtIndex:index];
465 [self makeSegments];
466 }
467 return;
468}

References controlPoints, count, and makeSegments.

Referenced by StickProfileScreen::deleteSelected.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ controlPoints

- (NSMutableArray*) controlPoints
private

Definition at line 402 of file OOJoystickProfile.m.

403{
404 return [NSArray arrayWithArray:controlPoints];
405}

Referenced by addControl:, StickProfileScreen(StickProfileInternal)::graphProfile:at:size:, init, moveControl:point:, pointAtIndex:, removeControl:, and OOJoystickManager::saveProfileForAxis:.

◆ segments

- (NSArray*) segments
private

Definition at line 76 of file OOJoystickProfile.h.

Referenced by init.


The documentation for this class was generated from the following files: