public override void draw() { CCTMXTiledMap map = (CCTMXTiledMap)getChildByTag(1); CCTMXObjectGroup group = map.objectGroupNamed("Object Group 1"); List<Dictionary<string, string>> objects = group.Objects; Dictionary<string, string> dict; for (int i = 0; i < objects.Count; i++) { dict = objects[i];//dynamic_cast<CCStringToStringDictionary*>(*it); if (dict == null) break; string key = "x"; int x = int.Parse(dict[key]);//dynamic_cast<NSNumber*>(dict->objectForKey("x"))->getNumber(); key = "y"; int y = int.Parse(dict[key]);//dynamic_cast<NSNumber*>(dict->objectForKey("y"))->getNumber(); key = "width"; int width = int.Parse(dict[key]);//dynamic_cast<NSNumber*>(dict->objectForKey("width"))->getNumber(); key = "height"; int height = int.Parse(dict[key]);//dynamic_cast<NSNumber*>(dict->objectForKey("height"))->getNumber(); //glLineWidth(3); ccColor4F color = new ccColor4F(255, 255, 255, 255); CCDrawingPrimitives.ccDrawLine(new CCPoint(x, y), new CCPoint(x + width, y), color); CCDrawingPrimitives.ccDrawLine(new CCPoint(x + width, y), new CCPoint(x + width, y + height), color); CCDrawingPrimitives.ccDrawLine(new CCPoint(x + width, y + height), new CCPoint(x, y + height), color); CCDrawingPrimitives.ccDrawLine(new CCPoint(x, y + height), new CCPoint(x, y), color); //glLineWidth(1); } }
public static bool ccc4FEqual(ccColor4F a, ccColor4F b) { if (a.r != b.r || a.g != b.g || a.b != b.b) { return(false); } return(a.a == b.a); }
public CCParticle() { this.pos = new CCPoint(); this.startPos = new CCPoint(); this.color = new ccColor4F(); this.deltaColor = new ccColor4F(); this.modeA = new CCParticle.sModeA(); this.modeB = new CCParticle.sModeB(); }
public override void doTest() { CCSize s = CCDirector.sharedDirector().getWinSize(); CCParticleSystem particleSystem = (CCParticleSystem)getChildByTag(PerformanceParticleTest.kTagParticleSystem); // duration particleSystem.Duration = -1; // gravity particleSystem.setGravity(new CCPoint(0, -90)); // angle particleSystem.Angle = 90; particleSystem.AngleVar = 0; // radial particleSystem.setRadialAccel(0); particleSystem.setRadialAccelVar(0); // speed of particles particleSystem.setSpeed(180); particleSystem.setSpeedVar(50); // emitter position particleSystem.position = new CCPoint(s.width / 2, 100); particleSystem.PosVar = new CCPoint(s.width / 2, 0); // life of particles particleSystem.Life = 2.0f; particleSystem.LifeVar = 1; // emits per frame particleSystem.EmissionRate = particleSystem.TotalParticles / particleSystem.Life; // color of particles ccColor4F startColor = new ccColor4F { r = 0.5f, g = 0.5f, b = 0.5f, a = 1.0f }; particleSystem.StartColor = startColor; ccColor4F startColorVar = new ccColor4F { r = 0.5f, g = 0.5f, b = 0.5f, a = 1.0f }; particleSystem.StartColorVar = startColorVar; ccColor4F endColor = new ccColor4F { r = 0.1f, g = 0.1f, b = 0.1f, a = 0.2f }; particleSystem.EndColor = endColor; ccColor4F endColorVar = new ccColor4F { r = 0.1f, g = 0.1f, b = 0.1f, a = 0.2f }; particleSystem.EndColorVar = endColorVar; // size, in pixels particleSystem.EndSize = 32.0f; particleSystem.StartSize = 32.0f; particleSystem.EndSizeVar = 0; particleSystem.StartSizeVar = 0; // additive particleSystem.IsBlendAdditive = false; }
public static void ccDrawLine(CCPoint origin, CCPoint destination, ccColor4F color) { float contentScaleFactor = CCDirector.sharedDirector().ContentScaleFactor; VertexPositionColor[] vertexPositionColor = new VertexPositionColor[] { new VertexPositionColor(new Vector3(origin.x * contentScaleFactor, origin.y * contentScaleFactor, 0f), new Color(color.r, color.g, color.b, color.a)), new VertexPositionColor(new Vector3(destination.x * contentScaleFactor, destination.y * contentScaleFactor, 0f), new Color(color.r, color.g, color.b, color.a)) }; CCApplication cCApplication = CCApplication.sharedApplication(); cCApplication.basicEffect.TextureEnabled = false; cCApplication.basicEffect.VertexColorEnabled = true; foreach (EffectPass pass in cCApplication.basicEffect.CurrentTechnique.Passes) { pass.Apply(); cCApplication.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineList, vertexPositionColor, 0, 1); } }
/// <summary> /// draws a line given the origin and destination point measured in points /// </summary> public static void ccDrawLine(CCPoint origin, CCPoint destination, ccColor4F color) { float factor = CCDirector.sharedDirector().ContentScaleFactor; VertexPositionColor[] vertices = new VertexPositionColor[2]; vertices[0] = new VertexPositionColor(new Vector3(origin.x * factor, origin.y * factor, 0), new Color(color.r, color.g, color.b, color.a)); vertices[1] = new VertexPositionColor(new Vector3(destination.x * factor, destination.y * factor, 0), new Color(color.r, color.g, color.b, color.a)); CCApplication app = CCApplication.sharedApplication(); app.basicEffect.TextureEnabled = false; app.basicEffect.VertexColorEnabled = true; foreach (var pass in app.basicEffect.CurrentTechnique.Passes) { pass.Apply(); app.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineList, vertices, 0, 1); } }
public CCParticle() { pos = new CCPoint(); startPos = new CCPoint(); color = new ccColor4F(); deltaColor = new ccColor4F(); modeA = new sModeA(); modeB = new sModeB(); }
/** Returns a ccColor4F from a ccColor4B. @since v0.99.1 */ public static ccColor4F ccc4FFromccc4B(ccColor4B c) { ccColor4F c4 = new ccColor4F(c.r / 255.0f, c.g / 255.0f, c.b / 255.0f, c.a / 255.0f); return c4; }
public override void onEnter() { base.onEnter(); Color = new ccColor3B(0,0,0); removeChild(m_background, true); m_background = null; m_emitter = new CCParticleSystemQuad(); m_emitter.initWithTotalParticles(100); addChild(m_emitter, 10); m_emitter.Texture = CCTextureCache.sharedTextureCache().addImage("Images/fire"); // duration m_emitter.Duration = (float)eParticleShowingProperty.kCCParticleDurationInfinity; // radius mode m_emitter.EmitterMode = (int)eParticleMode.kCCParticleModeRadius; // radius mode: start and end radius in pixels m_emitter.setStartRadius(50); m_emitter.setStartRadiusVar(0); m_emitter.setEndRadius((float)eParticleShowingProperty.kCCParticleStartRadiusEqualToEndRadius); m_emitter.setEndRadiusVar(0); // radius mode: degrees per second m_emitter.setRotatePerSecond(0); m_emitter.setRotatePerSecondVar(0); // angle m_emitter.Angle = 90; m_emitter.AngleVar = 0; // emitter position CCSize size = CCDirector.sharedDirector().getWinSize(); m_emitter.position = new CCPoint(size.width/2, size.height/2); m_emitter.PosVar = new CCPoint(0,0); // life of particles m_emitter.Life = 5; m_emitter.LifeVar = 0; // spin of particles m_emitter.StartSpin = 0; m_emitter.StartSpinVar = 0; m_emitter.EndSpin = 0; m_emitter.EndSpinVar = 0; // color of particles ccColor4F startColor = new ccColor4F(0.5f, 0.5f, 0.5f, 1.0f); m_emitter.StartColor = startColor; ccColor4F startColorVar = new ccColor4F(0.5f, 0.5f, 0.5f, 1.0f); m_emitter.StartColorVar = startColorVar; ccColor4F endColor = new ccColor4F(0.1f, 0.1f, 0.1f, 0.2f); m_emitter.EndColor = endColor; ccColor4F endColorVar = new ccColor4F(0.1f, 0.1f, 0.1f, 0.2f); m_emitter.EndColorVar = endColorVar; // size, in pixels m_emitter.StartSize = 16; m_emitter.StartSizeVar = 0; m_emitter.EndSize = (float)eParticleShowingProperty.kCCParticleStartSizeEqualToEndSize; // emits per second m_emitter.EmissionRate = m_emitter.TotalParticles / m_emitter.Life; // additive m_emitter.IsBlendAdditive = false; CCRotateBy rot = CCRotateBy.actionWithDuration(16, 360); m_emitter.runAction(CCRepeatForever.actionWithAction(rot)); }
public override void onEnter() { base.onEnter(); m_emitter = new CCParticleSystemPoint(); m_emitter.initWithTotalParticles(1000); //m_emitter.autorelease(); m_background.addChild(m_emitter, 10); ////m_emitter.release(); CCSize s = CCDirector.sharedDirector().getWinSize(); // duration m_emitter.Duration = -1; // gravity m_emitter.setGravity(new CCPoint(0, 0)); // angle m_emitter.Angle = 0; m_emitter.AngleVar = 360; // radial m_emitter.setRadialAccel(70); m_emitter.setRadialAccelVar(10); // tagential m_emitter.setTangentialAccel(80); m_emitter.setTangentialAccelVar(0); // speed of particles m_emitter.setSpeed(50); m_emitter.setSpeedVar(10); // emitter position m_emitter.position = new CCPoint(s.width / 2, s.height / 2); m_emitter.PosVar = new CCPoint(0, 0); // life of particles m_emitter.Life = 2.0f; m_emitter.LifeVar = 0.3f; // emits per frame m_emitter.EmissionRate = m_emitter.TotalParticles / m_emitter.Life; // color of particles ccColor4F startColor = new ccColor4F(0.5f, 0.5f, 0.5f, 1.0f); m_emitter.StartColor = startColor; ccColor4F startColorVar = new ccColor4F(0.5f, 0.5f, 0.5f, 1.0f); m_emitter.StartColorVar = startColorVar; ccColor4F endColor = new ccColor4F(0.1f, 0.1f, 0.1f, 0.2f); m_emitter.EndColor = endColor; ccColor4F endColorVar = new ccColor4F(0.1f, 0.1f, 0.1f, 0.2f); m_emitter.EndColorVar = endColorVar; // size, in pixels m_emitter.StartSize = 1.0f; m_emitter.StartSizeVar = 1.0f; m_emitter.EndSize = 32.0f; m_emitter.EndSizeVar = 8.0f; // texture m_emitter.Texture = CCTextureCache.sharedTextureCache().addImage(TestResource.s_fire); // additive m_emitter.IsBlendAdditive = false; setEmitterPosition(); }
/// <summary> /// draws a polygon given a pointer to CCPoint coordiantes and the number of vertices measured in points. /// The polygon can be closed or open and optionally filled with current GL color /// </summary> public static void ccDrawPoly(CCPoint[] vertices, int numOfVertices, bool closePolygon, bool fill, ccColor4F color) { VertexPositionColor[] newPoint = new VertexPositionColor[numOfVertices + 1]; for (int i = 0; i < numOfVertices; i++) { newPoint[i] = new VertexPositionColor(); newPoint[i].Position = new Vector3(vertices[i].x, vertices[i].y, 0); newPoint[i].Color = new Color(color.r, color.g, color.b, color.a); } CCApplication app = CCApplication.sharedApplication(); app.GraphicsDevice.RasterizerState = new RasterizerState() { CullMode = CullMode.None }; app.basicEffect.TextureEnabled = false; app.basicEffect.VertexColorEnabled = true; short[] indexes = new short[(numOfVertices - 2) * 3]; if (fill) { for (int i = 0; i < numOfVertices - 2; i++) { indexes[i * 3 + 0] = 0; indexes[i * 3 + 1] = (short)(i + 2); indexes[i * 3 + 2] = (short)(i + 1); } foreach (var pass in app.basicEffect.CurrentTechnique.Passes) { pass.Apply(); app.GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.TriangleStrip, newPoint, 0, numOfVertices, indexes, 0, numOfVertices - 2); } } else { if (closePolygon) { newPoint[numOfVertices] = newPoint[0]; numOfVertices += 1; } foreach (var pass in app.basicEffect.CurrentTechnique.Passes) { pass.Apply(); app.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineStrip, newPoint, 0, numOfVertices - 1); } } //if (closePolygon) //{ // glDrawArrays(fill ? GL_TRIANGLE_FAN : GL_LINE_LOOP, 0, numberOfPoints); //} //else //{ // glDrawArrays(fill ? GL_TRIANGLE_FAN : GL_LINE_STRIP, 0, numberOfPoints); //} }
/// <summary> /// draws a cubic bezier path /// @since v0.8 /// </summary> public static void ccDrawCubicBezier(CCPoint origin, CCPoint control1, CCPoint control2, CCPoint destination, int segments, ccColor4F color) { VertexPositionColor[] vertices = new VertexPositionColor[segments + 1]; float factor = CCDirector.sharedDirector().ContentScaleFactor; CCApplication app = CCApplication.sharedApplication(); float t = 0; for (int i = 0; i < segments; ++i) { float x = (float)Math.Pow(1 - t, 3) * origin.x + 3.0f * (float)Math.Pow(1 - t, 2) * t * control1.x + 3.0f * (1 - t) * t * t * control2.x + t * t * t * destination.x; float y = (float)Math.Pow(1 - t, 3) * origin.y + 3.0f * (float)Math.Pow(1 - t, 2) * t * control1.y + 3.0f * (1 - t) * t * t * control2.y + t * t * t * destination.y; vertices[i] = new VertexPositionColor(); vertices[i].Position = new Vector3(x * factor, y * factor, 0); vertices[i].Color = new Color(color.r, color.g, color.b, color.a); t += 1.0f / segments; } vertices[segments] = new VertexPositionColor() { Color = new Color(color.r, color.g, color.b, color.a), Position = new Vector3(destination.x * factor, destination.y * factor, 0) }; app.basicEffect.TextureEnabled = false; app.basicEffect.VertexColorEnabled = true; foreach (var pass in app.basicEffect.CurrentTechnique.Passes) { pass.Apply(); app.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineStrip, vertices, 0, segments); } // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY // Needed states: GL_VERTEX_ARRAY, // Unneeded states: GL_TEXTURE_2D, GL_TEXTURE_COORD_ARRAY, GL_COLOR_ARRAY //glDisable(GL_TEXTURE_2D); //glDisableClientState(GL_TEXTURE_COORD_ARRAY); //glDisableClientState(GL_COLOR_ARRAY); //glVertexPointer(2, GL_FLOAT, 0, vertices); //glDrawArrays(GL_LINE_STRIP, 0, (GLsizei)segments + 1); //delete[] vertices; //// restore default state //glEnableClientState(GL_COLOR_ARRAY); //glEnableClientState(GL_TEXTURE_COORD_ARRAY); //glEnable(GL_TEXTURE_2D); }
public static ccColor4F ccc4FFromccc4B(ccColor4B c) { ccColor4F _ccColor4F = new ccColor4F((float)c.r / 255f, (float)c.g / 255f, (float)c.b / 255f, (float)c.a / 255f); return(_ccColor4F); }
public static void ccDrawCubicBezier(CCPoint origin, CCPoint control1, CCPoint control2, CCPoint destination, int segments, ccColor4F color) { VertexPositionColor[] vector3 = new VertexPositionColor[segments + 1]; float contentScaleFactor = CCDirector.sharedDirector().ContentScaleFactor; CCApplication cCApplication = CCApplication.sharedApplication(); float single = 0f; for (int i = 0; i < segments; i++) { float single1 = (float)Math.Pow((double)(1f - single), 3) * origin.x + 3f * (float)Math.Pow((double)(1f - single), 2) * single * control1.x + 3f * (1f - single) * single * single * control2.x + single * single * single * destination.x; float single2 = (float)Math.Pow((double)(1f - single), 3) * origin.y + 3f * (float)Math.Pow((double)(1f - single), 2) * single * control1.y + 3f * (1f - single) * single * single * control2.y + single * single * single * destination.y; vector3[i] = new VertexPositionColor(); vector3[i].Position = new Vector3(single1 * contentScaleFactor, single2 * contentScaleFactor, 0f); vector3[i].Color = new Color(color.r, color.g, color.b, color.a); single = single + 1f / (float)segments; } VertexPositionColor vertexPositionColor = new VertexPositionColor() { Color = new Color(color.r, color.g, color.b, color.a), Position = new Vector3(destination.x * contentScaleFactor, destination.y * contentScaleFactor, 0f) }; vector3[segments] = vertexPositionColor; cCApplication.basicEffect.TextureEnabled = false; cCApplication.basicEffect.VertexColorEnabled = true; foreach (EffectPass pass in cCApplication.basicEffect.CurrentTechnique.Passes) { pass.Apply(); cCApplication.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineStrip, vector3, 0, segments); } }
public static void ccDrawPoly(CCPoint[] vertices, int numOfVertices, bool closePolygon, bool fill, ccColor4F color) { VertexPositionColor[] vector3 = new VertexPositionColor[numOfVertices + 1]; for (int i = 0; i < numOfVertices; i++) { vector3[i] = new VertexPositionColor(); vector3[i].Position = new Vector3(vertices[i].x, vertices[i].y, 0f); vector3[i].Color = new Color(color.r, color.g, color.b, color.a); } CCApplication rasterizerState = CCApplication.sharedApplication(); rasterizerState.GraphicsDevice.RasterizerState = new RasterizerState() { CullMode = CullMode.None }; rasterizerState.basicEffect.TextureEnabled = false; rasterizerState.basicEffect.VertexColorEnabled = true; short[] numArray = new short[(numOfVertices - 2) * 3]; if (!fill) { if (closePolygon) { vector3[numOfVertices] = vector3[0]; numOfVertices++; } foreach (EffectPass pass in rasterizerState.basicEffect.CurrentTechnique.Passes) { pass.Apply(); rasterizerState.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineStrip, vector3, 0, numOfVertices - 1); } } else { for (int j = 0; j < numOfVertices - 2; j++) { numArray[j * 3] = 0; numArray[j * 3 + 1] = (short)(j + 2); numArray[j * 3 + 2] = (short)(j + 1); } foreach (EffectPass effectPass in rasterizerState.basicEffect.CurrentTechnique.Passes) { effectPass.Apply(); rasterizerState.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionColor>(PrimitiveType.TriangleStrip, vector3, 0, numOfVertices, numArray, 0, numOfVertices - 2); } } }
/** Returns a ccColor4F from a ccColor4B. * @since v0.99.1 */ public static ccColor4F ccc4FFromccc4B(ccColor4B c) { ccColor4F c4 = new ccColor4F(c.r / 255.0f, c.g / 255.0f, c.b / 255.0f, c.a / 255.0f); return(c4); }
/** returns YES if both ccColor4F are equal. Otherwise it returns NO. * @since v0.99.1 */ public static bool ccc4FEqual(ccColor4F a, ccColor4F b) { return(a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a); }
public void initParticle(CCParticle particle) { particle.timeToLive = this.m_fLife + (this.m_fLifeVar * ccMacros.CCRANDOM_MINUS1_1()); particle.timeToLive = (0f > particle.timeToLive) ? 0f : particle.timeToLive; particle.pos.x = this.m_tSourcePosition.x + (this.m_tPosVar.x * ccMacros.CCRANDOM_MINUS1_1()); particle.pos.x *= CCDirector.sharedDirector().ContentScaleFactor; particle.pos.y = this.m_tSourcePosition.y + (this.m_tPosVar.y * ccMacros.CCRANDOM_MINUS1_1()); particle.pos.y *= CCDirector.sharedDirector().ContentScaleFactor; ccColor4F colorf = new ccColor4F { r = CCPointExtension.clampf(this.m_tStartColor.r + (this.m_tStartColorVar.r * ccMacros.CCRANDOM_MINUS1_1()), 0f, 1f), g = CCPointExtension.clampf(this.m_tStartColor.g + (this.m_tStartColorVar.g * ccMacros.CCRANDOM_MINUS1_1()), 0f, 1f), b = CCPointExtension.clampf(this.m_tStartColor.b + (this.m_tStartColorVar.b * ccMacros.CCRANDOM_MINUS1_1()), 0f, 1f), a = CCPointExtension.clampf(this.m_tStartColor.a + (this.m_tStartColorVar.a * ccMacros.CCRANDOM_MINUS1_1()), 0f, 1f) }; ccColor4F colorf2 = new ccColor4F { r = CCPointExtension.clampf(this.m_tEndColor.r + (this.m_tEndColorVar.r * ccMacros.CCRANDOM_MINUS1_1()), 0f, 1f), g = CCPointExtension.clampf(this.m_tEndColor.g + (this.m_tEndColorVar.g * ccMacros.CCRANDOM_MINUS1_1()), 0f, 1f), b = CCPointExtension.clampf(this.m_tEndColor.b + (this.m_tEndColorVar.b * ccMacros.CCRANDOM_MINUS1_1()), 0f, 1f), a = CCPointExtension.clampf(this.m_tEndColor.a + (this.m_tEndColorVar.a * ccMacros.CCRANDOM_MINUS1_1()), 0f, 1f) }; particle.color = colorf; particle.deltaColor.r = (colorf2.r - colorf.r) / particle.timeToLive; particle.deltaColor.g = (colorf2.g - colorf.g) / particle.timeToLive; particle.deltaColor.b = (colorf2.b - colorf.b) / particle.timeToLive; particle.deltaColor.a = (colorf2.a - colorf.a) / particle.timeToLive; float num = this.m_fStartSize + (this.m_fStartSizeVar * ccMacros.CCRANDOM_MINUS1_1()); num = (0f > num) ? 0f : num; num *= CCDirector.sharedDirector().ContentScaleFactor; particle.size = num; if (this.m_fEndSize == -1f) { particle.deltaSize = 0f; } else { float num2 = this.m_fEndSize + (this.m_fEndSizeVar * ccMacros.CCRANDOM_MINUS1_1()); num2 = (0f > num2) ? 0f : num2; num2 *= CCDirector.sharedDirector().ContentScaleFactor; particle.deltaSize = (num2 - num) / particle.timeToLive; } float num3 = this.m_fStartSpin + (this.m_fStartSpinVar * ccMacros.CCRANDOM_MINUS1_1()); float num4 = this.m_fEndSpin + (this.m_fEndSpinVar * ccMacros.CCRANDOM_MINUS1_1()); particle.rotation = num3; particle.deltaRotation = (num4 - num3) / particle.timeToLive; if (this.m_ePositionType == eParticlePositionType.kCCPositionTypeFree) { CCPoint v = base.convertToWorldSpace(new CCPoint(0f, 0f)); particle.startPos = CCPointExtension.ccpMult(v, CCDirector.sharedDirector().ContentScaleFactor); } else if (this.m_ePositionType == eParticlePositionType.kCCPositionTypeRelative) { particle.startPos = CCPointExtension.ccpMult(base.m_tPosition, CCDirector.sharedDirector().ContentScaleFactor); } float num5 = ccMacros.CC_DEGREES_TO_RADIANS(this.m_fAngle + (this.m_fAngleVar * ccMacros.CCRANDOM_MINUS1_1())); if (this.m_nEmitterMode == 0) { CCPoint point2 = new CCPoint((float)Math.Cos((double)num5), (float)Math.Sin((double)num5)); float s = this.modeA.speed + (this.modeA.speedVar * ccMacros.CCRANDOM_MINUS1_1()); s *= CCDirector.sharedDirector().ContentScaleFactor; particle.modeA.dir = CCPointExtension.ccpMult(point2, s); particle.modeA.radialAccel = this.modeA.radialAccel + (this.modeA.radialAccelVar * ccMacros.CCRANDOM_MINUS1_1()); particle.modeA.radialAccel *= CCDirector.sharedDirector().ContentScaleFactor; particle.modeA.tangentialAccel = this.modeA.tangentialAccel + (this.modeA.tangentialAccelVar * ccMacros.CCRANDOM_MINUS1_1()); particle.modeA.tangentialAccel *= CCDirector.sharedDirector().ContentScaleFactor; } else { float num7 = this.modeB.startRadius + (this.modeB.startRadiusVar * ccMacros.CCRANDOM_MINUS1_1()); float num8 = this.modeB.endRadius + (this.modeB.endRadiusVar * ccMacros.CCRANDOM_MINUS1_1()); num7 *= CCDirector.sharedDirector().ContentScaleFactor; num8 *= CCDirector.sharedDirector().ContentScaleFactor; particle.modeB.radius = num7; if (this.modeB.endRadius == -1f) { particle.modeB.deltaRadius = 0f; } else { particle.modeB.deltaRadius = (num8 - num7) / particle.timeToLive; } particle.modeB.angle = num5; particle.modeB.degreesPerSecond = ccMacros.CC_DEGREES_TO_RADIANS(this.modeB.rotatePerSecond + (this.modeB.rotatePerSecondVar * ccMacros.CCRANDOM_MINUS1_1())); } }
/// <summary> /// draws a polygon given a pointer to CCPoint coordiantes and the number of vertices measured in points. /// The polygon can be closed or open /// </summary> public static void ccDrawPoly(CCPoint[] vertices, int numOfVertices, bool closePolygon, ccColor4F color) { ccDrawPoly(vertices, numOfVertices, closePolygon, false, color); }
/// <summary> /// draws a quad bezier path /// @since v0.8 /// </summary> public static void ccDrawQuadBezier(CCPoint origin, CCPoint control, CCPoint destination, int segments, ccColor4F color) { VertexPositionColor[] vertices = new VertexPositionColor[segments + 1]; float factor = CCDirector.sharedDirector().ContentScaleFactor; CCApplication app = CCApplication.sharedApplication(); float t = 0.0f; for (int i = 0; i < segments; i++) { float x = (float)Math.Pow(1 - t, 2) * origin.x + 2.0f * (1 - t) * t * control.x + t * t * destination.x; float y = (float)Math.Pow(1 - t, 2) * origin.y + 2.0f * (1 - t) * t * control.y + t * t * destination.y; vertices[i] = new VertexPositionColor(); vertices[i].Position = new Vector3(x * factor, y * factor, 0); vertices[i].Color = new Color(color.r, color.g, color.b, color.a); t += 1.0f / segments; } vertices[segments] = new VertexPositionColor() { Position = new Vector3(destination.x * factor, destination.y * factor, 0), Color = new Color(color.r, color.g, color.b, color.a), }; app.basicEffect.TextureEnabled = false; app.basicEffect.VertexColorEnabled = true; foreach (var pass in app.basicEffect.CurrentTechnique.Passes) { pass.Apply(); app.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineStrip, vertices, 0, segments); } }
/// <summary> /// draws a polygon given a pointer to CCPoint coordiantes and the number of vertices measured in points. /// The polygon can be closed or open and optionally filled with current GL color /// </summary> public static void ccDrawPoly(CCPoint[] vertices, int numOfVertices, bool closePolygon, bool fill, ccColor4F color) { VertexPositionColor[] newPoint = new VertexPositionColor[numOfVertices + 1]; for (int i = 0; i < numOfVertices; i++) { newPoint[i] = new VertexPositionColor(); newPoint[i].Position = new Vector3(vertices[i].x, vertices[i].y, 0); newPoint[i].Color = new Color(color.r, color.g, color.b, color.a); } CCApplication app = CCApplication.sharedApplication(); app.GraphicsDevice.RasterizerState = new RasterizerState() { CullMode = CullMode.None }; app.basicEffect.TextureEnabled = false; app.basicEffect.VertexColorEnabled = true; short[] indexes = new short[(numOfVertices - 2) * 3]; if (fill) { for (int i = 0; i < numOfVertices - 2; i++) { indexes[i * 3 + 0] = 0; indexes[i * 3 + 1] = (short)(i + 2); indexes[i * 3 + 2] = (short)(i + 1); } foreach (var pass in app.basicEffect.CurrentTechnique.Passes) { pass.Apply(); app.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionColor>(PrimitiveType.TriangleStrip, newPoint, 0, numOfVertices, indexes, 0, numOfVertices - 2); } } else { if (closePolygon) { newPoint[numOfVertices] = newPoint[0]; numOfVertices += 1; } foreach (var pass in app.basicEffect.CurrentTechnique.Passes) { pass.Apply(); app.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineStrip, newPoint, 0, numOfVertices - 1); } } //if (closePolygon) //{ // glDrawArrays(fill ? GL_TRIANGLE_FAN : GL_LINE_LOOP, 0, numberOfPoints); //} //else //{ // glDrawArrays(fill ? GL_TRIANGLE_FAN : GL_LINE_STRIP, 0, numberOfPoints); //} }
public override void onEnter() { base.onEnter(); m_emitter = new CCParticleSystemQuad(); m_emitter.initWithTotalParticles(300); //m_emitter.autorelease(); m_background.addChild(m_emitter, 10); ////m_emitter.release(); // win32 : Remove this line m_emitter.Texture = CCTextureCache.sharedTextureCache().addImage(TestResource.s_stars2); // duration m_emitter.Duration = -1; // gravity m_emitter.setGravity( new CCPoint(0,0)); // angle m_emitter.Angle = 90; m_emitter.AngleVar = 360; // speed of particles m_emitter.setSpeed(160); m_emitter.setSpeedVar(20); // radial m_emitter.setRadialAccel(-120); m_emitter.setRadialAccelVar(0); // tagential m_emitter.setTangentialAccel(30); m_emitter.setTangentialAccelVar(0); // emitter position m_emitter.position = new CCPoint(160,240); m_emitter.PosVar = new CCPoint(0,0); // life of particles m_emitter.Life = 3; m_emitter.LifeVar = 1; // spin of particles m_emitter.StartSpin = 0; m_emitter.StartSpinVar = 0; m_emitter.EndSpin = 0; m_emitter.EndSpinVar = 2000; // color of particles ccColor4F startColor = new ccColor4F(0.5f, 0.5f, 0.5f, 1.0f); m_emitter.StartColor = startColor; ccColor4F startColorVar = new ccColor4F(0.5f, 0.5f, 0.5f, 1.0f); m_emitter.StartColorVar = startColorVar; ccColor4F endColor = new ccColor4F(0.1f, 0.1f, 0.1f, 0.2f); m_emitter.EndColor = endColor; ccColor4F endColorVar = new ccColor4F(0.1f, 0.1f, 0.1f, 0.2f); m_emitter.EndColorVar = endColorVar; // size, in pixels m_emitter.StartSize = 30.0f; m_emitter.StartSizeVar = 00.0f; m_emitter.EndSize = (float)eParticleShowingProperty.kParticleStartSizeEqualToEndSize; // emits per second m_emitter.EmissionRate = m_emitter.TotalParticles/m_emitter.Life; // additive m_emitter.IsBlendAdditive = false; setEmitterPosition(); }
/// <summary> /// draws a quad bezier path /// @since v0.8 /// </summary> public static void ccDrawQuadBezier(CCPoint origin, CCPoint control, CCPoint destination, int segments, ccColor4F color) { VertexPositionColor[] vertices = new VertexPositionColor[segments + 1]; float factor = CCDirector.sharedDirector().ContentScaleFactor; CCApplication app = CCApplication.sharedApplication(); float t = 0.0f; for (int i = 0; i < segments; i++) { float x = (float)Math.Pow(1 - t, 2) * origin.x + 2.0f * (1 - t) * t * control.x + t * t * destination.x; float y = (float)Math.Pow(1 - t, 2) * origin.y + 2.0f * (1 - t) * t * control.y + t * t * destination.y; vertices[i] = new VertexPositionColor(); vertices[i].Position = new Vector3(x * factor, y * factor, 0); vertices[i].Color = new Color(color.r, color.g, color.b, color.a); t += 1.0f / segments; } vertices[segments] = new VertexPositionColor() { Position = new Vector3(destination.x * factor, destination.y * factor, 0), Color = new Color(color.r, color.g, color.b, color.a), }; app.basicEffect.TextureEnabled = false; app.basicEffect.VertexColorEnabled = true; foreach (var pass in app.basicEffect.CurrentTechnique.Passes) { pass.Apply(); app.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineStrip, vertices, 0, segments); } }
/** returns YES if both ccColor4F are equal. Otherwise it returns NO. @since v0.99.1 */ public static bool ccc4FEqual(ccColor4F a, ccColor4F b) { return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a; }
/// <summary> /// draws a cubic bezier path /// @since v0.8 /// </summary> public static void ccDrawCubicBezier(CCPoint origin, CCPoint control1, CCPoint control2, CCPoint destination, int segments, ccColor4F color) { VertexPositionColor[] vertices = new VertexPositionColor[segments + 1]; float factor = CCDirector.sharedDirector().ContentScaleFactor; CCApplication app = CCApplication.sharedApplication(); float t = 0; for (int i = 0; i < segments; ++i) { float x = (float)Math.Pow(1 - t, 3) * origin.x + 3.0f * (float)Math.Pow(1 - t, 2) * t * control1.x + 3.0f * (1 - t) * t * t * control2.x + t * t * t * destination.x; float y = (float)Math.Pow(1 - t, 3) * origin.y + 3.0f * (float)Math.Pow(1 - t, 2) * t * control1.y + 3.0f * (1 - t) * t * t * control2.y + t * t * t * destination.y; vertices[i] = new VertexPositionColor(); vertices[i].Position = new Vector3(x * factor, y * factor, 0); vertices[i].Color = new Color(color.r, color.g, color.b, color.a); t += 1.0f / segments; } vertices[segments] = new VertexPositionColor() { Color = new Color(color.r, color.g, color.b, color.a), Position = new Vector3(destination.x * factor, destination.y * factor, 0) }; app.basicEffect.TextureEnabled = false; app.basicEffect.VertexColorEnabled = true; foreach (var pass in app.basicEffect.CurrentTechnique.Passes) { pass.Apply(); app.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineStrip, vertices, 0, segments); } // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY // Needed states: GL_VERTEX_ARRAY, // Unneeded states: GL_TEXTURE_2D, GL_TEXTURE_COORD_ARRAY, GL_COLOR_ARRAY //glDisable(GL_TEXTURE_2D); //glDisableClientState(GL_TEXTURE_COORD_ARRAY); //glDisableClientState(GL_COLOR_ARRAY); //glVertexPointer(2, GL_FLOAT, 0, vertices); //glDrawArrays(GL_LINE_STRIP, 0, (GLsizei)segments + 1); //delete[] vertices; //// restore default state //glEnableClientState(GL_COLOR_ARRAY); //glEnableClientState(GL_TEXTURE_COORD_ARRAY); //glEnable(GL_TEXTURE_2D); }
public ccV2F_C4F_T2F() { vertices = new ccVertex2F(); colors = new ccColor4F(); texCoords = new ccTex2F(); }
//! Initializes a particle public void initParticle(CCParticle particle) { Debug.Assert(null != particle, "particle shouldn't be null."); // timeToLive // no negative life. prevent division by 0 particle.timeToLive = m_fLife + m_fLifeVar * ccMacros.CCRANDOM_MINUS1_1(); particle.timeToLive = (((0) > (particle.timeToLive)) ? (0) : (particle.timeToLive)); // position particle.pos.x = m_tSourcePosition.x + m_tPosVar.x * ccMacros.CCRANDOM_MINUS1_1(); particle.pos.x *= CCDirector.sharedDirector().ContentScaleFactor; particle.pos.y = m_tSourcePosition.y + m_tPosVar.y * ccMacros.CCRANDOM_MINUS1_1(); particle.pos.y *= CCDirector.sharedDirector().ContentScaleFactor; // Color ccColor4F start = new ccColor4F(); start.r = CCPointExtension.clampf(m_tStartColor.r + m_tStartColorVar.r * ccMacros.CCRANDOM_MINUS1_1(), 0, 1); start.g = CCPointExtension.clampf(m_tStartColor.g + m_tStartColorVar.g * ccMacros.CCRANDOM_MINUS1_1(), 0, 1); start.b = CCPointExtension.clampf(m_tStartColor.b + m_tStartColorVar.b * ccMacros.CCRANDOM_MINUS1_1(), 0, 1); start.a = CCPointExtension.clampf(m_tStartColor.a + m_tStartColorVar.a * ccMacros.CCRANDOM_MINUS1_1(), 0, 1); ccColor4F end = new ccColor4F(); end.r = CCPointExtension.clampf(m_tEndColor.r + m_tEndColorVar.r * ccMacros.CCRANDOM_MINUS1_1(), 0, 1); end.g = CCPointExtension.clampf(m_tEndColor.g + m_tEndColorVar.g * ccMacros.CCRANDOM_MINUS1_1(), 0, 1); end.b = CCPointExtension.clampf(m_tEndColor.b + m_tEndColorVar.b * ccMacros.CCRANDOM_MINUS1_1(), 0, 1); end.a = CCPointExtension.clampf(m_tEndColor.a + m_tEndColorVar.a * ccMacros.CCRANDOM_MINUS1_1(), 0, 1); particle.color = start; particle.deltaColor.r = (end.r - start.r) / particle.timeToLive; particle.deltaColor.g = (end.g - start.g) / particle.timeToLive; particle.deltaColor.b = (end.b - start.b) / particle.timeToLive; particle.deltaColor.a = (end.a - start.a) / particle.timeToLive; // size float startS = m_fStartSize + m_fStartSizeVar * ccMacros.CCRANDOM_MINUS1_1(); startS = (((0) > (startS)) ? (0) : (startS)); // No negative value startS *= CCDirector.sharedDirector().ContentScaleFactor; particle.size = startS; if( m_fEndSize == (float)eParticleShowingProperty.kCCParticleStartSizeEqualToEndSize ) { particle.deltaSize = 0; } else { float endS = m_fEndSize + m_fEndSizeVar * ccMacros.CCRANDOM_MINUS1_1(); endS = (((0) > (endS)) ? (0) : (endS)); // No negative values endS *= CCDirector.sharedDirector().ContentScaleFactor; particle.deltaSize = (endS - startS) / particle.timeToLive; } // rotation float startA = m_fStartSpin + m_fStartSpinVar * ccMacros.CCRANDOM_MINUS1_1(); float endA = m_fEndSpin + m_fEndSpinVar * ccMacros.CCRANDOM_MINUS1_1(); particle.rotation = startA; particle.deltaRotation = (endA - startA) / particle.timeToLive; // position if( m_ePositionType == eParticlePositionType.kCCPositionTypeFree ) { CCPoint p = this.convertToWorldSpace(new CCPoint(0,0)); particle.startPos = CCPointExtension.ccpMult( p, CCDirector.sharedDirector().ContentScaleFactor ); } else if ( m_ePositionType == eParticlePositionType.kCCPositionTypeRelative ) { particle.startPos = CCPointExtension.ccpMult( m_tPosition, CCDirector.sharedDirector().ContentScaleFactor ); } // direction float a = ccMacros.CC_DEGREES_TO_RADIANS(m_fAngle + m_fAngleVar * ccMacros.CCRANDOM_MINUS1_1()); // Mode Gravity: A if( m_nEmitterMode == (int)eParticleMode.kCCParticleModeGravity ) { CCPoint v = new CCPoint( (float)System.Math.Cos( a ), (float)System.Math.Sin( a )); float s = modeA.speed + modeA.speedVar * ccMacros.CCRANDOM_MINUS1_1(); s *= CCDirector.sharedDirector().ContentScaleFactor; // direction particle.modeA.dir = CCPointExtension.ccpMult( v, s ); // radial accel particle.modeA.radialAccel = modeA.radialAccel + modeA.radialAccelVar * ccMacros.CCRANDOM_MINUS1_1(); particle.modeA.radialAccel *= CCDirector.sharedDirector().ContentScaleFactor; // tangential accel particle.modeA.tangentialAccel = modeA.tangentialAccel + modeA.tangentialAccelVar * ccMacros.CCRANDOM_MINUS1_1(); particle.modeA.tangentialAccel *= CCDirector.sharedDirector().ContentScaleFactor; } // Mode Radius: B else { // Set the default diameter of the particle from the source position float startRadius = modeB.startRadius + modeB.startRadiusVar * ccMacros.CCRANDOM_MINUS1_1(); float endRadius = modeB.endRadius + modeB.endRadiusVar * ccMacros.CCRANDOM_MINUS1_1(); startRadius *= CCDirector.sharedDirector().ContentScaleFactor; endRadius *= CCDirector.sharedDirector().ContentScaleFactor; particle.modeB.radius = startRadius; if( modeB.endRadius == (float)eParticleShowingProperty.kCCParticleStartRadiusEqualToEndRadius ) particle.modeB.deltaRadius = 0; else particle.modeB.deltaRadius = (endRadius - startRadius) / particle.timeToLive; particle.modeB.angle = a; particle.modeB.degreesPerSecond = ccMacros.CC_DEGREES_TO_RADIANS(modeB.rotatePerSecond + modeB.rotatePerSecondVar * ccMacros.CCRANDOM_MINUS1_1()); } }
public ccV2F_C4F_T2F() { this.vertices = new ccVertex2F(); this.colors = new ccColor4F(); this.texCoords = new ccTex2F(); }