Switch cameras #598
Answered
by
robertosfield
valleymouth
asked this question in
Q&A
Replies: 2 comments 1 reply
-
On Fri, 18 Nov 2022 at 15:07, valleymouth ***@***.***> wrote:
What is the correct/best way to switch cameras? Let's say I have multiple
cameras in the scene, and I want to switch between them to select which one
is rendering.
Message ID: ***@***.***>
In the VSG the vsg::Camera is best thought of as just the camera settings
used by a RenderGraph/View to control the viewing direction and projection
(lens) used when traversing a subgraph. So it's the RenderGraph/View that
is really responsible for the rendering.
If you have various viewpoints in your scene graph that you wish to become
the the view you want to render then you update the View's Camera's
viewMatrix to a new value. The vsg::Trackball
<https://github.com/vsg-dev/VulkanSceneGraph/blob/master/include/vsg/app/Trackball.h>has
a support for mapping key presses to different look at settings that do
this job:
/// add Key to Viewpoint binding using a LookAt to define the
viewpoint
void addKeyViewpoint(KeySymbol key, ref_ptr<LookAt> lookAt, double
duration = 1.0);
/// add Key to Viewpoint binding using a latitude, longitude and
altitude to define the viewpoint. Requires an EllipsoidModel to be assigned
when constructing the Trackball
void addKeyViewpoint(KeySymbol key, double latitude, double
longitude, double altitude, double duration = 1.0);
This essentially copies the selected LookAt values to the
Camrea->viewMatrix to update the view, handling animation between the
current and the new viewpoint.
Another approach is the vsg::TrackingViewMatrix
<https://github.com/vsg-dev/VulkanSceneGraph/blob/master/include/vsg/app/ViewMatrix.h#L117>
subclass from vsg::ViewMatrix that you can set up to follow objects in the
scene graph, so as they move - such as a MatrixTransform moving them, then
the ViewMatrix value will be updated and then Camera will then take it's
view matrix for this on each new frame.
Cheers,
Robert.
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
robertosfield
-
As well as updating what the Camera looks at by modifying the Camera's viewMatrix, you can also change the Camera that is being rendered by a View is to simply change the camera assigned to the View i.e.
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi guys,
What is the correct/best way to switch cameras? Let's say I have multiple cameras in the scene, and I want to switch between them to select which one is rendering.
Cheers,
Denis
Beta Was this translation helpful? Give feedback.
All reactions