Autor Beitrag
C#Leon
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Mo 12.05.14 13:52 
Hallo zusammen
Ich habe eine library geschrieben mit dieser lässt sich ein Würfel darstellen der auf jeder der 6 Seite ein anderes Bild hat. Es ist C# Code.
Mit XAML habe ich in VS02012 Prof ein GUI erstellt mit einem Anzeigefeld. Ich habe die library eingefügt und wenn ich auf den Würfel Knopf drücke erscheint der Würfel, mit den 6 Bildern. Es gibt noch einige Funktionen:
Würfel auf der X, Y oder Z- Achse rotieren lassen.
Würfel einblenden.
Würfel ausblenden.
Würfel in die Ausgangsposition zurücksetzen diese Funktionen kann man mit Knöpfen ausführen sie funktionieren alle.
Ich wollte jetzt es so machen das man zwischen 2 Würfeln mit verschiedenen Bildern entscheiden kann.
So habe ich die library kopiert und einige Sachen geändert zu einem heisst die library anders nämlich ClassLibary1. Das private void CreateCube wurde zu private void CreateCube2. Die Änderungen wurden mit rechtsklick refactor geändert. Alles andere ist 1 zu 1 übernommen worden doch es hat nicht funktioniert. Was ich auch nicht erwartet hätte.

Die Lösung mit 2 Bibliotheken ist natürlich sche**** (sorry für dem Ausdruck) es sollte doch möglich sein in der vorhanden Library je nach Knopf druck den Würfel mit den gewünschten Bildern darzustellen, also das der Würfel genau gleich erstellt wird aber das er je nach Knopf über den ersten oder zweiten Pfad auf die Bilder zugreift.
Ich brauche das Programm da es zu einem Teil eines Projektes gehört es ist erlaubt fremden Code zu übernehmen solange man angibt woher man ihn hat. Falls mir jemand den Code schreiben könnet (Überarbeitung meiner bestehenden Lösung) wäre ich auch bereit das zu bezahlen (wenn es funktioniert). Aber ich würde mich auch über eine Hilfe oder einen Tipp freuen wie man das lösen könnte.
Im Anhang findet ihr meine bestehnde Klasse.
Gruss C#Leon
Einloggen, um Attachments anzusehen!
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mo 12.05.14 14:19 
Hallo C#Leon,

also die Grundlagen der Programmierung solltest du beherschen (bevor du so ein Projekt angehst)!

Übergib einfach der CreateCube-Methode die Pfade zu den Bildern als Parameter (anstatt diese hart als Strings zu kodieren).

Was ist das eigentlich für ein Projekt, an dem du jetzt schon Wochen (oder sogar Monate) sitzt?
C#
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 561
Erhaltene Danke: 65

Windows 10, Kubuntu, Android
Visual Studio 2017, C#, C++/CLI, C++/CX, C++, F#, R, Python
BeitragVerfasst: Mo 12.05.14 14:24 
Zwei verschiedene Bibliotheken ist keine gute Idee. Setz den Pfad zum Ordner doch einfach als Parameter im Konstruktor deines Würfels, also:
ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
public Cube(Point3D center, string imagePath)
        {
            // Erstellung erstets 3D Obejekt 
            Name = "cube1";
            meshGroup = new Model3DGroup();
            this.center = center;
            CreateCube(imagePath);

            // Roation um X Achse
            myXRotateTransform3D = new RotateTransform3D();
            myXAxisAngleRotation3d = new AxisAngleRotation3D();
            myXAxisAngleRotation3d.Angle = 0;
            myXRotateTransform3D.Rotation = myXAxisAngleRotation3d;

            // Roation Un Y Achse
            myYRotateTransform3D = new RotateTransform3D();
            myYAxisAngleRotation3d = new AxisAngleRotation3D();
            myYAxisAngleRotation3d.Angle = 0;
            myYRotateTransform3D.Rotation = myYAxisAngleRotation3d;

            // Roation um Z Achse
            myZRotateTransform3D = new RotateTransform3D();
            myZAxisAngleRotation3d = new AxisAngleRotation3D();
            myZAxisAngleRotation3d.Angle = 0;
            myZRotateTransform3D.Rotation = myZAxisAngleRotation3d;

            // Grupireung der Roation um sauberer Derhung zu erhalten
            Transform3DGroup rotate = new Transform3DGroup();
            rotate.Children.Add(myXRotateTransform3D);
            rotate.Children.Add(myYRotateTransform3D);
            rotate.Children.Add(myZRotateTransform3D);
            
            meshGroup.Transform = rotate;


        }

und bei CreateCube dann einfach:
ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
 //Wuerfel erstllung
        private void CreateCube(string imagePath)
        {
            // Punkte im Kordianten system definierung
            Point3D a = new Point3D(center.X - 1, center.Y - 1, center.Z + 1); 
            Point3D b = new Point3D(center.X + 1, center.Y - 1, center.Z + 1); 
            Point3D c = new Point3D(center.X + 1, center.Y + 1, center.Z + 1); 
            Point3D d = new Point3D(center.X - 1, center.Y + 1, center.Z + 1); 
            Point3D e = new Point3D(center.X + 1, center.Y - 1, center.Z - 1); 
            Point3D f = new Point3D(center.X - 1, center.Y - 1, center.Z - 1);
            Point3D g = new Point3D(center.X - 1, center.Y + 1, center.Z - 1); 
            Point3D h = new Point3D(center.X + 1, center.Y + 1, center.Z - 1);

            //Erstellung der Seite1 mit Bild1
            GeometryModel3D front = new GeometryModel3D(BuildRectangle(a, b, c, d, new Vector3D(00, +1)), new DiffuseMaterial(new ImageBrush(new BitmapImage(
                new Uri(Path.Combine(imagePath, "1.jpg"), UriKind.Absolute)))));
            
            //Rückseite der Seite1 mit Bild 1 bestückt
            front.BackMaterial = new DiffuseMaterial(new ImageBrush(new BitmapImage(
                new Uri(Path.Combine(imagePath, "2.jpg"), UriKind.Absolute))));

            //Ertsellung der Seite2 mit Bild2
            GeometryModel3D back = new GeometryModel3D(BuildRectangle(e, f, g, h, new Vector3D(00, -1)), new DiffuseMaterial(new ImageBrush(new BitmapImage(
                new Uri(Path.Combine(imagePath, "2.jpg"), UriKind.Absolute)))));
                
            //Rückseite der Seite2 mit Bild2 bestückt
            back.BackMaterial = new DiffuseMaterial(new ImageBrush(new BitmapImage(
                new Uri(Path.Combine(imagePath, "2.jpg"), UriKind.Absolute))));
            
            //Erstellung der Seite3 mit Bild3
            GeometryModel3D right = new GeometryModel3D(BuildRectangle(b, e, h, c, new Vector3D(100)), new DiffuseMaterial(new ImageBrush(new BitmapImage(
                new Uri(Path.Combine(imagePath, "3.jpg"), UriKind.Absolute)))));
            
            //Rückseite der Seite3 mit Bild3 der bestückt
            right.BackMaterial = new DiffuseMaterial(new ImageBrush(new BitmapImage(
                new Uri(Path.Combine(imagePath, "3.jpg"), UriKind.Absolute))));
                
            //Erstellung der Seite4 mit Bild4
            GeometryModel3D left = new GeometryModel3D(BuildRectangle(f, a, d, g, new Vector3D(-100)), new DiffuseMaterial(new ImageBrush(new BitmapImage(
                new Uri(Path.Combine(imagePath, "4.jpg"), UriKind.Absolute)))));
             
            //Rückseite der Seite4 mit Bild4 der bestückt
            left.BackMaterial = new DiffuseMaterial(new ImageBrush(new BitmapImage(
                new Uri(Path.Combine(imagePath, "4.jpg"), UriKind.Absolute))));
                
            //Erstellung der Seite5 mit Bild5
            GeometryModel3D bottom = new GeometryModel3D(BuildRectangle(e, b, a, f, new Vector3D(0, -10)), new DiffuseMaterial(new ImageBrush(new BitmapImage(
                new Uri(Path.Combine(imagePath, "5.jpg"), UriKind.Absolute)))));
               
            //Rückseite der Seite5 mit Bild5 bestückt
            bottom.BackMaterial = new DiffuseMaterial(new ImageBrush(new BitmapImage(
                new Uri(Path.Combine(imagePath, "5.jpg"), UriKind.Absolute))));
                
           //Erstellung der Seite6 mit Bild6
            GeometryModel3D top = new GeometryModel3D(BuildRectangle(d, c, h, g, new Vector3D(010)), new DiffuseMaterial(new ImageBrush(new BitmapImage(
                new Uri(Path.Combine(imagePath, "6.jpg"), UriKind.Absolute)))));

            //Rückseite der Seite6 mit Bild6 bestückt
            top.BackMaterial = new DiffuseMaterial(new ImageBrush(new BitmapImage(
                new Uri(Path.Combine(imagePath, "6.jpg"), UriKind.Absolute))));
                
            
            // Seite für den betrachter definierung
            meshGroup.Children.Add(front);
            meshGroup.Children.Add(back);
            meshGroup.Children.Add(right);
            meshGroup.Children.Add(left);
            meshGroup.Children.Add(bottom);
            meshGroup.Children.Add(top);

            this.Content = meshGroup;
        }


Und beim erstellen des Würfels (außerhalb deiner Library):
ausblenden C#-Quelltext
1:
2:
3:
...
Cube cube1 = new Cube(new Point3D(0,0,0), @"C:\Users\hagger\Pictures\IPA\vercicle");
Cube cube2 = new Cube(new Point3D(0,0,0), @"C:\Users\hagger\Pictures\WAS\AUCH\IMMER");

_________________
Der längste Typ-Name im .NET-Framework ist: ListViewVirtualItemsSelectionRangeChangedEventHandler

Für diesen Beitrag haben gedankt: C#Leon
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mo 12.05.14 14:57 
Ja genau so habe ich auch meine Antwort gemeint.
Aber fest-verdrahtete Pfade (insbesondere zu User-Verzeichnissen) sollten im Sourcecode nichts verloren haben - entweder aus einer Konfigurationsdatei und/oder über einen OpenfileDialog oder aber mittels z.B. Getting the application's directory from a WPF application o.ä.
C#
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 561
Erhaltene Danke: 65

Windows 10, Kubuntu, Android
Visual Studio 2017, C#, C++/CLI, C++/CX, C++, F#, R, Python
BeitragVerfasst: Mo 12.05.14 15:05 
Ja war an meiner Antwort gerade dran als du deine geschrieben hast. Dachte, wenn ich schon dabei bin mach ichs fertig :D

_________________
Der längste Typ-Name im .NET-Framework ist: ListViewVirtualItemsSelectionRangeChangedEventHandler
C#Leon Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Mo 12.05.14 15:17 
Danke dir für den Code.

Gruss C#Leon