Esempio n. 1
0
        public void BufferData(OpenGL gl,
            uint[] indices, float[] vertices, float[] normals, Material[] materials)
        {
            IndicesCount = indices.Length;

            var color3Size = 3 * materials.Length;
            float[] ambs = new float[color3Size],
                diffs = new float[color3Size],
                specs = new float[color3Size],
                shinis = new float[materials.Length];

            // Convert materials to float arrays.
            var newPos = 0;
            for (int i = 0; i < materials.Length; i++)
            {
                var mat = materials[i];
                for (int j = 0; j < 3; j++)
                {
                    ambs[newPos] = mat.Ambient[j+1];
                    diffs[newPos] = mat.Diffuse[j+1];
                    specs[newPos] = mat.Specular[j+1];
                    newPos++;
                }
                shinis[i] = mat.Shininess;
            }

            // Set buffer data.
            BufferData(gl, indices, vertices, normals,
                ambs, diffs, specs, shinis);
        }
Esempio n. 2
0
        public void BufferData(OpenGL gl,
            uint[] indices, float[] vertices, float[] normals, Material[] materials)
        {
            IndicesCount = indices.Length;

            var color3Size = 3 * materials.Length;
            float[] ambs = new float[color3Size],
                diffs = new float[color3Size],
                specs = new float[color3Size],
                shinis = new float[materials.Length];

            // Convert materials to float arrays.
            var newPos = 0;
            for (int i = 0; i < materials.Length; i++)
            {
                var mat = materials[i];
                for (int j = 0; j < 3; j++)
                {
                    ambs[newPos] = mat.Ambient[j+1];
                    diffs[newPos] = mat.Diffuse[j+1];
                    specs[newPos] = mat.Specular[j+1];
                    newPos++;
                }
                shinis[i] = mat.Shininess;
            }

            // Because an Index Buffer Object ID is unique, we'll use this to generate a hit test color.
            var htColor = new ColorF(Ibo);
            var htColorID = htColor.ToRGB();

            // Set buffer data.
            BufferData(gl, indices, vertices, normals,
                ambs, diffs, specs, shinis, htColorID);
        }
Esempio n. 3
0
        public void BufferData(OpenGL gl,
            uint[] indices, float[] vertices, float[] normals, 
            mat4[] transformations, Material[] materials)
        {
            // Use the amount of transformations to decide how many particles of this object should be drawn.
            ParticleCount = transformations.Length;
            IndicesCount = indices.Length;

            var tColSize = 4 * transformations.Length;
            var color3Size = 3 * materials.Length;
            float[] tCol1 = new float[tColSize],
                tCol2 = new float[tColSize],
                tCol3 = new float[tColSize],
                tCol4 = new float[tColSize],
                ambs = new float[color3Size],
                diffs = new float[color3Size],
                specs = new float[color3Size],
                shinis = new float[materials.Length];

            // Convert transformations to float arrays.
            var newPos = 0;
            foreach (var trans in transformations)
            {
                for (int i = 0; i < 4; i++)
                {
                    tCol1[newPos] = trans[i][0];
                    tCol2[newPos] = trans[i][1];
                    tCol3[newPos] = trans[i][2];
                    tCol4[newPos] = trans[i][3];
                    newPos++;
                }
            }

            // Convert materials to float arrays.
            newPos = 0;
            for (int i = 0; i < materials.Length; i++)
            {
                var mat = materials[i];
                for (int j = 0; j < 3; j++)
                {
                    ambs[newPos] = mat.Ambient[j+1];
                    diffs[newPos] = mat.Diffuse[j+1];
                    specs[newPos] = mat.Specular[j+1];
                    newPos++;
                }
                shinis[i] = mat.Shininess;
            }

            // Set buffer data.
            BufferData(gl, indices, vertices, normals,
                tCol1, tCol2, tCol3, tCol4,
                ambs, diffs, specs, shinis);
        }