public CCBatchCommand(float globalZOrder, CCBlendFunc blendType, CCTextureAtlas texture, CCAffineTransform modelViewTransform, int flags) : base(globalZOrder, modelViewTransform, flags) { CommandType = CommandType.BATCH_COMMAND; Texture = texture; BlendType = blendType; }
public CCQuadCommand(float globalDepth, CCAffineTransform worldTransform, CCTexture2D texture, CCBlendFunc blendType, int quadCount, params CCV3F_C4B_T2F_Quad[] quads) : base(globalDepth, worldTransform) { Quads = quads; QuadCount = quadCount; Texture = texture; BlendType = blendType; }
internal static void CGAffineToGL(CCAffineTransform t, ref float[] m) { // | m[0] m[4] m[8] m[12] | | m11 m21 m31 m41 | | a c 0 tx | // | m[1] m[5] m[9] m[13] | | m12 m22 m32 m42 | | b d 0 ty | // | m[2] m[6] m[10] m[14] | <=> | m13 m23 m33 m43 | <=> | 0 0 1 0 | // | m[3] m[7] m[11] m[15] | | m14 m24 m34 m44 | | 0 0 0 1 | m[2] = m[3] = m[6] = m[7] = m[8] = m[9] = m[11] = m[14] = 0.0f; m[10] = m[15] = 1.0f; m[0] = t.A; m[4] = t.C; m[12] = t.Tx; m[1] = t.B; m[5] = t.D; m[13] = t.Ty; }
public override void Visit(ref CCAffineTransform parentWorldTransform) { CCPoint pos = AbsolutePosition; if (!pos.Equals(lastPosition)) { foreach(CCPointObject point in ParallaxArray) { point.Child.Position = -pos + (pos * point.Ratio) + point.Offset; } lastPosition = pos; } base.Visit(ref parentWorldTransform); }
public override void Visit (ref CCAffineTransform parentWorldTransform) { if (!Visible || Scene == null) return; var worldTransform = CCAffineTransform.Identity; var affineLocalTransform = AffineLocalTransform; CCAffineTransform.Concat(ref affineLocalTransform, ref parentWorldTransform, out worldTransform); if (Grid != null && Grid.Active) { renderGrid.GlobalDepth = worldTransform.Tz; Renderer.AddCommand(renderGrid); renderBeginGrid.WorldTransform = worldTransform; Renderer.PushGroup(); Renderer.AddCommand(renderBeginGrid); } SortAllChildren(); VisitRenderer(ref worldTransform); if (Target != null) Target.Visit (ref worldTransform); if(Children != null) { var elements = Children.Elements; for(int i = 0, N = Children.Count; i < N; ++i) { var child = elements[i]; if (child.Visible) child.Visit(ref worldTransform); } } if (Grid != null && Grid.Active) { renderEndGrid.GlobalDepth = worldTransform.Tz; Renderer.AddCommand(renderEndGrid); Renderer.PopGroup(); } }
public CCRenderCommand(float globalZOrder, CCAffineTransform modelViewTransform, int flags = 0, int materialId = CCRenderer.MATERIAL_ID_DO_NOT_BATCH) { if (modelViewTransform == null) modelViewTransform = CCAffineTransform.Identity; CommandType = CommandType.UNKNOWN_COMMAND; GlobalOrder = globalZOrder; IsTransparent = true; IsSkipBatching = false; Is3D = false; Depth = 0; ModelViewTransform = modelViewTransform; MaterialId = materialId; }
public CCRenderCommand(float globalZOrder, CCAffineTransform modelViewTransform, int flags = 0, int materialId = CCRenderer.MATERIAL_ID_DO_NOT_BATCH) { if (modelViewTransform == null) { modelViewTransform = CCAffineTransform.Identity; } CommandType = CommandType.UNKNOWN_COMMAND; GlobalOrder = globalZOrder; IsTransparent = true; IsSkipBatching = false; Is3D = false; Depth = 0; ModelViewTransform = modelViewTransform; MaterialId = materialId; }
public CCQuadCommand(float globalZOrder, CCTexture2D texture, CCBlendFunc blendType, CCV3F_C4B_T2F_Quad[] quads, int quadCount, CCAffineTransform modelViewTransform, int flags = 0) : base(globalZOrder, modelViewTransform, flags) { CommandType = CommandType.QUAD_COMMAND; Quads = quads; QuadCount = quadCount; Texture = texture; BlendType = blendType; var textureId = texture == null ? 0 : texture.TextureId; // +=========================================================+ // | Material Id 24 bits | // +============================+============================+ // | Texture ID | BlendFunc (Src ^ Dest) | // | 12 bits | 12 bits | // +============================+============================+ MaterialId = textureId << 12 | BlendType.GetHashCode(); System.Diagnostics.Debug.Assert(MaterialId != 0, "Material Id not set"); }
public void Concat(ref CCAffineTransform m) { float t_a = A; float t_b = B; float t_c = C; float t_d = D; float t_tx = Tx; float t_ty = Ty; float m_a = m.A; float m_b = m.B; float m_c = m.C; float m_d = m.D; A = m_a * t_a + m_c * t_b; B = m_b * t_a + m_d * t_b; C = m_a * t_c + m_c * t_d; D = m_b * t_c + m_d * t_d; Tx = m_a * t_tx + m_c * t_ty + m.Tx; Ty = m_b * t_tx + m_d * t_ty + m.Ty; }
public CCBoundingBoxI Transform(CCAffineTransform matrix) { var top = MinY; var left = MinX; var right = MaxX; var bottom = MaxY; var topLeft = new CCPointI(left, top); var topRight = new CCPointI(right, top); var bottomLeft = new CCPointI(left, bottom); var bottomRight = new CCPointI(right, bottom); matrix.Transform(ref topLeft.X, ref topLeft.Y); matrix.Transform(ref topRight.Y, ref topRight.Y); matrix.Transform(ref bottomLeft.X, ref bottomLeft.Y); matrix.Transform(ref bottomRight.X, ref bottomRight.Y); int minX = Math.Min(Math.Min(topLeft.X, topRight.X), Math.Min(bottomLeft.X, bottomRight.X)); int maxX = Math.Max(Math.Max(topLeft.X, topRight.X), Math.Max(bottomLeft.X, bottomRight.X)); int minY = Math.Min(Math.Min(topLeft.Y, topRight.Y), Math.Min(bottomLeft.Y, bottomRight.Y)); int maxY = Math.Max(Math.Max(topLeft.Y, topRight.Y), Math.Max(bottomLeft.Y, bottomRight.Y)); return(new CCBoundingBoxI(minX, minY, maxX, maxY)); }
public static bool Equal(CCAffineTransform t1, CCAffineTransform t2) { return (t1.A == t2.A && t1.B == t2.B && t1.C == t2.C && t1.D == t2.D && t1.Tx == t2.Tx && t1.Ty == t2.Ty); }
public static void LerpCopy(ref CCAffineTransform m1, ref CCAffineTransform m2, float t, out CCAffineTransform res) { res.A = MathHelper.Lerp(m1.A, m2.A, t); res.B = MathHelper.Lerp(m1.B, m2.B, t); res.C = MathHelper.Lerp(m1.C, m2.C, t); res.D = MathHelper.Lerp(m1.D, m2.D, t); res.Tx = MathHelper.Lerp(m1.Tx, m2.Tx, t); res.Ty = MathHelper.Lerp(m1.Ty, m2.Ty, t); }
public static CCAffineTransform Translate(CCAffineTransform t, float tx, float ty) { return new CCAffineTransform(t.A, t.B, t.C, t.D, t.Tx + t.A * tx + t.C * ty, t.Ty + t.B * tx + t.D * ty); }
public static CCAffineTransform ScaleCopy(CCAffineTransform t, float sx, float sy) { return new CCAffineTransform(t.A * sx, t.B * sx, t.C * sy, t.D * sy, t.Tx, t.Ty); }
public override void Visit(ref CCAffineTransform parentWorldTransform) { if (Stencil == null || !Stencil.Visible) { if (Inverted) { // draw everything base.Visit(ref parentWorldTransform); } return; } if (Window.DrawManager.BeginDrawMask(Viewport.ViewportInPixels, Inverted, AlphaThreshold)) { Window.DrawManager.PushMatrix();; Stencil.Visit(ref parentWorldTransform); Window.DrawManager.PopMatrix(); Window.DrawManager.EndDrawMask(); base.Visit(ref parentWorldTransform); Window.DrawManager.EndMask(); } else { base.Visit(ref parentWorldTransform); } }
public static CCPoint Transform(CCPoint point, CCAffineTransform t) { return new CCPoint( t.A * point.X + t.C * point.Y + t.Tx, t.B * point.X + t.D * point.Y + t.Ty ); }
public bool Equals(ref CCAffineTransform t) { return(A == t.A && B == t.B && C == t.C && D == t.D && Tx == t.Tx && Ty == t.Ty); }
public CCCustomCommand(float globalZOrder, CCAffineTransform worldTransform, Action action) : base(globalZOrder, worldTransform) { Action = action; }
public override void Visit(ref CCAffineTransform parentWorldTransform) { base.Visit(ref parentWorldTransform); }
public static void TransformNormal(ref CCVector2 normal, ref CCAffineTransform affineTransform, out CCVector2 result) { result = new CCVector2((normal.X * affineTransform.A) + (normal.Y * affineTransform.C), (normal.X * affineTransform.B) + (normal.Y * affineTransform.D)); }
public static void Transform(ref CCVector2 position, ref CCAffineTransform affineTransform, out CCVector2 result) { result = new CCVector2((position.X * affineTransform.A) + (position.Y * affineTransform.C) + affineTransform.Tx, (position.X * affineTransform.B) + (position.Y * affineTransform.D) + affineTransform.Ty); }
public static CCVector2 Transform(CCVector2 position, CCAffineTransform matrix) { Transform(ref position, ref matrix, out position); return(position); }
public bool Equals(ref CCAffineTransform t) { return A == t.A && B == t.B && C == t.C && D == t.D && Tx == t.Tx && Ty == t.Ty; }
public static CCRect Transform(CCRect rect, CCAffineTransform anAffineTransform) { return(anAffineTransform.Transform(rect)); }
public virtual bool CollidesWith(CCMaskedSprite target, out CCPoint pt) { pt = CCPoint.Zero; CCAffineTransform affine1 = target.AffineLocalTransform; CCAffineTransform affine2 = target.AffineLocalTransform; CCRect myBBInWorld = Layer.VisibleBoundsWorldspace; CCRect targetBBInWorld = target.BoundingBox; if (!myBBInWorld.IntersectsRect(targetBBInWorld)) { return(false); } // Based upon http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series2D/Putting_CD_into_practice.php var affine1to2 = affine1 * CCAffineTransform.Invert(affine2); int width2 = (int)target.ContentSize.Width; int height2 = (int)target.ContentSize.Height; int width1 = (int)ContentSize.Width; int height1 = (int)ContentSize.Height; byte[] maskA = CollisionMask; byte[] maskB = target.CollisionMask; if (maskA == null || maskB == null) { return(false); } for (int x1 = 0; x1 < width1; x1++) { for (int y1 = 0; y1 < height1; y1++) { var pos1 = new CCVector2(x1, y1); var pos2 = CCVector2.Transform(pos1, affine1to2); int x2 = (int)pos2.X; int y2 = (int)pos2.Y; if ((x2 >= 0) && (x2 < width2)) { if ((y2 >= 0) && (y2 < height2)) { int iA = x1 + (height1 - y1) * width1; int iB = x2 + (height2 - y2) * width2; if (iA >= maskA.Length || iB >= maskB.Length) { continue; } if (maskA[iA] > 0) { if (maskB[iB] > 0) { CCVector2 screenPos = CCVector2.Transform(pos1, affine1); pt = new CCPoint(screenPos); return(true); } } } } } } return(false); }
internal static void GLToCGAffine(float[] m, CCAffineTransform t) { t.A = m[0]; t.C = m[4]; t.Tx = m[12]; t.B = m[1]; t.D = m[5]; t.Ty = m[13]; }
protected override void VisitRenderer(ref CCAffineTransform worldTransform) { Renderer.AddCommand(new CCCustomCommand(worldTransform.Tz, worldTransform, RenderDrawPrimTest)); }
public CCQuadCommand(float globalDepth, CCAffineTransform worldTransform, CCTexture2D texture, CCBlendFunc blendType, params CCV3F_C4B_T2F_Quad[] quads) : this(globalDepth, worldTransform, texture, blendType, quads.Length, quads) { }
protected override void VisitRenderer(ref CCAffineTransform worldTransform) { tileRenderCommand.GlobalDepth = worldTransform.Tz + minVertexZ; tileRenderCommand.WorldTransform = worldTransform; DrawManager.Renderer.AddCommand(tileRenderCommand); }
public static CCSize Transform(CCSize size, CCAffineTransform t) { var s = new CCSize(); s.Width = (float) ((double) t.A * size.Width + (double) t.C * size.Height); s.Height = (float) ((double) t.B * size.Width + (double) t.D * size.Height); return s; }
public static bool Equal(CCAffineTransform t1, CCAffineTransform t2) { return(t1.A == t2.A && t1.B == t2.B && t1.C == t2.C && t1.D == t2.D && t1.Tx == t2.Tx && t1.Ty == t2.Ty); }
public static CCAffineTransform Rotate(CCAffineTransform t, float anAngle) { var fSin = (float) Math.Sin(anAngle); var fCos = (float) Math.Cos(anAngle); return new CCAffineTransform(t.A * fCos + t.C * fSin, t.B * fCos + t.D * fSin, t.C * fCos - t.A * fSin, t.D * fCos - t.B * fSin, t.Tx, t.Ty); }
public CCQuadCommand(float globalZOrder, CCTexture2D texture, CCBlendFunc blendType, CCV3F_C4B_T2F_Quad quad, CCAffineTransform modelViewTransform, int flags = 0) : this(globalZOrder, texture, blendType, new CCV3F_C4B_T2F_Quad[] { quad }, 1, modelViewTransform, flags) { }
/// <summary> /// Concatenate `t2' to `t1' and return the result: /// t' = t1 * t2 */s /// </summary> /// <param name="t1"></param> /// <param name="t2"></param> /// <returns></returns> public static CCAffineTransform Concat(CCAffineTransform t1, CCAffineTransform t2) { return new CCAffineTransform(t1.A * t2.A + t1.B * t2.C, t1.A * t2.B + t1.B * t2.D, //a,b t1.C * t2.A + t1.D * t2.C, t1.C * t2.B + t1.D * t2.D, //c,d t1.Tx * t2.A + t1.Ty * t2.C + t2.Tx, //tx t1.Tx * t2.B + t1.Ty * t2.D + t2.Ty); //ty }
public static CCAffineTransform ScaleCopy(CCAffineTransform t, float sx, float sy) { return(new CCAffineTransform(t.A * sx, t.B * sx, t.C * sy, t.D * sy, t.Tx, t.Ty)); }
public static CCAffineTransform Invert(CCAffineTransform t) { float determinant = 1 / (t.A * t.D - t.B * t.C); return new CCAffineTransform(determinant * t.D, -determinant * t.B, -determinant * t.C, determinant * t.A, determinant * (t.C * t.Ty - t.D * t.Tx), determinant * (t.B * t.Tx - t.A * t.Ty)); }
void UpdateTileCoordsToNodeTransform() { CCSize texToContentScaling = CCTileMapLayer.DefaultTexelToContentSizeRatios; float width = TileTexelSize.Width * texToContentScaling.Width; float height = TileTexelSize.Height * texToContentScaling.Height; float yOffset = (LayerSize.Row - 1) * height; switch (MapType) { case CCTileMapType.Ortho: // Note: For an orthographic map, top-left represents the origin (0,0) // Moving right increases the column // Moving left increases the row tileCoordsToNodeTransform = new CCAffineTransform(new Matrix ( width, 0.0f, 0.0f, 0.0f, 0.0f, -height, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, yOffset, 0.0f, 1.0f )); break; case CCTileMapType.Iso: // Note: For an isometric map, top-right tile represents the origin (0,0) // Moving left increases the column // Moving right increases the row float xOffset = (LayerSize.Column - 1) * (width / 2); tileCoordsToNodeTransform = new CCAffineTransform(new Matrix ( width / 2 , -height / 2, 0.0f, 0.0f, -width/ 2, -height / 2, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, xOffset, yOffset, 0.0f, 1.0f )); break; case CCTileMapType.Hex: tileCoordsToNodeTransform = new CCAffineTransform(new Matrix ( height * (float)Math.Sqrt(0.75), -height/2, 0.0f, 0.0f, 0.0f , -height, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, yOffset, 0.0f, 1.0f )); break; default: tileCoordsToNodeTransform = CCAffineTransform.Identity; break; } nodeToTileCoordsTransform = tileCoordsToNodeTransform.Inverse; }
public static CCRect Transform(CCRect rect, CCAffineTransform anAffineTransform) { return anAffineTransform.Transform(rect); }
protected override void VisitRenderer(ref CCAffineTransform worldTransform) { // Optimization: Fast Dispatch if (TextureAtlas == null || TextureAtlas.TotalQuads == 0) { return; } // Loop through each of our children nodes that may have actions attached. foreach(CCSprite child in Children) { if (child.Tag >= 0) { child.UpdateLocalTransformedSpriteTextureQuads(); } } quadCommand.GlobalDepth = worldTransform.Tz; quadCommand.WorldTransform = worldTransform; Renderer.AddCommand(quadCommand); }
protected override void VisitRenderer(ref CCAffineTransform worldTransform) { base.VisitRenderer(ref worldTransform); Renderer.AddCommand(renderCommand); }
protected override void VisitRenderer(ref CCAffineTransform worldTransform) { if(this.Visible && InnerScene != null) InnerScene.Visit(ref worldTransform); }
protected override void VisitRenderer(ref CCAffineTransform worldTransform) { if (triangleVertices.Count > 0 || lineVertices.Count > 0 || (spriteFont != null && stringData != null && stringData.Count > 0)) { if (triangleVertices.Count > 0) { renderTriangles.GlobalDepth = worldTransform.Tz; renderTriangles.WorldTransform = worldTransform; AddCustomCommandOnDraw(renderTriangles); } if (lineVertices.Count > 0) { renderLines.GlobalDepth = worldTransform.Tz; renderLines.WorldTransform = worldTransform; AddCustomCommandOnDraw(renderLines); } if (spriteFont != null && stringData != null && stringData.Count > 0) { renderStrings.GlobalDepth = worldTransform.Tz; renderStrings.WorldTransform = worldTransform; AddCustomCommandOnDraw(renderStrings); } } }
public static CCAffineTransform Translate(CCAffineTransform t, float tx, float ty) { return(new CCAffineTransform(t.A, t.B, t.C, t.D, t.Tx + t.A * tx + t.C * ty, t.Ty + t.B * tx + t.D * ty)); }
void UpdateTileCoordsToNodeTransform() { CCSize texToContentScaling = CCTileMapLayer.DefaultTexelToContentSizeRatios; float width = TileTexelSize.Width * texToContentScaling.Width; float height = TileTexelSize.Height * texToContentScaling.Height; float yOffset = (LayerSize.Row - 1) * height; tileCoordsToNodeTransformOdd = CCAffineTransform.Identity; switch (MapType) { case CCTileMapType.Ortho: // Note: For an orthographic map, top-left represents the origin (0,0) // Moving right increases the column // Moving left increases the row tileCoordsToNodeTransform = new CCAffineTransform(new Matrix ( width, 0.0f, 0.0f, 0.0f, 0.0f, -height, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, yOffset, 0.0f, 1.0f )); break; case CCTileMapType.Iso: // Note: For an isometric map, top-right tile represents the origin (0,0) // Moving left increases the column // Moving right increases the row float xOffset = (LayerSize.Column - 1) * (width / 2); tileCoordsToNodeTransform = new CCAffineTransform(new Matrix ( width / 2, -height / 2, 0.0f, 0.0f, -width / 2, -height / 2, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, xOffset, yOffset, 0.0f, 1.0f )); break; case CCTileMapType.Hex: tileCoordsToNodeTransform = new CCAffineTransform(new Matrix ( height * (float)Math.Sqrt(0.75), 0.0f, 0.0f, 0.0f, 0.0f, -height, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, yOffset, 0.0f, 1.0f )); tileCoordsToNodeTransformOdd = new CCAffineTransform(new Matrix ( height * (float)Math.Sqrt(0.75), 0.0f, 0.0f, 0.0f, 0.0f, -height, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, yOffset - height / 2, 0.0f, 1.0f )); break; case CCTileMapType.Staggered: tileCoordsToNodeTransform = new CCAffineTransform(new Matrix ( width, 0.0f, 0.0f, 0.0f, 0.0f, -height / 2, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, yOffset / 2, 0.0f, 1.0f )); tileCoordsToNodeTransformOdd = new CCAffineTransform(new Matrix ( width, 0.0f, 0.0f, 0.0f, 0.0f, -height / 2, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, width / 2, yOffset / 2, 0.0f, 1.0f )); break; default: tileCoordsToNodeTransform = CCAffineTransform.Identity; break; } // Adding global tile offsets that are specified by the layer info CCPoint tileOffset = LayerOffset(TileCoordOffset); tileCoordsToNodeTransform.Tx += tileOffset.X; tileCoordsToNodeTransform.Ty += tileOffset.Y; tileCoordsToNodeTransformOdd.Tx += tileOffset.X; tileCoordsToNodeTransformOdd.Ty += tileOffset.Y; nodeToTileCoordsTransform = tileCoordsToNodeTransform.Inverse; nodeToTileCoordsTransformOdd = tileCoordsToNodeTransformOdd.Inverse; }
public void Concat(CCAffineTransform m) { Concat(ref m); }
protected override void VisitRenderer(ref CCAffineTransform worldTransform) { base.VisitRenderer(ref worldTransform); root.Draw(elapsedGameTime); debug.Draw(); }
internal CCGeometryInstanceAttributes() { BlendState = BlendState.AlphaBlend; AdditionalTransform = CCAffineTransform.Identity; PrimitiveType = PrimitiveType.TriangleList; }
private void UpdatePositionTransform() { // Since we are extending SpriteBatchNode we will have to do our own transforms on the sprites. // Translate values float x = Position.X; float y = Position.Y; var affineLocalTransform = CCAffineTransform.Identity; if (IgnoreAnchorPointForPosition) { x += anchorPointInPoints.X; y += anchorPointInPoints.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 (RotationX != 0 || RotationY != 0) { float radiansX = -CCMacros.CCDegreesToRadians(RotationX); float radiansY = -CCMacros.CCDegreesToRadians(RotationY); cx = (float)Math.Cos(radiansX); sx = (float)Math.Sin(radiansX); cy = (float)Math.Cos(radiansY); sy = (float)Math.Sin(radiansY); } bool needsSkewMatrix = (SkewX != 0f || SkewY != 0f); // optimization: // inline anchor point calculation if skew is not needed if (!needsSkewMatrix && !anchorPointInPoints.Equals(CCPoint.Zero)) { x += cy * -anchorPointInPoints.X * ScaleX + -sx * -anchorPointInPoints.Y * ScaleY; y += sy * -anchorPointInPoints.X * ScaleX + cx * -anchorPointInPoints.Y * ScaleY; } // Build Transform Matrix // Adjusted transform calculation for rotational skew affineLocalTransform.A = cy * ScaleX; affineLocalTransform.B = sy * ScaleX; affineLocalTransform.C = -sx * ScaleY; affineLocalTransform.D = cx * ScaleY; affineLocalTransform.Tx = x; affineLocalTransform.Ty = y; // XXX: Try to inline skew // If skew is needed, apply skew and then anchor point if (needsSkewMatrix) { var skewMatrix = new CCAffineTransform( 1.0f, (float)Math.Tan(CCMacros.CCDegreesToRadians(SkewY)), (float)Math.Tan(CCMacros.CCDegreesToRadians(SkewX)), 1.0f, 0.0f, 0.0f); affineLocalTransform = CCAffineTransform.Concat(skewMatrix, affineLocalTransform); // adjust anchor point if (!anchorPointInPoints.Equals(CCPoint.Zero)) { affineLocalTransform = CCAffineTransform.Translate(affineLocalTransform, -anchorPointInPoints.X, -anchorPointInPoints.Y); } } if (Children != null && Children.Count != 0) { CCNode[] elements = Children.Elements; for (int i = 0, count = Children.Count; i < count; i++) { var sprite = elements[i] as CCSprite; if (sprite.Visible) { var pos = affineLocalTransform.Transform(sprite.Position); sprite.PositionX = pos.X; sprite.PositionY = pos.Y; sprite.ScaleX = ScaleX; sprite.ScaleY = ScaleY; sprite.SkewX = SkewX; sprite.SkewY = SkewY; } } } }
public override void Visit(ref CCAffineTransform parentWorldTransform) { if (!Visible || string.IsNullOrEmpty(Text)) { return; } if (systemFontDirty) { UpdateFont(); } if (IsDirty) { UpdateContent(); } var worldTransform = CCAffineTransform.Identity; var affineLocalTransform = AffineLocalTransform; CCAffineTransform.Concat(ref affineLocalTransform, ref parentWorldTransform, out worldTransform); if (textSprite != null) textSprite.Visit(ref worldTransform); else VisitRenderer(ref worldTransform); }
protected override void VisitRenderer(ref CCAffineTransform worldTransform) { geomRenderCommand.GlobalDepth = worldTransform.Tz; geomRenderCommand.WorldTransform = worldTransform; Renderer.AddCommand(geomRenderCommand); }
protected override void VisitRenderer(ref CCAffineTransform worldTransform) { Renderer.AddCommand(new CCCustomCommand(worldTransform.Tz, worldTransform, RenderLabel)); }
public CCBoundingBoxI Transform(CCAffineTransform matrix) { var top = MinY; var left = MinX; var right = MaxX; var bottom = MaxY; var topLeft = new CCPointI(left, top); var topRight = new CCPointI(right, top); var bottomLeft = new CCPointI(left, bottom); var bottomRight = new CCPointI(right, bottom); matrix.Transform(ref topLeft.X, ref topLeft.Y); matrix.Transform(ref topRight.Y, ref topRight.Y); matrix.Transform(ref bottomLeft.X, ref bottomLeft.Y); matrix.Transform(ref bottomRight.X, ref bottomRight.Y); int minX = Math.Min(Math.Min(topLeft.X, topRight.X), Math.Min(bottomLeft.X, bottomRight.X)); int maxX = Math.Max(Math.Max(topLeft.X, topRight.X), Math.Max(bottomLeft.X, bottomRight.X)); int minY = Math.Min(Math.Min(topLeft.Y, topRight.Y), Math.Min(bottomLeft.Y, bottomRight.Y)); int maxY = Math.Max(Math.Max(topLeft.Y, topRight.Y), Math.Max(bottomLeft.Y, bottomRight.Y)); return new CCBoundingBoxI(minX, minY, maxX, maxY); }
public CCCustomCommand(float globalZOrder, CCAffineTransform modelViewTransform, int flags = 0) : base(globalZOrder, modelViewTransform, flags) { CommandType = CommandType.CUSTOM_COMMAND; }
public bool UpdateWithBatchNode(CCSpriteBatchNode batchnode, CCRect rect, bool rotated, CCRect capInsets) { var opacity = Opacity; var color = Color; // Release old sprites RemoveAllChildren(true); scale9Image = batchnode; scale9Image.RemoveAllChildren(true); this.capInsets = capInsets; spriteFrameRotated = rotated; // If there is no given rect if (rect.Equals(CCRect.Zero)) { // Get the texture size as original CCSize textureSize = scale9Image.TextureAtlas.Texture.ContentSizeInPixels; rect = new CCRect(0, 0, textureSize.Width, textureSize.Height); } // Set the given rect's size as original size spriteRect = rect; originalSize = rect.Size; preferredSize = originalSize; capInsetsInternal = capInsets; float h = rect.Size.Height; float w = rect.Size.Width; // If there is no specified center region if (capInsetsInternal.Equals(CCRect.Zero)) { capInsetsInternal = new CCRect(w / 3, h / 3, w / 3, h / 3); } float left_w = capInsetsInternal.Origin.X; float center_w = capInsetsInternal.Size.Width; float right_w = rect.Size.Width - (left_w + center_w); float top_h = capInsetsInternal.Origin.Y; float center_h = capInsetsInternal.Size.Height; float bottom_h = rect.Size.Height - (top_h + center_h); // calculate rects // ... top row float x = 0.0f; float y = 0.0f; // top left CCRect lefttopbounds = new CCRect(x, y, left_w, top_h); // top center x += left_w; CCRect centertopbounds = new CCRect(x, y, center_w, top_h); // top right x += center_w; CCRect righttopbounds = new CCRect(x, y, right_w, top_h); // ... center row x = 0.0f; y = 0.0f; y += top_h; // center left CCRect leftcenterbounds = new CCRect(x, y, left_w, center_h); // center center x += left_w; CCRect centerbounds = new CCRect(x, y, center_w, center_h); // center right x += center_w; CCRect rightcenterbounds = new CCRect(x, y, right_w, center_h); // ... bottom row x = 0.0f; y = 0.0f; y += top_h; y += center_h; // bottom left CCRect leftbottombounds = new CCRect(x, y, left_w, bottom_h); // bottom center x += left_w; CCRect centerbottombounds = new CCRect(x, y, center_w, bottom_h); // bottom right x += center_w; CCRect rightbottombounds = new CCRect(x, y, right_w, bottom_h); if (!rotated) { CCAffineTransform t = CCAffineTransform.Identity; t = CCAffineTransform.Translate(t, rect.Origin.X, rect.Origin.Y); centerbounds = CCAffineTransform.Transform(centerbounds, t); rightbottombounds = CCAffineTransform.Transform(rightbottombounds, t); leftbottombounds = CCAffineTransform.Transform(leftbottombounds, t); righttopbounds = CCAffineTransform.Transform(righttopbounds, t); lefttopbounds = CCAffineTransform.Transform(lefttopbounds, t); rightcenterbounds = CCAffineTransform.Transform(rightcenterbounds, t); leftcenterbounds = CCAffineTransform.Transform(leftcenterbounds, t); centerbottombounds = CCAffineTransform.Transform(centerbottombounds, t); centertopbounds = CCAffineTransform.Transform(centertopbounds, t); // Centre centre = new CCSprite(scale9Image.Texture, centerbounds); scale9Image.AddChild(centre, 0, (int)Positions.Centre); // Top top = new CCSprite(scale9Image.Texture, centerbounds); scale9Image.AddChild(top, 1, (int)Positions.Top); // Bottom bottom = new CCSprite(scale9Image.Texture, centerbottombounds); scale9Image.AddChild(bottom, 1, (int)Positions.Bottom); // Left left = new CCSprite(scale9Image.Texture, leftcenterbounds); scale9Image.AddChild(left, 1, (int)Positions.Left); // Right right = new CCSprite(scale9Image.Texture, rightcenterbounds); scale9Image.AddChild(right, 1, (int)Positions.Right); // Top left topLeft = new CCSprite(scale9Image.Texture, lefttopbounds); scale9Image.AddChild(topLeft, 2, (int)Positions.TopLeft); // Top right topRight = new CCSprite(scale9Image.Texture, righttopbounds); scale9Image.AddChild(topRight, 2, (int)Positions.TopRight); // Bottom left bottomLeft = new CCSprite(scale9Image.Texture, leftbottombounds); scale9Image.AddChild(bottomLeft, 2, (int)Positions.BottomLeft); // Bottom right bottomRight = new CCSprite(scale9Image.Texture, rightbottombounds); scale9Image.AddChild(bottomRight, 2, (int)Positions.BottomRight); } else { // set up transformation of coordinates // to handle the case where the sprite is stored rotated // in the spritesheet // CCLog("rotated"); CCAffineTransform t = CCAffineTransform.Identity; CCRect rotatedcenterbounds = centerbounds; CCRect rotatedrightbottombounds = rightbottombounds; CCRect rotatedleftbottombounds = leftbottombounds; CCRect rotatedrighttopbounds = righttopbounds; CCRect rotatedlefttopbounds = lefttopbounds; CCRect rotatedrightcenterbounds = rightcenterbounds; CCRect rotatedleftcenterbounds = leftcenterbounds; CCRect rotatedcenterbottombounds = centerbottombounds; CCRect rotatedcentertopbounds = centertopbounds; t = CCAffineTransform.Translate(t, rect.Size.Height + rect.Origin.X, rect.Origin.Y); t = CCAffineTransform.Rotate(t, 1.57079633f); centerbounds = CCAffineTransform.Transform(centerbounds, t); rightbottombounds = CCAffineTransform.Transform(rightbottombounds, t); leftbottombounds = CCAffineTransform.Transform(leftbottombounds, t); righttopbounds = CCAffineTransform.Transform(righttopbounds, t); lefttopbounds = CCAffineTransform.Transform(lefttopbounds, t); rightcenterbounds = CCAffineTransform.Transform(rightcenterbounds, t); leftcenterbounds = CCAffineTransform.Transform(leftcenterbounds, t); centerbottombounds = CCAffineTransform.Transform(centerbottombounds, t); centertopbounds = CCAffineTransform.Transform(centertopbounds, t); rotatedcenterbounds.Origin = centerbounds.Origin; rotatedrightbottombounds.Origin = rightbottombounds.Origin; rotatedleftbottombounds.Origin = leftbottombounds.Origin; rotatedrighttopbounds.Origin = righttopbounds.Origin; rotatedlefttopbounds.Origin = lefttopbounds.Origin; rotatedrightcenterbounds.Origin = rightcenterbounds.Origin; rotatedleftcenterbounds.Origin = leftcenterbounds.Origin; rotatedcenterbottombounds.Origin = centerbottombounds.Origin; rotatedcentertopbounds.Origin = centertopbounds.Origin; // Centre centre = new CCSprite(scale9Image.Texture, rotatedcenterbounds, true); //centre.InitWithTexture(scale9Image.Texture, rotatedcenterbounds, true); scale9Image.AddChild(centre, 0, (int)Positions.Centre); // Top top = new CCSprite(scale9Image.Texture, rotatedcentertopbounds, true); //top.InitWithTexture(scale9Image.Texture, rotatedcentertopbounds, true); scale9Image.AddChild(top, 1, (int)Positions.Top); // Bottom bottom = new CCSprite(scale9Image.Texture, rotatedcenterbottombounds, true); //bottom.InitWithTexture(scale9Image.Texture, rotatedcenterbottombounds, true); scale9Image.AddChild(bottom, 1, (int)Positions.Bottom); // Left left = new CCSprite(scale9Image.Texture, rotatedleftcenterbounds, true); //left.InitWithTexture(scale9Image.Texture, rotatedleftcenterbounds, true); scale9Image.AddChild(left, 1, (int)Positions.Left); // Right right = new CCSprite(scale9Image.Texture, rotatedrightcenterbounds, true); //right.InitWithTexture(scale9Image.Texture, rotatedrightcenterbounds, true); scale9Image.AddChild(right, 1, (int)Positions.Right); // Top left topLeft = new CCSprite(scale9Image.Texture, rotatedlefttopbounds, true); //topLeft.InitWithTexture(scale9Image.Texture, rotatedlefttopbounds, true); scale9Image.AddChild(topLeft, 2, (int)Positions.TopLeft); // Top right topRight = new CCSprite(scale9Image.Texture, rotatedrighttopbounds, true); //topRight.InitWithTexture(scale9Image.Texture, rotatedrighttopbounds, true); scale9Image.AddChild(topRight, 2, (int)Positions.TopRight); // Bottom left bottomLeft = new CCSprite(scale9Image.Texture, rotatedleftbottombounds, true); //bottomLeft.InitWithTexture(scale9Image.Texture, rotatedleftbottombounds, true); scale9Image.AddChild(bottomLeft, 2, (int)Positions.BottomLeft); // Bottom right bottomRight = new CCSprite(scale9Image.Texture, rotatedrightbottombounds, true); //bottomRight.InitWithTexture(scale9Image.Texture, rotatedrightbottombounds, true); scale9Image.AddChild(bottomRight, 2, (int)Positions.BottomRight); } ContentSize = rect.Size; AddChild(scale9Image); if (spritesGenerated) { // Restore color and opacity Opacity = opacity; Color = color; } spritesGenerated = true; return(true); }
public void MultMatrix(CCAffineTransform transform, float z) { MultMatrix(ref transform, z); }