Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to create my own camera class?
#1
For various reason's I'd like to be able to create my own camera class. Can this be achieved by implementing ICamera? Or do I have to inherit from one of your pre-existing camera classes?
#2
There are multiple options to create your own cameras.

As you mentioned, you can create your own class that implements the ICamera and then assign it to the SceneView.Camera property. In this case the scene will be viewed by your camera. Also the CameraAxisPanel will correctly show the camera axes. The MouseCameraController will be able to rotate the camera (using ICamera.RotateCamera method). To zoom the camera with MouseCameraController, you will also need to implement IDistanceCamera. To move the camera with MouseCameraController, you will need to implement ICameraPositionCamera or ITargetPositionCamera.

It is recommended that you try to implement as many camera interfaces as possible - see list of them in the reference help page: https://www.ab4d.com/help/SharpEngine/ht...ameras.htm


Another option is to derive your camera from an existing camera class, such as Camera, SphericalCamera or even TargetPositionCamera, FirstPersonCamera or FreeCamera. Then, you can override some of the methods to provide your own camera logic.


May I also ask you what are the various reasons that you have. I am interested in what is missing from the existing cameras, so I may try to implement that in the next versions.
Andrej Benedik
#3
The existing cameras don't easily give us access to all of the camera properties. For example, I want to be able to place the camera almost always using a matrix. Working with euler rotation values is annoying - constructing a transform matrix is significantly easier (but I'd still like to be able to work with euler rotation if necessary). Our camera implementation gives easy access to the transform matrix, the projection matrix, as well as more convenient properties such as position, rotation, and look at position. It also provides methods to "tumble" around the look at point, set the fov, or ortho width/height. Essentially, it would be nice to have all of the camera functionality exposed on one camera.
#4
If you already have the code to define your own cameras and are familiar with their properties and methods, you can easily implement a custom camera, as I described in my previous post.

You can also use MatrixCamera and define the view and projection matrices by using methods from Matrix4x4 class, for example: CreateLookAt, CreateOrthographic, CreatePerspective, etc. From your post, I assume you are currently using that.

But also the existing cameras provide most of the functionality that you described. All cameras in SharpEngine provide the following methods from your list (defined in ICamera interface):
- GetCameraMatrices (returns view and projection matrix),
- GetViewProjectionMatrix
- GetCameraPosition
- GetLookDirection
- GetUpDirection

If you provide a custom view matrix (you call it a transformation matrix), then only a look direction vector is defined and you cannot get a loot-at-position from that. Also if you provide a custom projection matrix, then it is hard to get the projection type (orthographic / perspective), fov, orthographic width/height.

But if you let the camera to define the view and projection matrices, then you can work by using higher level properties (position, direction, projection type, fov, orthographic width/height).

But also there it is not possible to have one camera that fits all cases. For example if you have a FirstPersonCamera, then it has the camera position (the position of the viewer) and the look direction. In this case, it is not possible to get the camera's look-at-position (TargetPosition). Also the FreeCamera provides CameraPosition and LookDirection and there it is also not possible to get the TargetPosition. But if you want a camera that can be rotated around a custom position (look-at-position), then you can use the TargetPositionCamera. In this case you also need the Distance to that position and an angle at which the camera is looking at that position. In the case of TargetPositionCamera, Euler angles are used (Heading, Attitude, Bank) because it is much easier for a human to work with that than with LookDirection and UpDirection vectors that need to be normalized and perpendicular.

Also note that all three types of cameras that were mentioned (FirstPersonCamera, FreeCamera and TargetPositionCamera) define: ProjectionType (orthographic / perspective), FieldOfView (used in case of  perspective projection) and CameraWidth (used in case of orthographic camera).
Andrej Benedik
  


Forum Jump:


Users browsing this thread:
3 Guest(s)