AB4D Forum

Full Version: Flying the camera around a 3D object?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a 3D polyline object that I'm seeing with a camera defined thusly . . . 

        <cameras:TargetPositionCamera Name="Camera1"
                                      Heading="0" Attitude="0" Bank="0" TargetPosition="0 0 0"
                                      CameraType="OrthographicCamera"
                                      CameraWidth="936"
                                      ShowCameraLight="Always"
                                      TargetViewport3D="{Binding ElementName=MainViewport}"/>

But what I really want to do is "fly" the camera around the object so I can see my 3D object from different angles.

What is the right way to think about this?   Does the camera have a "position" or is the TargetPosition camera-relative, i.e., do I "move the camera" by changing the target position, or what?

Is there any sample code that does something similar to what I'm asking about?

Thanks in advance.
Ab3d.PowerToys library comes with many types of cameras.

You can see a sample of each camera type in the "Cameras/Main Cameras Sample" samples project.

You can also see a quick overview of cameras in the following pdf (though FreeCamera is missing here):
https://www.ab4d.com/Documents/Ab3d%20Ca...0sheet.pdf


In many cases you want that the camera is looking at a specified position and then the user can rotate the camera around that position.
In this case it is best to use TargetPositionCamera - you can specify TargetPosition to a center of a 3D object. Then user can change angles at which he watches the TargetPosition and the distance of the camera from that position.

You can move the TargetPositionCamera  with changing the TargetPosition - if you change it by (100, 0, 0), then the camera will also move by this amount. Note that the camera position can also move with changing heading, attitude, bank or distance.

You can also use Move... methods to move the camera - for example MoveLeft strafes the camera into the left side.


If you want to have a camera that is similar to third-person shooter game where you watch the scene from the eyes of the main character, then you can use FirstPersonCamera. In this case you set the Position property - this defines the position of the camera (eyes of the main character). In this case heading, attitude and bank define the angles of the camera (head) at which camera is watching the world.


You have the most control of the camera when you use FreeCamera - there you define the TargetPosition and CameraPosition (you can also set UpDirection).


If you want to create a fly-by effect where you will present a specified 3D object, I would recommend you to use TargetPositionCamera and animate heading, attitude, distance and TargetPosition.

The next version of Ab3d.PowerToys will have great support for camera and object animations with using key frames. This way you will be able to easily create camera animations. If everything will go according to plan, then the next version can be released at the end of next week.

If you want to try the pre-release version, please write me a PM and I will send you a download link.
I'm sorry, but I'm still confused.   You wrote...


. . .
You have the most control of the camera when you use FreeCamera - there you define the TargetPosition and CameraPosition (you can also set UpDirection).


. . .


If you want to create a fly-by effect where you will present a specified 3D object, I would recommend you to use TargetPositionCamera and animate heading, attitude, distance and TargetPosition.


That's what I'm using now, as you see in the sample code I posted in the question.   But I don't understand how to "fly" it around my object.   If I change the target position then I'm flying the object around the camera, instead of the camera around the object.

So wouldn't the FreeCamera be a better choice, because it has a CameraPosition parameter as well as a TargetPosition?    Although I'm a bit confused about the Freecamera too, because I'll need to set its look direction, so I can keep it looking at the object while I move it.  But the documentation says

LookDirection    Gets or sets a Vector3D which defines the upward direction of the camera.

I think of "up direction" and "look direction" as different things.    

Thanks in advance for further clarification
If you want to fly the camera around your object at a constant distance, then it is best to use TargetPositionCamera: just set the TargetPosition to the center of your object, then specify the Distance and then you can animate the Heading and Attitude properties to rotate the camera around your object.

You can also use StartRotation method on the camera object to start a rotation around the TargetPosition.

The idea of TargetPositionCamera is that you do not need to calculate the camera's position - for example if you want to look at specific object you set TargetPosition to the center of that object (or to some other part of that object). Then you want to look at your object slightly from the left (you set Heading to 30) and slightly from above (set Attitude to -20) and at a distance of 200 units. What is more, you can preview the scene in Visual Studio designer and easily adjust the angles and distance to suite your need. This way of defining the camera is much more intuitive then using Camera position and LookDirection (as with standard WPF camera).



The FreeCamera will give you full control of CameraPositon and TragetPositon, but you will not be able to use handy angles and distance to position the camera (though in the Ab3d.PowerToys v8.0+ there will be new SetCameraPosition and SetTargetPosition methods that will allow you to define the camera by the angles and distance). To create a animation with changing CameraPositon and TragetPositon were cameras flies around the object will require some math.

With FreeCamera you also do not need to define the LookDirection - this is already defined by the CameraPositon and TragetPositon properties.
The text from documentation was not correct. It was on a LookDirection property that only had a getter and is a helper property to easily retrieve LookDirection. The correct text is: "Gets a Vector3D which defines the look direction of the camera."

I am sorry for that mistake that was misleading.


I would also like to invite you to try the beta version of the new Ab3d.PowerToys v8.0. This version has a build in support for camera and object animations (and many many other great new features). I will send you a download link as a private message. If others would also like to try the new version, please contact me with PM or by email.