Help changing camera related properties of the axes

3 views (last 30 days)
I have created a robot maze and I need to adjust the way the camera works in the 3D axes. I need to change the camera related properties to these values
  • set CameraViewingAngleMode, CameraTargetMode, and CameraPositonMode to 'manual'
  • set Projection to 'perspective'
  • set CameraViewAngle to 90
function [maze_figure, maze_axes] = drawMaze3d(maze)
% prepare figure and axes
maze_figure = figure;
maze_axes = axes;
axis equal;
hold on;
title('this will become the 3d maze')
% set axis properties depending on maze size
axis([0 maze.number_of_columns 0 maze.number_of_rows+2]);
set(gca, 'xlim', [0 maze.number_of_columns], 'ylim', [2 maze.number_of_rows+2], 'xtick', [], 'ytick', []);
set(gca, 'xtick', [], 'ytick', [], 'ztick', []);
% ----------------------------------------------------------------------------------------------------------------------
% remove this line and specify camera properties of the maze_axes here for (b)
% ----------------------------------------------------------------------------------------------------------------------
%floor
patch([0,maze.number_of_columns,maze.number_of_columns,0],...
[2,2,maze.number_of_columns+2,maze.number_of_columns+2],...
[0,0,0,0],[.7,.7,.7]);
% draw the grid
for i_col = 1:maze.number_of_columns
for i_row = 1:maze.number_of_rows
% draw the northern wall
if maze.hasWall(i_row, i_col, 1)
drawWallNorth(maze, i_row, i_col);
end
% draw the eastern wall
if maze.hasWall(i_row, i_col, 2)
drawWallEast(maze, i_row, i_col);
end
% draw the southern wall
if maze.hasWall(i_row, i_col, 3)
drawWallSouth(maze, i_row, i_col);
end
% draw the western wall
if maze.hasWall(i_row, i_col, 4)
drawWallWest(maze, i_row, i_col);
end
end
end
end
% nested functions
function drawWallNorth(maze, row, column)
x1 = column-1;
x2 = column;
y1 = maze.number_of_rows - row + 3;
y2 = maze.number_of_rows - row + 3;
patch([x1,x2,x2,x1],[y1,y2,y2,y1],[0,0,1,1],'r');
%plot([x1, x2], [y1, y2], 'k', 'linewidth', 4);
% ----------------------------------------------------------------------------------------------------------------------
% add a 3d patch here for (a)
% ----------------------------------------------------------------------------------------------------------------------
end
function drawWallEast(maze, row, column)
x1 = column;
x2 = column;
y1 = maze.number_of_rows - row + 3;
y2 = maze.number_of_rows - row + 2;
patch([x1,x2,x2,x1],[y1,y2,y2,y1],[0,0,1,1],'g');
%plot([x1, x2], [y1, y2], 'k', 'linewidth', 4);
% ----------------------------------------------------------------------------------------------------------------------
% add a 3d patch here for (a)
% ----------------------------------------------------------------------------------------------------------------------
end
function drawWallSouth(maze, row, column)
x1 = column-1;
x2 = column;
y1 = maze.number_of_rows - row + 2;
y2 = maze.number_of_rows - row + 2;
patch([x1,x2,x2,x1],[y1,y2,y2,y1],[0,0,1,1],'b');
%plot([x1, x2], [y1, y2], 'k', 'linewidth', 4);
% ----------------------------------------------------------------------------------------------------------------------
% add a 3d patch here for (a)
% ----------------------------------------------------------------------------------------------------------------------
end
function drawWallWest(maze, row, column)
x1 = column-1;
x2 = column-1;
y1 = maze.number_of_rows - row + 3;
y2 = maze.number_of_rows - row + 2;
patch([x1,x2,x2,x1],[y1,y2,y2,y1],[0,0,1,1],'Yellow');
% plot([x1, x2], [y1, y2], 'k', 'linewidth', 4);
% ----------------------------------------------------------------------------------------------------------------------
% add a 3d patch here for (a)
% ----------------------------------------------------------------------------------------------------------------------
end

Answers (1)

Voss
Voss on 6 Dec 2022
camva(maze_axes,'manual') % CameraViewingAngleMode
campos(maze_axes,'manual') % CameraPositonMode
set(maze_axes, ...
'CameraTargetMode','manual', ...
'Projection','perspective', ...
'CameraViewAngle',90)

Categories

Find more on View and Analyze Simulation Results in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!