void spRegionAttachment_updateQuad(ref RegionAttachment self, ref Slot slot, CCV3F_C4B_T2F_Quad quad, bool premultipliedAlpha) { float[] vertices = new float[8]; self.ComputeWorldVertices(slot.Skeleton.X, slot.Skeleton.Y, slot.Bone, vertices); float r = (slot.Skeleton.R * slot.R * 255); float g = (slot.Skeleton.G * slot.G * 255); float b = (slot.Skeleton.B * slot.B * 255); float normalizedAlpha = slot.Skeleton.A * slot.A; if (premultipliedAlpha) { r *= normalizedAlpha; g *= normalizedAlpha; b *= normalizedAlpha; } float a = normalizedAlpha * 255; quad.BottomLeft.Colors.R = Convert.ToByte(r); quad.BottomLeft.Colors.G = Convert.ToByte(g); quad.BottomLeft.Colors.B = Convert.ToByte(b); quad.BottomLeft.Colors.A = Convert.ToByte(a); quad.TopLeft.Colors.R = Convert.ToByte(r); quad.TopLeft.Colors.G = Convert.ToByte(g); quad.TopLeft.Colors.B = Convert.ToByte(b); quad.TopLeft.Colors.A = Convert.ToByte(a); quad.TopRight.Colors.R = Convert.ToByte(r); quad.TopRight.Colors.G = Convert.ToByte(g); quad.TopRight.Colors.B = Convert.ToByte(b); quad.TopRight.Colors.A = Convert.ToByte(a); quad.BottomRight.Colors.R = Convert.ToByte(r); quad.BottomRight.Colors.G = Convert.ToByte(g); quad.BottomRight.Colors.B = Convert.ToByte(b); quad.BottomRight.Colors.A = Convert.ToByte(a); quad.BottomLeft.Vertices.X = vertices[RegionAttachment.X1]; quad.BottomLeft.Vertices.Y = vertices[RegionAttachment.Y1]; quad.TopLeft.Vertices.X = vertices[RegionAttachment.X2]; quad.TopLeft.Vertices.Y = vertices[RegionAttachment.Y2]; quad.TopRight.Vertices.X = vertices[RegionAttachment.X3]; quad.TopRight.Vertices.Y = vertices[RegionAttachment.Y3]; quad.BottomRight.Vertices.X = vertices[RegionAttachment.X4]; quad.BottomRight.Vertices.Y = vertices[RegionAttachment.Y4]; quad.BottomLeft.TexCoords.U = self.UVs[RegionAttachment.X1]; quad.BottomLeft.TexCoords.V = self.UVs[RegionAttachment.Y1]; quad.TopLeft.TexCoords.U = self.UVs[RegionAttachment.X2]; quad.TopLeft.TexCoords.V = self.UVs[RegionAttachment.Y2]; quad.TopRight.TexCoords.U = self.UVs[RegionAttachment.X3]; quad.TopRight.TexCoords.V = self.UVs[RegionAttachment.Y3]; quad.BottomRight.TexCoords.U = self.UVs[RegionAttachment.X4]; quad.BottomRight.TexCoords.V = self.UVs[RegionAttachment.Y4]; }
void spRegionAttachment_updateQuad(RegionAttachment self, Slot slot, CCV3F_C4B_T2F_Quad quad, bool premultipliedAlpha = false) { float[] vertices = new float[8]; self.ComputeWorldVertices(slot.Skeleton.X, slot.Skeleton.Y, slot.Bone, vertices); byte r = Convert.ToByte(slot.Skeleton.R * slot.R * 255); byte g =Convert.ToByte( slot.Skeleton.G * slot.G * 255); byte b = Convert.ToByte(slot.Skeleton.B * slot.B * 255); byte normalizedAlpha = Convert.ToByte( slot.Skeleton.A * slot.A); if (premultipliedAlpha) { r *= normalizedAlpha; g *= normalizedAlpha; b *= normalizedAlpha; } byte a = Convert.ToByte(normalizedAlpha * 255); quad.BottomLeft.Colors.R = r; quad.BottomLeft.Colors.G = g; quad.BottomLeft.Colors.B = b; quad.BottomLeft.Colors.A = a; quad.TopLeft.Colors.R = r; quad.TopLeft.Colors.G = g; quad.TopLeft.Colors.B = b; quad.TopLeft.Colors.A = a; quad.TopRight.Colors.R = r; quad.TopRight.Colors.G = g; quad.TopRight.Colors.B = b; quad.TopRight.Colors.A = a; quad.BottomRight.Colors.R = r; quad.BottomRight.Colors.G = g; quad.BottomRight.Colors.B = b; quad.BottomRight.Colors.A = a; quad.BottomLeft.Vertices.X = vertices[VERTEX_X1]; quad.BottomLeft.Vertices.Y = vertices[VERTEX_Y1]; quad.TopLeft.Vertices.X = vertices[VERTEX_X2]; quad.TopLeft.Vertices.Y = vertices[VERTEX_Y2]; quad.TopRight.Vertices.X = vertices[VERTEX_X3]; quad.TopRight.Vertices.Y = vertices[VERTEX_Y3]; quad.BottomRight.Vertices.X = vertices[VERTEX_X4]; quad.BottomRight.Vertices.Y = vertices[VERTEX_Y4]; quad.BottomLeft.TexCoords.U = self.UVs[VERTEX_X1]; quad.BottomLeft.TexCoords.V = self.UVs[VERTEX_Y1]; quad.TopLeft.TexCoords.U = self.UVs[VERTEX_X2]; quad.TopLeft.TexCoords.V = self.UVs[VERTEX_Y2]; quad.TopRight.TexCoords.U = self.UVs[VERTEX_X3]; quad.TopRight.TexCoords.V = self.UVs[VERTEX_Y3]; quad.BottomRight.TexCoords.U = self.UVs[VERTEX_X4]; quad.BottomRight.TexCoords.V = self.UVs[VERTEX_Y4]; }
protected CCTex2F TextureCoordFromAlphaPoint(CCPoint alpha) { var ret = new CCTex2F(0.0f, 0.0f); if (m_pSprite == null) { return(ret); } CCV3F_C4B_T2F_Quad quad = m_pSprite.Quad; var min = new CCPoint(quad.BottomLeft.TexCoords.U, quad.BottomLeft.TexCoords.V); var max = new CCPoint(quad.TopRight.TexCoords.U, quad.TopRight.TexCoords.V); // Fix bug #1303 so that progress timer handles sprite frame texture rotation if (m_pSprite.IsTextureRectRotated) { float tmp = alpha.X; alpha.X = alpha.Y; alpha.Y = tmp; } return(new CCTex2F(min.X * (1f - alpha.X) + max.X * alpha.X, min.Y * (1f - alpha.Y) + max.Y * alpha.Y)); }
private void UpdateQuad(ref CCV3F_C4B_T2F_Quad quad, ref CCParticle particle) { CCPoint newPosition; if (m_ePositionType == CCPositionType.Free || m_ePositionType == CCPositionType.Relative) { newPosition.X = particle.pos.X - (s_currentPosition.X - particle.startPos.X); newPosition.Y = particle.pos.Y - (s_currentPosition.Y - particle.startPos.Y); } else { newPosition = particle.pos; } // translate newPos to correct position, since matrix transform isn't performed in batchnode // don't update the particle with the new position information, it will interfere with the radius and tangential calculations if (m_pBatchNode != null) { newPosition.X += m_obPosition.X; newPosition.Y += m_obPosition.Y; } CCColor4B color; if (m_bOpacityModifyRGB) { color.R = (byte)(particle.color.R * particle.color.A * 255); color.G = (byte)(particle.color.G * particle.color.A * 255); color.B = (byte)(particle.color.B * particle.color.A * 255); color.A = (byte)(particle.color.A * 255); } else { color.R = (byte)(particle.color.R * 255); color.G = (byte)(particle.color.G * 255); color.B = (byte)(particle.color.B * 255); color.A = (byte)(particle.color.A * 255); } quad.BottomLeft.Colors = color; quad.BottomRight.Colors = color; quad.TopLeft.Colors = color; quad.TopRight.Colors = color; // vertices float size_2 = particle.size / 2; if (particle.rotation != 0.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 = -CCMathHelper.ToRadians(particle.rotation); float cr = CCMathHelper.Cos(r); float sr = CCMathHelper.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.BottomLeft.Vertices.X = ax; quad.BottomLeft.Vertices.Y = ay; // bottom-right vertex: quad.BottomRight.Vertices.X = bx; quad.BottomRight.Vertices.Y = by; // top-left vertex: quad.TopLeft.Vertices.X = dx; quad.TopLeft.Vertices.Y = dy; // top-right vertex: quad.TopRight.Vertices.X = cx; quad.TopRight.Vertices.Y = cy; } else { // bottom-left vertex: quad.BottomLeft.Vertices.X = newPosition.X - size_2; quad.BottomLeft.Vertices.Y = newPosition.Y - size_2; // bottom-right vertex: quad.BottomRight.Vertices.X = newPosition.X + size_2; quad.BottomRight.Vertices.Y = newPosition.Y - size_2; // top-left vertex: quad.TopLeft.Vertices.X = newPosition.X - size_2; quad.TopLeft.Vertices.Y = newPosition.Y + size_2; // top-right vertex: quad.TopRight.Vertices.X = newPosition.X + size_2; quad.TopRight.Vertices.Y = newPosition.Y + size_2; } }
/// <summary> /// Inserts a Quad (texture, vertex and color) at a certain index /// index must be between 0 and the atlas capacity - 1 /// @since v0.8 /// </summary> public void InsertQuad(ref CCV3F_C4B_T2F_Quad quad, int index) { Debug.Assert(index < m_pQuads.Capacity, "insertQuadWithTexture: Invalid index"); m_pQuads.Insert(index, quad); Dirty = true; }
public bool InitWithTexture(CCTexture2D pTexture, CCRect rect, bool rotated) { base.Init(); m_pobBatchNode = null; // shader program //setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor)); m_bRecursiveDirty = false; Dirty = false; m_bOpacityModifyRGB = true; m_sBlendFunc = CCBlendFunc.AlphaBlend; m_bFlipX = m_bFlipY = false; // default transform anchor: center AnchorPoint = new CCPoint(0.5f, 0.5f); // zwoptex default values m_obOffsetPosition = CCPoint.Zero; m_bHasChildren = false; // clean the Quad m_sQuad = new CCV3F_C4B_T2F_Quad(); // Atlas: Color var tmpColor = new CCColor4B(255, 255, 255, 255); m_sQuad.BottomLeft.Colors = tmpColor; m_sQuad.BottomRight.Colors = tmpColor; m_sQuad.TopLeft.Colors = tmpColor; m_sQuad.TopRight.Colors = tmpColor; // update texture (calls updateBlendFunc) Texture = pTexture; SetTextureRect(rect, rotated, rect.Size); // by default use "Self Render". // if the sprite is added to a batchnode, then it will automatically switch to "batchnode Render" BatchNode = null; return true; }
private void UpdateQuad(ref CCV3F_C4B_T2F_Quad quad, ref CCParticle particle) { CCPoint newPosition; if (m_ePositionType == CCPositionType.Free || m_ePositionType == CCPositionType.Relative) { newPosition.X = particle.pos.X - (s_currentPosition.X - particle.startPos.X); newPosition.Y = particle.pos.Y - (s_currentPosition.Y - particle.startPos.Y); } else { newPosition = particle.pos; } // translate newPos to correct position, since matrix transform isn't performed in batchnode // don't update the particle with the new position information, it will interfere with the radius and tangential calculations if (m_pBatchNode != null) { newPosition.X += m_obPosition.X; newPosition.Y += m_obPosition.Y; } CCColor4B color; if (m_bOpacityModifyRGB) { color.R = (byte) (particle.color.R * particle.color.A * 255); color.G = (byte) (particle.color.G * particle.color.A * 255); color.B = (byte) (particle.color.B * particle.color.A * 255); color.A = (byte)(particle.color.A * 255); } else { color.R = (byte)(particle.color.R * 255); color.G = (byte)(particle.color.G * 255); color.B = (byte)(particle.color.B * 255); color.A = (byte)(particle.color.A * 255); } quad.BottomLeft.Colors = color; quad.BottomRight.Colors = color; quad.TopLeft.Colors = color; quad.TopRight.Colors = color; // vertices float size_2 = particle.size / 2; if (particle.rotation != 0.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 = -CCMathHelper.ToRadians(particle.rotation); float cr = CCMathHelper.Cos(r); float sr = CCMathHelper.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.BottomLeft.Vertices.X = ax; quad.BottomLeft.Vertices.Y = ay; // bottom-right vertex: quad.BottomRight.Vertices.X = bx; quad.BottomRight.Vertices.Y = by; // top-left vertex: quad.TopLeft.Vertices.X = dx; quad.TopLeft.Vertices.Y = dy; // top-right vertex: quad.TopRight.Vertices.X = cx; quad.TopRight.Vertices.Y = cy; } else { // bottom-left vertex: quad.BottomLeft.Vertices.X = newPosition.X - size_2; quad.BottomLeft.Vertices.Y = newPosition.Y - size_2; // bottom-right vertex: quad.BottomRight.Vertices.X = newPosition.X + size_2; quad.BottomRight.Vertices.Y = newPosition.Y - size_2; // top-left vertex: quad.TopLeft.Vertices.X = newPosition.X - size_2; quad.TopLeft.Vertices.Y = newPosition.Y + size_2; // top-right vertex: quad.TopRight.Vertices.X = newPosition.X + size_2; quad.TopRight.Vertices.Y = newPosition.Y + size_2; } }
/// <summary> /// updates a Quad (texture, vertex and color) at a certain index /// index must be between 0 and the atlas capacity - 1 /// @since v0.8 /// </summary> public void UpdateQuad(ref CCV3F_C4B_T2F_Quad quad, int index) { Debug.Assert(index >= 0 && index < m_pQuads.Capacity, "updateQuadWithTexture: Invalid index"); m_pQuads.count = Math.Max(index + 1, m_pQuads.count); m_pQuads.Elements[index] = quad; Dirty = true; }
public void FillWithEmptyQuadsFromIndex(int index, int amount) { int to = index + amount; CCV3F_C4B_T2F_Quad[] elements = m_pQuads.Elements; var empty = new CCV3F_C4B_T2F_Quad(); for (int i = index; i < to; i++) { elements[i] = empty; } Dirty = true; }
public void MoveQuadsFromIndex(int oldIndex, int amount, int newIndex) { Debug.Assert(newIndex + amount <= m_pQuads.count, "insertQuadFromIndex:atIndex: Invalid index"); Debug.Assert(oldIndex < m_pQuads.count, "insertQuadFromIndex:atIndex: Invalid index"); if (oldIndex == newIndex) { return; } var tmp = new CCV3F_C4B_T2F_Quad[amount]; Array.Copy(m_pQuads.Elements, oldIndex, tmp, 0, amount); if (newIndex < oldIndex) { // move quads from newIndex to newIndex + amount to make room for buffer Array.Copy(m_pQuads.Elements, newIndex + amount, m_pQuads.Elements, newIndex, oldIndex - newIndex); //memmove(&m_pQuads[newIndex], &m_pQuads[newIndex + amount], (oldIndex - newIndex) * quadSize); } else { // move quads above back Array.Copy(m_pQuads.Elements, oldIndex + amount, m_pQuads.Elements, oldIndex, newIndex - oldIndex); //memmove(&m_pQuads[oldIndex], &m_pQuads[oldIndex + amount], (newIndex - oldIndex) * quadSize); } //memcpy(&m_pQuads[newIndex], tempQuads, amount * quadSize); Array.Copy(tmp, 0, m_pQuads.Elements, newIndex, amount); Dirty = true; }
public override void Draw() { base.Draw(); // CC_NODE_DRAW_SETUP(); CCDrawManager.BlendFunc(blendFunc); CCColor3B color = Color; skeleton.R = color.R / 255f ; skeleton.G = color.G / 255f; skeleton.B = color.B / 255f; skeleton.A = Opacity / 255f; bool additive = false; CCTextureAtlas textureAtlas = null; CCV3F_C4B_T2F_Quad quad = new CCV3F_C4B_T2F_Quad(); quad.TopLeft.Vertices.Z = 0; quad.TopRight.Vertices.Z = 0; quad.BottomLeft.Vertices.Z = 0; quad.BottomRight.Vertices.Z = 0; for (int i = 0; i < skeleton.Slots.Count; i++) { Slot slot = skeleton.DrawOrder[i]; if (slot.Attachment == null || slot.Attachment.GetType().ToString() != "Spine.RegionAttachment") continue; //=> ?????????????? RegionAttachment attachment = (RegionAttachment)slot.Attachment; CCTextureAtlas regionTextureAtlas = GetTextureAtlas(attachment); regionTextureAtlas.DrawQuads(); //retain(); //self.rendererObject = textureAtlas; //self.width = texture.PixelsWide; //self.height = texture.PixelsHigh; if (slot.Data.AdditiveBlending != additive) { if (textureAtlas != null) { textureAtlas.DrawQuads(); textureAtlas.RemoveAllQuads(); } additive = !additive; CCDrawManager.BlendFunc(new CCBlendFunc(blendFunc.Source, (additive) ? CCOGLES.GL_ONE : blendFunc.Destination) ); } else if (textureAtlas != null && regionTextureAtlas != textureAtlas) { textureAtlas.DrawQuads(); textureAtlas.RemoveAllQuads(); } textureAtlas = regionTextureAtlas; int quadCount = textureAtlas.TotalQuads; if (textureAtlas.Capacity == quadCount) { textureAtlas.DrawQuads(); textureAtlas.RemoveAllQuads(); if (!textureAtlas.ResizeCapacity(textureAtlas.Capacity * 2)) return; } spRegionAttachment_updateQuad(attachment, slot, ref quad, premultipliedAlpha); textureAtlas.UpdateQuad(ref quad, quadCount); } if (textureAtlas != null) { textureAtlas.DrawQuads(); textureAtlas.RemoveAllQuads(); } if (debugSlots) { CCPoint[] points = new CCPoint[4]; CCV3F_C4B_T2F_Quad quada = new CCV3F_C4B_T2F_Quad(); for (int i = 0, n = skeleton.Slots.Count; i < n; i++) { Slot slot = skeleton.DrawOrder[i]; if (slot.Attachment == null || slot.Attachment.Name != "ATTACHMENT_REGION") continue; RegionAttachment attachment = (RegionAttachment)slot.Attachment; spRegionAttachment_updateQuad(attachment, slot, ref quad); points[0] = new CCPoint(quada.BottomLeft.Vertices.X, quada.BottomLeft.Vertices.Y); points[1] = new CCPoint(quada.BottomRight.Vertices.X, quada.BottomRight.Vertices.Y); points[2] = new CCPoint(quada.TopRight.Vertices.X, quada.TopRight.Vertices.Y); points[3] = new CCPoint(quada.TopLeft.Vertices.X, quada.TopLeft.Vertices.Y); CCDrawingPrimitives.DrawPoly(points, 4, true, new CCColor4B(0, 0, 255, 255)); } } if (debugBones) { // Bone lengths. for (int i = 0; i < skeleton.Bones.Count; i++) { Bone bone = skeleton.Bones[i]; float x = bone.Data.Length * bone.M00 + bone.WorldX; float y = bone.Data.Length * bone.M10 + bone.WorldY; CCDrawingPrimitives.Begin(); CCDrawingPrimitives.DrawLine(new CCPoint(bone.WorldX, bone.WorldY), new CCPoint(x, y), new CCColor4B(255, 0, 0, 255)); CCDrawingPrimitives.End(); } // Bone origins. for (int i = 0; i < skeleton.Bones.Count; i++) { Bone bone = skeleton.Bones[i]; CCDrawingPrimitives.Begin(); CCDrawingPrimitives.DrawPoint(new CCPoint(bone.WorldX, bone.WorldY), 4, new CCColor4B(0, 0, 255, 255)); CCDrawingPrimitives.End(); } } }