Hallo liebe Community!
EDIT: Erledigt... DataStream.WriteRange existert...
Hat jemand von euch Erfahrung mit SharpDX? Ich versuche im Moment die Direct3D9 CDraw::Circle Funktion welche ich hier gefunden habe nach C# zu porten.
Spoiler anzeigen
Hier der C++ Code von der Webseite
Nur habe ich ein Problem: Ich weiß nicht wie ich das vertex array in den SharpDX.Direct3D9.VertexBuffer kopieren kann mit C#
Hier mal der C# Code:
Habe leider auch kein Erfolg beim googeln gehabt für SharpDX.Direct3D9...
Ich würde mich sehr über Hilfe von euch freuen! (Ich bin übrigens auf Direct3D9 angewiesen und kann leider nicht upgraden)
EDIT: Erledigt... DataStream.WriteRange existert...
Hat jemand von euch Erfahrung mit SharpDX? Ich versuche im Moment die Direct3D9 CDraw::Circle Funktion welche ich hier gefunden habe nach C# zu porten.
Hier der C++ Code von der Webseite
C-Quellcode
- struct vertex
- {
- FLOAT x, y, z, rhw;
- DWORD color;
- };
- void CDraw::Circle(float x, float y, float radius, int rotate, int type, bool smoothing, int resolution, DWORD color)
- {
- std::vector<vertex> circle(resolution + 2);
- float angle = rotate*D3DX_PI/180;
- float pi;
- if(type == full) pi = D3DX_PI; // Full circle
- if(type == half) pi = D3DX_PI/2; // 1/2 circle
- if(type == quarter) pi = D3DX_PI/4; // 1/4 circle
- for(int i = 0; i < resolution + 2; i++)
- {
- circle[i].x = (float)(x - radius*cos(i*(2*pi/resolution)));
- circle[i].y = (float)(y - radius*sin(i*(2*pi/resolution)));
- circle[i].z = 0;
- circle[i].rhw = 1;
- circle[i].color = color;
- }
- // Rotate matrix
- int _res = resolution + 2;
- for(int i = 0; i < _res; i++)
- {
- circle[i].x = x + cos(angle)*(circle[i].x - x) - sin(angle)*(circle[i].y - y);
- circle[i].y = y + sin(angle)*(circle[i].x - x) + cos(angle)*(circle[i].y - y);
- }
- pDevice->CreateVertexBuffer((resolution + 2) * sizeof(vertex), D3DUSAGE_WRITEONLY, D3DFVF_XYZRHW|D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, &g_pVB, NULL);
- VOID* pVertices;
- g_pVB->Lock(0, (resolution + 2) * sizeof(vertex), (void**)&pVertices, 0);
- memcpy(pVertices, &circle[0], (resolution + 2) * sizeof(vertex));
- g_pVB->Unlock();
- pDevice->SetTexture(0, NULL);
- pDevice->SetPixelShader(NULL);
- if (smoothing)
- {
- pDevice->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE);
- pDevice->SetRenderState(D3DRS_ANTIALIASEDLINEENABLE, TRUE);
- }
- pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
- pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
- pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
- pDevice->SetStreamSource(0, g_pVB, 0, sizeof(vertex));
- pDevice->SetFVF(D3DFVF_XYZRHW|D3DFVF_DIFFUSE);
- pDevice->DrawPrimitive(D3DPT_LINESTRIP, 0, resolution);
- if(g_pVB != NULL) g_pVB->Release();
- }
Nur habe ich ein Problem: Ich weiß nicht wie ich das vertex array in den SharpDX.Direct3D9.VertexBuffer kopieren kann mit C#
Hier mal der C# Code:
C#-Quellcode
- public struct vertex {
- public float x, y, z, rhw;
- public int color;
- };
- public static void DrawCircle(IntPtr device, float x, float y, float radius, int rotate, int type, bool smoothing, int resolution, Color color)
- {
- vertex[] circle = new vertex[resolution + 2];
- circle.Initialize();
- float angle = rotate * (float)Math.PI / 180f;
- float pi = 0f;
- if (type == 0) pi = (float)Math.PI;
- if (type == 1) pi = (float)Math.PI / 2;
- if (type == 2) pi = (float)Math.PI / 4;
- for (int i = 0; i < circle.Length; i++) {
- circle[i].x = (float)(x - radius * Math.Cos(i * (2 * Math.PI / resolution)));
- circle[i].y = (float)(y - radius * Math.Sin(i * (2 * Math.PI / resolution)));
- circle[i].z = 0f;
- circle[i].rhw = 1f;
- circle[i].color = color.ToArgb();
- }
- // Rotate matrix
- int _res = resolution + 2;
- for (int i = 0; i < _res; i++) {
- circle[i].x = (float)(x + Math.Cos(angle) * (circle[i].x - x) - Math.Sin(angle) * (circle[i].y - y));
- circle[i].y = (float)(y + Math.Sin(angle) * (circle[i].x - x) + Math.Cos(angle) * (circle[i].y - y));
- }
- Device d = (Device)device;
- // VertexBuffer Source: https://github.com/sharpdx/SharpDX/blob/master/Source/SharpDX.Direct3D9/VertexBuffer.cs
- VertexBuffer g_pVB = new VertexBuffer(d, (resolution + 2) * Marshal.SizeOf(typeof(vertex)), Usage.WriteOnly, VertexFormat.PositionRhw | VertexFormat.Diffuse, Pool.Managed);
- // DataStream Source: https://github.com/sharpdx/SharpDX/blob/master/Source/SharpDX/DataStream.cs
- DataStream ds = g_pVB.Lock(0, (resolution + 2) * Marshal.SizeOf(typeof(vertex)), LockFlags.None);
- // g_pVB <- circle ?
- g_pVB.Unlock();
- d.SetStreamSource(0, g_pVB, 0, Marshal.SizeOf(typeof(vertex)));
- d.VertexFormat = VertexFormat.PositionRhw | VertexFormat.Diffuse;
- d.DrawPrimitives(PrimitiveType.LineStrip, 0, resolution);
- if (g_pVB != null) g_pVB.Dispose();
- }
Habe leider auch kein Erfolg beim googeln gehabt für SharpDX.Direct3D9...
Ich würde mich sehr über Hilfe von euch freuen! (Ich bin übrigens auf Direct3D9 angewiesen und kann leider nicht upgraden)
Wenn ich dir auf irgendeiner Art und Weise helfen konnte, drück doch bitte den "Hilfreich" Button
Für VB.NET Entwickler: Option Strict On nicht vergessen!
Für VB.NET Entwickler: Option Strict On nicht vergessen!
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „ClonkAndre“ () aus folgendem Grund: Erledigt... DataStream.WriteRange existert...