diff --git a/Extensions/CCSpine/CCSpineBezierCurve.h b/Extensions/CCSpine/CCSpineCurve.h similarity index 98% rename from Extensions/CCSpine/CCSpineBezierCurve.h rename to Extensions/CCSpine/CCSpineCurve.h index 34b843c..121713d 100644 --- a/Extensions/CCSpine/CCSpineBezierCurve.h +++ b/Extensions/CCSpine/CCSpineCurve.h @@ -38,7 +38,7 @@ typedef NS_ENUM(NSInteger, CCSpineInterpolation) // ---------------------------------------------------------------------------------------------- -@interface CCSpineBezierCurve : NSObject +@interface CCSpineCurve : NSObject // ---------------------------------------------------------------------------------------------- diff --git a/Extensions/CCSpine/CCSpineBezierCurve.m b/Extensions/CCSpine/CCSpineCurve.m similarity index 75% rename from Extensions/CCSpine/CCSpineBezierCurve.m rename to Extensions/CCSpine/CCSpineCurve.m index 64a08f8..72151c7 100644 --- a/Extensions/CCSpine/CCSpineBezierCurve.m +++ b/Extensions/CCSpine/CCSpineCurve.m @@ -24,22 +24,23 @@ * THE SOFTWARE. */ -#import "CCSpineBezierCurve.h" +#import "CCSpineCurve.h" // ---------------------------------------------------------------------------------------------- -@implementation CCSpineBezierCurve +@implementation CCSpineCurve { CCSpineInterpolation _interpolation; NSInteger _count; CGPoint *_bezier; + CGPoint *_coefficient; } // ---------------------------------------------------------------------------------------------- + (instancetype)bezierCurveWithDictionary:(NSDictionary *)dict { - return([[CCSpineBezierCurve alloc] initWithDictionary:dict]); + return([[CCSpineCurve alloc] initWithDictionary:dict]); } // ---------------------------------------------------------------------------------------------- @@ -53,6 +54,7 @@ - (instancetype)initWithDictionary:(NSDictionary *)dict _interpolation = CCSpineInterpolationLinear; _count = 0; _bezier = NULL; + _coefficient = NULL; // load values from dictionary id object = [dict objectForKey:@"curve"]; if ([object isKindOfClass:[NSString class]]) @@ -71,9 +73,9 @@ - (instancetype)initWithDictionary:(NSDictionary *)dict } else if ([object isKindOfClass:[NSArray class]]) { - // curve defined as an array - // this must be an array of floats - // add 0 at the begining and 1 at the end, to make later interpolation easier + // curve defined as two points + // start point is 0,0 + // end point is 1,1 NSArray* array = object; if (array.count > 0) { @@ -84,9 +86,21 @@ - (instancetype)initWithDictionary:(NSDictionary *)dict for (NSNumber* value in array) { // read alternating values as x, y - if ((index & 1) == 0) _bezier[index / 2].x = [value floatValue]; else _bezier[index / 2].y = [value floatValue]; + if ((index & 1) == 0) + { + _bezier[index / 2].x = [value floatValue]; + } + else + { + _bezier[index / 2].y = [value floatValue]; + } index ++; } + // calculate coefficients + _coefficient = malloc(3 * sizeof(CGPoint)); + _coefficient[2] = ccpMult(_bezier[0], 3); + _coefficient[1] = ccpSub(ccpMult(ccpSub(_bezier[1], _bezier[0]), 3), _coefficient[2]); + _coefficient[0] = ccpSub(ccpSub(ccp(1,1), _coefficient[2]), _coefficient[1]); } } @@ -100,6 +114,7 @@ - (void)dealloc { // clean up if (_bezier != NULL) free(_bezier); + if (_coefficient != NULL) free(_coefficient); } @@ -115,13 +130,20 @@ - (float)translate:(float)value case CCSpineInterpolationStepped: return(0); case CCSpineInterpolationBezier: + { + float t2 = value * value; + float t3 = t2 * value; + float result = (_coefficient[0].y * t3) + (_coefficient[1].y * t2) + (_coefficient[2].y * value); + + + // TODO // convert according to bezier curve - return(value); - + return(result); + } } - NSAssert(NO, @"[CCSpineBezierCurve translate] Invalid interpolation"); + NSAssert(NO, @"[CCSpineCurve translate] Invalid interpolation"); return(0); } diff --git a/Extensions/CCSpine/CCSpineSample.h b/Extensions/CCSpine/CCSpineSample.h index 1fab2a3..95c4df3 100644 --- a/Extensions/CCSpine/CCSpineSample.h +++ b/Extensions/CCSpine/CCSpineSample.h @@ -26,7 +26,7 @@ #import #import "CCDictionary.h" -#import "CCSpineBezierCurve.h" +#import "CCSpineCurve.h" // ---------------------------------------------------------------------------------------------- @@ -55,7 +55,7 @@ typedef struct @property (nonatomic, readonly) float time; @property (nonatomic, readonly) CCSpineSampleType type; @property (nonatomic, readonly) CCSpineBoneData data; -@property (nonatomic, readonly) CCSpineBezierCurve *curve; +@property (nonatomic, readonly) CCSpineCurve *curve; // TODO add color diff --git a/Extensions/CCSpine/CCSpineSample.m b/Extensions/CCSpine/CCSpineSample.m index 08af0cd..baebc39 100644 --- a/Extensions/CCSpine/CCSpineSample.m +++ b/Extensions/CCSpine/CCSpineSample.m @@ -73,7 +73,7 @@ - (instancetype)initDictionary:(NSDictionary *)dict andType:(CCSpineSampleType)t } // load curve - _curve = [CCSpineBezierCurve bezierCurveWithDictionary:dict]; + _curve = [CCSpineCurve bezierCurveWithDictionary:dict]; // done return(self); diff --git a/cocos2d-iphone-ext.xcodeproj/project.pbxproj b/cocos2d-iphone-ext.xcodeproj/project.pbxproj index a30ddb4..4066b19 100644 --- a/cocos2d-iphone-ext.xcodeproj/project.pbxproj +++ b/cocos2d-iphone-ext.xcodeproj/project.pbxproj @@ -10,6 +10,7 @@ 0E21D306198A47A400E84AB1 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 0E21D305198A47A400E84AB1 /* README.md */; }; 0E21D30C198A484600E84AB1 /* CCSpriteMultiTouch.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E21D30B198A484600E84AB1 /* CCSpriteMultiTouch.m */; }; 0E21D30F198A637900E84AB1 /* CCSpriteMultiTouchTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E21D30E198A637900E84AB1 /* CCSpriteMultiTouchTest.m */; }; + 0ED73BB51997951A00C83507 /* CCSpineCurve.m in Sources */ = {isa = PBXBuildFile; fileRef = 0ED73BB41997951A00C83507 /* CCSpineCurve.m */; }; A6270E62193757E400196BD3 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A6270E61193757E400196BD3 /* QuartzCore.framework */; }; A6270E64193757E400196BD3 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A6270E63193757E400196BD3 /* OpenGLES.framework */; }; A6270E66193757E400196BD3 /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A6270E65193757E400196BD3 /* OpenAL.framework */; }; @@ -83,7 +84,6 @@ A66C582E193A0C87009D2BD4 /* chase_johnson.png in Resources */ = {isa = PBXBuildFile; fileRef = A66C5815193A0C87009D2BD4 /* chase_johnson.png */; }; A66C5830193A0C87009D2BD4 /* CCSpineAnimation.m in Sources */ = {isa = PBXBuildFile; fileRef = A66C5819193A0C87009D2BD4 /* CCSpineAnimation.m */; }; A66C5831193A0C87009D2BD4 /* CCSpineAnimationControl.m in Sources */ = {isa = PBXBuildFile; fileRef = A66C581B193A0C87009D2BD4 /* CCSpineAnimationControl.m */; }; - A66C5832193A0C87009D2BD4 /* CCSpineBezierCurve.m in Sources */ = {isa = PBXBuildFile; fileRef = A66C581D193A0C87009D2BD4 /* CCSpineBezierCurve.m */; }; A66C5833193A0C87009D2BD4 /* CCSpineBone.m in Sources */ = {isa = PBXBuildFile; fileRef = A66C581F193A0C87009D2BD4 /* CCSpineBone.m */; }; A66C5834193A0C87009D2BD4 /* CCSpineSample.m in Sources */ = {isa = PBXBuildFile; fileRef = A66C5821193A0C87009D2BD4 /* CCSpineSample.m */; }; A66C5835193A0C87009D2BD4 /* CCSpineSkeleton.m in Sources */ = {isa = PBXBuildFile; fileRef = A66C5823193A0C87009D2BD4 /* CCSpineSkeleton.m */; }; @@ -125,6 +125,8 @@ 0E21D30A198A484600E84AB1 /* CCSpriteMultiTouch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCSpriteMultiTouch.h; path = Extensions/CCSpriteMultiTouch/CCSpriteMultiTouch.h; sourceTree = SOURCE_ROOT; }; 0E21D30B198A484600E84AB1 /* CCSpriteMultiTouch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CCSpriteMultiTouch.m; path = Extensions/CCSpriteMultiTouch/CCSpriteMultiTouch.m; sourceTree = SOURCE_ROOT; }; 0E21D30E198A637900E84AB1 /* CCSpriteMultiTouchTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CCSpriteMultiTouchTest.m; path = Classes/Tests/CCSpriteMultiTouchTest.m; sourceTree = ""; }; + 0ED73BB31997951A00C83507 /* CCSpineCurve.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCSpineCurve.h; path = Extensions/CCSpine/CCSpineCurve.h; sourceTree = SOURCE_ROOT; }; + 0ED73BB41997951A00C83507 /* CCSpineCurve.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CCSpineCurve.m; path = Extensions/CCSpine/CCSpineCurve.m; sourceTree = SOURCE_ROOT; }; A6254BAF193A1438006BD09E /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = README.md; path = Extensions/CCNodeTag/README.md; sourceTree = SOURCE_ROOT; }; A6254BB1193A144A006BD09E /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = README.md; path = Extensions/CCDictionary/README.md; sourceTree = SOURCE_ROOT; }; A6254BB3193A145D006BD09E /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = README.md; path = Extensions/CCSpine/README.md; sourceTree = SOURCE_ROOT; }; @@ -212,8 +214,6 @@ A66C5819193A0C87009D2BD4 /* CCSpineAnimation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CCSpineAnimation.m; path = Extensions/CCSpine/CCSpineAnimation.m; sourceTree = SOURCE_ROOT; }; A66C581A193A0C87009D2BD4 /* CCSpineAnimationControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCSpineAnimationControl.h; path = Extensions/CCSpine/CCSpineAnimationControl.h; sourceTree = SOURCE_ROOT; }; A66C581B193A0C87009D2BD4 /* CCSpineAnimationControl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CCSpineAnimationControl.m; path = Extensions/CCSpine/CCSpineAnimationControl.m; sourceTree = SOURCE_ROOT; }; - A66C581C193A0C87009D2BD4 /* CCSpineBezierCurve.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCSpineBezierCurve.h; path = Extensions/CCSpine/CCSpineBezierCurve.h; sourceTree = SOURCE_ROOT; }; - A66C581D193A0C87009D2BD4 /* CCSpineBezierCurve.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CCSpineBezierCurve.m; path = Extensions/CCSpine/CCSpineBezierCurve.m; sourceTree = SOURCE_ROOT; }; A66C581E193A0C87009D2BD4 /* CCSpineBone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCSpineBone.h; path = Extensions/CCSpine/CCSpineBone.h; sourceTree = SOURCE_ROOT; }; A66C581F193A0C87009D2BD4 /* CCSpineBone.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CCSpineBone.m; path = Extensions/CCSpine/CCSpineBone.m; sourceTree = SOURCE_ROOT; }; A66C5820193A0C87009D2BD4 /* CCSpineSample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCSpineSample.h; path = Extensions/CCSpine/CCSpineSample.h; sourceTree = SOURCE_ROOT; }; @@ -498,8 +498,8 @@ A66C5819193A0C87009D2BD4 /* CCSpineAnimation.m */, A66C581A193A0C87009D2BD4 /* CCSpineAnimationControl.h */, A66C581B193A0C87009D2BD4 /* CCSpineAnimationControl.m */, - A66C581C193A0C87009D2BD4 /* CCSpineBezierCurve.h */, - A66C581D193A0C87009D2BD4 /* CCSpineBezierCurve.m */, + 0ED73BB31997951A00C83507 /* CCSpineCurve.h */, + 0ED73BB41997951A00C83507 /* CCSpineCurve.m */, A66C581E193A0C87009D2BD4 /* CCSpineBone.h */, A66C581F193A0C87009D2BD4 /* CCSpineBone.m */, A66C5820193A0C87009D2BD4 /* CCSpineSample.h */, @@ -715,6 +715,7 @@ buildActionMask = 2147483647; files = ( 0E21D30F198A637900E84AB1 /* CCSpriteMultiTouchTest.m in Sources */, + 0ED73BB51997951A00C83507 /* CCSpineCurve.m in Sources */, A6994F85194A2FAC00B97481 /* CCTransformationNodeTest.m in Sources */, A627126E19375F2700196BD3 /* TestBase.m in Sources */, A66C5838193A0C87009D2BD4 /* CCSpineTexture.m in Sources */, @@ -736,7 +737,6 @@ 0E21D30C198A484600E84AB1 /* CCSpriteMultiTouch.m in Sources */, A66C5837193A0C87009D2BD4 /* CCSpineSprite.m in Sources */, A66C580E193A0C69009D2BD4 /* CCNodeTag.m in Sources */, - A66C5832193A0C87009D2BD4 /* CCSpineBezierCurve.m in Sources */, A627110B193757E600196BD3 /* AppDelegate.m in Sources */, A66C5834193A0C87009D2BD4 /* CCSpineSample.m in Sources */, ); diff --git a/cocos2d-iphone-ext.xcodeproj/project.xcworkspace/xcuserdata/Birkemose.xcuserdatad/UserInterfaceState.xcuserstate b/cocos2d-iphone-ext.xcodeproj/project.xcworkspace/xcuserdata/Birkemose.xcuserdatad/UserInterfaceState.xcuserstate index 006dd65..bfee2ff 100644 Binary files a/cocos2d-iphone-ext.xcodeproj/project.xcworkspace/xcuserdata/Birkemose.xcuserdatad/UserInterfaceState.xcuserstate and b/cocos2d-iphone-ext.xcodeproj/project.xcworkspace/xcuserdata/Birkemose.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/cocos2d-iphone-ext.xcodeproj/project.xcworkspace/xcuserdata/Birkemose.xcuserdatad/WorkspaceSettings.xcsettings b/cocos2d-iphone-ext.xcodeproj/project.xcworkspace/xcuserdata/Birkemose.xcuserdatad/WorkspaceSettings.xcsettings new file mode 100644 index 0000000..bfffcfe --- /dev/null +++ b/cocos2d-iphone-ext.xcodeproj/project.xcworkspace/xcuserdata/Birkemose.xcuserdatad/WorkspaceSettings.xcsettings @@ -0,0 +1,10 @@ + + + + + HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges + + SnapshotAutomaticallyBeforeSignificantChanges + + +