public bool initWithTarget(CCNode followedNode, CCRect rect) { this.m_pobFollowedNode = followedNode; this.m_bBoundarySet = true; this.m_bBoundaryFullyCovered = false; CCSize size = CCDirector.sharedDirector().getWinSize(); this.m_obFullScreenSize = new CCPoint(size.width, size.height); this.m_obHalfScreenSize = CCPointExtension.ccpMult(this.m_obFullScreenSize, 0.5f); this.m_fLeftBoundary = -((rect.origin.x + rect.size.width) - this.m_obFullScreenSize.x); this.m_fRightBoundary = -rect.origin.x; this.m_fLeftBoundary = -rect.origin.y; this.m_fBottomBoundary = -((rect.origin.y + rect.size.height) - this.m_obFullScreenSize.y); if (this.m_fRightBoundary < this.m_fLeftBoundary) { this.m_fRightBoundary = this.m_fLeftBoundary = (this.m_fLeftBoundary + this.m_fRightBoundary) / 2f; } if (this.m_fTopBoundary < this.m_fBottomBoundary) { this.m_fTopBoundary = this.m_fBottomBoundary = (this.m_fTopBoundary + this.m_fBottomBoundary) / 2f; } if ((this.m_fTopBoundary == this.m_fBottomBoundary) && (this.m_fLeftBoundary == this.m_fRightBoundary)) { this.m_bBoundaryFullyCovered = true; } return(true); }
public override void update(float time) { if (this.m_bDirty) { for (int i = 0; i < this.m_sGridSize.x + 1; i++) { for (int j = 0; j < this.m_sGridSize.y + 1; j++) { ccVertex3F _ccVertex3F = base.originalVertex(new ccGridSize(i, j)); CCPoint cCPoint = new CCPoint(this.m_positionInPixels.x - (new CCPoint(_ccVertex3F.x, _ccVertex3F.y)).x, this.m_positionInPixels.y - (new CCPoint(_ccVertex3F.x, _ccVertex3F.y)).y); float mFRadius = CCPointExtension.ccpLength(cCPoint); if (mFRadius < this.m_fRadius) { mFRadius = this.m_fRadius - mFRadius; float single = mFRadius / this.m_fRadius; if (single == 0f) { single = 0.001f; } float single1 = (float)Math.Log((double)single) * this.m_fLensEffect; float single2 = (float)Math.Exp((double)single1) * this.m_fRadius; if (Math.Sqrt((double)(cCPoint.x * cCPoint.x + cCPoint.y * cCPoint.y)) > 0) { cCPoint = CCPointExtension.ccpNormalize(cCPoint); CCPoint cCPoint1 = CCPointExtension.ccpMult(cCPoint, single2); ccVertex3F _ccVertex3F1 = _ccVertex3F; _ccVertex3F1.z = _ccVertex3F1.z + CCPointExtension.ccpLength(cCPoint1) * this.m_fLensEffect; } } base.setVertex(new ccGridSize(i, j), _ccVertex3F); } } this.m_bDirty = false; } }
public CCPoint convertToWorldSpace(CCPoint nodePoint) { if (CCDirector.sharedDirector().ContentScaleFactor == 1f) { return(CCAffineTransform.CCPointApplyAffineTransform(nodePoint, this.nodeToWorldTransform())); } return(CCPointExtension.ccpMult(CCAffineTransform.CCPointApplyAffineTransform(CCPointExtension.ccpMult(nodePoint, CCDirector.sharedDirector().ContentScaleFactor), this.nodeToWorldTransform()), 1f / CCDirector.sharedDirector().ContentScaleFactor)); }
protected override void updateColor() { base.updateColor(); float single = CCPointExtension.ccpLength(this.m_AlongVector); if (single == 0f) { return; } double num = Math.Sqrt(2); CCPoint cCPoint = new CCPoint(this.m_AlongVector.x / single, this.m_AlongVector.y / single); if (this.m_bCompressedInterpolation) { float single1 = 1f / (Math.Abs(cCPoint.x) + Math.Abs(cCPoint.y)); cCPoint = CCPointExtension.ccpMult(cCPoint, single1 * (float)num); } float mCOpacity = (float)this.m_cOpacity / 255f; ccColor4B _ccColor4B = new ccColor4B() { r = this.m_tColor.r, g = this.m_tColor.g, b = this.m_tColor.b, a = (byte)((float)this.m_cStartOpacity * mCOpacity) }; ccColor4B _ccColor4B1 = _ccColor4B; ccColor4B _ccColor4B2 = new ccColor4B() { r = this.m_endColor.r, g = this.m_endColor.g, b = this.m_endColor.b, a = (byte)((float)this.m_cEndOpacity * mCOpacity) }; ccColor4B _ccColor4B3 = _ccColor4B2; this.m_pSquareColors[0].r = (byte)((double)_ccColor4B3.r + (double)(_ccColor4B1.r - _ccColor4B3.r) * ((num + (double)cCPoint.x + (double)cCPoint.y) / (2 * num))); this.m_pSquareColors[0].g = (byte)((double)_ccColor4B3.g + (double)(_ccColor4B1.g - _ccColor4B3.g) * ((num + (double)cCPoint.x + (double)cCPoint.y) / (2 * num))); this.m_pSquareColors[0].b = (byte)((double)_ccColor4B3.b + (double)(_ccColor4B1.b - _ccColor4B3.b) * ((num + (double)cCPoint.x + (double)cCPoint.y) / (2 * num))); this.m_pSquareColors[0].a = (byte)((double)_ccColor4B3.a + (double)(_ccColor4B1.a - _ccColor4B3.a) * ((num + (double)cCPoint.x + (double)cCPoint.y) / (2 * num))); this.m_pSquareColors[1].r = (byte)((double)_ccColor4B3.r + (double)(_ccColor4B1.r - _ccColor4B3.r) * ((num - (double)cCPoint.x + (double)cCPoint.y) / (2 * num))); this.m_pSquareColors[1].g = (byte)((double)_ccColor4B3.g + (double)(_ccColor4B1.g - _ccColor4B3.g) * ((num - (double)cCPoint.x + (double)cCPoint.y) / (2 * num))); this.m_pSquareColors[1].b = (byte)((double)_ccColor4B3.b + (double)(_ccColor4B1.b - _ccColor4B3.b) * ((num - (double)cCPoint.x + (double)cCPoint.y) / (2 * num))); this.m_pSquareColors[1].a = (byte)((double)_ccColor4B3.a + (double)(_ccColor4B1.a - _ccColor4B3.a) * ((num - (double)cCPoint.x + (double)cCPoint.y) / (2 * num))); this.m_pSquareColors[2].r = (byte)((double)_ccColor4B3.r + (double)(_ccColor4B1.r - _ccColor4B3.r) * ((num + (double)cCPoint.x - (double)cCPoint.y) / (2 * num))); this.m_pSquareColors[2].g = (byte)((double)_ccColor4B3.g + (double)(_ccColor4B1.g - _ccColor4B3.g) * ((num + (double)cCPoint.x - (double)cCPoint.y) / (2 * num))); this.m_pSquareColors[2].b = (byte)((double)_ccColor4B3.b + (double)(_ccColor4B1.b - _ccColor4B3.b) * ((num + (double)cCPoint.x - (double)cCPoint.y) / (2 * num))); this.m_pSquareColors[2].a = (byte)((double)_ccColor4B3.a + (double)(_ccColor4B1.a - _ccColor4B3.a) * ((num + (double)cCPoint.x - (double)cCPoint.y) / (2 * num))); this.m_pSquareColors[3].r = (byte)((double)_ccColor4B3.r + (double)(_ccColor4B1.r - _ccColor4B3.r) * ((num - (double)cCPoint.x - (double)cCPoint.y) / (2 * num))); this.m_pSquareColors[3].g = (byte)((double)_ccColor4B3.g + (double)(_ccColor4B1.g - _ccColor4B3.g) * ((num - (double)cCPoint.x - (double)cCPoint.y) / (2 * num))); this.m_pSquareColors[3].b = (byte)((double)_ccColor4B3.b + (double)(_ccColor4B1.b - _ccColor4B3.b) * ((num - (double)cCPoint.x - (double)cCPoint.y) / (2 * num))); this.m_pSquareColors[3].a = (byte)((double)_ccColor4B3.a + (double)(_ccColor4B1.a - _ccColor4B3.a) * ((num - (double)cCPoint.x - (double)cCPoint.y) / (2 * num))); this.vertices[0].Color = new Microsoft.Xna.Framework.Color((int)this.m_pSquareColors[0].r, (int)this.m_pSquareColors[0].g, (int)this.m_pSquareColors[0].b, (int)this.m_pSquareColors[0].a); this.vertices[1].Color = new Microsoft.Xna.Framework.Color((int)this.m_pSquareColors[1].r, (int)this.m_pSquareColors[1].g, (int)this.m_pSquareColors[1].b, (int)this.m_pSquareColors[1].a); this.vertices[2].Color = new Microsoft.Xna.Framework.Color((int)this.m_pSquareColors[2].r, (int)this.m_pSquareColors[2].g, (int)this.m_pSquareColors[2].b, (int)this.m_pSquareColors[2].a); this.vertices[3].Color = new Microsoft.Xna.Framework.Color((int)this.m_pSquareColors[3].r, (int)this.m_pSquareColors[3].g, (int)this.m_pSquareColors[3].b, (int)this.m_pSquareColors[3].a); }
public bool initWithTarget(CCNode followedNode) { this.m_pobFollowedNode = followedNode; this.m_bBoundarySet = false; this.m_bBoundaryFullyCovered = false; CCSize size = CCDirector.sharedDirector().getWinSize(); this.m_obFullScreenSize = new CCPoint(size.width, size.height); this.m_obHalfScreenSize = CCPointExtension.ccpMult(this.m_obFullScreenSize, 0.5f); return(true); }
public CCPoint convertToNodeSpaceAR(CCPoint worldPoint) { CCPoint tAnchorPointInPixels; CCPoint point = this.convertToNodeSpace(worldPoint); if (CCDirector.sharedDirector().ContentScaleFactor == 1f) { tAnchorPointInPixels = this.m_tAnchorPointInPixels; } else { tAnchorPointInPixels = CCPointExtension.ccpMult(this.m_tAnchorPointInPixels, 1f / CCDirector.sharedDirector().ContentScaleFactor); } return(CCPointExtension.ccpSub(point, tAnchorPointInPixels)); }
public bool initWithTarget(CCNode followedNode) { Debug.Assert(followedNode != null); m_pobFollowedNode = followedNode; m_bBoundarySet = false; m_bBoundaryFullyCovered = false; CCSize winSize = CCDirector.sharedDirector().getWinSize(); m_obFullScreenSize = new CCPoint(winSize.width, winSize.height); m_obHalfScreenSize = CCPointExtension.ccpMult(m_obFullScreenSize, 0.5f); return(true); }
/// <summary> /// Converts a Point to node (local) space coordinates. The result is in Points. /// treating the returned/received node point as anchor relative. /// </summary> public CCPoint ConvertToNodeSpaceAR(CCPoint worldPoint) { CCPoint nodePoint = ConvertToNodeSpace(worldPoint); CCPoint anchorInPoints; if (Director.SharedDirector.ContentScaleFactor == 1) { anchorInPoints = AnchorPointInPixels; } else { anchorInPoints = CCPointExtension.ccpMult(AnchorPointInPixels, 1 / Director.SharedDirector.ContentScaleFactor); } return(CCPointExtension.ccpSub(nodePoint, anchorInPoints)); }
public CCPoint convertToWorldSpaceAR(CCPoint nodePoint) { CCPoint tAnchorPointInPixels; if (CCDirector.sharedDirector().ContentScaleFactor == 1f) { tAnchorPointInPixels = this.m_tAnchorPointInPixels; } else { tAnchorPointInPixels = CCPointExtension.ccpMult(this.m_tAnchorPointInPixels, 1f / CCDirector.sharedDirector().ContentScaleFactor); } CCPoint point2 = CCPointExtension.ccpAdd(nodePoint, tAnchorPointInPixels); return(this.convertToWorldSpace(point2)); }
/// <summary>Converts a Point to world space coordinates. The result is in Points.</summary> public CCPoint ConvertToWorldSpace(CCPoint nodePoint) { CCPoint ret; if (Director.SharedDirector.ContentScaleFactor == 1) { ret = CCAffineTransform.CCPointApplyAffineTransform(nodePoint, nodeToWorldTransform()); } else { ret = CCPointExtension.ccpMult(nodePoint, Director.SharedDirector.ContentScaleFactor); ret = CCAffineTransform.CCPointApplyAffineTransform(ret, nodeToWorldTransform()); ret = CCPointExtension.ccpMult(ret, 1 / Director.SharedDirector.ContentScaleFactor); } return(ret); }
/// <summary> /// Converts a local Point to world space coordinates.The result is in Points. /// treating the returned/received node point as anchor relative. /// </summary> public CCPoint ConvertToWorldSpaceAR(CCPoint nodePoint) { CCPoint anchorInPoints; if (Director.SharedDirector.ContentScaleFactor == 1) { anchorInPoints = AnchorPointInPixels; } else { anchorInPoints = CCPointExtension.ccpMult(AnchorPointInPixels, 1 / Director.SharedDirector.ContentScaleFactor); } CCPoint pt = CCPointExtension.ccpAdd(nodePoint, anchorInPoints); return(ConvertToWorldSpace(pt)); }
public override void Update(float time) { if (m_bDirty) { int i, j; for (i = 0; i < m_sGridSize.x + 1; ++i) { for (j = 0; j < m_sGridSize.y + 1; ++j) { ccVertex3F v = originalVertex(new ccGridSize(i, j)); CCPoint vect = new CCPoint(m_positionInPixels.X - new CCPoint(v.x, v.y).X, m_positionInPixels.Y - new CCPoint(v.x, v.y).Y); float r = CCPointExtension.ccpLength(vect); if (r < m_fRadius) { r = m_fRadius - r; float pre_log = r / m_fRadius; if (pre_log == 0) { pre_log = 0.001f; } float l = (float)Math.Log(pre_log) * m_fLensEffect; float new_r = (float)Math.Exp(l) * m_fRadius; if (Math.Sqrt((vect.X * vect.X + vect.Y * vect.Y)) > 0) { vect = CCPointExtension.ccpNormalize(vect); CCPoint new_vect = CCPointExtension.ccpMult(vect, new_r);; v.z += CCPointExtension.ccpLength(new_vect) * m_fLensEffect; } } setVertex(new ccGridSize(i, j), v); } } m_bDirty = false; } }
public bool initWithTarget(CCNode followedNode, CCRect rect) { Debug.Assert(followedNode != null); m_pobFollowedNode = followedNode; m_bBoundarySet = true; m_bBoundaryFullyCovered = false; CCSize winSize = CCDirector.sharedDirector().getWinSize(); m_obFullScreenSize = new CCPoint(winSize.width, winSize.height); m_obHalfScreenSize = CCPointExtension.ccpMult(m_obFullScreenSize, 0.5f); m_fLeftBoundary = -((rect.origin.x + rect.size.width) - m_obFullScreenSize.x); m_fRightBoundary = -rect.origin.x; m_fLeftBoundary = -rect.origin.y; m_fBottomBoundary = -((rect.origin.y + rect.size.height) - m_obFullScreenSize.y); if (m_fRightBoundary < m_fLeftBoundary) { // screen width is larger than world's boundary width //set both in the middle of the world m_fRightBoundary = m_fLeftBoundary = (m_fLeftBoundary + m_fRightBoundary) / 2; } if (m_fTopBoundary < m_fBottomBoundary) { // screen width is larger than world's boundary width //set both in the middle of the world m_fTopBoundary = m_fBottomBoundary = (m_fTopBoundary + m_fBottomBoundary) / 2; } if ((m_fTopBoundary == m_fBottomBoundary) && (m_fLeftBoundary == m_fRightBoundary)) { m_bBoundaryFullyCovered = true; } return(true); }
/// <summary> /// Update does the work of mapping the texture onto the triangles // It now doesn't occur the cost of free/alloc data every update cycle. // It also only changes the percentage point but no other points if they have not // been modified. // // It now deals with flipped texture. If you run into this problem, just use the // sprite property and enable the methods flipX, flipY. /// </summary> protected void updateRadial() { // Texture Max is the actual max coordinates to deal with non-power of 2 textures float fXMax = Math.Max(m_pSprite.quad.br.texCoords.u, m_pSprite.quad.bl.texCoords.u); float fXMin = Math.Min(m_pSprite.quad.br.texCoords.u, m_pSprite.quad.bl.texCoords.u); float fYMax = Math.Max(m_pSprite.quad.tl.texCoords.v, m_pSprite.quad.bl.texCoords.v); float fYMin = Math.Min(m_pSprite.quad.tl.texCoords.v, m_pSprite.quad.bl.texCoords.v); CCPoint tMax = new CCPoint(fXMax, fYMax); CCPoint tMin = new CCPoint(fXMin, fYMin); // Grab the midpoint CCPoint midpoint = CCPointExtension.ccpAdd(tMin, CCPointExtension.ccpCompMult(m_tAnchorPoint, CCPointExtension.ccpSub(tMax, tMin))); float alpha = m_fPercentage / 100.0f; // Otherwise we can get the angle from the alpha float angle = 2.0f * ((float)Math.PI) * (m_eType == CCProgressTimerType.kCCProgressTimerTypeRadialCW ? alpha : 1.0f - alpha); // We find the vector to do a hit detection based on the percentage // We know the first vector is the one @ 12 o'clock (top,mid) so we rotate // from that by the progress angle around the midpoint pivot CCPoint topMid = new CCPoint(midpoint.x, tMin.y); CCPoint percentagePt = CCPointExtension.ccpRotateByAngle(topMid, midpoint, angle); int index = 0; CCPoint hit = new CCPoint(); if (alpha == 0.0f) { // More efficient since we don't always need to check intersection // If the alpha is zero then the hit point is top mid and the index is 0. hit = topMid; index = 0; } else if (alpha == 1.0f) { // More efficient since we don't always need to check intersection // If the alpha is one then the hit point is top mid and the index is 4. hit = topMid; index = 4; } else { // We run a for loop checking the edges of the texture to find the // intersection point // We loop through five points since the top is split in half float min_t = float.MaxValue; for (int i = 0; i <= kProgressTextureCoordsCount; ++i) { int pIndex = (i + (kProgressTextureCoordsCount - 1)) % kProgressTextureCoordsCount; CCPoint edgePtA = CCPointExtension.ccpAdd(tMin, CCPointExtension.ccpCompMult(boundaryTexCoord(i % kProgressTextureCoordsCount), CCPointExtension.ccpSub(tMax, tMin))); CCPoint edgePtB = CCPointExtension.ccpAdd(tMin, CCPointExtension.ccpCompMult(boundaryTexCoord(pIndex), CCPointExtension.ccpSub(tMax, tMin))); // Remember that the top edge is split in half for the 12 o'clock position // Let's deal with that here by finding the correct endpoints if (i == 0) { edgePtB = CCPointExtension.ccpLerp(edgePtA, edgePtB, 0.5f); } else if (i == 4) { edgePtA = CCPointExtension.ccpLerp(edgePtA, edgePtB, 0.5f); } // s and t are returned by ccpLineIntersect float s = 0; float t = 0; if (CCPointExtension.ccpLineIntersect(edgePtA, edgePtB, midpoint, percentagePt, ref s, ref t)) { // Since our hit test is on rays we have to deal with the top edge // being in split in half so we have to test as a segment if (i == 0 || i == 4) { // s represents the point between edgePtA--edgePtB if (!(0.0f <= s && s <= 1.0f)) { continue; } } // As long as our t isn't negative we are at least finding a // correct hitpoint from midpoint to percentagePt. if (t >= 0.0f) { // Because the percentage line and all the texture edges are // rays we should only account for the shortest intersection if (t < min_t) { min_t = t; index = i; } } } } // Now that we have the minimum magnitude we can use that to find our intersection hit = CCPointExtension.ccpAdd(midpoint, CCPointExtension.ccpMult(CCPointExtension.ccpSub(percentagePt, midpoint), min_t)); } // The size of the vertex data is the index from the hitpoint // the 3 is for the midpoint, 12 o'clock point and hitpoint position. bool sameIndexCount = true; if (m_nVertexDataCount != index + 3) { sameIndexCount = false; if (m_pVertexData != null) { m_pVertexData = null; m_nVertexDataCount = 0; } } if (m_pVertexData == null) { m_nVertexDataCount = index + 3; m_pVertexData = new ccV2F_C4B_T2F[m_nVertexDataCount]; for (int i = 0; i < m_nVertexDataCount; i++) { m_pVertexData[i] = new ccV2F_C4B_T2F(); } Debug.Assert(m_pVertexData != null); updateColor(); } if (!sameIndexCount) { // First we populate the array with the midpoint, then all // vertices/texcoords/colors of the 12 'o clock start and edges and the hitpoint m_pVertexData[0].texCoords = new ccTex2F(midpoint.x, midpoint.y); m_pVertexData[0].vertices = vertexFromTexCoord(midpoint); m_pVertexData[1].texCoords = new ccTex2F(midpoint.x, tMin.y); m_pVertexData[1].vertices = vertexFromTexCoord(new CCPoint(midpoint.x, tMin.y)); for (int i = 0; i < index; ++i) { CCPoint texCoords = CCPointExtension.ccpAdd(tMin, CCPointExtension.ccpCompMult(boundaryTexCoord(i), CCPointExtension.ccpSub(tMax, tMin))); m_pVertexData[i + 2].texCoords = new ccTex2F(texCoords.x, texCoords.y); m_pVertexData[i + 2].vertices = vertexFromTexCoord(texCoords); } // Flip the texture coordinates if set if (m_pSprite.IsFlipX || m_pSprite.IsFlipY) { for (int i = 0; i < m_nVertexDataCount - 1; ++i) { if (m_pSprite.IsFlipX) { m_pVertexData[i].texCoords.u = tMin.x + tMax.x - m_pVertexData[i].texCoords.u; } if (m_pSprite.IsFlipY) { m_pVertexData[i].texCoords.v = tMin.y + tMax.y - m_pVertexData[i].texCoords.v; } } } } // hitpoint will go last m_pVertexData[m_nVertexDataCount - 1].texCoords = new ccTex2F(hit.x, hit.y); m_pVertexData[m_nVertexDataCount - 1].vertices = vertexFromTexCoord(hit); if (m_pSprite.IsFlipX || m_pSprite.IsFlipY) { if (m_pSprite.IsFlipX) { m_pVertexData[m_nVertexDataCount - 1].texCoords.u = tMin.x + tMax.x - m_pVertexData[m_nVertexDataCount - 1].texCoords.u; } if (m_pSprite.IsFlipY) { m_pVertexData[m_nVertexDataCount - 1].texCoords.v = tMin.y + tMax.y - m_pVertexData[m_nVertexDataCount - 1].texCoords.v; } } }
public override void update(float dt) { if (this.m_bIsActive && (this.m_fEmissionRate != 0f)) { float num = 1f / this.m_fEmissionRate; this.m_fEmitCounter += dt; while ((this.m_uParticleCount < this.m_uTotalParticles) && (this.m_fEmitCounter > num)) { this.addParticle(); this.m_fEmitCounter -= num; } this.m_fElapsed += dt; if ((this.m_fDuration != -1f) && (this.m_fDuration < this.m_fElapsed)) { this.stopSystem(); } } this.m_uParticleIdx = 0; CCPoint tPosition = new CCPoint(0f, 0f); if (this.m_ePositionType == eParticlePositionType.kCCPositionTypeFree) { tPosition = base.convertToWorldSpace(new CCPoint(0f, 0f)); tPosition.x *= CCDirector.sharedDirector().ContentScaleFactor; tPosition.y *= CCDirector.sharedDirector().ContentScaleFactor; } else if (this.m_ePositionType == eParticlePositionType.kCCPositionTypeRelative) { tPosition = base.m_tPosition; tPosition.x *= CCDirector.sharedDirector().ContentScaleFactor; tPosition.y *= CCDirector.sharedDirector().ContentScaleFactor; } while (this.m_uParticleIdx < this.m_uParticleCount) { CCParticle particle = this.m_pParticles[this.m_uParticleIdx]; particle.timeToLive -= dt; if (particle.timeToLive > 0f) { CCPoint pos; if (this.m_nEmitterMode == 0) { CCPoint v = new CCPoint(0f, 0f); if ((particle.pos.x != 0f) || (particle.pos.y != 0f)) { v = CCPointExtension.ccpNormalize(particle.pos); } CCPoint point4 = v; v = CCPointExtension.ccpMult(v, particle.modeA.radialAccel); float x = point4.x; point4.x = -point4.y; point4.y = x; point4 = CCPointExtension.ccpMult(point4, particle.modeA.tangentialAccel); CCPoint point2 = CCPointExtension.ccpMult(CCPointExtension.ccpAdd(CCPointExtension.ccpAdd(v, point4), this.modeA.gravity), dt); particle.modeA.dir = CCPointExtension.ccpAdd(particle.modeA.dir, point2); point2 = CCPointExtension.ccpMult(particle.modeA.dir, dt); particle.pos = CCPointExtension.ccpAdd(particle.pos, point2); } else { particle.modeB.angle += particle.modeB.degreesPerSecond * dt; particle.modeB.radius += particle.modeB.deltaRadius * dt; particle.pos.x = -((float)Math.Cos((double)particle.modeB.angle)) * particle.modeB.radius; particle.pos.y = -((float)Math.Sin((double)particle.modeB.angle)) * particle.modeB.radius; } particle.color.r += particle.deltaColor.r * dt; particle.color.g += particle.deltaColor.g * dt; particle.color.b += particle.deltaColor.b * dt; particle.color.a += particle.deltaColor.a * dt; particle.size += particle.deltaSize * dt; particle.size = (0f > particle.size) ? 0f : particle.size; particle.rotation += particle.deltaRotation * dt; if ((this.m_ePositionType == eParticlePositionType.kCCPositionTypeFree) || (this.m_ePositionType == eParticlePositionType.kCCPositionTypeRelative)) { CCPoint point6 = CCPointExtension.ccpSub(tPosition, particle.startPos); pos = CCPointExtension.ccpSub(particle.pos, point6); } else { pos = particle.pos; } this.updateQuadWithParticle(particle, pos); this.m_uParticleIdx++; } else { if (this.m_uParticleIdx != (this.m_uParticleCount - 1)) { this.m_pParticles[this.m_uParticleIdx].copy(this.m_pParticles[(int)((IntPtr)(this.m_uParticleCount - 1))]); } this.m_uParticleCount--; if ((this.m_uParticleCount == 0) && this.m_bIsAutoRemoveOnFinish) { base.unscheduleUpdate(); base.m_pParent.removeChild(this, true); return; } } } this.postStep(); }
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())); } }
protected void updateRadial() { float single = Math.Max(this.m_pSprite.quad.br.texCoords.u, this.m_pSprite.quad.bl.texCoords.u); float single1 = Math.Min(this.m_pSprite.quad.br.texCoords.u, this.m_pSprite.quad.bl.texCoords.u); float single2 = Math.Max(this.m_pSprite.quad.tl.texCoords.v, this.m_pSprite.quad.bl.texCoords.v); float single3 = Math.Min(this.m_pSprite.quad.tl.texCoords.v, this.m_pSprite.quad.bl.texCoords.v); CCPoint cCPoint = new CCPoint(single, single2); CCPoint cCPoint1 = new CCPoint(single1, single3); CCPoint cCPoint2 = CCPointExtension.ccpAdd(cCPoint1, CCPointExtension.ccpCompMult(this.m_tAnchorPoint, CCPointExtension.ccpSub(cCPoint, cCPoint1))); float mFPercentage = this.m_fPercentage / 100f; float single4 = 6.28318548f * (this.m_eType == CCProgressTimerType.kCCProgressTimerTypeRadialCW ? mFPercentage : 1f - mFPercentage); CCPoint cCPoint3 = new CCPoint(cCPoint2.x, cCPoint1.y); CCPoint cCPoint4 = CCPointExtension.ccpRotateByAngle(cCPoint3, cCPoint2, single4); int num = 0; CCPoint cCPoint5 = new CCPoint(); if (mFPercentage == 0f) { cCPoint5 = cCPoint3; num = 0; } else if (mFPercentage != 1f) { float single5 = float.MaxValue; for (int i = 0; i <= 4; i++) { int num1 = (i + 3) % 4; CCPoint cCPoint6 = CCPointExtension.ccpAdd(cCPoint1, CCPointExtension.ccpCompMult(this.boundaryTexCoord(i % 4), CCPointExtension.ccpSub(cCPoint, cCPoint1))); CCPoint cCPoint7 = CCPointExtension.ccpAdd(cCPoint1, CCPointExtension.ccpCompMult(this.boundaryTexCoord(num1), CCPointExtension.ccpSub(cCPoint, cCPoint1))); if (i == 0) { cCPoint7 = CCPointExtension.ccpLerp(cCPoint6, cCPoint7, 0.5f); } else if (i == 4) { cCPoint6 = CCPointExtension.ccpLerp(cCPoint6, cCPoint7, 0.5f); } float single6 = 0f; float single7 = 0f; if (CCPointExtension.ccpLineIntersect(cCPoint6, cCPoint7, cCPoint2, cCPoint4, ref single6, ref single7) && (i != 0 && i != 4 || 0f <= single6 && single6 <= 1f) && single7 >= 0f && single7 < single5) { single5 = single7; num = i; } } cCPoint5 = CCPointExtension.ccpAdd(cCPoint2, CCPointExtension.ccpMult(CCPointExtension.ccpSub(cCPoint4, cCPoint2), single5)); } else { cCPoint5 = cCPoint3; num = 4; } bool flag = true; if (this.m_nVertexDataCount != num + 3) { flag = false; if (this.m_pVertexData != null) { this.m_pVertexData = null; this.m_nVertexDataCount = 0; } } if (this.m_pVertexData == null) { this.m_nVertexDataCount = num + 3; this.m_pVertexData = new ccV2F_C4B_T2F[this.m_nVertexDataCount]; for (int j = 0; j < this.m_nVertexDataCount; j++) { this.m_pVertexData[j] = new ccV2F_C4B_T2F(); } this.updateColor(); } if (!flag) { this.m_pVertexData[0].texCoords = new ccTex2F(cCPoint2.x, cCPoint2.y); this.m_pVertexData[0].vertices = this.vertexFromTexCoord(cCPoint2); this.m_pVertexData[1].texCoords = new ccTex2F(cCPoint2.x, cCPoint1.y); this.m_pVertexData[1].vertices = this.vertexFromTexCoord(new CCPoint(cCPoint2.x, cCPoint1.y)); for (int k = 0; k < num; k++) { CCPoint cCPoint8 = CCPointExtension.ccpAdd(cCPoint1, CCPointExtension.ccpCompMult(this.boundaryTexCoord(k), CCPointExtension.ccpSub(cCPoint, cCPoint1))); this.m_pVertexData[k + 2].texCoords = new ccTex2F(cCPoint8.x, cCPoint8.y); this.m_pVertexData[k + 2].vertices = this.vertexFromTexCoord(cCPoint8); } if (this.m_pSprite.IsFlipX || this.m_pSprite.IsFlipY) { for (int l = 0; l < this.m_nVertexDataCount - 1; l++) { if (this.m_pSprite.IsFlipX) { this.m_pVertexData[l].texCoords.u = cCPoint1.x + cCPoint.x - this.m_pVertexData[l].texCoords.u; } if (this.m_pSprite.IsFlipY) { this.m_pVertexData[l].texCoords.v = cCPoint1.y + cCPoint.y - this.m_pVertexData[l].texCoords.v; } } } } this.m_pVertexData[this.m_nVertexDataCount - 1].texCoords = new ccTex2F(cCPoint5.x, cCPoint5.y); this.m_pVertexData[this.m_nVertexDataCount - 1].vertices = this.vertexFromTexCoord(cCPoint5); if (this.m_pSprite.IsFlipX || this.m_pSprite.IsFlipY) { if (this.m_pSprite.IsFlipX) { this.m_pVertexData[this.m_nVertexDataCount - 1].texCoords.u = cCPoint1.x + cCPoint.x - this.m_pVertexData[this.m_nVertexDataCount - 1].texCoords.u; } if (this.m_pSprite.IsFlipY) { this.m_pVertexData[this.m_nVertexDataCount - 1].texCoords.v = cCPoint1.y + cCPoint.y - this.m_pVertexData[this.m_nVertexDataCount - 1].texCoords.v; } } }
protected override void updateColor() { base.updateColor(); float h = CCPointExtension.ccpLength(m_AlongVector); if (h == 0) { return; } double c = Math.Sqrt(2.0); CCPoint u = new CCPoint(m_AlongVector.X / h, m_AlongVector.Y / h); // Compressed Interpolation mode if (m_bCompressedInterpolation) { float h2 = 1 / (Math.Abs(u.X) + Math.Abs(u.Y)); u = CCPointExtension.ccpMult(u, h2 * (float)c); } float opacityf = (float)m_cOpacity / 255.0f; ccColor4B S = new ccColor4B { r = m_tColor.r, g = m_tColor.g, b = m_tColor.b, a = (byte)(m_cStartOpacity * opacityf) }; ccColor4B E = new ccColor4B { r = m_endColor.r, g = m_endColor.g, b = m_endColor.b, a = (byte)(m_cEndOpacity * opacityf) }; // (-1, -1) m_pSquareColors[0].r = (byte)(E.r + (S.r - E.r) * ((c + u.X + u.Y) / (2.0f * c))); m_pSquareColors[0].g = (byte)(E.g + (S.g - E.g) * ((c + u.X + u.Y) / (2.0f * c))); m_pSquareColors[0].b = (byte)(E.b + (S.b - E.b) * ((c + u.X + u.Y) / (2.0f * c))); m_pSquareColors[0].a = (byte)(E.a + (S.a - E.a) * ((c + u.X + u.Y) / (2.0f * c))); // (1, -1) m_pSquareColors[1].r = (byte)(E.r + (S.r - E.r) * ((c - u.X + u.Y) / (2.0f * c))); m_pSquareColors[1].g = (byte)(E.g + (S.g - E.g) * ((c - u.X + u.Y) / (2.0f * c))); m_pSquareColors[1].b = (byte)(E.b + (S.b - E.b) * ((c - u.X + u.Y) / (2.0f * c))); m_pSquareColors[1].a = (byte)(E.a + (S.a - E.a) * ((c - u.X + u.Y) / (2.0f * c))); // (-1, 1) m_pSquareColors[2].r = (byte)(E.r + (S.r - E.r) * ((c + u.X - u.Y) / (2.0f * c))); m_pSquareColors[2].g = (byte)(E.g + (S.g - E.g) * ((c + u.X - u.Y) / (2.0f * c))); m_pSquareColors[2].b = (byte)(E.b + (S.b - E.b) * ((c + u.X - u.Y) / (2.0f * c))); m_pSquareColors[2].a = (byte)(E.a + (S.a - E.a) * ((c + u.X - u.Y) / (2.0f * c))); // (1, 1) m_pSquareColors[3].r = (byte)(E.r + (S.r - E.r) * ((c - u.X - u.Y) / (2.0f * c))); m_pSquareColors[3].g = (byte)(E.g + (S.g - E.g) * ((c - u.X - u.Y) / (2.0f * c))); m_pSquareColors[3].b = (byte)(E.b + (S.b - E.b) * ((c - u.X - u.Y) / (2.0f * c))); m_pSquareColors[3].a = (byte)(E.a + (S.a - E.a) * ((c - u.X - u.Y) / (2.0f * c))); vertices[0].Color = new Color(m_pSquareColors[0].r, m_pSquareColors[0].g, m_pSquareColors[0].b, m_pSquareColors[0].a); vertices[1].Color = new Color(m_pSquareColors[1].r, m_pSquareColors[1].g, m_pSquareColors[1].b, m_pSquareColors[1].a); vertices[2].Color = new Color(m_pSquareColors[2].r, m_pSquareColors[2].g, m_pSquareColors[2].b, m_pSquareColors[2].a); vertices[3].Color = new Color(m_pSquareColors[3].r, m_pSquareColors[3].g, m_pSquareColors[3].b, m_pSquareColors[3].a); }
public static CCPoint ccpLerp(CCPoint a, CCPoint b, float alpha) { return(CCPointExtension.ccpAdd(CCPointExtension.ccpMult(a, 1f - alpha), CCPointExtension.ccpMult(b, alpha))); }
public static void LineToPolygon(CCPoint[] points, float stroke, ccVertex2F[] vertices, int offset, int nuPoints) { int num; CCPoint cCPoint; nuPoints = nuPoints + offset; if (nuPoints <= 1) { return; } stroke = stroke * 0.5f; int num1 = nuPoints - 1; for (int i = offset; i < nuPoints; i++) { num = i * 2; CCPoint cCPoint1 = points[i]; if (i == 0) { cCPoint = CCPointExtension.ccpPerp(CCPointExtension.ccpNormalize(CCPointExtension.ccpSub(cCPoint1, points[i + 1]))); } else if (i != num1) { CCPoint cCPoint2 = points[i + 1]; CCPoint cCPoint3 = points[i - 1]; CCPoint cCPoint4 = CCPointExtension.ccpNormalize(CCPointExtension.ccpSub(cCPoint2, cCPoint1)); CCPoint cCPoint5 = CCPointExtension.ccpNormalize(CCPointExtension.ccpSub(cCPoint3, cCPoint1)); float single = (float)Math.Acos((double)CCPointExtension.ccpDot(cCPoint4, cCPoint5)); if (single >= ccMacros.CC_DEGREES_TO_RADIANS(70f)) { cCPoint = (single >= ccMacros.CC_DEGREES_TO_RADIANS(170f) ? CCPointExtension.ccpPerp(CCPointExtension.ccpNormalize(CCPointExtension.ccpSub(cCPoint2, cCPoint3))) : CCPointExtension.ccpNormalize(CCPointExtension.ccpMidpoint(cCPoint4, cCPoint5))); } else { cCPoint = CCPointExtension.ccpPerp(CCPointExtension.ccpNormalize(CCPointExtension.ccpMidpoint(cCPoint4, cCPoint5))); } } else { cCPoint = CCPointExtension.ccpPerp(CCPointExtension.ccpNormalize(CCPointExtension.ccpSub(points[i - 1], cCPoint1))); } cCPoint = CCPointExtension.ccpMult(cCPoint, stroke); vertices[num] = new ccVertex2F(cCPoint1.x + cCPoint.x, cCPoint1.y + cCPoint.y); vertices[num + 1] = new ccVertex2F(cCPoint1.x - cCPoint.x, cCPoint1.y - cCPoint.y); } offset = (offset == 0 ? 0 : offset - 1); for (int j = offset; j < num1; j++) { num = j * 2; int num2 = num + 2; ccVertex2F _ccVertex2F = vertices[num]; ccVertex2F _ccVertex2F1 = vertices[num + 1]; ccVertex2F _ccVertex2F2 = vertices[num2]; ccVertex2F _ccVertex2F3 = vertices[num2 + 1]; float single1 = 0f; bool flag = !CCVertex.LineIntersect(_ccVertex2F.x, _ccVertex2F.y, _ccVertex2F3.x, _ccVertex2F3.y, _ccVertex2F1.x, _ccVertex2F1.y, _ccVertex2F2.x, _ccVertex2F2.y, out single1); if (!flag && (single1 < 0f || single1 > 1f)) { flag = true; } if (flag) { vertices[num2] = _ccVertex2F3; vertices[num2 + 1] = _ccVertex2F2; } } }
public static void LineToPolygon(CCPoint[] points, float stroke, ccVertex2F[] vertices, int offset, int nuPoints) { nuPoints += offset; if (nuPoints <= 1) { return; } stroke *= 0.5f; int idx; int nuPointsMinus = nuPoints - 1; for (int i = offset; i < nuPoints; i++) { idx = i * 2; CCPoint p1 = points[i]; CCPoint perpVector; if (i == 0) { perpVector = CCPointExtension.ccpPerp(CCPointExtension.ccpNormalize(CCPointExtension.ccpSub(p1, points[i + 1]))); } else if (i == nuPointsMinus) { perpVector = CCPointExtension.ccpPerp(CCPointExtension.ccpNormalize(CCPointExtension.ccpSub(points[i - 1], p1))); } else { CCPoint p2 = points[i + 1]; CCPoint p0 = points[i - 1]; CCPoint p2p1 = CCPointExtension.ccpNormalize(CCPointExtension.ccpSub(p2, p1)); CCPoint p0p1 = CCPointExtension.ccpNormalize(CCPointExtension.ccpSub(p0, p1)); // Calculate angle between vectors float angle = (float)Math.Acos(CCPointExtension.ccpDot(p2p1, p0p1)); if (angle < ccMacros.CC_DEGREES_TO_RADIANS(70)) { perpVector = CCPointExtension.ccpPerp(CCPointExtension.ccpNormalize(CCPointExtension.ccpMidpoint(p2p1, p0p1))); } else if (angle < ccMacros.CC_DEGREES_TO_RADIANS(170)) { perpVector = CCPointExtension.ccpNormalize(CCPointExtension.ccpMidpoint(p2p1, p0p1)); } else { perpVector = CCPointExtension.ccpPerp(CCPointExtension.ccpNormalize(CCPointExtension.ccpSub(p2, p0))); } } perpVector = CCPointExtension.ccpMult(perpVector, stroke); vertices[idx] = new ccVertex2F(p1.x + perpVector.x, p1.y + perpVector.y); vertices[idx + 1] = new ccVertex2F(p1.x - perpVector.x, p1.y - perpVector.y); } // Validate vertexes offset = (offset == 0) ? 0 : (offset - 1); for (int i = offset; i < nuPointsMinus; i++) { idx = i * 2; int idx1 = idx + 2; ccVertex2F p1 = vertices[idx]; ccVertex2F p2 = vertices[idx + 1]; ccVertex2F p3 = vertices[idx1]; ccVertex2F p4 = vertices[idx1 + 1]; float s = 0f; //BOOL fixVertex = !ccpLineIntersect(ccp(p1.x, p1.y), ccp(p4.x, p4.y), ccp(p2.x, p2.y), ccp(p3.x, p3.y), &s, &t); bool fixVertex = !LineIntersect(p1.x, p1.y, p4.x, p4.y, p2.x, p2.y, p3.x, p3.y, out s); if (!fixVertex) { if (s < 0.0f || s > 1.0f) { fixVertex = true; } } if (fixVertex) { vertices[idx1] = p4; vertices[idx1 + 1] = p3; } } }
public static CCPoint ccpMidpoint(CCPoint v1, CCPoint v2) { return(CCPointExtension.ccpMult(CCPointExtension.ccpAdd(v1, v2), 0.5f)); }
public static CCPoint ccpNormalize(CCPoint v) { return(CCPointExtension.ccpMult(v, 1f / CCPointExtension.ccpLength(v))); }
public static CCPoint ccpProject(CCPoint v1, CCPoint v2) { return(CCPointExtension.ccpMult(v2, CCPointExtension.ccpDot(v1, v2) / CCPointExtension.ccpDot(v2, v2))); }