private PropertyBufferPtr GetPositionBufferPtr(string varNameInShader)
        {
            PropertyBufferPtr ptr = null;
            using (var buffer = new PropertyBuffer<HexahedronPosition>(varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
            {
                int dimSize = this.DataSource.DimenSize;
                buffer.Alloc(dimSize);
                unsafe
                {
                    var array = (HexahedronPosition*)buffer.Header.ToPointer();
                    int I, J, K;
                    for (int gridIndex = 0; gridIndex < dimSize; gridIndex++)
                    {
                        this.DataSource.InvertIJK(gridIndex, out I, out J, out K);
                        array[gridIndex].FLT = this.DataSource.TranslateMatrix + this.DataSource.PointFLT(I, J, K);
                        array[gridIndex].FRT = this.DataSource.TranslateMatrix + this.DataSource.PointFRT(I, J, K);
                        array[gridIndex].BRT = this.DataSource.TranslateMatrix + this.DataSource.PointBRT(I, J, K);
                        array[gridIndex].BLT = this.DataSource.TranslateMatrix + this.DataSource.PointBLT(I, J, K);
                        array[gridIndex].FLB = this.DataSource.TranslateMatrix + this.DataSource.PointFLB(I, J, K);
                        array[gridIndex].FRB = this.DataSource.TranslateMatrix + this.DataSource.PointFRB(I, J, K);
                        array[gridIndex].BRB = this.DataSource.TranslateMatrix + this.DataSource.PointBRB(I, J, K);
                        array[gridIndex].BLB = this.DataSource.TranslateMatrix + this.DataSource.PointBLB(I, J, K);
                    }
                }
                ptr = buffer.GetBufferPtr() as PropertyBufferPtr;
            }

            return ptr;
        }
Example #2
0
        public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader)
        {
            if (bufferName == position)
            {
                if (!propertyBufferPtrDict.ContainsKey(bufferName))
                {
                    using (var buffer = new PropertyBuffer<vec3>(
                        varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
                    {
                        buffer.Alloc(BigDipperModel.positions.Length);
                        unsafe
                        {
                            var array = (vec3*)buffer.Header.ToPointer();
                            for (int i = 0; i < BigDipperModel.positions.Length; i++)
                            {
                                array[i] = BigDipperModel.positions[i];
                            }
                        }

                        propertyBufferPtrDict.Add(bufferName, buffer.GetBufferPtr() as PropertyBufferPtr);
                    }
                }
                return propertyBufferPtrDict[bufferName];
            }
            else if (bufferName == color)
            {
                if (!propertyBufferPtrDict.ContainsKey(bufferName))
                {
                    using (var buffer = new PropertyBuffer<vec3>(
                        varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
                    {
                        buffer.Alloc(BigDipperModel.colors.Length);
                        unsafe
                        {
                            var array = (vec3*)buffer.Header.ToPointer();
                            for (int i = 0; i < BigDipperModel.colors.Length; i++)
                            {
                                array[i] = BigDipperModel.colors[i];
                            }
                        }

                        propertyBufferPtrDict.Add(bufferName, buffer.GetBufferPtr() as PropertyBufferPtr);
                    }
                }
                return propertyBufferPtrDict[bufferName];
            }
            else
            {
                throw new NotImplementedException();
            }
        }
            public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader)
            {
                if (bufferName == strPosition)
                {
                    if (positionBufferPtr == null)
                    {
                        using (var buffer = new PropertyBuffer<vec3>(
                            varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
                        {
                            buffer.Alloc(particleCount);
                            unsafe
                            {
                                var array = (vec3*)buffer.Header.ToPointer();
                                for (int i = 0; i < particleCount; i++)
                                {
                                    double beta = random.NextDouble() * Math.PI;
                                    double theta = random.NextDouble() * Math.PI * 2;
                                    float x = (float)(a * Math.Sin(beta) * Math.Cos(theta));
                                    float y = (float)(b * Math.Sin(beta) * Math.Sin(theta));
                                    float z = (float)(c * Math.Cos(beta));
                                    array[i] = new vec3(x, y, z);
                                }
                            }

                            positionBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
                        }
                    }

                    return positionBufferPtr;
                }
                else
                {
                    throw new ArgumentException();
                }
            }
 public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader)
 {
     if (bufferName == strPosition)
     {
         if (this.positionBufferPtr == null)
         {
             const float lower = -0.3f;
             var positions = new vec2[codedColors.Length * 2 + 4];
             for (int i = 0; i < codedColors.Length; i++)
             {
                 positions[i * 2 + 0] = new vec2(codedColors[i].Coord*2, lower);
                 positions[i * 2 + 1] = new vec2(codedColors[i].Coord * 2, 1);
             }
             int index = codedColors.Length * 2 + 0;
             positions[index++] = new vec2(codedColors[0].Coord * 2, 0);
             positions[index++] = new vec2(codedColors[codedColors.Length - 1].Coord * 2, 0);
             positions[index++] = new vec2(codedColors[0].Coord * 2, 1);
             positions[index++] = new vec2(codedColors[codedColors.Length - 1].Coord * 2, 1);
             // Move2Cente
             float min = positions[0].x, max = positions[0].x;
             for (int i = 1; i < positions.Length; i++)
             {
                 vec2 value = positions[i];
                 if (value.x < min) { min = value.x; }
                 if (max < value.x) { max = value.x; }
             }
             float mid = max / 2 + min / 2;
             for (int i = 0; i < positions.Length; i++)
             {
                 positions[i].x = positions[i].x - mid;
             }
             using (var buffer = new PropertyBuffer<vec2>(varNameInShader, 2, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
             {
                 buffer.Alloc(positions.Length);
                 unsafe
                 {
                     var array = (vec2*)buffer.Header.ToPointer();
                     for (int i = 0; i < positions.Length; i++)
                     { array[i] = positions[i]; }
                 }
                 this.positionBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
             }
         }
         return this.positionBufferPtr;
     }
     else
     {
         throw new NotImplementedException();
     }
 }
Example #5
0
 public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader)
 {
     if (bufferName == strPosition)
     {
         if (positionBufferPtr == null)
         {
             using (var buffer = new PropertyBuffer<vec3>(varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
             {
                 buffer.Alloc(model.positions.Length);
                 unsafe
                 {
                     var array = (vec3*)buffer.Header.ToPointer();
                     for (int i = 0; i < model.positions.Length; i++)
                     {
                         array[i] = model.positions[i];
                     }
                 }
                 positionBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
             }
         }
         return positionBufferPtr;
     }
         else if (bufferName == strNormal)
     {
         if (normalBufferPtr == null)
         {
             using (var buffer = new PropertyBuffer<vec3>(varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
             {
                 buffer.Alloc(model.normals.Length);
                 unsafe
                 {
                     var array = (vec3*)buffer.Header.ToPointer();
                     for (int i = 0; i < model.normals.Length; i++)
                     {
                         array[i] = model.normals[i];
                     }
                 }
                 normalBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
             }
         }
         return normalBufferPtr;
     }
     else if (bufferName == strColor)
     {
         if (colorBufferPtr == null)
         {
             using (var buffer = new PropertyBuffer<vec3>(varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
             {
                 buffer.Alloc(model.colors.Length);
                 unsafe
                 {
                     var array = (vec3*)buffer.Header.ToPointer();
                     for (int i = 0; i < model.colors.Length; i++)
                     {
                         array[i] = model.colors[i];
                     }
                 }
                 colorBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
             }
         }
         return colorBufferPtr;
     }
     else if (bufferName == strUV)
     {
         if (uvBufferPtr == null)
         {
             using (var buffer = new PropertyBuffer<vec2>(varNameInShader, 2, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
             {
                 buffer.Alloc(model.uv.Length);
                 unsafe
                 {
                     var array = (vec2*)buffer.Header.ToPointer();
                     for (int i = 0; i < model.uv.Length; i++)
                     {
                         array[i] = model.uv[i];
                     }
                 }
                 uvBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
             }
         }
         return uvBufferPtr;
     }
     else
     {
         return null;
     }
 }
 public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader)
 {
     if (bufferName == strposition)
     {
         if (positionBufferPtr == null)
         {
             using (var buffer = new PropertyBuffer<vec3>(varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
             {
                 buffer.Alloc(4);
                 unsafe
                 {
                     var array = (vec3*)buffer.Header.ToPointer();
                     array[0] = new vec3(-1.0f, -1.0f, 0.5f);
                     array[1] = new vec3(1.0f, -1.0f, 0.5f);
                     array[2] = new vec3(1.0f, 1.0f, 0.5f);
                     array[3] = new vec3(-1.0f, 1.0f, 0.5f);
                 }
                 positionBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
             }
         }
         return positionBufferPtr;
     }
     else if (bufferName == struv)
     {
         if (uvBufferPtr == null)
         {
             using (var buffer = new PropertyBuffer<vec2>(varNameInShader, 2, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
             {
                 buffer.Alloc(4);
                 unsafe
                 {
                     var array = (vec2*)buffer.Header.ToPointer();
                     array[0] = new vec2(1, 1);
                     array[1] = new vec2(0, 1);
                     array[2] = new vec2(0, 0);
                     array[3] = new vec2(1, 0);
                 }
                 uvBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
             }
         }
         return uvBufferPtr;
     }
     else
     { throw new NotImplementedException(); }
 }