Hallo
Ich arbeite derzeit an einem Rubiks Cube Solver und würde gerne eine 3D Darstellung des Würfels in mein Programm einbringnen. Die 3D-Würfel soll ungefähr in dieser Form dargestellt werden:
Ich habe erste Versuche mit GDI gewagt und bin mit einer Transformationsmatrix auf folgendes Ergebnis gestoßen:
Mit der Up-Fläche hat das ganz gut geklappt. Bei der Right-Ebene komme ich jedoch nicht mehr weiter. Ich habe mal einen Ansatz gemacht:
Das Ergebnis schaut nicht sehr vielversprechend aus:
Ist es überhaupt möglich mit GDI komfortabel 3D-Würfel zu zeichnen oder habe ich einen komplett falschen Ansatz
Hier zur Sicherheit noch der Code der gesamten Methode:
Danke
Switcherlapp97
Ich arbeite derzeit an einem Rubiks Cube Solver und würde gerne eine 3D Darstellung des Würfels in mein Programm einbringnen. Die 3D-Würfel soll ungefähr in dieser Form dargestellt werden:
Ich habe erste Versuche mit GDI gewagt und bin mit einer Transformationsmatrix auf folgendes Ergebnis gestoßen:
C#-Quellcode
- //bl = Blocklänge
- //br SolidBrush mit der Farbe der Fläche
- //b ist ein Block-Objekt; X,Y und Z beschreiben die Position des Blocks
- br.Color = GetColor(b.BlockColors[0]);
- int x = 3 * bl + b.X * bl - bl;
- int y = bl + b.Z * bl / 2 - bl/2;
- Matrix m = new Matrix();
- m.Shear(-1, 0);
- g.Transform = m;
- g.FillRectangle(br, x, y, bl, bl / 2);
- g.DrawRectangle(Pens.Black, x, y, bl, bl / 2);
Mit der Up-Fläche hat das ganz gut geklappt. Bei der Right-Ebene komme ich jedoch nicht mehr weiter. Ich habe mal einen Ansatz gemacht:
Das Ergebnis schaut nicht sehr vielversprechend aus:
Ist es überhaupt möglich mit GDI komfortabel 3D-Würfel zu zeichnen oder habe ich einen komplett falschen Ansatz
Hier zur Sicherheit noch der Code der gesamten Methode:
C#-Quellcode
- public void Draw3DTop(Graphics g, int BlockHeight)
- {
- int bl = BlockHeight;
- SolidBrush br = new SolidBrush(Color.Black);
- foreach (Block b in Blocks)
- {
- //Up
- if (b.Y == 3)
- {
- br.Color = GetColor(b.BlockColors[0]);
- int x = 3 * bl + b.X * bl - bl;
- int y = bl + b.Z * bl / 2 - bl/2;
- Matrix m = new Matrix();
- m.Shear(-1, 0, MatrixOrder.Append);
- g.Transform = m;
- g.FillRectangle(br, x, y, bl, bl / 2);
- g.DrawRectangle(Pens.Black, x, y, bl, bl / 2);
- }
- //Right
- if (b.X == 3)
- {
- br.Color = GetColor(b.BlockColors[2]);
- int x = 6 * bl - b.Y * bl / 2;
- int y = 7 * bl - b.Z * bl;
- Matrix m = new Matrix();
- m.Rotate(-45);
- m.Shear(-1, 0);
- g.Transform = m;
- g.FillRectangle(br, x, y, bl / 2, bl);
- g.DrawRectangle(Pens.Black, x, y, bl / 2, bl);
- }
- }
- }
Danke
Switcherlapp97
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „Switcherlapp97“ ()