Skip to content

Commit 46ac5df

Browse files
examples, comments
1 parent df9b09b commit 46ac5df

File tree

5 files changed

+54
-21
lines changed

5 files changed

+54
-21
lines changed

examples/example_callbacks.m

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
hGrid = uigridlayout([1 2]);
2+
hGrid.Parent.Name = "Orbit3d for multiple axes (Press h for help)";
3+
4+
hAxes1 = uiaxes("Parent", hGrid);
5+
hAxes2 = uiaxes("Parent", hGrid);
6+
7+
gfx.orbit3d(hAxes1);
8+
gfx.orbit3d(hAxes2);
9+
10+
mesh = load('trimesh3d');
11+
12+
hPatch1 = patch("parent", hAxes1, "Vertices", [mesh.x mesh.y mesh.z], "Faces", mesh.tri, "FaceColor", "y");
13+
hPatch2 = patch("parent", hAxes2, "Vertices", [mesh.x mesh.y mesh.z], "Faces", mesh.tri, "FaceColor", "r");
14+
15+
% right click on first axes changes mesh color
16+
gfx.FigureEventDispatcher.addAxesEvent(...
17+
"WindowMousePress", @(~,~)set(hPatch1, 'FaceColor', rand(1, 3)), ...
18+
hAxes1, @(f,~)f.SelectionType == "alt");
19+
20+
% pressing v toggles hAxes1 visibility, no matter what is the current object
21+
gfx.FigureEventDispatcher.addFigureEvent(...
22+
"KeyPress", @(~,ev)toggleAxesVisibility(hAxes1, ev.Key), hGrid.Parent);
23+
24+
function toggleAxesVisibility(hAxes, key)
25+
if isequal(key, 'v')
26+
hAxes.Visible = ~ hAxes.Visible;
27+
end
28+
end
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
mesh = load('trimesh3d');
22

33
%% equivalent to cla(): create a new figure with a new axes if no figure exists yet
4-
gfx.clearOrNewUiAxes3d
4+
gfx.clearUiAxes3d;
55
patch("Vertices", [mesh.x mesh.y mesh.z], "Faces", mesh.tri, "FaceColor", "y");
66

77
%% equivalent to figure(): always create a new figure
8-
gfx.newUiAxes3d;
8+
gfx.newUiFigure3d;
99
patch("Vertices", [mesh.x mesh.y mesh.z], "Faces", mesh.tri, "FaceColor", "r");
1010

1111
%% equivalent to cla(): clear the red mesh of the current figure and plot a new blue one
12-
gfx.clearOrNewUiAxes3d;
12+
gfx.clearUiAxes3d;
1313
patch("Vertices", [mesh.x mesh.y mesh.z], "Faces", mesh.tri, "FaceColor", "b");

readme.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ User-friendly, feature rich replacement of Matlab's `cameratoolbar`
33

44
Matlab lacks a powerful and user friendly interactive tool to handle 3d objects in a plot. Matlab's own `cameratoolbar` doesn't allow to zoom in/out with the scroll wheel, does not set the light properly and has a quite esoteric orbit function. Furthermore, as of Matlab 2022a, `cameratoolbar` does not support the new web-based `uiaxes`
55

6-
This toolbox implements a quaternion based 3d orbit. Multiple axes are supported, thanks to a newly implemented per-axes (rather than Matlab's own per-figure) event handler.
6+
This toolbox implements a quaternion based 3d orbit. Multiple axes are supported, thanks to a newly implemented per-axes (rather than Matlab's own per-figure) event handler. Both the old java based and the new web based figures/axes are supported.
77

88
## Features
99
|Event|Action |
1010
|--|--|
11-
|Right click & move | Rotate objects |
12-
|Right double-click| Set rotation center|
13-
|Left click |User defined callback |
11+
|Left-click & move | Rotate objects |
12+
|Double-click | Set rotation center|
13+
|Right-click |User defined callback |
1414
|Scroll wheel |Zoom towards to/away from mouse pointer |
1515
|Key r |Reset view |
1616
|Key t |Toggle transparency of selected obj |
1717
|Key w |Toggle wireframe of selected patch |
18-
|Key c|Toggle color of selected obj |
18+
|Key c |Toggle color of selected obj |
1919
|Key h |Show help |
2020

2121
## Example code
@@ -33,7 +33,11 @@ This toolbox implements a quaternion based 3d orbit. Multiple axes are supported
3333
"Faces", mesh.tri, ...
3434
"FaceColor", "y");
3535

36-
Please find more examples in the folder `examples`
36+
Please find more examples in the folder `examples` about the following topics
37+
* Simple 3d orbit
38+
* Multiple uiaxes
39+
* Per-figure and per-axes callbacks
40+
* gca/gcf/clf/cla replacements for uiaxes/uifigure containing a 3d orbit
3741

3842
## Installation
3943

src/+gfx/+internal/Orbit3d.m

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
% o3d = gfx.internal.Orbit3d;
44
%
55
% USER INTERACTIONS
6-
% Right mouse click & move: Rotate objects
7-
% Right double-click: Set rotation center
8-
% Left click: User defined callback
6+
% Left mouse click & move: Rotate objects
7+
% Double click: Set rotation center
8+
% Right click: User defined callback
99
% Scroll wheel: Zoom towards to/away from mouse pointer
1010
% Key r: Reset view
1111
% Key t: Toggle transparency of selected obj
@@ -286,12 +286,13 @@ function toggleColor(~, hObj)
286286
function toggleHelp(~, hFig)
287287
hHelp = findobj(hFig, "Tag", "help");
288288
if isempty(hHelp)
289-
uilabel("Parent",hFig,"Text","right click: rotate obj", "Position", [10 10 200 20], "Tag","help");
290-
uilabel("Parent",hFig,"Text","double right click: set new rotation center", "Position", [10 30 300 20], "Tag","help");
291-
uilabel("Parent",hFig,"Text","r: reset view", "Position", [10 50 200 20], "Tag","help");
292-
uilabel("Parent",hFig,"Text","w: wireframe", "Position", [10 70 200 20], "Tag","help");
293-
uilabel("Parent",hFig,"Text","c: next color", "Position", [10 90 200 20], "Tag","help");
294-
uilabel("Parent",hFig,"Text","t: transparency", "Position", [10 110 200 20], "Tag","help");
289+
uilabel("Parent",hFig,"Text","left click & move: rotate obj", "Position", [10 10 200 20], "Tag","help");
290+
uilabel("Parent",hFig,"Text","double click: set new rotation center", "Position", [10 30 300 20], "Tag","help");
291+
uilabel("Parent",hFig,"Text","scroll wheel: zoom", "Position", [10 50 300 20], "Tag","help");
292+
uilabel("Parent",hFig,"Text","r: reset view", "Position", [10 70 200 20], "Tag","help");
293+
uilabel("Parent",hFig,"Text","w: wireframe", "Position", [10 90 200 20], "Tag","help");
294+
uilabel("Parent",hFig,"Text","c: next color", "Position", [10 110 200 20], "Tag","help");
295+
uilabel("Parent",hFig,"Text","t: transparency", "Position", [10 130 200 20], "Tag","help");
295296
else
296297
delete(hHelp)
297298
end

src/+gfx/orbit3d.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ function orbit3d(hAxes)
33
% gfx.orbit3d(hAxes);
44
%
55
% USER INTERACTIONS
6-
% Right mouse click & move: Rotate objects
7-
% Right double-click: Set rotation center
8-
% Left click: User defined callback
6+
% Left mouse click & move: Rotate objects
7+
% Double click: Set rotation center
8+
% Right click: User defined callback
99
% Scroll wheel: Zoom towards to/away from mouse pointer
1010
% Key r: Reset view
1111
% Key t: Toggle transparency of selected obj

0 commit comments

Comments
 (0)