Help with camera angles?

1 vue (au cours des 30 derniers jours)
Amanda
Amanda le 7 Déc 2022
I have an assingment that I am taking a 2d maze and making it 3d. I am trying to change the camera angle so that it makes it look like I am in the maze. This is what I have but I dont know where I went wrong. I have attached a pciture of what view i am trying to getting in the maze.
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', []);
camva(maze_axes,'manual') % CameraViewingAngleMode
campos(maze_axes,'manual') % CameraPositonMode
set(maze_axes,'CameraTargetMode','manual', 'Projection','perspective','CameraViewAngle',90)
% ----------------------------------------------------------------------------------------------------------------------
% 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);
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);
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);
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);
end
function setRobotView(robot_location, robot_heading, axes3d)
camera_positon = [robot_location(1), robot_location(2),0.5];
axes3d.Cameraposition = camera_positon;
view_target = camera_positon;
if robot_heading == 1
view_target(2) = view_target(2) + 1;
elseif robot_heading == 2
view_target(1) = view_target(1) + 1;
elseif robot_heading == 3
view_target (2) = view_target(2) - 1;
elseif robot_heading == 4
view_target(1) = view_target(1) - 1;
end
axes3d.CameraTarget = view_target;
end

Réponses (0)

Catégories

En savoir plus sur MATLAB Support Package for IP Cameras dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by