public static Vector2 CGPointApplyAffineTransform(Vector2 point, CGAffineTransform xform){ Vector2 p; p.x=xform.a*point.x+xform.c*point.y+xform.tx; p.y=xform.b*point.x+xform.d*point.y+xform.ty; return p; }
public static bool EqualToTransform(CGAffineTransform t1,CGAffineTransform t2){ return FloatUtils.EQ(t1.a, t2.a) && FloatUtils.EQ(t1.b, t2.b) && FloatUtils.EQ(t1.c, t2.c) && FloatUtils.EQ(t1.d, t2.d) && FloatUtils.EQ(t1.tx, t2.tx) && FloatUtils.EQ(t1.ty, t2.ty); }
public static CGAffineTransform Concat(CGAffineTransform xform,CGAffineTransform append){ CGAffineTransform result; result.a=xform.a*append.a+xform.b*append.c; result.b=xform.a*append.b+xform.b*append.d; result.c=xform.c*append.a+xform.d*append.c; result.d=xform.c*append.b+xform.d*append.d; result.tx=xform.tx*append.a+xform.ty*append.c+append.tx; result.ty=xform.tx*append.b+xform.ty*append.d+append.ty; return result; }
public static CGAffineTransform Invert(CGAffineTransform xform){ CGAffineTransform result; float determinant; determinant=xform.a*xform.d-xform.c*xform.b; if(FloatUtils.EQ(determinant, 0)){ return xform; } result.a=xform.d/determinant; result.b=-xform.b/determinant; result.c=-xform.c/determinant; result.d=xform.a/determinant; result.tx=(-xform.d*xform.tx+xform.c*xform.ty)/determinant; result.ty=(xform.b*xform.tx-xform.a*xform.ty)/determinant; return result; }
public static CGAffineTransform Rotate(CGAffineTransform t, float angle){ CGAffineTransform rotate=MakeRotation(angle); return Concat(rotate,rotate); }
public static CGAffineTransform MakeScale(float sx, float sy) { CGAffineTransform t = Make(sx, 0, 0, sy, 0, 0); return(t); }
public static CGAffineTransform Scale(CGAffineTransform t, float sx, float sy){ CGAffineTransform scale=MakeScale(sx,sy); return Concat(scale,t); }
/** 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 */ public CGAffineTransform nodeToParentTransform() { if ( _isTransformDirty ) { // Translate values float x = _position.x; float y = _position.y; if ( _ignoreAnchorPointForPosition ) { x += _anchorPointInPixels.x; y += _anchorPointInPixels.y; } // Rotation values // Change rotation code to handle X and Y // If we skew with the exact same value for both x and y then we're simply just rotating float cx = 1, sx = 0, cy = 1, sy = 0; if(!FloatUtils.EQ(_rotation, 0)) { float radiansX = -ccUtils.CC_DEGREES_TO_RADIANS(_rotation); float radiansY = -ccUtils.CC_DEGREES_TO_RADIANS(_rotation); cx = Mathf.Cos(radiansX); sx = Mathf.Sin(radiansX); cy = Mathf.Cos(radiansY); sy = Mathf.Sin(radiansY); } // optimization: // inline anchor point calculation if skew is not needed // Adjusted transform calculation for rotational skew if( _anchorPointInPixels != Vector2.zero ) { x += cy * -_anchorPointInPixels.x * _scaleX + -sx * -_anchorPointInPixels.y * _scaleY; y += sy * -_anchorPointInPixels.x * _scaleX + cx * -_anchorPointInPixels.y * _scaleY; } // Build Transform Matrix // Adjusted transfor m calculation for rotational skew _transform = CGAffineTransform.Make( cy * _scaleX, sy * _scaleX, -sx * _scaleY, cx * _scaleY, x, y ); _isTransformDirty = false; } return _transform; }
public static bool IsIdentity(CGAffineTransform t){ return EqualToTransform (Identity, t); }
public static CGAffineTransform Rotate(CGAffineTransform t, float angle) { CGAffineTransform rotate = MakeRotation(angle); return(Concat(rotate, t)); }
void updateMesh() { if (_meshDirty) { int tilesCount = _tiles.DL_COUNT(); Vector3[] vertices = new Vector3[tilesCount * 4]; Vector3[] normals = new Vector3[vertices.Length]; Vector2[] uvs = new Vector2[vertices.Length]; int[] triangles = new int[tilesCount * 6]; int tileIndex = 0; for (var ent = _tiles.head; ent != null; ent = ent.next) { Tile tile = ent.obj; CCSpriteFrame spriteFrame = tile.spriteFrame; Rect uTextureRect = spriteFrame.textureRect; uTextureRect.position /= UIWindow.PIXEL_PER_UNIT; uTextureRect.size /= UIWindow.PIXEL_PER_UNIT; float uTextureWidth = spriteFrame.texture.width / UIWindow.PIXEL_PER_UNIT; float uTextureHeight = spriteFrame.texture.height / UIWindow.PIXEL_PER_UNIT; float uTextureRectWidth = uTextureRect.width; float uTextureRectHeigh = uTextureRect.height; Vector2 uSpriteOffset = spriteFrame.offset / UIWindow.PIXEL_PER_UNIT; Vector2 center = uSpriteOffset; float centerX = center.x; float centerY = center.y; float uViewWidth = uTextureRectWidth, uViewHeight = uTextureRectHeigh; if (spriteFrame.rotated) { uViewWidth = uTextureRectHeigh; uViewHeight = uTextureRectWidth; } int verticesIndex = tileIndex * 4; vertices [verticesIndex + 0] = new Vector3(centerX - uViewWidth / 2, centerY + uViewHeight / 2, 0); vertices [verticesIndex + 1] = new Vector3(centerX + uViewWidth / 2, centerY + uViewHeight / 2, 0); vertices [verticesIndex + 2] = new Vector3(centerX + uViewWidth / 2, centerY - uViewHeight / 2, 0); vertices [verticesIndex + 3] = new Vector3(centerX - uViewWidth / 2, centerY - uViewHeight / 2, 0); int trianglesIndex = tileIndex * 6; triangles [trianglesIndex + 0] = verticesIndex + 0; triangles [trianglesIndex + 1] = verticesIndex + 1; triangles [trianglesIndex + 2] = verticesIndex + 2; triangles [trianglesIndex + 3] = verticesIndex + 2; triangles [trianglesIndex + 4] = verticesIndex + 3; triangles [trianglesIndex + 5] = verticesIndex + 0; float uLeft = uTextureRect.xMin / uTextureWidth; float vBottom = uTextureRect.yMin / uTextureHeight; float uRight = uTextureRect.xMax / uTextureWidth; float vTop = uTextureRect.yMax / uTextureHeight; if (!spriteFrame.rotated) { uvs [verticesIndex + 0] = new Vector2(uLeft, vTop); //top-left uvs [verticesIndex + 1] = new Vector2(uRight, vTop); //top-right uvs [verticesIndex + 2] = new Vector2(uRight, vBottom); //bottom-right uvs [verticesIndex + 3] = new Vector2(uLeft, vBottom); //bottom-left } else { uvs [verticesIndex + 0] = new Vector2(uRight, vTop); //top-right uvs [verticesIndex + 1] = new Vector2(uRight, vBottom); //bottom-right uvs [verticesIndex + 2] = new Vector2(uLeft, vBottom); //bottom-left uvs [verticesIndex + 3] = new Vector2(uLeft, vTop); //top-left } //apply transform if (!CGAffineTransform.IsIdentity(tile.transform)) { for (int i = 0; i < 4; i++) { Vector2 vertex = vertices [verticesIndex + i]; vertex = CGAffineTransform.CGPointApplyAffineTransform(vertex, tile.transform); vertices [verticesIndex + i] = vertex; } } tileIndex++; } for (int i = 0; i < normals.Length; i++) { normals [i] = Vector3.back; } Mesh mesh = this.meshFilter.sharedMesh; if (mesh == null) { mesh = new Mesh(); } mesh.vertices = vertices; mesh.triangles = triangles; mesh.normals = normals; mesh.uv = uvs; this.meshFilter.sharedMesh = mesh; _meshDirty = false; } }
public static CGAffineTransform Scale(CGAffineTransform t, float sx, float sy) { CGAffineTransform scale = MakeScale(sx, sy); return(Concat(scale, t)); }
public static CGAffineTransform Translate(CGAffineTransform t, float tx, float ty) { CGAffineTransform translate = MakeTranslation(tx, ty); return(Concat(translate, t)); }
public static bool IsIdentity(CGAffineTransform t) { return(EqualToTransform(Identity, t)); }
public static Vector2 CGSizeApplyAffineTransform(Vector2 size,CGAffineTransform xform){ Vector2 s; s.x=xform.a*size.x+xform.c*size.y; s.y=xform.b*size.x+xform.d*size.y; return s; }
public static CGAffineTransform Translate(CGAffineTransform t, float tx, float ty){ CGAffineTransform translate = MakeTranslation(tx,ty); return Concat(translate,t); }
public static Rect CGRectApplyAffineTransform(Rect rect, CGAffineTransform transform) { float xMin = rect.position.x; float xMax = rect.position.x + rect.size.x; float yMin = rect.position.y; float yMax = rect.position.y + rect.size.y; Vector2[] points = new Vector2[4]{ CGPointApplyAffineTransform(new Vector2(xMin, yMin), transform), CGPointApplyAffineTransform(new Vector2(xMin, yMax), transform), CGPointApplyAffineTransform(new Vector2(xMax, yMin), transform), CGPointApplyAffineTransform(new Vector2(xMax, yMax), transform), }; float newXMin = float.MaxValue; float newXMax = float.MinValue; float newYMin = float.MaxValue; float newYMax = float.MinValue; for (int i = 0; i < 4; i++) { newXMax = Mathf.Max(newXMax, points[i].x); newYMax = Mathf.Max(newYMax, points[i].y); newXMin = Mathf.Min(newXMin, points[i].x); newYMin = Mathf.Min(newYMin, points[i].y); } Rect result = new Rect(newXMin, newYMin, newXMax - newXMin, newYMax - newYMin); return result; }
public static CGAffineTransform MakeTranslation(float tx, float ty) { CGAffineTransform t = Make(1, 0, 0, 1, tx, ty); return(t); }