Esempio n. 1
0
        //protected override void OnAttach(IPActor container)
        //{
        //    m_transformComponent = Container.GetFirstComponent<TransformComponent>();
        //}
        public void Draw()
        {
            if (m_transform == null || m_spriteSheet == null)
            {
                return;
            }

            Vector2 position, scale;
            float   rotation;

            m_transform.GetGlobalComponents(out position, out rotation, out scale);
            m_theGame.SpriteBatch.Draw(m_spriteSheet.Texture, position, SourceRectangle, m_renderColour, rotation, m_renderOrigin, scale, SpriteEffects.None, 0);

            //m_theGame.SpriteBatch.Draw(m_spriteSheet.Texture, DestinationRectangle, SourceRectangle, Colour, Rotation, m_renderOrigin, SpriteEffects.None, 0);
        }
Esempio n. 2
0
        public Rectangle GetBounds()
        {
            int   cx = (int)m_dimensions.X;
            int   cy = (int)m_dimensions.Y;
            float left, top, right, bottom;

            Vector2 pos, scl;
            float   rot;

            if (m_transform == null)
            {
                rot = 0;
                pos = Vector2.Zero;
                scl = new Vector2(1, 1);
            }
            else
            {
                m_transform.GetGlobalComponents(out pos, out rot, out scl);
            }

            int x  = (int)pos.X;
            int y  = (int)pos.Y;
            int ox = (int)(m_origin.X * m_dimensions.X);
            int oy = (int)(m_origin.Y * m_dimensions.Y);

            #region No Rotation

            if (rot == 0)
            {
                if (scl.X == 1.0f)
                {
                    left  = x - ox;
                    right = left + cx;
                }
                else
                {
                    left  = x - (int)(ox * scl.X);
                    right = left + (int)(cx * scl.X);
                }

                if (scl.Y == 1.0f)
                {
                    top    = y - oy;
                    bottom = top + cy;
                }
                else
                {
                    top    = y - (int)(oy * scl.Y);
                    bottom = top + (int)(cy * scl.Y);
                }
            }
            #endregion
            #region Rotation
            else
            {
                if (scl.X != 1.0f)
                {
                    ox = (int)(ox * scl.X);
                    cx = (int)(cx * scl.X);
                }

                if (scl.Y != 1.0f)
                {
                    oy = (int)(oy * scl.Y);
                    cy = (int)(cy * scl.Y);
                }

                //double alpha = Angle * Math.PI / 180.0f;
                float cosa = (float)Math.Cos(rot);
                float sina = (float)Math.Sin(rot);

                int nx1;
                int ny1;

                int nx2 = -(int)(cy * sina);
                int ny2 = (int)(cy * cosa);

                int nx4 = (int)(cx * cosa);
                int ny4 = (int)(cx * sina);

                int nx3 = nx2 + nx4;
                int ny3 = ny2 + ny4;

                // Faire translation par rapport au hotspot
                int xBase = x - (int)(ox * cosa - oy * sina);
                int yBase = y - (int)(oy * cosa + ox * sina);

                nx1 = xBase;
                ny1 = yBase;

                nx2 += xBase;
                ny2 += yBase;

                nx3 += xBase;
                ny3 += yBase;

                nx4 += xBase;
                ny4 += yBase;

                // Calculer la nouvelle bounding box (à optimiser éventuellement)
                left = Math.Min(nx1, nx2);
                left = Math.Min(left, nx3);
                left = Math.Min(left, nx4);

                right = Math.Max(nx1, nx2);
                right = Math.Max(right, nx3);
                right = Math.Max(right, nx4);

                //right++;	// new

                top = Math.Min(ny1, ny2);
                top = Math.Min(top, ny3);
                top = Math.Min(top, ny4);

                bottom = Math.Max(ny1, ny2);
                bottom = Math.Max(bottom, ny3);
                bottom = Math.Max(bottom, ny4);

                //bottom++;	// new
            }
            #endregion
            return(new Rectangle((int)left, (int)top, (int)(right - left), (int)(bottom - top)));
        }