Posts: 8
Threads: 4
Joined: Apr 2024
Reputation:
0
05-30-2024, 07:45 AM
(This post was last modified: 05-30-2024, 07:50 AM by zacfromaustinpowder.)
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?
Posts: 8
Threads: 4
Joined: Apr 2024
Reputation:
0
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.
Posts: 731
Threads: 8
Joined: Sep 2009
Reputation:
35
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