Exemplo n.º 1
0
        private void GenerateTranslationMatrix(SpriteTranslationKey key)
        {
            Single RadianAngle = DegreeToRadian(key.Angle);

            //TODO: Verify that these formulas are correct.
            Single x = key.X + (key.Scale * (FMath.Sin(RadianAngle) - FMath.Cos(RadianAngle)));
            Single y = key.Y + (key.Scale * (FMath.Cos(RadianAngle) + FMath.Sin(RadianAngle)));
            Single z = 0.0f;

            Vector3 transV = new Vector3(x, y, z);

            Matrix4 m = Matrix4.Translation(transV);

            //Add to cache
            TranslationMatrixCacheIndex.Enqueue(key);
            TranslationMatrixCache.Add(key, m);

            //Remove extra from cache
            Int32 limit = GetTranslationMatrixCacheLimit();
            while(TranslationMatrixCache.Count > limit)
            {
                SpriteTranslationKey old = TranslationMatrixCacheIndex.Dequeue();
                TranslationMatrixCache.Remove(old);
            }
        }
Exemplo n.º 2
0
        public Matrix4 GetTranslationMatrix(Single x, Single y, Single scale, Single angle)
        {
            SpriteTranslationKey key = new SpriteTranslationKey(x, y, scale, angle);

            if(!TranslationMatrixCache.ContainsKey(key))
                GenerateTranslationMatrix(key);
            return TranslationMatrixCache[key];
        }