diff options
Diffstat (limited to 'libs/cocos2d/CCRibbon.h')
-rwxr-xr-x | libs/cocos2d/CCRibbon.h | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/libs/cocos2d/CCRibbon.h b/libs/cocos2d/CCRibbon.h new file mode 100755 index 0000000..53898e6 --- /dev/null +++ b/libs/cocos2d/CCRibbon.h | |||
@@ -0,0 +1,117 @@ | |||
1 | /* | ||
2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org | ||
3 | * | ||
4 | * Copyright (c) 2008, 2009 Jason Booth | ||
5 | * | ||
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
7 | * of this software and associated documentation files (the "Software"), to deal | ||
8 | * in the Software without restriction, including without limitation the rights | ||
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
10 | * copies of the Software, and to permit persons to whom the Software is | ||
11 | * furnished to do so, subject to the following conditions: | ||
12 | * | ||
13 | * The above copyright notice and this permission notice shall be included in | ||
14 | * all copies or substantial portions of the Software. | ||
15 | * | ||
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
22 | * THE SOFTWARE. | ||
23 | * | ||
24 | */ | ||
25 | |||
26 | |||
27 | #import "CCNode.h" | ||
28 | #import "CCTexture2D.h" | ||
29 | #import "CCProtocols.h" | ||
30 | #import "Platforms/CCGL.h" | ||
31 | |||
32 | /** | ||
33 | * A CCRibbon is a dynamically generated list of polygons drawn as a single or series | ||
34 | * of triangle strips. The primary use of CCRibbon is as the drawing class of Motion Streak, | ||
35 | * but it is quite useful on it's own. When manually drawing a ribbon, you can call addPointAt | ||
36 | * and pass in the parameters for the next location in the ribbon. The system will automatically | ||
37 | * generate new polygons, texture them accourding to your texture width, etc, etc. | ||
38 | * | ||
39 | * CCRibbon data is stored in a CCRibbonSegment class. This class statically allocates enough verticies and | ||
40 | * texture coordinates for 50 locations (100 verts or 48 triangles). The ribbon class will allocate | ||
41 | * new segments when they are needed, and reuse old ones if available. The idea is to avoid constantly | ||
42 | * allocating new memory and prefer a more static method. However, since there is no way to determine | ||
43 | * the maximum size of some ribbons (motion streaks), a truely static allocation is not possible. | ||
44 | * | ||
45 | * @since v0.8.1 | ||
46 | */ | ||
47 | @interface CCRibbon : CCNode <CCTextureProtocol> | ||
48 | { | ||
49 | NSMutableArray* segments_; | ||
50 | NSMutableArray* deletedSegments_; | ||
51 | |||
52 | CGPoint lastPoint1_; | ||
53 | CGPoint lastPoint2_; | ||
54 | CGPoint lastLocation_; | ||
55 | int vertCount_; | ||
56 | float texVPos_; | ||
57 | float curTime_; | ||
58 | float fadeTime_; | ||
59 | float delta_; | ||
60 | float lastWidth_; | ||
61 | float lastSign_; | ||
62 | BOOL pastFirstPoint_; | ||
63 | |||
64 | // Texture used | ||
65 | CCTexture2D* texture_; | ||
66 | |||
67 | // texture length | ||
68 | float textureLength_; | ||
69 | |||
70 | // RGBA protocol | ||
71 | ccColor4B color_; | ||
72 | |||
73 | // blend func | ||
74 | ccBlendFunc blendFunc_; | ||
75 | } | ||
76 | |||
77 | /** Texture used by the ribbon. Conforms to CCTextureProtocol protocol */ | ||
78 | @property (nonatomic,readwrite,retain) CCTexture2D* texture; | ||
79 | |||
80 | /** Texture lengths in pixels */ | ||
81 | @property (nonatomic,readwrite) float textureLength; | ||
82 | |||
83 | /** GL blendind function */ | ||
84 | @property (nonatomic,readwrite,assign) ccBlendFunc blendFunc; | ||
85 | |||
86 | /** color used by the Ribbon (RGBA) */ | ||
87 | @property (nonatomic,readwrite) ccColor4B color; | ||
88 | |||
89 | /** creates the ribbon */ | ||
90 | +(id)ribbonWithWidth:(float)w image:(NSString*)path length:(float)l color:(ccColor4B)color fade:(float)fade; | ||
91 | /** init the ribbon */ | ||
92 | -(id)initWithWidth:(float)w image:(NSString*)path length:(float)l color:(ccColor4B)color fade:(float)fade; | ||
93 | /** add a point to the ribbon */ | ||
94 | -(void)addPointAt:(CGPoint)location width:(float)w; | ||
95 | /** polling function */ | ||
96 | -(void)update:(ccTime)delta; | ||
97 | /** determine side of line */ | ||
98 | -(float)sideOfLine:(CGPoint)p l1:(CGPoint)l1 l2:(CGPoint)l2; | ||
99 | |||
100 | @end | ||
101 | |||
102 | /** object to hold ribbon segment data */ | ||
103 | @interface CCRibbonSegment : NSObject | ||
104 | { | ||
105 | @public | ||
106 | GLfloat verts[50*6]; | ||
107 | GLfloat coords[50*4]; | ||
108 | GLubyte colors[50*8]; | ||
109 | float creationTime[50]; | ||
110 | BOOL finished; | ||
111 | uint end; | ||
112 | uint begin; | ||
113 | } | ||
114 | -(id)init; | ||
115 | -(void)reset; | ||
116 | -(void)draw:(float)curTime fadeTime:(float)fadeTime color:(ccColor4B)color; | ||
117 | @end | ||