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.Create(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.Position + this.DataSource.PointFLT(I, J, K); array[gridIndex].FRT = this.DataSource.Position + this.DataSource.PointFRT(I, J, K); array[gridIndex].BRT = this.DataSource.Position + this.DataSource.PointBRT(I, J, K); array[gridIndex].BLT = this.DataSource.Position + this.DataSource.PointBLT(I, J, K); array[gridIndex].FLB = this.DataSource.Position + this.DataSource.PointFLB(I, J, K); array[gridIndex].FRB = this.DataSource.Position + this.DataSource.PointFRB(I, J, K); array[gridIndex].BRB = this.DataSource.Position + this.DataSource.PointBRB(I, J, K); array[gridIndex].BLB = this.DataSource.Position + this.DataSource.PointBLB(I, J, K); } } ptr = buffer.GetBufferPtr() as PropertyBufferPtr; } return(ptr); }
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.Create(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); } }
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.Create(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(); } }
public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader) { if (bufferName == strPosition) { if (this.positionBufferPtr != null) { return(this.positionBufferPtr); } using (var buffer = new PropertyBuffer <vec3>(varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw)) { buffer.Create(this.positions.Count); unsafe { var array = (vec3 *)buffer.Header.ToPointer(); for (int i = 0; i < this.positions.Count; i++) { array[i] = this.positions[i]; } } this.positionBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr; } return(this.positionBufferPtr); } 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.Create(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(); } }
/// <summary> /// /// </summary> /// <param name="bufferName"></param> /// <param name="varNameInShader"></param> /// <returns></returns> public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader) { if (bufferName == position) { if (positionBufferPtr == null) { using (var buffer = new PropertyBuffer <vec3>( varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw)) { buffer.Create(this.markerCount * 2); unsafe { var array = (vec3 *)buffer.Header.ToPointer(); for (int i = 0; i < this.markerCount; i++) { array[i * 2 + 0] = new vec3(-0.5f + (float)i / (float)(this.markerCount - 1), 0.5f, 0); array[i * 2 + 1] = new vec3(-0.5f + (float)i / (float)(this.markerCount - 1), -0.5f, 0); } } positionBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr; } } return(positionBufferPtr); } else { throw new NotImplementedException(); } }
/// <summary> /// /// </summary> /// <param name="bufferName"></param> /// <param name="varNameInShader"></param> /// <returns></returns> public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader) { if (bufferName == position) { if (positionBufferPtr == null) { using (var buffer = new PropertyBuffer <vec3>( varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw)) { buffer.Create((this.quadCount + 1) * 2); unsafe { var array = (vec3 *)buffer.Header.ToPointer(); for (int i = 0; i < (this.quadCount + 1); i++) { array[i * 2 + 0] = new vec3(-0.5f + (float)i / (float)(this.quadCount), 0.5f, 0); array[i * 2 + 1] = new vec3(-0.5f + (float)i / (float)(this.quadCount), -0.5f, 0); } } positionBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr; } } return(positionBufferPtr); } else if (bufferName == color) { if (colorBufferPtr == null) { using (var buffer = new PropertyBuffer <vec3>( varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw)) { buffer.Create((this.quadCount + 1) * 2); unsafe { var array = (vec3 *)buffer.Header.ToPointer(); for (int i = 0; i < (this.quadCount + 1); i++) { int x = this.bitmap.Width * i / this.quadCount; if (x == this.bitmap.Width) { x = this.bitmap.Width - 1; } vec3 value = this.bitmap.GetPixel(x, 0).ToVec3(); array[i * 2 + 0] = value; array[i * 2 + 1] = value; } } colorBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr; } } return(colorBufferPtr); } 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.Create(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.Create(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(); } }
private PropertyBufferPtr GetColorBufferPtr(string varNameInShader) { PropertyBufferPtr ptr = null; using (var buffer = new PropertyBuffer <HexahedronTexCoord>(varNameInShader, 1, OpenGL.GL_FLOAT, BufferUsage.StaticDraw)) { float[] textures = GetTextureCoords(this.GridBlockProperties[this.defaultBlockPropertyIndex]); int gridCellCount = this.DataSource.DimenSize; buffer.Create(gridCellCount); unsafe { var array = (HexahedronTexCoord *)buffer.Header.ToPointer(); for (int gridIndex = 0; gridIndex < gridCellCount; gridIndex++) { array[gridIndex].SetCoord(textures[gridIndex]); } } ptr = buffer.GetBufferPtr() as PropertyBufferPtr; } return(ptr); }
public unsafe PropertyBufferPtr GetProperty(string bufferName, string varNameInShader) { if (bufferName == strPosition) { if (positionBufferPtr != null) { return(positionBufferPtr); } using (var buffer = new PropertyBuffer <vec3>(varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw)) { int vertexCount = (faceCount * 2 + 2) * (pipeline.Count - 1); buffer.Create(vertexCount); var array = (vec3 *)buffer.Header.ToPointer(); int index = 0; var max = new vec3(float.MinValue, float.MinValue, float.MinValue); var min = new vec3(float.MaxValue, float.MaxValue, float.MaxValue); for (int i = 1; i < pipeline.Count; i++) { vec3 p1 = pipeline[i - 1]; vec3 p2 = pipeline[i]; vec3 vector = p2 - p1;// 从p1到p2的向量 // 找到互相垂直的三个向量:vector, orthogontalVector1和orthogontalVector2 vec3 orthogontalVector1 = new vec3(vector.y - vector.z, vector.z - vector.x, vector.x - vector.y); vec3 orthogontalVector2 = vector.cross(orthogontalVector1); orthogontalVector1 = orthogontalVector1.normalize() * (float)Math.Sqrt(this.radius); orthogontalVector2 = orthogontalVector2.normalize() * (float)Math.Sqrt(this.radius); for (int faceIndex = 0; faceIndex < faceCount + 1; faceIndex++) { double angle = (Math.PI * 2 * faceIndex) / faceCount; vec3 delta = orthogontalVector1 * (float)Math.Cos(angle) + orthogontalVector2 * (float)Math.Sin(angle); vec3 tmp1 = p1 + delta, tmp2 = p2 + delta; tmp1.UpdateMax(ref max); tmp1.UpdateMin(ref min); tmp2.UpdateMax(ref max); tmp2.UpdateMin(ref min); array[index++] = tmp1; array[index++] = tmp2; } } this.lengths = max - min; positionBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr; } return(positionBufferPtr); } else if (bufferName == strBrightness) { if (brightnessBufferPtr != null) { return(brightnessBufferPtr); } using (var buffer = new PropertyBuffer <vec3>(varNameInShader, 3, OpenGL.GL_FLOAT, BufferUsage.StaticDraw)) { int vertexCount = (faceCount * 2 + 2) * (pipeline.Count - 1); buffer.Create(vertexCount); var array = (vec3 *)buffer.Header.ToPointer(); var random = new Random(); for (int i = 0; i < buffer.Length; i++) { var x = (float)(random.NextDouble() * 0.5 + 0.5); array[i] = new vec3(x, x, x); } brightnessBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr; } return(brightnessBufferPtr); } else { throw new ArgumentException(); } }
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.Create(particleCount); unsafe { var array = (vec4 *)buffer.Header.ToPointer(); for (int i = 0; i < particleCount; i++) { array[i] = new vec4( (float)(random.NextDouble() - 0.5) * 20, (float)(random.NextDouble() - 0.5) * 20, (float)(random.NextDouble() - 0.5) * 20, (float)(random.NextDouble()) ); } } positionBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr; } } return(positionBufferPtr); } else if (bufferName == strVelocity) { if (velocityBufferPtr == null) { using (var buffer = new PropertyBuffer <vec4>( varNameInShader, 4, OpenGL.GL_FLOAT, BufferUsage.DynamicCopy)) { buffer.Create(particleCount); unsafe { var array = (vec4 *)buffer.Header.ToPointer(); for (int i = 0; i < particleCount; i++) { array[i] = new vec4( (float)(random.NextDouble() - 0.5) * 0.2f, (float)(random.NextDouble() - 0.5) * 0.2f, (float)(random.NextDouble() - 0.5) * 0.2f, 0 ); } } velocityBufferPtr = buffer.GetBufferPtr() as PropertyBufferPtr; } } return(velocityBufferPtr); } else { throw new ArgumentException(); } }