GetNormals() public method

public GetNormals ( ) : float[]
return float[]
コード例 #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="bufferName"></param>
 /// <param name="varNameInShader"></param>
 /// <returns></returns>
 public VertexBuffer GetVertexAttributeBuffer(string bufferName, string varNameInShader)
 {
     if (bufferName == strPosition)
     {
         if (this.positionBuffer == null)
         {
             float[] positions = model.GetPositions();
             //int length = positions.Length;
             //VertexBuffer buffer = VertexBuffer.Create(typeof(float), length, VBOConfig.Vec3, varNameInShader, BufferUsage.StaticDraw);
             //unsafe
             //{
             //    IntPtr pointer = buffer.MapBuffer(MapBufferAccess.WriteOnly);
             //    var array = (float*)pointer;
             //    for (int i = 0; i < positions.Length; i++)
             //    {
             //        array[i] = positions[i];
             //    }
             //    buffer.UnmapBuffer();
             //}
             //this.positionBuffer = buffer;
             // another way to do this:
             this.positionBuffer = positions.GenVertexBuffer(VBOConfig.Vec3, varNameInShader, BufferUsage.StaticDraw);
         }
         return(this.positionBuffer);
     }
     else if (bufferName == strColor)
     {
         if (this.colorBuffer == null)
         {
             float[] normals = model.GetNormals();
             for (int i = 0; i < normals.Length; i++)
             {
                 if (normals[i] < 0)
                 {
                     normals[i] = -normals[i];
                 }
             }
             //int length = normals.Length;
             //VertexBuffer buffer = VertexBuffer.Create(typeof(float), length, VBOConfig.Vec3, varNameInShader, BufferUsage.StaticDraw);
             //unsafe
             //{
             //    IntPtr pointer = buffer.MapBuffer(MapBufferAccess.WriteOnly);
             //    var array = (float*)pointer;
             //    for (int i = 0; i < normals.Length; i++)
             //    {
             //        array[i] = normals[i];
             //    }
             //    buffer.UnmapBuffer();
             //}
             //this.colorBuffer = buffer;
             // another way to do this:
             this.colorBuffer = normals.GenVertexBuffer(VBOConfig.Vec3, varNameInShader, BufferUsage.StaticDraw);
         }
         return(this.colorBuffer);
     }
     else if (bufferName == strNormal)
     {
         if (this.normalBuffer == null)
         {
             float[] normals = model.GetNormals();
             //int length = normals.Length;
             //VertexBuffer buffer = VertexBuffer.Create(typeof(float), length, VBOConfig.Vec3, varNameInShader, BufferUsage.StaticDraw);
             //unsafe
             //{
             //    IntPtr pointer = buffer.MapBuffer(MapBufferAccess.WriteOnly);
             //    var array = (float*)pointer;
             //    for (int i = 0; i < normals.Length; i++)
             //    {
             //        array[i] = normals[i];
             //    }
             //    buffer.UnmapBuffer();
             //}
             //this.normalBuffer = buffer;
             // another way to do this:
             this.normalBuffer = normals.GenVertexBuffer(VBOConfig.Vec3, varNameInShader, BufferUsage.StaticDraw);
         }
         return(this.normalBuffer);
     }
     else
     {
         return(null);
     }
 }
コード例 #2
0
ファイル: Teapot.cs プロジェクト: bobbyzhu/CSharpGL
 /// <summary>
 ///
 /// </summary>
 /// <param name="bufferName"></param>
 /// <param name="varNameInShader"></param>
 /// <returns></returns>
 public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader)
 {
     if (bufferName == strPosition)
     {
         if (positionBufferPtr == null)
         {
             using (var buffer = new PropertyBuffer <float>(varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
             {
                 float[] positions = model.GetPositions();
                 buffer.Create(positions.Length);
                 unsafe
                 {
                     var array = (float *)buffer.Header.ToPointer();
                     for (int i = 0; i < positions.Length; i++)
                     {
                         array[i] = positions[i];
                     }
                 }
                 positionBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
             }
         }
         return(positionBufferPtr);
     }
     else if (bufferName == strColor)
     {
         if (colorBufferPtr == null)
         {
             using (var buffer = new PropertyBuffer <float>(varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
             {
                 float[] normals = model.GetNormals();
                 buffer.Create(normals.Length);
                 unsafe
                 {
                     var array = (float *)buffer.Header.ToPointer();
                     for (int i = 0; i < normals.Length; i++)
                     {
                         array[i] = normals[i];
                     }
                 }
                 colorBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
             }
         }
         return(colorBufferPtr);
     }
     else if (bufferName == strNormal)
     {
         if (normalBufferPtr == null)
         {
             using (var buffer = new PropertyBuffer <float>(varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw))
             {
                 float[] normals = model.GetNormals();
                 buffer.Create(normals.Length);
                 unsafe
                 {
                     var array = (float *)buffer.Header.ToPointer();
                     for (int i = 0; i < normals.Length; i++)
                     {
                         array[i] = normals[i];
                     }
                 }
                 normalBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr;
             }
         }
         return(normalBufferPtr);
     }
     else
     {
         return(null);
     }
 }