Click here to Skip to main content
15,943,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have created a 3D object in wpf 3d and used prospective camera the positions are changed by mouse move event.

below are the xaml code

XML
  d:DesignHeight="300" d:DesignWidth="600">
<Grid Name="objGrid" MouseDown="Grid_MouseDown" MouseUp="Grid_MouseUp" MouseMove="Grid_MouseMove"  Focusable="True">

    <Border Name="border" Background="White" MouseDown="border_MouseDown"
    BorderBrush="White"
    BorderThickness="2"
    CornerRadius="0"
    Padding="25"  Margin="0,-21,0,10">

        <Viewport3D Name="mainViewPort"  ClipToBounds="True" Opacity="10">
            <Viewport3D.Camera >
                <PerspectiveCamera x:Name="camera"
      FarPlaneDistance="100"
      LookDirection="0, 0, -5"
      UpDirection="0,1,0"
      NearPlaneDistance="1"
      Position="0, 0, 5"
      FieldOfView="50" />
            </Viewport3D.Camera>
            <ModelVisual3D>
                <ModelVisual3D.Content>
                    <AmbientLight x:Name="directionLightOfMainViewPort" Color="White"/>
                </ModelVisual3D.Content>
            </ModelVisual3D>
        </Viewport3D>


i want to manually set the camera position in a button click event.
i.e, i want that faces of the object appear in button click event .

What I have tried:

i want to do it on cs file not in xaml...

i had tried following code..

C#
TranslateTransform3D obj = new TranslateTransform3D();
            //solidCubeMV3D.Transform.Value.OffsetX = 0;

             //camera.Reset();
            //Vector3D lookDirection = new Vector3D(0, 0, -5);
            Vector3D updirection = new Vector3D(0, 1, 0);
            Point3D position = new Point3D(0, 0, 5);
            //camera.LookDirection = lookDirection;
            camera.UpDirection = updirection;
            camera.Position = position;           
                //camera.ChangeDirection(new Vector3D(0, 0, -5),new Vector3D(0,1,0),0.5);           
             mainViewPort.Camera = this.camera;
            
              // camera.Transform = new Transform3DGroup();
             //camera.Transform = trackball.Transform;           
            //solidCubeMV3D.Transform = camera.Transform;   
           //  trackball.EventSource = objGrid;
          //  camera.Transform = trackball.Transform;
         // objGrid.MouseWheel += new System.Windows.Input.MouseWheelEventHandler(objGrid_MouseWheel);      



please help me how to do as i am new to wpf
Posted
Updated 15-Dec-16 20:35pm
v2

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