Example #1
0
 public RawModel(VBOArrayF attributes)
 {
     this.shaderAttributes = attributes;
     Buffer = new VAO(this.shaderAttributes);
     VAOManager.genVAO(Buffer);
     VAOManager.setBufferData(OpenTK.Graphics.OpenGL.BufferTarget.ArrayBuffer, Buffer);
 }
Example #2
0
        //

        public PlantReadyMaster(IEnumerable <PlantUnit> plants, VBOArrayF modelAttribs, string[] textureSets, WindComponent component)
        {
            SetMemento(plants);
            this._postConstructor = true;
            this._texture         = new List <ITexture>();
            foreach (var item in textureSets)
            {
                _texture.Add(PoolProxy.GetResource <ObtainTexturePool, TextureAllocationPolicy, string, ITexture>(item));
            }
            this._attribs       = modelAttribs;
            this._wind          = component;
            this._grassMaterial = new Material(new Vector3(1.0f, 1.0f, 1.0f), new Vector3(1.0f, 1.0f, 1.0f),
                                               new Vector3(1.0f, 1.0f, 1.0f), new Vector3(1.0f, 1.0f, 1.0f), 10.0f, 1.0f);
            this._meshCenter = GetCenter();
        }
Example #3
0
        private void postConstructor(Landscape terrain = null)
        {
            if (this._postConstructor)
            {
                AlignPlantsToTerrain(terrain);
                this._attribs = PlantUserAttributeBuilder.BuildReadyUserAttributeBuffer(_plants, _attribs);
                _buffer       = new VAO(_attribs);

                VAOManager.genVAO(_buffer);
                VAOManager.setBufferData(BufferTarget.ArrayBuffer, _buffer);

                _shader = PoolProxy.GetResource <ObtainShaderPool, ShaderAllocationPolicy <PlantShader>, string, PlantShader>(ProjectFolders.ShadersPath + "plantVertexShader.glsl" + "," + ProjectFolders.ShadersPath + "plantFragmentShader.glsl");
                this._postConstructor = !this._postConstructor;
            }
        }
Example #4
0
 public Skybox()
 {
     attribs = new VBOArrayF(new float[6 * 6, 3] {
         { -SKYBOX_SIZE, SKYBOX_SIZE, -SKYBOX_SIZE }, { -SKYBOX_SIZE, -SKYBOX_SIZE, -SKYBOX_SIZE }, { SKYBOX_SIZE, -SKYBOX_SIZE, -SKYBOX_SIZE },
         { SKYBOX_SIZE, -SKYBOX_SIZE, -SKYBOX_SIZE }, { SKYBOX_SIZE, SKYBOX_SIZE, -SKYBOX_SIZE }, { -SKYBOX_SIZE, SKYBOX_SIZE, -SKYBOX_SIZE }, { -SKYBOX_SIZE, -SKYBOX_SIZE, SKYBOX_SIZE },
         { -SKYBOX_SIZE, -SKYBOX_SIZE, -SKYBOX_SIZE }, { -SKYBOX_SIZE, SKYBOX_SIZE, -SKYBOX_SIZE }, { -SKYBOX_SIZE, SKYBOX_SIZE, -SKYBOX_SIZE }, { -SKYBOX_SIZE, SKYBOX_SIZE, SKYBOX_SIZE },
         { -SKYBOX_SIZE, -SKYBOX_SIZE, SKYBOX_SIZE }, { SKYBOX_SIZE, -SKYBOX_SIZE, -SKYBOX_SIZE }, { SKYBOX_SIZE, -SKYBOX_SIZE, SKYBOX_SIZE }, { SKYBOX_SIZE, SKYBOX_SIZE, SKYBOX_SIZE },
         { SKYBOX_SIZE, SKYBOX_SIZE, SKYBOX_SIZE }, { SKYBOX_SIZE, SKYBOX_SIZE, -SKYBOX_SIZE }, { SKYBOX_SIZE, -SKYBOX_SIZE, -SKYBOX_SIZE }, { -SKYBOX_SIZE, -SKYBOX_SIZE, SKYBOX_SIZE },
         { -SKYBOX_SIZE, SKYBOX_SIZE, SKYBOX_SIZE }, { SKYBOX_SIZE, SKYBOX_SIZE, SKYBOX_SIZE }, { SKYBOX_SIZE, SKYBOX_SIZE, SKYBOX_SIZE }, { SKYBOX_SIZE, -SKYBOX_SIZE, SKYBOX_SIZE },
         { -SKYBOX_SIZE, -SKYBOX_SIZE, SKYBOX_SIZE }, { -SKYBOX_SIZE, SKYBOX_SIZE, -SKYBOX_SIZE }, { SKYBOX_SIZE, SKYBOX_SIZE, -SKYBOX_SIZE }, { SKYBOX_SIZE, SKYBOX_SIZE, SKYBOX_SIZE },
         { SKYBOX_SIZE, SKYBOX_SIZE, SKYBOX_SIZE }, { -SKYBOX_SIZE, SKYBOX_SIZE, SKYBOX_SIZE }, { -SKYBOX_SIZE, SKYBOX_SIZE, -SKYBOX_SIZE }, { -SKYBOX_SIZE, -SKYBOX_SIZE, -SKYBOX_SIZE },
         { -SKYBOX_SIZE, -SKYBOX_SIZE, SKYBOX_SIZE }, { SKYBOX_SIZE, -SKYBOX_SIZE, -SKYBOX_SIZE }, { SKYBOX_SIZE, -SKYBOX_SIZE, -SKYBOX_SIZE }, { -SKYBOX_SIZE, -SKYBOX_SIZE, SKYBOX_SIZE },
         { SKYBOX_SIZE, -SKYBOX_SIZE, SKYBOX_SIZE }
     });
 }
Example #5
0
        private VBOArrayF AlignMeshYAxis(VBOArrayF attribs)
        {
            //Выравнивает координаты травы до их обработки
            float tempBottom     = attribs.Vertices[0, 1];
            Int32 iterationCount = attribs.Vertices.Length / 3;

            for (Int32 i = 0; i < iterationCount; i++)
            {
                if (tempBottom > attribs.Vertices[i, 1])   //Находим минимум по Y
                {
                    tempBottom = attribs.Vertices[i, 1];
                }
            }

            attribs.verticesShift(0, -tempBottom, 0);
            return(attribs);
        }
Example #6
0
        public PlantReadyMaster(Int32 entityCount, float MAP_SIZE, VBOArrayF ModelAttribs, Vector3 Scale,
                                string[] textureSets, WindComponent component, MistComponent mist = null)
        {
            _postConstructor = true;
            _attribs         = ModelAttribs;
            _texture         = new List <ITexture>();
            foreach (var item in textureSets)
            {
                _texture.Add(PoolProxy.GetResource <ObtainTexturePool, TextureAllocationPolicy, string, ITexture>(item));
            }
            this.MAP_SIZE  = MAP_SIZE;
            entityCount    = entityCount > MAX_ENTITIES_COUNT ? MAX_ENTITIES_COUNT : entityCount;
            _grassMaterial = new Material(new Vector3(1.0f, 1.0f, 1.0f), new Vector3(1.0f, 1.0f, 1.0f),
                                          new Vector3(1.0f, 1.0f, 1.0f), new Vector3(1.0f, 1.0f, 1.0f), 10.0f, 1.0f);

            _meshCenter = GetCenter();
            _plants     = new List <PlantUnit>();
            for (Int32 i = 0; i < entityCount; i++)
            {
                _plants.Add(new PlantUnit(i, Scale, MAP_SIZE, new uint[] { 1, 2, 3 }));
            }
            this._wind = component;
            this._mist = mist;
        }
Example #7
0
        public static VBOArrayF BuildReadyUserAttributeBuffer(IEnumerable <PlantUnit> plants, VBOArrayF attribs)
        {
            if (plants.Count() == 0)
            {
                return(attribs);
            }

            Int32 size = plants.Count();

            float[] windS    = new float[size];
            float[] tSampler = new float[size];

            float[,] matrixColumn1 = new float[size, 4];
            float[,] matrixColumn2 = new float[size, 4];
            float[,] matrixColumn3 = new float[size, 4];
            float[,] matrixColumn4 = new float[size, 4];

            // magic
            unsafe
            {
                fixed(float *matrix1 = matrixColumn1)
                {
                    fixed(float *matrix2 = matrixColumn2)
                    {
                        fixed(float *matrix3 = matrixColumn3)
                        {
                            fixed(float *matrix4 = matrixColumn4)
                            {
                                for (Int32 i = 0, baseDim = 0; i < size; i++, baseDim += 4)
                                {
                                    var item        = plants.ElementAt(i);
                                    var modelMatrix = Matrix4.Identity;
                                    modelMatrix *= Matrix4.CreateRotationY(item.Rotation.Y);
                                    modelMatrix *= Matrix4.CreateScale(item.Scale);
                                    modelMatrix *= Matrix4.CreateTranslation(item.Translation);

                                    matrix1[baseDim]     = modelMatrix[0, 0];
                                    matrix1[baseDim + 1] = modelMatrix[0, 1];
                                    matrix1[baseDim + 2] = modelMatrix[0, 2];
                                    matrix1[baseDim + 3] = modelMatrix[0, 3];

                                    matrix2[baseDim]     = modelMatrix[1, 0];
                                    matrix2[baseDim + 1] = modelMatrix[1, 1];
                                    matrix2[baseDim + 2] = modelMatrix[1, 2];
                                    matrix2[baseDim + 3] = modelMatrix[1, 3];

                                    matrix3[baseDim]     = modelMatrix[2, 0];
                                    matrix3[baseDim + 1] = modelMatrix[2, 1];
                                    matrix3[baseDim + 2] = modelMatrix[2, 2];
                                    matrix3[baseDim + 3] = modelMatrix[2, 3];

                                    matrix4[baseDim]     = modelMatrix[3, 0];
                                    matrix4[baseDim + 1] = modelMatrix[3, 1];
                                    matrix4[baseDim + 2] = modelMatrix[3, 2];
                                    matrix4[baseDim + 3] = modelMatrix[3, 3];

                                    windS[i]    = item.WindLoop;
                                    tSampler[i] = item.textureID;
                                }
                            }
                        }
                    }
                }
            }
            return(new VBOArrayF(attribs.Vertices, attribs.Normals, attribs.TextureCoordinates,
                                 windS, tSampler, matrixColumn1, matrixColumn2, matrixColumn3, matrixColumn4));
        }