📄 cameratoolbar2.m
字号:
if isempty(Udata)
r = 'z';
else
r = Udata.coordsys;
end
case 'close'
restoreWindowCallbacks(hfig,Udata.wcb);
restoreWindowCursor(hfig,Udata.cursor);
cameratoolbar2('stopmoving')
h = [Udata.scenelights.h]; delete(h(ishandle(h)));
if ishandle(Udata.mainToolbarHandle) delete(Udata.mainToolbarHandle); end
setUdata([]);
case 'setaspectratio'
axis(haxes,lower(varargin{2}));
end
if nargout>0
ret = r;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function localDrawnow
Udata = getUdata;
% Calling drawnow will result in hang, see g201318
if Udata.moving == 1
drawnow
else
drawnow expose
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function orbitPangca(haxes,xy, mode)
Udata = getUdata;
%mode = 'o'; orbit
%mode = 'p'; pan
coordsys = lower(Udata.coordsys);
if coordsys(1)=='n'
coordsysval = 0;
else
coordsysval = coordsys(1) - 'x' + 1;
end
xy = -xy;
if mode=='p' % pan
panxy = xy*camva(haxes)/500;
end
if coordsysval>0
d = [0 0 0];
d(coordsysval) = 1;
up = camup(haxes);
upsidedown = (up(coordsysval) < 0);
if upsidedown
xy(1) = -xy(1);
d = -d;
end
% Check if the camera up vector is parallel with the view direction;
% if not, set the up vector
if any(crossSimple(d,campos(haxes)-camtarget(haxes)))
camup(haxes,d)
end
end
flag = 1;
while sum(abs(xy))> 0 & isstruct(Udata) & (flag | Udata.moving==1) & ishandle(haxes)
flag = 0;
Udata = getUdata;
if mode=='o' %orbit
if coordsysval==0 %unconstrained
camorbit(haxes,xy(1), xy(2), coordsys)
else
camorbit(haxes,xy(1), xy(2), 'data', coordsys)
end
else %pan
if coordsysval==0 %unconstrained
campan(haxes,panxy(1), panxy(2), coordsys)
else
campan(haxes,panxy(1), panxy(2), 'data', coordsys)
end
end
updateScenelightPosition(haxes);
localDrawnow;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function orbitLightgca(haxes,xy)
Udata = getUdata;
sl = Udata.scenelights;
ax = haxes;
index = find([sl.ax]==ax);
if sum(abs(xy))> 0 & ~sl(index).on
updateScenelightOnOff(haxes,1);
Udata = getUdata;
sl = Udata.scenelights;
end
% Check if the light is on the other side of the object
az = mod(abs(sl(index).az),360);
if az > 90 & az < 270
xy(2) = -xy(2);
end
flag = 1;
while sum(abs(xy))> 0 & isstruct(Udata) & (flag | Udata.moving==1) & ishandle(haxes)
Udata = getUdata;
flag = 0;
az = sl(index).az;
el = sl(index).el;
az = mod(az + xy(1), 360);
el = mod(el + xy(2), 360);
if abs(el) > 90
el = 180 - el;
az = 180 + az;
xy(2) = -xy(2);
end
sl(index).az = az;
sl(index).el = el;
Udata.scenelights = sl;
setUdata(Udata)
updateScenelightPosition(haxes);
localDrawnow
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function walkgca(haxes,xy1,walk_flag)
persistent xy v up d cva q
xy = xy1;
%Walk is unique in that it calls recursively, so we need to be
%careful not to blow the recursion limit. Here we check to see
%if we are just shy of the limit. If we are, stop walking.
if length(dbstack)<get(0,'recursionlimit')-16
Udata = getUdata;
coordsys = lower(Udata.coordsys);
if coordsys(1)=='n'
coordsysval = 0;
else
coordsysval = coordsys(1) - 'x' + 1;
end
if coordsysval>0
d = [0 0 0];
d(coordsysval) = 1;
up = camup(haxes);
if up(coordsysval) < 0
d = -d;
end
end
q = max(-.9, min(.9, xy(2)/700));
cva = camva(haxes);
recursionflag = 1;
while sum(abs(xy))> 0 & isstruct(Udata) & recursionflag & Udata.moving==1 & ishandle(haxes)
Udata = getUdata;
if coordsysval==0 %unconstrained
campan(haxes,xy(1)*cva/700, 0, 'camera')
v = q*(camtarget(haxes)-campos(haxes));
else
campan(haxes,xy(1)*cva/700, 0, 'data', d)
% Check if the camera up vector is parallel with the view direction;
% if not, set the up vector
if any(crossSimple(d,campos(haxes)-camtarget(haxes)))
camup(haxes,d);
end
v = q*(camtarget(haxes)-campos(haxes));
v(coordsysval) = 0;
end
camdolly(haxes,v(1), v(2), v(3), 'movetarget', 'data')
updateScenelightPosition(haxes);
if isempty(walk_flag)
localDrawnow;
else
drawnow expose
recursionflag = 0;
end
end
else
%In the event that we are near our recursion limit,
%stop moving the camera.
%
%This is essentially the code in "cameratoolbar('up')"
%it is copied here instead of referenced because calling
%cameratoolbar('up') from here seems to cause timing issues.
%Also, cameratoolbar('up') contains some checking for throws
%which we don't want here.
hfig = ancestor(haxes,'figure');
set(hfig, 'windowbuttonmotionfcn', '')
set(hfig, 'windowbuttonupfcn', '')
Udata = getUdata;
Udata.buttondown = 0;
Udata.moving = 0;
pt = hgconvertunits(hfig,[0 0 get(hfig,'CurrentPoint')],...
get(hfig,'Units'),'pixels',0);
pt = pt(3:4);
deltaPix = pt-Udata.figLastLastPoint;
deltaPixStart = pt-Udata.figStartPoint;
Udata.figLastPoint = pt;
setUdata(Udata)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function dollygca(haxes,xy)
camdolly(haxes,-xy(1), -xy(2), 0, 'movetarget', 'pixels')
updateScenelightPosition(haxes);
localDrawnow;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function zoomgca(haxes,xy)
q = max(-.9, min(.9, sum(xy)/70));
camzoom(haxes,1+q);
localDrawnow;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function forwardBackgca(haxes,xy, mode)
q = max(-.9, min(.9, sum(xy)/70));
if mode=='b'
camdolly(haxes,0,0,q);
else
camdolly(haxes,0,0,q, 'f');
end
updateScenelightPosition(haxes);
localDrawnow;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function rollgca(haxes,dxy, pt)
Udata = getUdata;
% find the pixel center of the axes
pos = hgconvertunits(ancestor(haxes,'figure'),get(haxes,'Position'),...
get(haxes,'Units'),'pixels',get(haxes,'parent'));
center = pos(1:2)+pos(3:4)/2;
startpt = pt - dxy;
v1 = pt-center;
v2 = startpt-center;
v1 = v1/norm(v1);
v2 = v2/norm(v2);
theta = acos(sum(v2.*v1)) * 180/pi;
cross = crossSimple([v1 0],[v2 0]);
if cross(3) >0
theta = -theta;
end
flag = 1;
while isstruct(Udata) & (flag | Udata.moving==1) & ishandle(haxes)
flag = 0;
Udata = getUdata;
camroll(haxes,theta);
updateScenelightPosition(haxes);
localDrawnow
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function h=createToolbar(hfig)
h = uitoolbar(hfig, 'HandleVisibility','off');
props.Parent = h;
Udata.mainToolbarHandle = h;
load camtoolbarimages
props.HandleVisibility = 'off';
u = [];
props.ClickedCallback = 'cameratoolbar(''setmodeGUI'', ''orbit'')';
props.ToolTip = 'Orbit Camera';
props.CData = camtoolbarimages.orbit;
props.Tag = 'orbit';
u(end+1) = uitoggletool(props);
props.ClickedCallback = 'cameratoolbar(''setmodeGUI'', ''orbitscenelight'')';
props.ToolTip = 'Orbit Scene Light';
props.CData = camtoolbarimages.orbitlight;
props.Tag = 'orbitscenelight';
u(end+1) = uitoggletool(props);
props.ClickedCallback = 'cameratoolbar(''setmodeGUI'', ''pan'')';
props.ToolTip = 'Pan/Tilt Camera';
props.CData = camtoolbarimages.pan;
props.Tag = 'pan';
u(end+1) = uitoggletool(props);
props.ClickedCallback = 'cameratoolbar(''setmodeGUI'', ''dollyhv'')';
props.ToolTip = 'Move Camera Horizontally/Vertically';
props.CData = camtoolbarimages.hv;
props.Tag = 'dollyhv';
u(end+1) = uitoggletool(props);
props.ClickedCallback = 'cameratoolbar(''setmodeGUI'', ''dollyfb'')';
props.ToolTip = 'Move Camera Forward/Back';
props.CData = camtoolbarimages.fb;
props.Tag = 'dollyfb';
u(end+1) = uitoggletool(props);
props.ClickedCallback = 'cameratoolbar(''setmodeGUI'', ''zoom'')';
props.ToolTip = 'Zoom Camera';
props.CData = camtoolbarimages.zoom;
props.Tag = 'zoom';
u(end+1) = uitoggletool(props);
props.ClickedCallback = 'cameratoolbar(''setmodeGUI'', ''roll'')';
props.ToolTip = 'Roll Camera';
props.CData = camtoolbarimages.roll;
props.Tag = 'roll';
u(end+1) = uitoggletool(props);
% props.ClickedCallback = 'cameratoolbar(''setmodeGUI'', ''walk'')';
% props.ToolTip = 'Walk Camera';
% props.CData = camtoolbarimages.walk;
% props.Tag = 'walk';
% u(end+1) = uitoggletool(props);
Udata.ModeHandles = u;
u = [];
props.ClickedCallback = 'cameratoolbar(''setcoordsys'', ''x'')';
props.ToolTip = 'Principal Axis X';
props.CData = camtoolbarimages.x;
props.Tag = 'x';
u(end+1) = uitoggletool(props,...
'Separator', 'on');
props.ClickedCallback = 'cameratoolbar(''setcoordsys'', ''y'')';
props.ToolTip = 'Principal Axis Y';
props.CData = camtoolbarimages.y;
props.Tag = 'y';
u(end+1) = uitoggletool(props);
props.ClickedCallback = 'cameratoolbar(''setcoordsys'', ''z'')';
props.ToolTip = 'Principal Axis Z';
props.CData = camtoolbarimages.z;
props.Tag = 'z';
u(end+1) = uitoggletool(props);
props.ClickedCallback = 'cameratoolbar(''setcoordsys'', ''none'')';
props.ToolTip = 'No Principal Axis';
props.CData = camtoolbarimages.none;
props.Tag = 'none';
u(end+1) = uitoggletool(props);
Udata.PrincipalAxisHandles = u;
u = [];
props.ClickedCallback = 'cameratoolbar(''togglescenelight'')';
props.ToolTip = 'Toggle Scene Light';
props.CData = camtoolbarimages.light;
u(end+1) = uipushtool(props,...
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -