예제 #1
0
 public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader)
 {
     if (bufferName == strPosition)
     {
         if (positionBuffer == null)
         {
             using (var buffer = new PropertyBuffer <float>(varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.DynamicDraw))
             {
                 buffer.Alloc(positions.Length);
                 unsafe
                 {
                     var array = (float *)buffer.Header.ToPointer();
                     for (int i = 0; i < positions.Length; i++)
                     {
                         array[i] = positions[i];
                     }
                 }
                 positionBuffer = buffer.GetBufferPtr() as PropertyBufferPtr;
             }
         }
         return(positionBuffer);
     }
     else
     {
         return(null);
     }
 }
        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;
        }
예제 #3
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(vertsData.Length);
                            unsafe
                            {
                                var array = (vec3 *)buffer.Header.ToPointer();
                                for (int i = 0; i < vertsData.Length; i++)
                                {
                                    array[i] = vertsData[i];
                                }
                            }

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

                    return(positionBufferPtr);
                }
                else
                {
                    throw new ArgumentException();
                }
            }
예제 #4
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();
            }
        }
예제 #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(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();
     }
 }
예제 #6
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(particleCount);
                            unsafe
                            {
                                var array = (vec3 *)buffer.Header.ToPointer();
                                for (int i = 0; i < particleCount; i++)
                                {
                                    //if (i % 2 == 0)
                                    {
                                        array[i] = new vec3(
                                            (float)((random.NextDouble() * 2 - 1) * backgroundRadius),
                                            (float)((random.NextDouble() * 2 - 1) * backgroundRadius),
                                            (float)((random.NextDouble() * 2 - 1) * backgroundRadius));
                                    }
                                    //else
                                    //{
                                    //    double theta = random.NextDouble() * 2 * Math.PI - Math.PI;
                                    //    double alpha = random.NextDouble() * 2 * Math.PI - Math.PI;
                                    //    array[i] = new vec3(
                                    //        (float)(Math.Sin(theta) * Math.Cos(alpha)) * backgroundRadius,
                                    //        (float)(Math.Sin(theta) * Math.Sin(alpha)) * backgroundRadius,
                                    //        (float)(Math.Cos(theta)) * backgroundRadius);
                                    //}
                                }
                            }

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

                    return(positionBufferPtr);
                }
                else
                {
                    throw new ArgumentException();
                }
            }
예제 #7
0
        public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader)
        {
            if (bufferName == strPosition)
            {
                if (positionBufferPtr == null)
                {
                    using (var buffer = new PropertyBuffer <vec4>(
                               varNameInShader, 4, OpenGL.GL_FLOAT, BufferUsage.DynamicCopy))
                    {
                        buffer.Alloc(particleCount);
                        unsafe
                        {
                            var array = (vec4 *)buffer.Header.ToPointer();
                            for (int i = 0; i < particleCount; i++)
                            {
                                array[i] = new vec4(
                                    (float)(
                                        (random.NextDouble() - 0.5) * 2
                                        * ((random.NextDouble() * (maxRadius - minRadius) + minRadius))
                                        ),
                                    (float)(
                                        (random.NextDouble() - 0.5) * 2
                                        * ((random.NextDouble() * (maxRadius - minRadius) + minRadius))
                                        ),
                                    (float)(
                                        (random.NextDouble() - 0.5) * 2
                                        * ((random.NextDouble() * (maxRadius - minRadius) + minRadius))
                                        ),
                                    (float)(random.NextDouble())
                                    );
                            }
                        }

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

                return(positionBufferPtr);
            }
            else
            {
                throw new ArgumentException();
            }
        }
예제 #8
0
        public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader)
        {
            if (bufferName == position)
            {
                using (var buffer = new PropertyBuffer <vec3>(
                           varNameInShader, 3, GL.GL_FLOAT, BufferUsage.StaticDraw))
                {
                    buffer.Alloc(model.Positions.Length);
                    unsafe
                    {
                        var array = (vec3 *)buffer.FirstElement();
                        for (int i = 0; i < model.Positions.Length; i++)
                        {
                            array[i] = model.Positions[i];
                        }
                    }

                    return(buffer.GetBufferPtr() as PropertyBufferPtr);
                }
            }
            else if (bufferName == color)
            {
                using (var buffer = new PropertyBuffer <vec3>(
                           varNameInShader, 3, GL.GL_FLOAT, BufferUsage.StaticDraw))
                {
                    buffer.Alloc(model.Colors.Length);
                    unsafe
                    {
                        var array = (vec3 *)buffer.FirstElement();
                        for (int i = 0; i < model.Colors.Length; i++)
                        {
                            array[i] = model.Colors[i];
                        }
                    }

                    return(buffer.GetBufferPtr() as PropertyBufferPtr);
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
예제 #9
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(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();
                }
            }
예제 #10
0
 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();
     }
 }
예제 #11
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;
     }
 }
예제 #12
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 == 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 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
     {
         throw new ArgumentException();
     }
 }
 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(); }
 }