CGAffineTransform PDFPageGetDrawingTransform(CGPDFPageRef page, CGPDFBox box, float scale) { CGRect boxRect = CGPDFPageGetBoxRect(page, box); int rotation = PDFPageGetRotation(page); CGAffineTransform transform = CGAffineTransformMakeScale(scale, scale); transform = CGAffineTransformRotate(transform, -(rotation * M_PI_2)); switch (rotation) { case 1: transform = CGAffineTransformTranslate(transform, -CGRectGetWidth(boxRect), 0); break; case 2: transform = CGAffineTransformTranslate(transform, -CGRectGetWidth(boxRect), 0); transform = CGAffineTransformTranslate(transform, 0, -CGRectGetHeight(boxRect)); break; case 3: transform = CGAffineTransformTranslate(transform, 0, -CGRectGetHeight(boxRect)); break; default: break; } transform = CGAffineTransformTranslate(transform, -boxRect.origin.x, -boxRect.origin.y); return transform; }
JNIEXPORT void JNICALL OS_NATIVE(CGAffineTransformRotate) (JNIEnv *env, jclass that, jfloatArray arg0, jfloat arg1, jfloatArray arg2) { jfloat *lparg0=NULL; jfloat *lparg2=NULL; OS_NATIVE_ENTER(env, that, CGAffineTransformRotate_FUNC); if (arg0) if ((lparg0 = (*env)->GetFloatArrayElements(env, arg0, NULL)) == NULL) goto fail; if (arg2) if ((lparg2 = (*env)->GetFloatArrayElements(env, arg2, NULL)) == NULL) goto fail; *(CGAffineTransform *)lparg2 = CGAffineTransformRotate(*(CGAffineTransform *)lparg0, arg1); fail: if (arg2 && lparg2) (*env)->ReleaseFloatArrayElements(env, arg2, lparg2, 0); if (arg0 && lparg0) (*env)->ReleaseFloatArrayElements(env, arg0, lparg0, JNI_ABORT); OS_NATIVE_EXIT(env, that, CGAffineTransformRotate_FUNC); }
void EJCanvasContext::rotate(float angle) { state->transform = CGAffineTransformRotate( state->transform, angle ); path->transform = state->transform; }
AffineTransform &AffineTransform::rotate(double d) { m_transform = CGAffineTransformRotate(m_transform, d * deg2rad); return *this; }
Transform2D Transform2D::rotate(Float angleInRadians) const { return CGAffineTransformRotate(*this, angleInRadians); }
void CCSprite::updateTransform(void) { assert(m_bUsesBatchNode); // optimization. Quick return if not dirty if (! m_bDirty) { return; } CGAffineTransform matrix; // Optimization: if it is not visible, then do nothing if (! m_bIsVisible) { m_sQuad.br.vertices = m_sQuad.tl.vertices = m_sQuad.tr.vertices = m_sQuad.bl.vertices = vertex3(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 (! m_pParent || m_pParent == m_pobBatchNode) { float radians = -CC_DEGREES_TO_RADIANS(m_fRotation); float c = cosf(radians); float s = sinf(radians); matrix = CGAffineTransformMake(c * m_fScaleX, s * m_fScaleX, -s * m_fScaleY, c * m_fScaleY, m_tPositionInPixels.x, m_tPositionInPixels.y); matrix = CGAffineTransformTranslate(matrix, -m_tAnchorPointInPixels.x, -m_tAnchorPointInPixels.y); } else // parent_ != batchNode_ { // else do affine transformation according to the HonorParentTransform matrix = CGAffineTransformIdentity; ccHonorParentTransform prevHonor = CC_HONOR_PARENT_TRANSFORM_ALL; for (CCNode *p = this; p && p != m_pobBatchNode; p = p->getParent()) { // Might happen. Issue #1053 // how to implement, we can not use dynamic // NSAssert( [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." ); struct transformValues_ tv; ((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 = vertex3(0,0,0); m_pobTextureAtlas->updateQuad(&m_sQuad, m_uAtlasIndex); m_bDirty = m_bRecursiveDirty = false; return; } CGAffineTransform newMatrix = CGAffineTransformIdentity; // 2nd: Translate, Rotate, Scale if( prevHonor & CC_HONOR_PARENT_TRANSFORM_TRANSLATE ) { newMatrix = CGAffineTransformTranslate(newMatrix, tv.pos.x, tv.pos.y); } if( prevHonor & CC_HONOR_PARENT_TRANSFORM_ROTATE ) { newMatrix = CGAffineTransformRotate(newMatrix, -CC_DEGREES_TO_RADIANS(tv.rotation)); } if( prevHonor & CC_HONOR_PARENT_TRANSFORM_SCALE ) { newMatrix = CGAffineTransformScale(newMatrix, tv.scale.x, tv.scale.y); } // 3rd: Translate anchor point newMatrix = CGAffineTransformTranslate(newMatrix, -tv.ap.x, -tv.ap.y); // 4th: Matrix multiplication matrix = CGAffineTransformConcat( matrix, newMatrix); prevHonor = ((CCSprite*)p)->getHornorParentTransform(); } } // // calculate the Quad based on the Affine Matrix // CGSize 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 = vertex3((float)RENDER_IN_SUBPIXEL(ax), (float)RENDER_IN_SUBPIXEL(ay), m_fVertexZ); m_sQuad.br.vertices = vertex3((float)RENDER_IN_SUBPIXEL(bx), (float)RENDER_IN_SUBPIXEL(by), m_fVertexZ); m_sQuad.tl.vertices = vertex3((float)RENDER_IN_SUBPIXEL(dx), (float)RENDER_IN_SUBPIXEL(dy), m_fVertexZ); m_sQuad.tr.vertices = vertex3((float)RENDER_IN_SUBPIXEL(cx), (float)RENDER_IN_SUBPIXEL(cy), m_fVertexZ); m_pobTextureAtlas->updateQuad(&m_sQuad, m_uAtlasIndex); m_bDirty = m_bRecursiveDirty = false; }