public LinuxFlag(int m, int n, float flagWidth, float spring_constant, float damping, float flagAltitude, float poleRadius) { //this.flagTexture = ResourceManager.GetTextureResource("tux.png"); this.m = m; this.n = n; int N = m*n; #region generate_vertices int n1 = n-0x01; int m1 = m-0x01; float t0x = 1.0f/n1; float t0y = 1.0f/m1; float d0 = flagWidth*t0x; this.d0 = d0; this.d1 = (float) (Math.Sqrt(2.0f)*d0); this.flagHeight = flagWidth*m/n; this.poleHeight = flagHeight+flagAltitude; this.poleRadius = poleRadius; int arrayPos = 0x00; VertexT2fN3fV3f[] vertices = new VertexT2fN3fV3f[N]; this.verticesHandle = GCHandle.Alloc(vertices,GCHandleType.Pinned); Vector3 nrm = new Vector3(0.0f,0.0f,-1.0f); float py, ty; for(int y = 0x00; y < m; y++) { py = flagHeight-d0*y+flagAltitude; ty = t0y*y; for(int x = 0x00; x < n; x++) { vertices[arrayPos].Texture = new Vector2(x*t0x,ty); vertices[arrayPos].Normal = nrm; vertices[arrayPos++].Position = new Vector3(d0*x,py,0.0f); } } int vertexBuffer; GL.GenBuffers(0x01,out vertexBuffer); this.vx_buffer = vertexBuffer; this.vx_Size = vertices.Length*0x08*sizeof(float); this.velocity = new Vector3[N]; this.vertices = vertices; this.loadVertices(); #endregion #region generate_indices this.elN = 6*m1*n1; int N2 = this.elN; int[] indices = new int[N2]; arrayPos = 0x00; int l1 = 0; int l2 = n; int l3; for(; l2 < N;) { l3 = l1+n1; for(; l1 < l3;) { indices[arrayPos++] = l2++; indices[arrayPos++] = l1; indices[arrayPos++] = l2;//l2+0x01 indices[arrayPos++] = l1++; indices[arrayPos++] = l1;//l1+0x01 indices[arrayPos++] = l2;//l2+0x01 } l1++; l2++; } int indexBuffer; GL.GenBuffers(0x01, out indexBuffer); GL.BindBuffer(BufferTarget.ElementArrayBuffer,indexBuffer); GL.BufferData(BufferTarget.ElementArrayBuffer,new IntPtr(indices.Length*sizeof(int)),indices,BufferUsageHint.StaticDraw); this.el_buffer = indexBuffer; #endregion #region set_variables this.spring_constant = spring_constant; this.damping = damping; #endregion }
public LinuxFlag(int m, int n, float flagWidth, float spring_constant, float damping, float flagAltitude, float poleRadius) { //this.flagTexture = ResourceManager.GetTextureResource("tux.png"); this.m = m; this.n = n; int N = m * n; #region generate_vertices int n1 = n - 0x01; int m1 = m - 0x01; float t0x = 1.0f / n1; float t0y = 1.0f / m1; float d0 = flagWidth * t0x; this.d0 = d0; this.d1 = (float)(Math.Sqrt(2.0f) * d0); this.flagHeight = flagWidth * m / n; this.poleHeight = flagHeight + flagAltitude; this.poleRadius = poleRadius; int arrayPos = 0x00; VertexT2fN3fV3f[] vertices = new VertexT2fN3fV3f[N]; this.verticesHandle = GCHandle.Alloc(vertices, GCHandleType.Pinned); Vector3 nrm = new Vector3(0.0f, 0.0f, -1.0f); float py, ty; for (int y = 0x00; y < m; y++) { py = flagHeight - d0 * y + flagAltitude; ty = t0y * y; for (int x = 0x00; x < n; x++) { vertices[arrayPos].Texture = new Vector2(x * t0x, ty); vertices[arrayPos].Normal = nrm; vertices[arrayPos++].Position = new Vector3(d0 * x, py, 0.0f); } } int vertexBuffer; GL.GenBuffers(0x01, out vertexBuffer); this.vx_buffer = vertexBuffer; this.vx_Size = vertices.Length * 0x08 * sizeof(float); this.velocity = new Vector3[N]; this.vertices = vertices; this.loadVertices(); #endregion #region generate_indices this.elN = 6 * m1 * n1; int N2 = this.elN; int[] indices = new int[N2]; arrayPos = 0x00; int l1 = 0; int l2 = n; int l3; for (; l2 < N;) { l3 = l1 + n1; for (; l1 < l3;) { indices[arrayPos++] = l2++; indices[arrayPos++] = l1; indices[arrayPos++] = l2; //l2+0x01 indices[arrayPos++] = l1++; indices[arrayPos++] = l1; //l1+0x01 indices[arrayPos++] = l2; //l2+0x01 } l1++; l2++; } int indexBuffer; GL.GenBuffers(0x01, out indexBuffer); GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexBuffer); GL.BufferData(BufferTarget.ElementArrayBuffer, new IntPtr(indices.Length * sizeof(int)), indices, BufferUsageHint.StaticDraw); this.el_buffer = indexBuffer; #endregion #region set_variables this.spring_constant = spring_constant; this.damping = damping; #endregion }