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



BeitragVerfasst: Di 06.05.14 15:52 
Hallo Leute

Ich hab einen Würfel den ich rotieren lassen kann. Ich möchte ihn ausblenden können und dann wieder einblenden aber er soll die selber Position haben als ich ihn ausgeblendet habe, dass soll nach einem Knopf-Druck funktionieren wer kann mir helfen? Der Code dafür wäre ganz nett.
Danke.

Gruss Leon
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4708
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Di 06.05.14 15:56 
Zitat:
Der Code dafür wäre ganz nett.


Wenn du das nicht lernen möchtest sondern lieber gemacht haben willst solltest du dein Angebot besser im Jobforum stellen.
Und wenn du das doch lieber lernen möchtest dann zeig uns was du im Moment hast, was du probiert hast, und woran du konkret hängst.
C#Leon Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Di 06.05.14 16:09 
Ja tut mir leid. Also ich habe einen Würfel den ich rotieren lassen kann auf den Achsen X, Y und Z. Wenn ich ihn z.B rotiere und der Würfel mir eine Seite zudreht und ich ihn nachher ausblenden möchte und dann wieder einblende soll er mir immer noch die selbe Seite zugedreht haben. Kann mir jemand einen Tipp geben wie das funktioniert.
Das GUI habe ich in mit WPF erstellt.

Hier ist der Code des Würfels:

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:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media.Media3D;
using System.Windows.Media;
using System.Windows;
using System.Windows.Media.Imaging;

namespace Cube3DLib
{
    public class Cube : ModelVisual3D
    {
        Model3DGroup meshGroup;
        RotateTransform3D myXRotateTransform3D;
        RotateTransform3D myYRotateTransform3D;
        RotateTransform3D myZRotateTransform3D;
        
        // Roation X Achse
        AxisAngleRotation3D myXAxisAngleRotation3d;
        //Roation Y Achse
        AxisAngleRotation3D myYAxisAngleRotation3d;
        // Roation Z Achse
        AxisAngleRotation3D myZAxisAngleRotation3d;
        

        //Zentrum des 3D Objektes
        Point3D center;


        public Cube(Point3D center)
        {
            Name = "cube1";
            meshGroup = new Model3DGroup();
            this.center = center;
            CreateCube();

            // 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;


        }

        

        // X Roatation  
        public void RotateX()
        {
            // Angabe auf welcher Achse der würfel rotiert
            myXAxisAngleRotation3d.Axis = new Vector3D(030);
            // Angabe um wie viel grad und auf welche Seite der Würfel drehen soll.
            myXAxisAngleRotation3d.Angle = myXAxisAngleRotation3d.Angle + 15;
        }


        // Y Rotation 
        public void RotateY()
        {
            // Angabe auf welcher Achse der würfel rotiert
            myYAxisAngleRotation3d.Axis = new Vector3D(300);
            // Angabe um wie viel grad und auf welche Seite der Würfel drehen soll.
            myYAxisAngleRotation3d.Angle = myYAxisAngleRotation3d.Angle + 15;
        }

        // Z Rotation
        public void RotateZ()
        {
            // Angabe auf welcher Achse der würfel rotiert
            myZAxisAngleRotation3d.Axis = new Vector3D(003);
            // Angabe um wie viel grad und auf welche Seite der Würfel drehen soll.
            myZAxisAngleRotation3d.Angle = myZAxisAngleRotation3d.Angle + 15;
       }
        

        public string Name { get; set; }

        // Wuerfel erstllung
        private void CreateCube()
        {
            // Ounkte 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 seiten mit farbe und vector
            GeometryModel3D front = new GeometryModel3D(BuildRectangle(a, b, c, d, new Vector3D(00, +1)), new DiffuseMaterial(new SolidColorBrush(
               Colors.Red))); 
             front.BackMaterial = new DiffuseMaterial(new SolidColorBrush(
                Colors.Red));

            GeometryModel3D back = new GeometryModel3D(BuildRectangle(e, f, g, h, new Vector3D(00, -1)), new DiffuseMaterial(new SolidColorBrush(
                Colors.Green)));
            // Einfärben der rückseite
            back.BackMaterial = new DiffuseMaterial(new SolidColorBrush(
                Colors.Green));
            // erstellung der seiten mit farbe und vector
            GeometryModel3D right = new GeometryModel3D(BuildRectangle(b, e, h, c, new Vector3D(100)), new DiffuseMaterial(new SolidColorBrush(
                Colors.Yellow)));
            // Einfärben der rückseite
            right.BackMaterial = new DiffuseMaterial(new SolidColorBrush(
                Colors.Yellow));
            // erstellung der seiten mit farbe und vector
            GeometryModel3D left = new GeometryModel3D(BuildRectangle(f, a, d, g, new Vector3D(-100)), new DiffuseMaterial(new SolidColorBrush(
                Colors.Orange)));
            // Einfärben der rückseite
            left.BackMaterial = new DiffuseMaterial(new SolidColorBrush(
                Colors.Orange));
            // erstellung der seiten mit farbe und vector
            GeometryModel3D bottom = new GeometryModel3D(BuildRectangle(e, b, a, f, new Vector3D(0, -10)), new DiffuseMaterial(new SolidColorBrush(
                Colors.Silver)));
            // Einfärben der rückseite
            bottom.BackMaterial = new DiffuseMaterial(new SolidColorBrush(
                Colors.Silver));
            // erstellung der seiten mit farbe und vector
            GeometryModel3D top = new GeometryModel3D(BuildRectangle(d, c, h, g, new Vector3D(010)), new DiffuseMaterial(new SolidColorBrush(
                Colors.Blue)));
            // Einfärben der rückseite
            top.BackMaterial = new DiffuseMaterial(new SolidColorBrush(
                Colors.Blue));
            
            // 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;
        }
        

        // Dreieckerstellung
        private MeshGeometry3D BuildRectangle(Point3D a, Point3D b, Point3D c, Point3D d, Vector3D normal)
        {
            MeshGeometry3D geometry = new MeshGeometry3D();
            int baseIndex = geometry.Positions.Count;

            geometry.Positions.Add(a);
            geometry.Positions.Add(b);
            geometry.Positions.Add(c);
            geometry.Positions.Add(d);

            // Farbverlauf falls erwuenscht es muessten 2 Farben vorhanden sein
            //geometry.TextureCoordinates.Add(new Point(0, 0));
            //geometry.TextureCoordinates.Add(new Point(0, 0));
            //geometry.TextureCoordinates.Add(new Point(0, 0));
            //geometry.TextureCoordinates.Add(new Point(0, 0));

            // Nomrlaverbindung 
            geometry.Normals.Add(normal);
            geometry.Normals.Add(normal);
            geometry.Normals.Add(normal);
            geometry.Normals.Add(normal);

            // Die Folge wei die 3 eckpunckte für die Dreicke ertslllt werden.
            geometry.TriangleIndices.Add(baseIndex + 0);
            geometry.TriangleIndices.Add(baseIndex + 1);
            geometry.TriangleIndices.Add(baseIndex + 3);
            geometry.TriangleIndices.Add(baseIndex + 1);
            geometry.TriangleIndices.Add(baseIndex + 2);
            geometry.TriangleIndices.Add(baseIndex + 3);

            return geometry;
        }
    }
}


Danke.

Gruss Leon

Moderiert von user profile iconTh69: Vollzitat entfernt.
Moderiert von user profile iconTh69: Doppelposting entfernt.