-
Notifications
You must be signed in to change notification settings - Fork 0
/
m_Figure.m
74 lines (67 loc) · 2.09 KB
/
m_Figure.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
function [sHandle, sx, sy, sz] = m_Figure(body, numSpheres, activate_stars)
% function M_FIGURE creates the figure, plots all surfaces, and
% sets up all other visualization settings.
% INPUT: (body, numSpheres, activate_stars)
% 'body' is a STRUCT
% The structure storing the object's parameters
% 'numSpheres' is a SCALAR
% The number of spheres to initialize
% 'activate_stars' is a BOOLEON
% True enables starry background; False enables default display
% options
%
% OUTPUT: (sHandle, sx, sy, sz)
% 'sHandle' is a GOBJECT HANDLE
% The graphic object containing the handles for all the bodies
% 'sx', 'sy', 'sx' are MATRICES
% The output of the 'SPHERE' function, used for updating spheres
%
% All visualization features are set up here, including the axes,
% background, camera, etc.
% FIGURE
% Create current figure and axes
fig = figure('Name','Gravity Simulation','NumberTitle','off');
% Change figure size [left bottom width height] (pixels)
fig.Position = [100 50 650 650];
ax = axes(fig);
% PLOT PLANETS
[sx, sy, sz] = sphere; % Create the 3 arrays of spherical points
sHandle = gobjects(1, numSpheres); % Create sphere container
for k = 1:numSpheres
% Plot the surface
sHandle(k) = surf(ax, sx, sy, sz);
sHandle(k).Visible = 'off';
hold on
end
% Plot each sphere
[sHandle] = c_Sphere(sHandle, body, sx, sy, sz);
% BACKGROUND/CAMERA
if activate_stars
% STARMAP BACKGROUND
R = 100;
s = surf(ax, R*sx, R*sy, R*sz);
hold off
s.FaceColor = 'texturemap';
s.FaceLighting = 'none';
s.CData = imread('starmap_4k.jpg');
s.EdgeColor = 'none';
cameratoolbar;
camva(70);
campos([-30, 0, 0]);
camtarget([0, 0, 0]);
camproj('perspective');
material dull
else
% DEFAULT DISPLAY
fig.Color = [0.05 0.05 0.15]; % dark grey background
camproj('perspective');
axis(20*[-1, 1, -1, 1, -1, 1]);
ax.Color = 'none'; % transparent axes
ax.XColor = 'none'; % transparent gridlines/labels
ax.YColor = 'none';
ax.ZColor = 'none';
ax.Clipping = 'off';
end
% LIGHTING
light
lighting gouraud