예제 #1
0
        private void UpdateQuad(ref CCV3F_C4B_T2F_Quad quad, ref CCParticle particle)
        {
            CCPoint newPosition;

            if (m_ePositionType == CCPositionType.kCCPositionTypeFree || m_ePositionType == CCPositionType.kCCPositionTypeRelative)
            {
                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_tPosition.X;
                newPosition.Y += m_tPosition.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 = -MathHelper.ToRadians(particle.rotation);
                float cr = MHelper.Cos(r);
                float sr = MHelper.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;
            }
        }
예제 #2
0
        public bool InitWithTexture(CCTexture2D pTexture, CCRect rect, bool rotated)
        {
            m_pobBatchNode = null;

            // shader program
            //setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor));

            m_bRecursiveDirty = false;
            Dirty = false;

            m_bOpacityModifyRGB = true;
            m_nOpacity = 255;
            m_sColor = m_sColorUnmodified = CCTypes.CCWhite;

            m_sBlendFunc.Source = CCMacros.CCDefaultSourceBlending;
            m_sBlendFunc.Destination = CCMacros.CCDefaultDestinationBlending;

            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;
        }
예제 #3
0
 /// <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;
 }
예제 #4
0
        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;
        }
예제 #5
0
 /// <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;
 }
예제 #6
0
        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;
        }