Click here to Skip to main content
15,901,283 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there, i am trying to move my 3Dcamera with buttons on a single touch display.
For that i added a perspective camera to the helix viewport and bind its properties.
XML
<h:HelixViewport3D.Camera>
                <PerspectiveCamera
                LookDirection="{Binding PerspectiveCamera.LookDirection, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
                Position="{Binding PerspectiveCamera.Position,  UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"
                UpDirection="{Binding PerspectiveCamera.UpDirection,  UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"
                />
            </h:HelixViewport3D.Camera>


In the code behind i change these properties like that:
C#
this.PerspectiveCamera.Position = new Point3D(PerspectiveCamera.Position.X, PerspectiveCamera.Position.Y, perspectiveCamera.Position.Z - 50);


My question is, if it is possible to use an animation or the camera controller to change the properties of the camera.

Thanks for your help!
Posted

1 solution

If you want to use the keyboard, additional to the buttons,
Add the following to your HelixViewPort:

XML
IsMoveEnabled="False" IsPanEnabled="False" IsRotationEnabled="False"


On your button left click:
(repeat for the other buttons, lookdirection an updirection)

C#
PerspectiveCamera cam = ((PerspectiveCamera)h3d.DefaultCamera);
                h3d.Camera.AnimateTo(new Point3D()
                {
                    X = cam.Position.X - ViewPortScale * 2,
                    Y = cam.Position.Y,
                    Z = cam.Position.Z
                },
                   cam.LookDirection,
                   cam.UpDirection,
                1000);



You need some kind of scale for your model.
(How much does the camera have to move)
Try experimenting with this.

C#
double ViewPortScale = GetViewPortScale(Visual3DHelper.FindBounds(myModelVisual3D, Transform3D.Identity));



C#
private double GetViewPortScale(Rect3D bounds)
        {
            //calculate contour diameter
            double biggestSize = 0;
            if (bounds.SizeX > biggestSize) biggestSize = bounds.SizeX;
            if (bounds.SizeY > biggestSize) biggestSize = bounds.SizeY;
            if (bounds.SizeZ > biggestSize) biggestSize = bounds.SizeZ;
            ViewPortScale = biggestSize / 100;
            return biggestSize / 100;
        }


C#

 
Share this answer
 

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