Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,since i'm too fresh in wpf i dont know lots of things and the problem now im facing is that i have three sliders in my application and what i need is once the sliders change the position my camera also changes its position,sliders are in different xamls and camera settings are in another xaml.I've already defined dependency property for x,y,z coordination:

C#
<local:Panel3D
              corX="{Binding Value,  ElementName=EditorX}"
              corY="{Binding Value,  ElementName=EditorY}"
              corZ="{Binding Value,  ElementName=EditorZ}"

editor x,y, are my sliders.now in another xaml i want to use there cor x,y,z as coordination of my camera position but i dont know how to do that

XML
<Viewport3D.Camera>
        <PerspectiveCamera
          LookDirection="0,0,-10"
          Position=???
          UpDirection="0,10,0"
          />
    </Viewport3D.Camera

>

if anyone gives me some guidelines i would really appreciate it,thank you.
Posted

1 solution

In the Panel3D control, since you have 3 dp's for X, Y, Z you can achieve the required by creating one more dependancy property of type Point3D and bind it to the Position property of the PerspectiveCamera, like below.

<Viewport3D.Camera>
        <PerspectiveCamera
          LookDirection="0,0,-10"
          Position={Binding Calculated3DPoint}
          UpDirection="0,10,0"
          />
</Viewport3D.Camera



In the callback of each dependancy property calculate update the Caluclated3DPoint property like.

#region Properties

        public double CorX
        {
            get { return (double)GetValue(CorXProperty); }
            set { SetValue(CorXProperty, value); }
        }

        public double CorY
        {
            get { return (double)GetValue(CorYProperty); }
            set { SetValue(CorYProperty, value); }
        }

        public double CorZ
        {
            get { return (double)GetValue(CorZProperty); }
            set { SetValue(CorZProperty, value); }
        }

        public Point3D Calculated3DPoint
        {
            get { return (Point3D)GetValue(Calculated3DPointProperty); }
            set { SetValue(Calculated3DPointProperty, value); }
        }

        #endregion

        #region Dependency Properties

        public static readonly DependencyProperty CorXProperty =
            DependencyProperty.Register("CorX", typeof(double), typeof(MainWindow), new UIPropertyMetadata(0d, (dependencyObject, e) =>
            {
                var v = (MainWindow)dependencyObject;

                if (v != null)
                {
                    v.Calculated3DPoint = new Point3D((double)e.NewValue, v.CorY, v.CorZ);
                }
            }));

        public static readonly DependencyProperty CorYProperty =
            DependencyProperty.Register("CorY", typeof(double), typeof(MainWindow), new UIPropertyMetadata(0d, (dependencyObject, e) =>
            {
                var v = (MainWindow)dependencyObject;

                if (v != null)
                {
                    v.Calculated3DPoint = new Point3D(v.CorX, (double)e.NewValue, v.CorZ);
                }
            }));

        public static readonly DependencyProperty CorZProperty =
            DependencyProperty.Register("CorZ", typeof(double), typeof(MainWindow), new UIPropertyMetadata(0d, (dependencyObject, e) =>
            {
                var v = (MainWindow)dependencyObject;

                if (v != null)
                {
                    v.Calculated3DPoint = new Point3D(v.CorX, v.CorY, (double)e.NewValue);
                }
            }));

        public static readonly DependencyProperty Calculated3DPointProperty =
            DependencyProperty.Register("Calculated3DPoint", typeof(Point3D), typeof(MainWindow), new UIPropertyMetadata(new Point3D()));

        #endregion


HTH
 
Share this answer
 
Comments
BaharDev 11-Oct-10 2:40am    
thank you so much for your solution but i think my problem is more than that,since the viewport control(camera,positon,...)is in a xaml without code behind and my dependencies are in a separate class and my sliders are in a different xaml.the point is i cannot get the value of x,y,z inside the first xaml since i can get the values of x,y,z inside the class but not in xaml.
this is the code for first xaml:

<viewport3d
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
="" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<viewport3d.camera>
<PerspectiveCamera
LookDirection="0,0,-10"
Position= "{Binding Calculated3DPoint}"
UpDirection="0,10,0"
/>


<modelvisual3d>
<modelvisual3d.content>
<AmbientLight Color="White" />




I think the problem is a bit more complicated than i thought:( but tanxx for your help:)
PumbaPumba 11-Oct-10 2:47am    
@BaharDev if you have any sample please give. I'll look into it possibly.
BaharDev 11-Oct-10 3:01am    
http://joshsmithonwpf.wordpress.com/2008/03/30/animating-images-in-a-3d-itemscontrol/
the sample which now im using is josh smith's code,i put 3 sliders inside window1 and i put my dependencies inside panel3D.cs and im trying to modify scene.xaml which I cant:D thankss
PumbaPumba 11-Oct-10 5:18am    
@BaharDev I've modified the sample. please check that in the following location https://sites.google.com/site/html5tutorials/ImageViewer3D.zip?attredirects=0&d=1
BaharDev 11-Oct-10 5:40am    
thousand thankss pumba u're really an angel ,i think i have to learn so many things from you,again thanksss:D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900