public override CCFiniteTimeAction reverse() { ccBezierConfig r; r.endPosition = CCPointExtension.ccpNeg(m_sConfig.endPosition); r.controlPoint_1 = CCPointExtension.ccpAdd(m_sConfig.controlPoint_2, CCPointExtension.ccpNeg(m_sConfig.endPosition)); r.controlPoint_2 = CCPointExtension.ccpAdd(m_sConfig.controlPoint_1, CCPointExtension.ccpNeg(m_sConfig.endPosition)); CCBezierBy action = CCBezierBy.actionWithDuration(m_fDuration, r); return(action); }
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. /// @since v0.7.1 /// </summary> public CCPoint convertToNodeSpaceAR(CCPoint worldPoint) { CCPoint nodePoint = convertToNodeSpace(worldPoint); CCPoint anchorInPoints; if (CCDirector.sharedDirector().ContentScaleFactor == 1) { anchorInPoints = m_tAnchorPointInPixels; } else { anchorInPoints = CCPointExtension.ccpMult(m_tAnchorPointInPixels, 1 / CCDirector.sharedDirector().ContentScaleFactor); } return(CCPointExtension.ccpSub(nodePoint, anchorInPoints)); }
/// <summary> /// Converts a local Point to world space coordinates.The result is in Points. /// treating the returned/received node point as anchor relative. /// @since v0.7.1 /// </summary> public CCPoint convertToWorldSpaceAR(CCPoint nodePoint) { CCPoint anchorInPoints; if (CCDirector.sharedDirector().ContentScaleFactor == 1) { anchorInPoints = m_tAnchorPointInPixels; } else { anchorInPoints = CCPointExtension.ccpMult(m_tAnchorPointInPixels, 1 / CCDirector.sharedDirector().ContentScaleFactor); } CCPoint pt = CCPointExtension.ccpAdd(nodePoint, anchorInPoints); return(convertToWorldSpace(pt)); }
/// <summary> /// Converts a Point to world space coordinates. The result is in Points. /// @since v0.7.1 /// </summary> public CCPoint convertToWorldSpace(CCPoint nodePoint) { CCPoint ret; if (CCDirector.sharedDirector().ContentScaleFactor == 1) { ret = CCAffineTransform.CCPointApplyAffineTransform(nodePoint, nodeToWorldTransform()); } else { ret = CCPointExtension.ccpMult(nodePoint, CCDirector.sharedDirector().ContentScaleFactor); ret = CCAffineTransform.CCPointApplyAffineTransform(ret, nodeToWorldTransform()); ret = CCPointExtension.ccpMult(ret, 1 / CCDirector.sharedDirector().ContentScaleFactor); } return(ret); }
public override void step(float dt) { if (m_bBoundarySet) { // whole map fits inside a single screen, no need to modify the position - unless map boundaries are increased if (m_bBoundaryFullyCovered) { return; } CCPoint tempPos = CCPointExtension.ccpSub(m_obHalfScreenSize, m_pobFollowedNode.position); m_pTarget.position = CCPointExtension.ccp(CCPointExtension.clampf(tempPos.x, m_fLeftBoundary, m_fRightBoundary), CCPointExtension.clampf(tempPos.y, m_fBottomBoundary, m_fTopBoundary)); } else { m_pTarget.position = CCPointExtension.ccpSub(m_obHalfScreenSize, m_pobFollowedNode.position); } }
public override void update(float dt) { if (m_pTarget != null) { float xa = 0; float xb = m_sConfig.controlPoint_1.x; float xc = m_sConfig.controlPoint_2.x; float xd = m_sConfig.endPosition.x; float ya = 0; float yb = m_sConfig.controlPoint_1.y; float yc = m_sConfig.controlPoint_2.y; float yd = m_sConfig.endPosition.y; float x = bezierat(xa, xb, xc, xd, dt); float y = bezierat(ya, yb, yc, yd, dt); m_pTarget.position = CCPointExtension.ccpAdd(m_startPosition, CCPointExtension.ccp(x, y)); } }
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); }
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 CCLayer() { anchorPoint = CCPointExtension.ccp(0.5f, 0.5f); isRelativeAnchorPoint = false; }
public CCScene() { isRelativeAnchorPoint = false; anchorPoint = CCPointExtension.ccp(0.5f, 0.5f); m_eSceneType = ccSceneFlag.ccNormalScene; }