C#Leon
      
Beiträge: 16
|
Verfasst: Fr 27.06.14 11:30
Hallo zusammen
Ich habe ein Programm geschrieben das eingesetzt wird um bei Besuchstagen (Tag der offen Türe) unsere Projekte vorzustellen. Es werden auf einem 3D Würfel dargestellt mit Bilder der Projekte die wir führen, da der zutritt zu den Projekten verboten ist. Nun wurde mit mitgeteilt das die Bilder vergrössern oder verkleinern sollte. Ich möchte gerne den Würfel vergrössern/verkleinern über die Position="9,10,9" . Wie kann ich die Position ändern über 2 Knöpfe einen Vergösserungs und einen Verkleinerungs Knopf. Die max Position soll 4,5,4 sein das die min soll 9,10,9 sein.
Ich habe es probiert mit einem Binding nur leider ist mir nicht gelungen, könnte mir jemand dabei helfen das Beispiel aus msdn hat mir nicht geholfen.
War mein Ansatz richtig oder hat jemand einer besseren Lösung für das meine Projekt.
Ich würde das Programm auch anders schreiben oder so aber ich habe strikte Vorgaben wie es gelöst werden muss.
Alles wurde mit VS 2012 Prof geschrieben das Programm läuft auf Win 7, win 8 und auf Tablets mit win 8.1. 32 bit oder 64 bit alles perfekt.
Hier ist der Code:
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:
| using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Windows.Media.Media3D; using Cube3DLib;
namespace Cube3D { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); }
Cube cube1; int PN = 0; private void Button_Click_8(object sender, RoutedEventArgs e) { Cube_Port.Children.Remove(cube1); cube1 = new Cube3DLib.Cube(new Point3D(0, 0, 0), @"ProjektBilder\MenschimBüro"); Cube_Port.Children.Add(cube1); PN = 1; }
private void Button_Click_6(object sender, RoutedEventArgs e) { Cube_Port.Children.Remove(cube1); cube1 = new Cube3DLib.Cube(new Point3D(0, 0, 0), @"ProjektBilder\vercicle"); Cube_Port.Children.Add(cube1); PN = 2; }
private void Button_Click_7(object sender, RoutedEventArgs e) { Cube_Port.Children.Remove(cube1); cube1 = new Cube3DLib.Cube(new Point3D(0, 0, 0), @"ProjektBilder\DynamicsHumaKnee"); Cube_Port.Children.Add(cube1); PN = 3; }
private void Button_Click_1(object sender, RoutedEventArgs e) { cube1.RotateY(); Textbox2.Clear(); }
private void Button_Click_2(object sender, RoutedEventArgs e) { cube1.RotateZ(); Textbox2.Clear(); } private void RepeatButton_Click_1(object sender, RoutedEventArgs e) { cube1.RotateX(); Textbox2.Clear(); }
private void Button_Click(object sender, RoutedEventArgs e) { Textbox.Text = "Willommen wählen sie einer der 3 Würfel. Um den Würfel aud der X, Y oder Z Achse rotieren zu lassen halten sie den Knopf gedrückt. Alle anderen Funktionen können gestaretet werden wenn sie einmal auf den Knopf drücken."; Textbox2.Clear(); }
private void Button_Click_3(object sender, RoutedEventArgs e) { switch (PN) { case 1: Cube_Port.Children.Remove(cube1); cube1 = new Cube3DLib.Cube(new Point3D(0, 0, 0), @"ProjektBilder\MenschimBüro"); Cube_Port.Children.Add(cube1); PN = 1; break;
case 2: Cube_Port.Children.Remove(cube1); cube1 = new Cube3DLib.Cube(new Point3D(0, 0, 0), @"ProjektBilder\vercicle"); Cube_Port.Children.Add(cube1); PN = 2; break;
case 3: Cube_Port.Children.Remove(cube1); cube1 = new Cube3DLib.Cube(new Point3D(0, 0, 0), @"ProjektBilder\DynamicsHumaKnee"); Cube_Port.Children.Add(cube1); PN = 3; break;
default:
Textbox2.Text = " Es muss ein Würfel dargestllt werden um ihn in die Ausgangspostion zu setzen."; break;
}
}
private void Button_Click_4(object sender, RoutedEventArgs e) { Cube_Port.Children.Remove(cube1); Textbox2.Clear();
} private void Button_Click_5(object sender, RoutedEventArgs e) { try { Cube_Port.Children.Add(cube1); }
catch (ArgumentException) { Textbox2.Text = "Nicht mehr als ein Würfel!"; } }
private void Button_Click_9(object sender, RoutedEventArgs e) { Textbox2.Clear(); }
private void Button_Click_10(object sender, RoutedEventArgs e) { Textbox2.Clear(); Textbox2.Text = "Diese Funktion funktioniert noch nicht"; }
private void Textbox2_TextChanged(object sender, TextChangedEventArgs e) {
} } } |
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: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210:
| 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; using System.IO;
namespace Cube3DLib { public class Cube : ModelVisual3D { Model3DGroup meshGroup; RotateTransform3D myXRotateTransform3D; RotateTransform3D myYRotateTransform3D; RotateTransform3D myZRotateTransform3D; AxisAngleRotation3D myXAxisAngleRotation3d; AxisAngleRotation3D myYAxisAngleRotation3d; AxisAngleRotation3D myZAxisAngleRotation3d; Point3D center;
public Cube(Point3D center, string imagePath) { Name = "cube1"; meshGroup = new Model3DGroup(); this.center = center; CreateCube(imagePath);
myXRotateTransform3D = new RotateTransform3D(); myXAxisAngleRotation3d = new AxisAngleRotation3D(); myXAxisAngleRotation3d.Angle = 40; myXRotateTransform3D.Rotation = myXAxisAngleRotation3d;
myYRotateTransform3D = new RotateTransform3D(); myYAxisAngleRotation3d = new AxisAngleRotation3D(); myYAxisAngleRotation3d.Angle = 0; myYRotateTransform3D.Rotation = myYAxisAngleRotation3d;
myZRotateTransform3D = new RotateTransform3D(); myZAxisAngleRotation3d = new AxisAngleRotation3D(); myZAxisAngleRotation3d.Angle = 0; myZRotateTransform3D.Rotation = myZAxisAngleRotation3d;
Transform3DGroup rotate = new Transform3DGroup(); rotate.Children.Add(myXRotateTransform3D); rotate.Children.Add(myYRotateTransform3D); rotate.Children.Add(myZRotateTransform3D); meshGroup.Transform = rotate;
}
public void RotateX() { myXAxisAngleRotation3d.Axis = new Vector3D(0, 3, 0); myXAxisAngleRotation3d.Angle = myXAxisAngleRotation3d.Angle + 15; }
public void RotateY() { myYAxisAngleRotation3d.Axis = new Vector3D(3, 0, 0); myYAxisAngleRotation3d.Angle = myYAxisAngleRotation3d.Angle + 15; }
public void RotateZ() { myZAxisAngleRotation3d.Axis = new Vector3D(0, 0, 3); myZAxisAngleRotation3d.Angle = myZAxisAngleRotation3d.Angle + 15; } public string Name { get; set; }
private void CreateCube(string imagePath) { 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);
GeometryModel3D front = new GeometryModel3D(BuildRectangle(a, b, c, d, new Vector3D(0, 0, +1)), new DiffuseMaterial(new ImageBrush(new BitmapImage( new Uri(Path.Combine(imagePath, "1.jpg"), UriKind.Relative)))));
front.BackMaterial = new DiffuseMaterial(new ImageBrush(new BitmapImage( new Uri(Path.Combine(imagePath, "1.jpg"), UriKind.Relative))));
GeometryModel3D back = new GeometryModel3D(BuildRectangle(e, f, g, h, new Vector3D(0, 0, -1)), new DiffuseMaterial(new ImageBrush(new BitmapImage( new Uri(Path.Combine(imagePath, "2.Jpg"), UriKind.Relative)))));
back.BackMaterial = new DiffuseMaterial(new ImageBrush(new BitmapImage( new Uri(Path.Combine(imagePath, "2.jpg"), UriKind.Relative))));
GeometryModel3D right = new GeometryModel3D(BuildRectangle(b, e, h, c, new Vector3D(1, 0, 0)), new DiffuseMaterial(new ImageBrush(new BitmapImage( new Uri(Path.Combine(imagePath, "3.jpg"), UriKind.Relative)))));
right.BackMaterial = new DiffuseMaterial(new ImageBrush(new BitmapImage( new Uri(Path.Combine(imagePath, "3.jpg"), UriKind.Relative))));
GeometryModel3D left = new GeometryModel3D(BuildRectangle(f, a, d, g, new Vector3D(-1, 0, 0)), new DiffuseMaterial(new ImageBrush(new BitmapImage( new Uri(Path.Combine(imagePath, "4.jpg"), UriKind.Relative)))));
left.BackMaterial = new DiffuseMaterial(new ImageBrush(new BitmapImage( new Uri(Path.Combine(imagePath, "4.jpg"), UriKind.Relative))));
GeometryModel3D bottom = new GeometryModel3D(BuildRectangle(e, b, a, f, new Vector3D(0, -1, 0)), new DiffuseMaterial(new ImageBrush(new BitmapImage( new Uri(Path.Combine(imagePath, "5.jpg"), UriKind.Relative)))));
bottom.BackMaterial = new DiffuseMaterial(new ImageBrush(new BitmapImage( new Uri(Path.Combine(imagePath, "5.jpg"), UriKind.Relative))));
GeometryModel3D top = new GeometryModel3D(BuildRectangle(d, c, h, g, new Vector3D(0, 1, 0)), new DiffuseMaterial(new ImageBrush(new BitmapImage( new Uri(Path.Combine(imagePath, "6.jpg"), UriKind.Relative)))));
top.BackMaterial = new DiffuseMaterial(new ImageBrush(new BitmapImage( new Uri(Path.Combine(imagePath, "6.jpg"), UriKind.Relative)))); 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; }
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);
geometry.TextureCoordinates.Add(new Point(0, 1)); geometry.TextureCoordinates.Add(new Point(1, 1)); geometry.TextureCoordinates.Add(new Point(1, 0)); geometry.TextureCoordinates.Add(new Point(0, 0));
geometry.Normals.Add(normal); geometry.Normals.Add(normal); geometry.Normals.Add(normal); geometry.Normals.Add(normal);
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; } } } |
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:
| <Window x:Class="Cube3D.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" Title="Würfel mit Bildern" Height="372.072" Width="825.066" Background="Gray" WindowState="Maximized"> <Grid Margin="0,0,-164,-8" HorizontalAlignment="Left" Width="847" Height="350" VerticalAlignment="Bottom"> <Grid.ColumnDefinitions> <ColumnDefinition Width="113*"/> <ColumnDefinition Width="569*"/> <ColumnDefinition Width="165*"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="182*"/> <RowDefinition Height="71*"/> <RowDefinition Height="67*"/> </Grid.RowDefinitions> <Grid Background="Black" Height="1145" VerticalAlignment="Top" HorizontalAlignment="Left" Width="1066" Grid.RowSpan="3" Grid.ColumnSpan="3" Margin="0,-805,-219,0"> <Grid.ColumnDefinitions> <ColumnDefinition Width="187*"/> <ColumnDefinition Width="226*"/> </Grid.ColumnDefinitions> <Viewport3D x:Name="Cube_Port" Grid.ColumnSpan="2" RenderTransformOrigin="0.462,0.499" Margin="0,-13,0,251"> <Viewport3D.Camera> <PerspectiveCamera x:Name="camera1" Position="9,10,9" LookDirection="-10,-10,-10" UpDirection="0,1,0" FieldOfView="45" NearPlaneDistance="1" FarPlaneDistance="100"/> </Viewport3D.Camera>
<ModelVisual3D> <ModelVisual3D.Content> <Model3DGroup> <AmbientLight Color="White" /> <DirectionalLight Color="White" Direction="-5,-5,-7" > <DirectionalLight.Transform> <Transform3DGroup> <TranslateTransform3D OffsetZ="0" OffsetX="0" OffsetY="0"/> <ScaleTransform3D ScaleZ="1" ScaleY="1" ScaleX="1"/> <RotateTransform3D d:EulerAngles="159.111,27.715,159.328"> <RotateTransform3D.Rotation> <AxisAngleRotation3D Axis="0.133,0.982,0.136" Angle="149.468"/> </RotateTransform3D.Rotation> </RotateTransform3D> <TranslateTransform3D OffsetZ="0" OffsetX="0" OffsetY="0"/> <TranslateTransform3D OffsetZ="-3.41" OffsetX="2.673" OffsetY="3.57"/> </Transform3DGroup> </DirectionalLight.Transform> </DirectionalLight> </Model3DGroup> </ModelVisual3D.Content> </ModelVisual3D>
</Viewport3D> </Grid>
<RepeatButton Delay="500" Interval="100" Content=" Rotation Y-Achse" HorizontalAlignment="Left" Margin="744,-184,-693,0" VerticalAlignment="Top" Width="114" Click="Button_Click_1" Grid.Column="2" Height="59"/> <RepeatButton Delay="500" Interval="100" Content=" Rotation Z-Achse" HorizontalAlignment="Left" VerticalAlignment="Top" Width="114" Click="Button_Click_2" Grid.Column="2" Margin="744,-79,-693,0" Height="59"/> <RepeatButton Content="Rotation X-Achse" Delay="500" Interval="100" HorizontalAlignment="Left" Margin="744,-266,-693,0" VerticalAlignment="Top" Width="114" Click="RepeatButton_Click_1" Grid.Column="2" Height="59" /> <Button Content="Help" Grid.Column="2" HorizontalAlignment="Left" Margin="444,-626,-454,0" VerticalAlignment="Top" Width="175" Click="Button_Click" Height="59"/> <TextBox Grid.Column="2" HorizontalAlignment="Left" Height="53" Margin="444,-529,-444,0" TextWrapping="Wrap" Text="Willkommen benützen sie die Knöpfe um den Würfel zu steuern." VerticalAlignment="Top" Width="165" Name="Textbox"> <TextBox.RenderTransform> <TransformGroup> <ScaleTransform/> <SkewTransform/> <RotateTransform Angle="-0.098"/> <TranslateTransform/> </TransformGroup> </TextBox.RenderTransform> </TextBox> <Button Content="Wüefel verkleinern" Grid.Column="2" HorizontalAlignment="Left" Margin="444,-184,-416,0" VerticalAlignment="Top" Width="137" Click="Button_Click_9" Height="59"/> <Button Content="Würfel ausblenden" Grid.Column="2" HorizontalAlignment="Left" Margin="444,-79,-416,0" VerticalAlignment="Top" Width="137" Click="Button_Click_4" Height="59"/> <Button Content="Reset" Grid.Column="2" HorizontalAlignment="Left" Margin="445,123,-416,0" VerticalAlignment="Top" Width="136" Click="Button_Click_3" Height="59"/> <Button Content="Würfel einblenden" Grid.Column="2" HorizontalAlignment="Left" Margin="445,24,-416,0" VerticalAlignment="Top" Width="136" Click="Button_Click_5" Height="59"/> <TextBox Grid.Column="2" HorizontalAlignment="Left" Height="133" Margin="433,-444,-535,0" TextWrapping="Wrap" Text="Fehler Meldungen" VerticalAlignment="Top" Width="267" Name="Textbox2"/> <Button Content="Projekt eins" Grid.Column="2" HorizontalAlignment="Left" Margin="755,-626,-704,0" VerticalAlignment="Top" Width="114" Click="Button_Click_6" Height="59"/> <Button Content="Projekt zwei" Grid.Column="2" HorizontalAlignment="Left" Margin="755,-531,-704,0" VerticalAlignment="Top" Width="114" Click="Button_Click_7" Height="59"/> <Button Content="Projekt drei" Grid.Column="2" HorizontalAlignment="Left" Margin="755,-444,-704,0" VerticalAlignment="Top" Width="114" Click="Button_Click_8" Height="59"/> <Button Content="Würfel vergrösseren" Grid.Column="2" HorizontalAlignment="Left" Margin="445,-266,-416,0" VerticalAlignment="Top" Width="136" Click="Button_Click_9" Height="59"/>
</Grid> </Window> |
Danke für Tipps und so,
Gruss Leon Moderiert von Th69: Topic aus Multimedia / Grafik verschoben am Fr 27.06.2014 um 11:33
|