예제 #1
0
 private void CalculateUVEntries()
 {
     for (int y = 0; y < Rows; y++)
     {
         for (int x = 0; x < Columns; x++)
         {
             uvEntries[x + (y * Columns)] = new UVEntry
             {
                 UV1 = new Vector2((float)x / (float)Columns, (float)y / (float)Rows),
                 UV2 = new Vector2((float)(x + 1) / (float)Columns, (float)y / (float)Rows),
                 UV3 = new Vector2((float)x / (float)Columns, (float)(y + 1) / (float)Rows),
                 UV4 = new Vector2((float)(x + 1) / (float)Columns, (float)(y + 1) / (float)Rows)
             };
         }
     }
 }
예제 #2
0
        public void OnUpdate(Primitive.TextureEntry textures)
        {
            List <Primitive.TextureEntryFace> faces = new List <Primitive.TextureEntryFace>()
            {
                textures.GetFace(3),                 // Ten-thousands
                textures.GetFace(7),                 // Thousands
                textures.GetFace(4),                 // Hundreds
                textures.GetFace(6),                 // Tens
                textures.GetFace(1),                 // Ones
            };

            int score = 0;

            for (int faceIndex = 0; faceIndex < faces.Count; faceIndex++)
            {
                UVEntry currentUv  = new UVEntry(faces[faceIndex].OffsetU, faces[faceIndex].OffsetV);
                bool    foundDigit = false;
                score *= 10;

                for (int digit = 0; digit < perScoreFaceUVs.GetLength(1); digit++)
                {
                    if (Utils.IsAboutEqual(currentUv.U, perScoreFaceUVs[faceIndex, digit].U) && Utils.IsAboutEqual(currentUv.V, perScoreFaceUVs[faceIndex, digit].V))
                    {
                        if (digit <= 9)
                        {
                            score += digit;
                        }

                        foundDigit = true;
                        break;
                    }
                }

                if (!foundDigit)
                {
                    Utils.OutputLine("ScoreDisplay: ***  ERROR: Failed to find digit", Utils.OutputLevel.Error);
                }
            }

            ScoreChanged(score);
        }
예제 #3
0
        /// <summary>
        /// Generates the table of UV corrdinates for each face of the score should have
        /// for each digit (0-9 followed by BLANK).
        /// These values are not exact so a slightly larger epsilon (0.0001 seems to work)
        /// will be needed when comparing these values against the actual UV coordinates
        /// the faces have.
        /// </summary>
        private static UVEntry[,] GenerateScoreFaceUVs()
        {
            UVEntry[,] perScoreFaceUVs = new UVEntry[5, 11];

            // Character width in UV coordinates (all characters are square)
            const float baseScoreWidth = 0.1000091f;

            // 'V' offset to get to row containing digits 0-7
            const float faceVOffset = -0.04998932f;

            // 'U' offset for the first digit (zero) for the faces of ones, tens, thousands, ten thousands. Each face
            //   seems to have a different starting 'U' offset, but the same 'V' offset.
            float[] perFaceUOffset = new float[]
            {
                -0.205023236f,                  // 10000's U offset for '0' digit
                -0.2500076f,                    // 1000's U offset for '0' digit
                -0.5900143f,                    // 100's U offset for '0' digit
                -0.2500076f,                    // 10's U offset for '0' digit
                -0.2949919f                     // 1's U offset for '0' digit
            };

            // The number of characters we need to travel horizontally to reach the image
            //   for 0-9 and BLANK. Index 0 represents digit 0, 1 represents digit 1 and so
            //   on. The last index represents the blank character.
            //
            // finalUOffset = baseUOffset + (CharacterWidth * uOffsets[digit])
            int[] uOffsets = new int[]
            {
                0, 1, 2, 3, 4, 5, 6, 7, -2, -1, 2
            };

            // The number of characters we need to travel vertically to reach the image
            //   for 0-9 and BLANK. Index 0 represents digit 0, 1 represents digit 1 and so
            //   on. The last index represents the blank character.
            int[] vOffsets = new int[]
            {
                0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -4
            };

            //             RAW OFFSETS                          Generalized offsets
            // Digit: Uoffset | vOffset			      Uoffset            , VOffset
            // 0: -0.5900143  | -0.04998932        || BaseU + (Width * 0), BaseV + (Width * 0)
            // 1: -0.4900052  | -0.04998932        || BaseU + (Width * 1), BaseV + (Width * 0)
            // 2: -0.389996   | -0.04998932        || BaseU + (Width * 2), BaseV + (Width * 0)
            // 3: -0.2899869  | -0.04998932        || BaseU + (Width * 3), BaseV + (Width * 0)
            // 4: -0.1900082  | -0.04998932        || BaseU + (Width * 4), BaseV + (Width * 0)
            // 5: -0.08999909 | -0.04998932        || BaseU + (Width * 5), BaseV + (Width * 0)
            // 6: 0.01001007  | -0.04998932        || BaseU + (Width * 6), BaseV + (Width * 0)
            // 7: 0.1099887   | -0.04998932        || BaseU + (Width * 7), BaseV + (Width * 0)
            // 8: -0.7900021  | -0.1499985         || BaseU + (Width * -2), BaseV + (Width * -1)
            // 9: -0.689993   | -0.1499985         || BaseU + (Width * -1), BaseV + (Width * -1)
            // x: -0.389996   | -0.4499954         || BaseU + (Width * 2), BaseV + (Width * -4)
            //
            // where BaseV = -0.04998932
            //       Width =  0.1000091  (about)
            //       BaseU = (See perFaceUOffset)

            for (int faceIndex = 0; faceIndex < perScoreFaceUVs.GetLength(0); faceIndex++)
            {
                for (int digitIndex = 0; digitIndex < perScoreFaceUVs.GetLength(1); digitIndex++)
                {
                    perScoreFaceUVs[faceIndex, digitIndex] = new UVEntry(perFaceUOffset[faceIndex] + (baseScoreWidth * uOffsets[digitIndex]), faceVOffset + (baseScoreWidth * vOffsets[digitIndex]));
                }
            }

            return(perScoreFaceUVs);
        }
예제 #4
0
            public void CreateCloud()
            {
                float   cloudRadius = RadiusRange.Random();
                Vector3 pos         = UnityEngine.Random.insideUnitSphere * BoundsRadius;

                pos.y = Mathf.Abs(pos.y * 0.5f) + BoundsHeightRange.Random();
                //pos.y = BoundsHeightRange.Random();

                // for debugging with particle alpha blend shader
                //vertices[0] = pos - new Vector3(radius, 0.0f, radius);
                //vertices[1] = pos - new Vector3(-radius, 0.0f, radius);
                //vertices[2] = pos - new Vector3(radius, 0.0f, -radius);
                //vertices[3] = pos - new Vector3(-radius, 0.0f, -radius);

                vertices.Add(pos);
                vertices.Add(pos);
                vertices.Add(pos);
                vertices.Add(pos);

                UVEntry uv = uvEntries[UnityEngine.Random.Range(0, uvEntries.Length)];

                uvs.Add(new Vector4(uv.UV1.x, uv.UV1.y, quadUV1.x, quadUV1.y));
                uvs.Add(new Vector4(uv.UV2.x, uv.UV2.y, quadUV2.x, quadUV2.y));
                uvs.Add(new Vector4(uv.UV3.x, uv.UV3.y, quadUV3.x, quadUV3.y));
                uvs.Add(new Vector4(uv.UV4.x, uv.UV4.y, quadUV4.x, quadUV4.y));

                float   fadeTime      = FadeTimeRange.Random();
                float   totalLifeTime = LifeTimeRange.Random();
                Vector4 lifeTime      = new Vector4(Time.timeSinceLevelLoad + fadeTimeDelay, fadeTime, totalLifeTime); // creation time, fade in/out time in seconds, total life time in seconds

                fadeTimeDelay += FadeTimeDelayRange.Random();
                lifeTimes.Add(lifeTime);
                lifeTimes.Add(lifeTime);
                lifeTimes.Add(lifeTime);
                lifeTimes.Add(lifeTime);

                colors.Add(whiteColor);
                colors.Add(whiteColor);
                colors.Add(whiteColor);
                colors.Add(whiteColor);

                float   velocityX = VelocityRangeX.Random();
                float   velocityZ = VelocityRangeZ.Random();
                Vector3 velocity  = new Vector3(velocityX, 0.0f, velocityZ);

                velocities.Add(velocity);
                velocities.Add(velocity);
                velocities.Add(velocity);
                velocities.Add(velocity);

                float startAngle      = UnityEngine.Random.Range(-Mathf.PI, Mathf.PI);
                float angularVelocity = AngularVelocityRange.Random();

                others.Add(new Vector4(startAngle, angularVelocity, -cloudRadius, -cloudRadius));
                others.Add(new Vector4(startAngle, angularVelocity, cloudRadius, -cloudRadius));
                others.Add(new Vector4(startAngle, angularVelocity, -cloudRadius, cloudRadius));
                others.Add(new Vector4(startAngle, angularVelocity, cloudRadius, cloudRadius));

                indices.Add(++indice);
                indices.Add(++indice);
                indices.Add(++indice);
                indices.Add(indice--);
                indices.Add(indice--);
                indices.Add(indice += 3);
            }