public int GetIntegerForKey(string pKey, int defaultValue) { string value = getValueForKey(pKey); int ret = defaultValue; if (value != null) { ret = CCUtils.CCParseInt(value); } return(ret); }
/// <summary>initializes a CCOrbitCamera action with radius, delta-radius, z, deltaZ, x, deltaX </summary> public CCOrbitCamera(float t, float radius, float deltaRadius, float angleZ, float deltaAngleZ, float angleX, float deltaAngleX) { if (initWithDuration(t)) { this._radius = radius; this._deltaRadius = deltaRadius; this._angleZ = angleZ; this._deltaAngleZ = deltaAngleZ; this._angleX = angleX; this._deltaAngleX = deltaAngleX; this._radDeltaZ = CCUtils.CC_DEGREES_TO_RADIANS(deltaAngleZ); this._radDeltaX = CCUtils.CC_DEGREES_TO_RADIANS(deltaAngleX); } }
public static CCSize CCSizeFromString(string pszContent) { CCSize ret = new CCSize(); do { List <string> strs = new List <string>(); if (!CCUtils.SplitWithForm(pszContent, strs)) { break; } float width = CCUtils.CCParseFloat(strs[0]); float height = CCUtils.CCParseFloat(strs[1]); ret = new CCSize(width, height); } while (false); return(ret); }
public static CCPoint CCPointFromString(string pszContent) { CCPoint ret = CCPoint.Zero; do { List <string> strs = new List <string>(); if (!CCUtils.SplitWithForm(pszContent, strs)) { break; } float x = CCUtils.CCParseFloat(strs[0]); float y = CCUtils.CCParseFloat(strs[1]); ret.X = x; ret.Y = y; } while (false); return(ret); }
public override void StartWithTarget(Node pTarget) { base.startWithTargetUsedByCCOrbitCamera(pTarget); float r, zenith, azimuth; this.sphericalRadius(out r, out zenith, out azimuth); if (float.IsNaN(_radius)) { this._radius = r; } if (float.IsNaN(_angleZ)) { this._angleZ = CCUtils.CC_RADIANS_TO_DEGREES(zenith); } if (float.IsNaN(_angleX)) { this._angleX = CCUtils.CC_RADIANS_TO_DEGREES(azimuth); } this._radZ = CCUtils.CC_DEGREES_TO_RADIANS(_angleZ); this._radX = CCUtils.CC_DEGREES_TO_RADIANS(_angleX); }
// BatchNode methods /// <summary> /// updates the quad according the the rotation, position, scale values. /// </summary> public void updateTransform() { Debug.Assert(m_bUsesBatchNode != null); // optimization. Quick return if not dirty if (!m_bDirty) { return; } CCAffineTransform matrix; // Optimization: if it is not visible, then do nothing if (!Visible) { m_sQuad.br.vertices = m_sQuad.tl.vertices = m_sQuad.tr.vertices = m_sQuad.bl.vertices = new ccVertex3F(0, 0, 0); m_pobTextureAtlas.updateQuad(m_sQuad, m_uAtlasIndex); //m_bDirty = m_bRecursiveDirty = false; return; } // Optimization: If parent is batchnode, or parent is nil // build Affine transform manually if (Parent == null || Parent == m_pobBatchNode) { float radians = -CCUtils.CC_DEGREES_TO_RADIANS(_rotation); float c = (float)Math.Cos(radians); float s = (float)Math.Sin(radians); matrix = CCAffineTransform.CCAffineTransformMake(c * _scaleX, s * _scaleX, -s * _scaleY, c * _scaleY, _positionInPixels.X, _positionInPixels.Y); if (_skewX > 0 || _skewY > 0) { CCAffineTransform skewMatrix = CCAffineTransform.CCAffineTransformMake(1.0f, (float)Math.Tan(CCUtils.CC_DEGREES_TO_RADIANS(_skewY)), (float)Math.Tan(CCUtils.CC_DEGREES_TO_RADIANS(_skewX)), 1.0f, 0.0f, 0.0f); matrix = CCAffineTransform.CCAffineTransformConcat(skewMatrix, matrix); } matrix = CCAffineTransform.CCAffineTransformTranslate(matrix, -AnchorPointInPixels.X, -AnchorPointInPixels.Y); } else // parent_ != batchNode_ { // else do affine transformation according to the HonorParentTransform matrix = CCAffineTransform.CCAffineTransformMakeIdentity(); ccHonorParentTransform prevHonor = ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_ALL; Node p = this; while (p != null && p is CCSprite && p != m_pobBatchNode) { // Might happen. Issue #1053 // how to implement, we can not use dynamic // CCAssert( [p isKindOfClass:[CCSprite class]], @"CCSprite should be a CCSprite subclass. Probably you initialized an sprite with a batchnode, but you didn't add it to the batch node." ); transformValues_ tv = new transformValues_(); ((CCSprite)p).getTransformValues(tv); // If any of the parents are not visible, then don't draw this node if (!tv.visible) { m_sQuad.br.vertices = m_sQuad.tl.vertices = m_sQuad.tr.vertices = m_sQuad.bl.vertices = new ccVertex3F(0, 0, 0); m_pobTextureAtlas.updateQuad(m_sQuad, m_uAtlasIndex); m_bDirty = m_bRecursiveDirty = false; return; } CCAffineTransform newMatrix = CCAffineTransform.CCAffineTransformMakeIdentity(); // 2nd: Translate, Skew, Rotate, Scale if ((int)prevHonor != 0 & (int)ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_TRANSLATE != 0) { newMatrix = CCAffineTransform.CCAffineTransformTranslate(newMatrix, tv.pos.X, tv.pos.Y); } if ((int)prevHonor != 0 & (int)ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_ROTATE != 0) { newMatrix = CCAffineTransform.CCAffineTransformRotate(newMatrix, -CCUtils.CC_DEGREES_TO_RADIANS(tv.rotation)); } if ((int)prevHonor != 0 & (int)ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_SKEW != 0) { CCAffineTransform skew = CCAffineTransform.CCAffineTransformMake(1.0f, (float)Math.Tan(CCUtils.CC_DEGREES_TO_RADIANS(tv.skew.Y)), (float)Math.Tan(CCUtils.CC_DEGREES_TO_RADIANS(tv.skew.X)), 1.0f, 0.0f, 0.0f); // apply the skew to the transform newMatrix = CCAffineTransform.CCAffineTransformConcat(skew, newMatrix); } if ((int)prevHonor != 0 & (int)ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_SCALE != 0) { newMatrix = CCAffineTransform.CCAffineTransformScale(newMatrix, tv.scale.X, tv.scale.Y); } // 3rd: Translate anchor point newMatrix = CCAffineTransform.CCAffineTransformTranslate(newMatrix, -tv.ap.X, -tv.ap.Y); // 4th: Matrix multiplication matrix = CCAffineTransform.CCAffineTransformConcat(matrix, newMatrix); prevHonor = ((CCSprite)p).honorParentTransform; p = p.Parent; } } // // calculate the Quad based on the Affine Matrix // CCSize size = m_obRectInPixels.Size; float x1 = m_obOffsetPositionInPixels.X; float y1 = m_obOffsetPositionInPixels.Y; float x2 = x1 + size.Width; float y2 = y1 + size.Height; float x = matrix.tx; float y = matrix.ty; float cr = matrix.a; float sr = matrix.b; float cr2 = matrix.d; float sr2 = -matrix.c; float ax = x1 * cr - y1 * sr2 + x; float ay = x1 * sr + y1 * cr2 + y; float bx = x2 * cr - y1 * sr2 + x; float by = x2 * sr + y1 * cr2 + y; float cx = x2 * cr - y2 * sr2 + x; float cy = x2 * sr + y2 * cr2 + y; float dx = x1 * cr - y2 * sr2 + x; float dy = x1 * sr + y2 * cr2 + y; m_sQuad.bl.vertices = new ccVertex3F((float)ax, (float)ay, _vertexZ); m_sQuad.br.vertices = new ccVertex3F((float)bx, (float)by, _vertexZ); m_sQuad.tl.vertices = new ccVertex3F((float)dx, (float)dy, _vertexZ); m_sQuad.tr.vertices = new ccVertex3F((float)cx, (float)cy, _vertexZ); m_pobTextureAtlas.updateQuad(m_sQuad, m_uAtlasIndex); m_bDirty = m_bRecursiveDirty = false; }
public override void updateQuadWithParticle(CCParticle particle, CCPoint newPosition) { // colors ccV2F_C4B_T2F_Quad quad = m_pQuads[m_uParticleIdx]; ccColor4B color = new ccColor4B((Byte)(particle.color.r * 255), (Byte)(particle.color.g * 255), (Byte)(particle.color.b * 255), (Byte)(particle.color.a * 255)); quad.bl.colors = color; quad.br.colors = color; quad.tl.colors = color; quad.tr.colors = color; // vertices float size_2 = particle.size / 2; if (particle.rotation != 0) { float x1 = -size_2; float y1 = -size_2; float x2 = size_2; float y2 = size_2; float x = newPosition.X; float y = newPosition.Y; float r = -CCUtils.CC_DEGREES_TO_RADIANS(particle.rotation); float cr = (float)System.Math.Cos(r); float sr = (float)System.Math.Sin(r); float ax = x1 * cr - y1 * sr + x; float ay = x1 * sr + y1 * cr + y; float bx = x2 * cr - y1 * sr + x; float by = x2 * sr + y1 * cr + y; float cx = x2 * cr - y2 * sr + x; float cy = x2 * sr + y2 * cr + y; float dx = x1 * cr - y2 * sr + x; float dy = x1 * sr + y2 * cr + y; // bottom-left quad.bl.vertices.x = ax; quad.bl.vertices.y = ay; // bottom-right vertex: quad.br.vertices.x = bx; quad.br.vertices.y = by; // top-left vertex: quad.tl.vertices.x = dx; quad.tl.vertices.y = dy; // top-right vertex: quad.tr.vertices.x = cx; quad.tr.vertices.y = cy; } else { // bottom-left vertex: quad.bl.vertices.x = newPosition.X - size_2; quad.bl.vertices.y = newPosition.Y - size_2; // bottom-right vertex: quad.br.vertices.x = newPosition.X + size_2; quad.br.vertices.y = newPosition.Y - size_2; // top-left vertex: quad.tl.vertices.x = newPosition.X - size_2; quad.tl.vertices.y = newPosition.Y + size_2; // top-right vertex: quad.tr.vertices.x = newPosition.X + size_2; quad.tr.vertices.y = newPosition.Y + size_2; } }
public static CCRect CCRectFromString(string pszContent) { CCRect result = CCRect.Zero; do { if (pszContent == null) { break; } string content = pszContent; // find the first '{' and the third '}' int nPosLeft = content.IndexOf('{'); int nPosRight = content.IndexOf('}'); for (int i = 1; i < 3; ++i) { if (nPosRight == -1) { break; } nPosRight = content.IndexOf('}', nPosRight + 1); } if (nPosLeft == -1 || nPosRight == -1) { break; } content = content.Substring(nPosLeft + 1, nPosRight - nPosLeft - 1); int nPointEnd = content.IndexOf('}'); if (nPointEnd == -1) { break; } nPointEnd = content.IndexOf(',', nPointEnd); if (nPointEnd == -1) { break; } // get the point string and size string string pointStr = content.Substring(0, nPointEnd); string sizeStr = content.Substring(nPointEnd + 1); //, content.Length - nPointEnd // split the string with ',' List <string> pointInfo = new List <string>(); if (!CCUtils.SplitWithForm(pointStr, pointInfo)) { break; } List <string> sizeInfo = new List <string>(); if (!CCUtils.SplitWithForm(sizeStr, sizeInfo)) { break; } float x = CCUtils.CCParseFloat(pointInfo[0]); float y = CCUtils.CCParseFloat(pointInfo[1]); float width = CCUtils.CCParseFloat(sizeInfo[0]); float height = CCUtils.CCParseFloat(sizeInfo[1]); result = new CCRect(x, y, width, height); } while (false); return(result); }
/// <summary> /// Returns the matrix that transform the node's (local) space coordinates into the parent's space coordinates. /// The matrix is in Pixels. /// @since v0.7.1 /// </summary> public CCAffineTransform nodeToParentTransform() { if (_isTransformDirty) { _transform = CCAffineTransform.CCAffineTransformMakeIdentity(); if (!IsRelativeAnchorPoint && !AnchorPointInPixels.IsZero) { _transform = CCAffineTransform.CCAffineTransformTranslate(_transform, AnchorPointInPixels.X, AnchorPointInPixels.Y); } if (!_positionInPixels.IsZero) { _transform = CCAffineTransform.CCAffineTransformTranslate(_transform, _positionInPixels.X, _positionInPixels.Y); } if (_rotation != 0f) { _transform = CCAffineTransform.CCAffineTransformRotate(_transform, -CCUtils.CC_DEGREES_TO_RADIANS(_rotation)); } if (_skewX != 0f || _skewY != 0f) { // create a skewed coordinate system CCAffineTransform skew = CCAffineTransform.CCAffineTransformMake(1.0f, (float)Math.Tan(CCUtils.CC_DEGREES_TO_RADIANS(_skewY)), (float)Math.Tan(CCUtils.CC_DEGREES_TO_RADIANS(_skewX)), 1.0f, 0.0f, 0.0f); // apply the skew to the transform _transform = CCAffineTransform.CCAffineTransformConcat(skew, _transform); } if (!(_scaleX == 1f && _scaleY == 1f)) { _transform = CCAffineTransform.CCAffineTransformScale(_transform, _scaleX, _scaleY); } if (!AnchorPointInPixels.IsZero) { _transform = CCAffineTransform.CCAffineTransformTranslate(_transform, -AnchorPointInPixels.X, -AnchorPointInPixels.Y); } _isTransformDirty = false; } return(_transform); }