Click here to Skip to main content
15,905,785 members
Home / Discussions / WPF
   

WPF

 
QuestionViewing Design Time Data in Visual Studio 2008 Cider Designer in WPF and Silverlight Projects Pin
User 27100911-Oct-08 11:47
User 27100911-Oct-08 11:47 
GeneralWPF Mediaelement and stream Pin
prasad00711-Oct-08 1:18
prasad00711-Oct-08 1:18 
GeneralRe: WPF Mediaelement and stream Pin
Syed Mehroz Alam11-Oct-08 4:11
Syed Mehroz Alam11-Oct-08 4:11 
QuestionCreating user control for WPF Pin
Charith Jayasundara10-Oct-08 16:03
Charith Jayasundara10-Oct-08 16:03 
AnswerRe: Creating user control for WPF Pin
User 27100911-Oct-08 11:51
User 27100911-Oct-08 11:51 
GeneralRe: Creating user control for WPF Pin
Charith Jayasundara11-Oct-08 15:33
Charith Jayasundara11-Oct-08 15:33 
GeneralRe: Creating user control for WPF Pin
User 27100911-Oct-08 15:38
User 27100911-Oct-08 15:38 
QuestionHow to create a stacked of 3 images that can be rotated and zoomed in WPF Pin
garlover8-Oct-08 15:46
garlover8-Oct-08 15:46 
I'm new to WPF. I'm trying to create an application that displays 3 images stacked on top of one another. The images shall be zoomable and rotateable just like in 3D. I wonder how to achieve this.

What I have done is I have created 3 mesh surfaces stacked on top of one another in 3D using Viewport3D and GeometryModel3D. It's based on a sample program I got from the internet. I haven't figured out how to paint images on the 3 surfaces.

For zooming and rotating, this code uses Transform3DGroup. It's working like a charm.

My final product will have to also have 3D markers scattered on the 3 images and when the user clicks on a marker, some tips shall be displayed. I'm not so concerned about this feature yet as it's a good to have, not must have. I need to get the foundation right first before adding this fancy feature.


Before I continue down this path, I wonder if I'm on the right track.

Any suggestions would be appreciated.

Here's my code:



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.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using System.Windows.Media.Media3D;

namespace Wpf3DTest {

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {

private GeometryModel3D mGeometry;
private bool mDown;
private Point mLastPos;

public MainWindow() {
InitializeComponent();

BuildSolid();
}

private void BuildSolid() {
// Define 3D mesh object
MeshGeometry3D mesh = new MeshGeometry3D();

mesh.Positions.Add(new Point3D(-1, -1, 1));
mesh.Positions.Add(new Point3D(1, -1, 1));
mesh.Positions.Add(new Point3D(-1, -1, -1));
mesh.Positions.Add(new Point3D(1, -1, -1));

mesh.Positions.Add(new Point3D(-1, 0, 1));
mesh.Positions.Add(new Point3D(1, 0, 1));
mesh.Positions.Add(new Point3D(-1, 0, -1));
mesh.Positions.Add(new Point3D(1, 0, -1));


mesh.Positions.Add(new Point3D(-1, 1, 1));
mesh.Positions.Add(new Point3D(1, 1, 1));
mesh.Positions.Add(new Point3D(-1, 1, -1));
mesh.Positions.Add(new Point3D(1, 1, -1));

//mesh.Positions.Add(new Point3D(-0.5, -0.5, 1));
//mesh.Normals.Add(new Vector3D(0, 0, 1));
//mesh.Positions.Add(new Point3D(0.5, -0.5, 1));
//mesh.Normals.Add(new Vector3D(0, 0, 1));
//mesh.Positions.Add(new Point3D(0.5, 0.5, 1));
//mesh.Normals.Add(new Vector3D(0, 0, 1));
//mesh.Positions.Add(new Point3D(-0.5, 0.5, 1));
//mesh.Normals.Add(new Vector3D(0, 0, 1));

//mesh.Positions.Add(new Point3D(-1, -1, -1));
//mesh.Normals.Add(new Vector3D(0, 0, -1));
//mesh.Positions.Add(new Point3D(1, -1, -1));
//mesh.Normals.Add(new Vector3D(0, 0, -1));
//mesh.Positions.Add(new Point3D(1, 1, -1));
//mesh.Normals.Add(new Vector3D(0, 0, -1));
//mesh.Positions.Add(new Point3D(-1, 1, -1));
//mesh.Normals.Add(new Vector3D(0, 0, -1));

//my code for the bottom face
mesh.TriangleIndices.Add(0);
mesh.TriangleIndices.Add(1);
mesh.TriangleIndices.Add(3);
mesh.TriangleIndices.Add(3);
mesh.TriangleIndices.Add(2);
mesh.TriangleIndices.Add(0);

mesh.TriangleIndices.Add(4);
mesh.TriangleIndices.Add(5);
mesh.TriangleIndices.Add(7);
mesh.TriangleIndices.Add(7);
mesh.TriangleIndices.Add(6);
mesh.TriangleIndices.Add(4);


mesh.TriangleIndices.Add(8);
mesh.TriangleIndices.Add(9);
mesh.TriangleIndices.Add(11);
mesh.TriangleIndices.Add(11);
mesh.TriangleIndices.Add(10);
mesh.TriangleIndices.Add(8);

/*
// Front face
mesh.TriangleIndices.Add(0);
mesh.TriangleIndices.Add(1);
mesh.TriangleIndices.Add(2);
mesh.TriangleIndices.Add(2);
mesh.TriangleIndices.Add(3);
mesh.TriangleIndices.Add(0);

// Back face
mesh.TriangleIndices.Add(6);
mesh.TriangleIndices.Add(5);
mesh.TriangleIndices.Add(4);
mesh.TriangleIndices.Add(4);
mesh.TriangleIndices.Add(7);
mesh.TriangleIndices.Add(6);

// Right face
mesh.TriangleIndices.Add(1);
mesh.TriangleIndices.Add(5);
mesh.TriangleIndices.Add(2);
mesh.TriangleIndices.Add(5);
mesh.TriangleIndices.Add(6);
mesh.TriangleIndices.Add(2);

// Top face
mesh.TriangleIndices.Add(2);
mesh.TriangleIndices.Add(6);
mesh.TriangleIndices.Add(3);
mesh.TriangleIndices.Add(3);
mesh.TriangleIndices.Add(6);
mesh.TriangleIndices.Add(7);

// Bottom face
mesh.TriangleIndices.Add(5);
mesh.TriangleIndices.Add(1);
mesh.TriangleIndices.Add(0);
mesh.TriangleIndices.Add(0);
mesh.TriangleIndices.Add(4);
mesh.TriangleIndices.Add(5);

// Right face
mesh.TriangleIndices.Add(4);
mesh.TriangleIndices.Add(0);
mesh.TriangleIndices.Add(3);
mesh.TriangleIndices.Add(3);
mesh.TriangleIndices.Add(7);
mesh.TriangleIndices.Add(4);
*/
// Geometry creation
mGeometry = new GeometryModel3D(mesh, new DiffuseMaterial(Brushes.YellowGreen));
mGeometry.Transform = new Transform3DGroup();
group.Children.Add(mGeometry);
}

private void Grid_MouseWheel(object sender, MouseWheelEventArgs e) {
camera.Position = new Point3D(camera.Position.X, camera.Position.Y, camera.Position.Z - e.Delta / 250D);
}

private void Button_Click(object sender, RoutedEventArgs e) {
camera.Position = new Point3D(camera.Position.X, camera.Position.Y, 5);
mGeometry.Transform = new Transform3DGroup();
}

private void Grid_MouseMove(object sender, MouseEventArgs e) {
if(mDown) {
Point pos = Mouse.GetPosition(viewport);
Point actualPos = new Point(pos.X - viewport.ActualWidth / 2, viewport.ActualHeight / 2 - pos.Y);
double dx = actualPos.X - mLastPos.X, dy = actualPos.Y - mLastPos.Y;

double mouseAngle = 0;
if(dx != 0 && dy != 0) {
mouseAngle = Math.Asin(Math.Abs(dy) / Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2)));
if(dx < 0 && dy > 0) mouseAngle += Math.PI / 2;
else if(dx < 0 && dy < 0) mouseAngle += Math.PI;
else if(dx > 0 && dy < 0) mouseAngle += Math.PI * 1.5;
}
else if(dx == 0 && dy != 0) mouseAngle = Math.Sign(dy) > 0 ? Math.PI / 2 : Math.PI * 1.5;
else if(dx != 0 && dy == 0) mouseAngle = Math.Sign(dx) > 0 ? 0 : Math.PI;

double axisAngle = mouseAngle + Math.PI / 2;

Vector3D axis = new Vector3D(Math.Cos(axisAngle) * 4, Math.Sin(axisAngle) * 4, 0);

double rotation = 0.01 * Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2));

Transform3DGroup group = mGeometry.Transform as Transform3DGroup;
QuaternionRotation3D r = new QuaternionRotation3D(new Quaternion(axis, rotation * 180 / Math.PI));
group.Children.Add(new RotateTransform3D(r));

mLastPos = actualPos;
}
}

private void Grid_MouseDown(object sender, MouseButtonEventArgs e) {
if(e.LeftButton != MouseButtonState.Pressed) return;
mDown = true;
Point pos = Mouse.GetPosition(viewport);
mLastPos = new Point(pos.X - viewport.ActualWidth / 2, viewport.ActualHeight / 2 - pos.Y);
}

private void Grid_MouseUp(object sender, MouseButtonEventArgs e) {
mDown = false;
}

}

}
AnswerRe: How to create a stacked of 3 images that can be rotated and zoomed in WPF Pin
ColinM1238-Oct-08 18:46
ColinM1238-Oct-08 18:46 
QuestionDatabinding driving me crazy! Pin
esjq8-Oct-08 10:15
esjq8-Oct-08 10:15 
AnswerRe: Databinding driving me crazy! Pin
Adam Maras8-Oct-08 10:39
Adam Maras8-Oct-08 10:39 
AnswerRe: Databinding driving me crazy! Pin
Pete O'Hanlon8-Oct-08 11:47
mvePete O'Hanlon8-Oct-08 11:47 
GeneralRe: Databinding driving me crazy! Pin
ColinM1238-Oct-08 12:32
ColinM1238-Oct-08 12:32 
AnswerRe: Databinding driving me crazy! Pin
esjq9-Oct-08 10:25
esjq9-Oct-08 10:25 
GeneralRe: Databinding driving me crazy! Pin
Pete O'Hanlon9-Oct-08 22:01
mvePete O'Hanlon9-Oct-08 22:01 
QuestionMoXAML Power Toys 2 just released. Pin
Pete O'Hanlon7-Oct-08 12:11
mvePete O'Hanlon7-Oct-08 12:11 
AnswerRe: MoXAML Power Toys 2 just released. Pin
Mark Salsbery8-Oct-08 13:03
Mark Salsbery8-Oct-08 13:03 
GeneralRe: MoXAML Power Toys 2 just released. Pin
Pete O'Hanlon8-Oct-08 21:44
mvePete O'Hanlon8-Oct-08 21:44 
GeneralRe: MoXAML Power Toys 2 just released. Pin
User 27100910-Oct-08 0:40
User 27100910-Oct-08 0:40 
QuestionUIElement and InotifyPropertyChanged Pin
ezazazel7-Oct-08 2:07
ezazazel7-Oct-08 2:07 
AnswerRe: UIElement and InotifyPropertyChanged Pin
Insincere Dave7-Oct-08 6:48
Insincere Dave7-Oct-08 6:48 
GeneralRe: UIElement and InotifyPropertyChanged Pin
ezazazel7-Oct-08 7:08
ezazazel7-Oct-08 7:08 
GeneralControl in ItemTemplate can't bind to owner control dependency property? [modified] Pin
Zvorko7-Oct-08 1:31
Zvorko7-Oct-08 1:31 
AnswerRe: Control in ItemTemplate can't bind to owner control dependency property? Pin
User 27100910-Oct-08 0:45
User 27100910-Oct-08 0:45 
GeneralRe: Control in ItemTemplate can't bind to owner control dependency property? Pin
Zvorko10-Oct-08 0:52
Zvorko10-Oct-08 0:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.