How do display visuals of one player on multiple monitors, while using Unreal Engine and MATLAB Simulink to start the program?
조회 수: 14 (최근 30일)
이전 댓글 표시
Kaitlyn Woolf
2023년 8월 31일
답변: MathWorks Support Team
2023년 10월 12일
I am using MATLAB R2021b and Unreal Engine. How can I split the visuals of a single person driving in a driving simulator, which operates on Unreal Engine, and display them on two screens?
댓글 수: 3
채택된 답변
MathWorks Support Team
2023년 10월 12일
To display visuals of a single person driving on multiple monitors using MATLAB R2021b and Unreal Engine you can use one of the following two workflows:
Using the Simulink 3D Animation Toolbox:
You can do this by placing two "Simulation 3D Camera" blocks in your Simulink model and adjust the parameters so that they cover the parts of the scene that you desire. To visualize the camera images that are output by the "Image" port of that block, use a "Video Viewer" or a "To Video Display" block. This will open the view from each camera in a separate window.
Using the Image Processing Toolbox and the Image Acquisition Toolbox:
You can do this by following the steps below:
- Set up the driving simulation in Unreal Engine and ensure it is working correctly with a single screen.
- Use the MATLAB Simulink Integration with Unreal Engine to capture the rendered frames. You can use the "From Video Device" block in the "Image Acquisition Toolbox" library to capture the frames as an input signal.
- Display each stream on its respective screen using the "imshow" function. Use the "ScreenNumber" Name-Value pair to specify the monitor where you want each stream to be displayed (0 represents the primary monitor and higher numbers represent additional monitors).
The following code will display the driving simulation visual on two screens:
Please note that this code example assumes two screens connected to the primary computer, and that each half needs to be displayed on a separate screen.
% Capture frames from Unreal Engine using Simulink
videoInput = Simulink.Signal;
videoInput.DataType = 'uint8';
videoInput.SampleTime = -1;
videoInput.Complexity = 'real';
videoInput.Name = 'VideoInput';
% Split the frames into two halves
frameWidth = size(videoInput, 2);
halfWidth = frameWidth / 2;
leftHalf = videoInput(:, 1:halfWidth);
rightHalf = videoInput(:, halfWidth+1:end);
% Display each half on its respective screen
figure('Position', [0 0 halfWidth size(videoInput, 1)]);
imshow(leftHalf, 'InitialMagnification', 'fit', 'Border', 'tight', 'ScreenNumber', 1);
figure('Position', [halfWidth 0 halfWidth size(videoInput, 1)]);
imshow(rightHalf, 'InitialMagnification', 'fit', 'Border', 'tight', 'ScreenNumber', 2);
For a different monitor configuration or to split the visuals in a different way, the code can be modified accordingly.
댓글 수: 0
추가 답변 (1개)
Nishan Nekoo
2023년 9월 5일
Kaitlyn, one way to do this might be to place two Simulation 3D Camera blocks in your Simulink model and adjust the parameters so that they cover the parts of the scene that you desire.
To visualize the camera images that are output by the Image port of that block, use a Video Viewer or To Video Display block. This will open the view from each camera in a separate window.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!