Sign in to follow this  
cforlife

[.net] c# geometry class

Recommended Posts

I'm trying to set up a geometry class by passing an enum(FVF) on what the vertex format looks like. Then you can create a segment with a number of vertices and indices. This internally creates buffers for the user to fill with data. After the buffers are filled you call updatebuffers which makes the real verts. MGeometry hGeometry = new MGeometry(PrimitiveType.TriangleList, D3D.VertexFormats.Position | D3D.VertexFormats.Diffuse, false); // Create a segment ( num verts, num index ) MSegment hSegment = hGeometry.CreateSegment(3, 3); object[] vPositions = hSegment.GetVertexComponent(D3D.VertexFormats.Position); object[] vColors = hSegment.GetVertexComponent(D3D.VertexFormats.Diffuse); UInt16[] uIndices = hSegment.GetIndices(); // fill the buffers. vPositions[0] = new MVector3(0, 0, 0); vPositions[1] = new MVector3(1, 0, 0); vPositions[2] = new MVector3(1, 1, 0); vColors[0] = 255; vColors[1] = 100; vColors[2] = 255; uIndices[0] = 0; uIndices[1] = 1; uIndices[2] = 2; // Create the user data or the direct3d buffers. hSegment.UpdateBuffers(); I've tried doing something like this. This is hard coded but it would look the same: object[] vertices = new object[3]; object[] vert0 = new object[] { new Vector3(0, 0, 0), 255 }; object[] vert1 = new object[] { new Vector3(10, 0, 0), 255 }; object[] vert2 = new object[] { new Vector3(10, 10, 0), 255 }; vertices[0] = vert0; vertices[1] = vert1; vertices[2] = vert2; DrawIndexedUserPrimitives seems to only work if you have an array of structs. I dont have a stuct but i do know their vertex format. In c++ this is easy. Just create an array and start filling while increment the pointer. It would really help if anyone knows how to get around this in C# without having to create a tons of structs. [Edited by - cforlife on August 17, 2006 2:18:25 AM]

Share this post


Link to post
Share on other sites
After looking round i found a better way to fill the buffer. But it still doesn't work. This is what im trying.

int nSize = D3D.VertexInformation.GetFormatSize(D3D.VertexFormats.Position | D3D.VertexFormats.Diffuse);

// Create the vertex buffer
m_hVertexBuffer = new D3D.VertexBuffer(Rendering.MRenderView.GraphicsDevice,
nSize * 3,
D3D.Usage.None,
D3D.VertexFormats.Position | D3D.VertexFormats.Diffuse,
D3D.Pool.Managed);

DX.GraphicsStream vbData = m_hVertexBuffer.Lock(0, nSize * 3, D3D.LockFlags.None);


byte* pBuffer = (byte*)vbData.InternalDataPointer;

*(float*)pBuffer = 0.0f; pBuffer += sizeof(float);
*(float*)pBuffer = 0.0f; pBuffer += sizeof(float);
*(float*)pBuffer = 0.0f; pBuffer += sizeof(float);
*(int*)pBuffer = 255; pBuffer += sizeof(int);
*(float*)pBuffer = 0.0f; pBuffer += sizeof(float);
*(float*)pBuffer = 100.0f; pBuffer += sizeof(float);
*(float*)pBuffer = 0.0f; pBuffer += sizeof(float);
*(int*)pBuffer = 255; pBuffer += sizeof(int);
*(float*)pBuffer = 100.0f; pBuffer += sizeof(float);
*(float*)pBuffer = 100.0f; pBuffer += sizeof(float);
*(float*)pBuffer = 0.0f; pBuffer += sizeof(float);
*(int*)pBuffer = 255; pBuffer += sizeof(int);

//Unlock the buffer
m_hVertexBuffer.Unlock();


If i create the vertex buffer with a type it works.

m_hVertexBuffer = new D3D.VertexBuffer( typeof(D3D.CustomVertex.PositionColored),
3,
MRenderView.GraphicsDevice,
D3D.Usage.None,
D3D.VertexFormats.Position | D3D.VertexFormats.Diffuse,
D3D.Pool.Managed);


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this