Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

[.net] c# geometry class

Started by cforlife Aug 17, 2006 at 2:01 AM 0 replies 1.3k views
Original Post
cforlife
cforlife
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]
cforlife
cforlife
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);


Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.