summary refs log tree commit diff stats
path: root/libs/cocos2d/CCRibbon.h
blob: 53898e67a18983af0f6d4aadafbf37f65592e7f6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
 * cocos2d for iPhone: http://www.cocos2d-iphone.org
 *
 * Copyright (c) 2008, 2009 Jason Booth
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */


#import "CCNode.h"
#import "CCTexture2D.h"
#import "CCProtocols.h"
#import "Platforms/CCGL.h"

/**
 * A CCRibbon is a dynamically generated list of polygons drawn as a single or series
 * of triangle strips. The primary use of CCRibbon is as the drawing class of Motion Streak,
 * but it is quite useful on it's own. When manually drawing a ribbon, you can call addPointAt
 * and pass in the parameters for the next location in the ribbon. The system will automatically
 * generate new polygons, texture them accourding to your texture width, etc, etc.
 *
 * CCRibbon data is stored in a CCRibbonSegment class. This class statically allocates enough verticies and
 * texture coordinates for 50 locations (100 verts or 48 triangles). The ribbon class will allocate
 * new segments when they are needed, and reuse old ones if available. The idea is to avoid constantly
 * allocating new memory and prefer a more static method. However, since there is no way to determine
 * the maximum size of some ribbons (motion streaks), a truely static allocation is not possible.
 *
 * @since v0.8.1
 */
@interface CCRibbon : CCNode <CCTextureProtocol>
{
	NSMutableArray*	segments_;
	NSMutableArray*	deletedSegments_;

	CGPoint			lastPoint1_;
	CGPoint			lastPoint2_;
	CGPoint			lastLocation_;
	int					vertCount_;
	float				texVPos_;
	float				curTime_;
	float				fadeTime_;
	float				delta_;
	float				lastWidth_;
	float				lastSign_;
	BOOL				pastFirstPoint_;

	// Texture used
	CCTexture2D*		texture_;

	// texture length
	float			textureLength_;

	// RGBA protocol
	ccColor4B color_;

	// blend func
	ccBlendFunc		blendFunc_;
}

/** Texture used by the ribbon. Conforms to CCTextureProtocol protocol */
@property (nonatomic,readwrite,retain) CCTexture2D* texture;

/** Texture lengths in pixels */
@property (nonatomic,readwrite) float textureLength;

/** GL blendind function */
@property (nonatomic,readwrite,assign) ccBlendFunc blendFunc;

/** color used by the Ribbon (RGBA) */
@property (nonatomic,readwrite) ccColor4B color;

/** creates the ribbon */
+(id)ribbonWithWidth:(float)w image:(NSString*)path length:(float)l color:(ccColor4B)color fade:(float)fade;
/** init the ribbon */
-(id)initWithWidth:(float)w image:(NSString*)path length:(float)l color:(ccColor4B)color fade:(float)fade;
/** add a point to the ribbon */
-(void)addPointAt:(CGPoint)location width:(float)w;
/** polling function */
-(void)update:(ccTime)delta;
/** determine side of line */
-(float)sideOfLine:(CGPoint)p l1:(CGPoint)l1 l2:(CGPoint)l2;

@end

/** object to hold ribbon segment data */
@interface CCRibbonSegment : NSObject
{
@public
	GLfloat	verts[50*6];
	GLfloat	coords[50*4];
	GLubyte	colors[50*8];
	float		creationTime[50];
	BOOL		finished;
	uint		end;
	uint		begin;
}
-(id)init;
-(void)reset;
-(void)draw:(float)curTime fadeTime:(float)fadeTime color:(ccColor4B)color;
@end