Azzera filtri
Azzera filtri

Zooming in and out removing

7 visualizzazioni (ultimi 30 giorni)
Julián Francisco
Julián Francisco il 4 Gen 2012
I am using the rotate3d function to allow 3D rotation of a sphere through the mouse movement. However, when I rotate it, it zooms in and out. How can I disable this effect?
function ex2
global state;
fh = figure('Menu','none','Toolbar','none','Units','characters',...
'Renderer','OpenGL');
hPanAni = uipanel('parent',fh,'Units','characters','Position',...
[22.6 10.4 53 23],'title','Controls','FontSize',11,...
'FontAngle','italic','FontWeight','bold');
hIniAni = uicontrol(hPanAni,'Style','pushbutton','Units','normalized',...
'Position',[0.14 0.75 0.5 0.12],'String','Spin',...
'FontSize',10,'Callback',@hIniAniCallback);
hFinAni = uicontrol(hPanAni,'Style','pushbutton','Units','normalized',...
'Position',[0.14 0.5 0.5 0.12],'String','Stop',...
'FontSize',10,'Callback',@hFinAniCallback);
hResetAni = uicontrol(hPanAni,'Style','pushbutton','Units','normalized',...
'Position',[0.14 0.25 0.5 0.12],'String','Reset',...
'FontSize',10,'Callback',@hResetAniCallback);
hPantSim = uipanel('Parent',fh,'Units','characters',...
'Position',[107.87 8 157.447 42],'title',...
'Screen','FontSize',11,'FontAngle','italic',...
'FontWeight','bold','BorderType','none');
hPantSimInt = uipanel('Parent',hPantSim,'Units','normalized','Position',...
[0 0 1 1],'BorderType','line','BackgroundColor','k');
axes('Parent',hPantSimInt,'Units','normalized','Position',[0 0 1 1]);
stars = rand(100,2);
scatter(stars(:,1),stars(:,2),6,'w','Marker','+');
axis off;
ah4 = axes('Parent',hPantSimInt,'Units','normalized','Position',...
[0 0 1 1],'Color','none','Visible','off','DataAspectRatio',...
[1 1 1],'NextPlot','add');
hgrot = hgtransform('Parent',ah4);
T1 = 0:pi/1000:2*pi;
Fin = numel(T1);
if (Fin>1000)
Incr = floor(Fin/1000);
else
Incr = 1;
end
Y = zeros(numel(T1),3);
Y(:,1) = 7000*cos(T1);
Y(:,2) = 7000*sin(T1);
R_esf = 6378;
[x_esf,y_esf,z_esf] = sphere(50);
x_esf = R_esf*x_esf;
y_esf = R_esf*y_esf;
z_esf = R_esf*z_esf;
xmin = min(x_esf);
xmax = max(z_esf);
ymin = min(y_esf);
ymax = max(y_esf);
zmin = min(z_esf);
zmax = max(z_esf);
props.FaceColor = 'texture';
props.EdgeColor = 'none';
props.CData = [1 0 1 1 0 1 1 0 1];
props.Parent = hgrot;
surface(x_esf,y_esf,z_esf,props);
handles.psat = line('parent',ah4,'XData',Y(1,1), 'YData',Y(1,2),...
'ZData',Y(1,3),'Marker','o', 'MarkerSize',10,'MarkerFaceColor','w');
handles.tray = line('parent',ah4,'XData',Y(1,1), 'YData',Y(1,2),...
'ZData',Y(1,3),'LineWidth',1,'Color','y');
quiver3(0,0,0,1.44*R_esf,0,0,0,'Color','g','LineStyle','-');
text(1.5*R_esf,0,0,'X','Color','g');
quiver3(0,0,0,0,1.44*R_esf,0,0,'Color','g','LineStyle','-');
text(0,1.5*R_esf,0,'Y','Color','g');
quiver3(0,0,0,0,0,1.44*R_esf,0,'Color','g','LineStyle','-');
text(0,0,1.5*R_esf,'Z','Color','g');
set(ah4,'XLim',[min([-R_esf,xmin]) max([R_esf,xmax])],'YLim',...
[min([-1.55*R_esf,ymin]) max([1.55*R_esf,ymax])],'ZLim',[min([-1.55*R_esf,zmin]) ...
max([1.55*R_esf,zmax])]);
rotate3d on;
zoom off;
view([129 10]);
k = 2;
ind_ini = 0;
state = 0;
az = 0;
function hIniAniCallback(hObject,evt)
tic;
if (ind_ini == 1)
return;
end
ind_ini = 1;
state = 0;
while (k<=Fin)
az = az + 0.01745329252;
set(hgrot,'Matrix',makehgtform('zrotate',az));
set(handles.tray,'XData',Y(1:k,1),'YData',Y(1:k,2),'ZData',...
Y(1:k,3));
set(handles.psat,'XData',Y(k,1),'YData',Y(k,2),'ZData',Y(k,3));
pause(eps);
if (k == Fin)
toc;
end
k = k + Incr;
if (state == 1)
state = 0;
break;
end
end
end
function hFinAniCallback(hObject,evt)
ind_ini = 0;
state = 1;
end
function hResetAniCallback(hObject,evt)
ind_ini = 0;
state = 1;
k = 2;
az = 0;
set(hgrot,'Matrix',makehgtform('zrotate',az));
set(handles.tray,'XData',Y(1,1), 'YData',Y(1,2),'ZData',Y(1,3));
set(handles.psat,'XData',Y(1,1), 'YData',Y(1,2),'ZData',Y(1,3));
view([129 10]);
end
end

Risposta accettata

Titus Edelhofer
Titus Edelhofer il 6 Gen 2012
Hi,
O.K., I think I've found it: you need to move the camera far away from the object, so add the following line after the "view" line:
set(gca,'CameraViewAngle', 15)
You will need to make your earth larger again, but not the effect of becoming larger and smaller during rotation is (nearly 100%) gone.
Titus
  1 Commento
Julián Francisco
Julián Francisco il 6 Gen 2012
@Titus Edelhofer: Thank you very much for your answer.

Accedi per commentare.

Più risposte (2)

Titus Edelhofer
Titus Edelhofer il 4 Gen 2012
You should mutually disable the "other" functionality: when you do a
rotate3d on
add a
zoom off
and vice versa.
Titus
  2 Commenti
Julián Francisco
Julián Francisco il 5 Gen 2012
@Titus Edelhofer: Thank you so much for your answer. However, it does not work for my problem. I have just added my code to show it.
Titus Edelhofer
Titus Edelhofer il 6 Gen 2012
O.K., now I understand what you mean. I'll give it a try but it's not just a trivial setting that's wrong ...

Accedi per commentare.


Amit Kumar
Amit Kumar il 4 Gen 2012
Not able to understand this too.Please explain it little bit .
  2 Commenti
Titus Edelhofer
Titus Edelhofer il 4 Gen 2012
Both zooming and rotating follow the mouse moves. To be sure what the moving should do it's good practice to allow only one at the time, i.e., either zooming or rotating. So: when I turn on rotating (rotate3d on) I turn of zooming (zoom off). If I turn on zooming somewhere in my code (zoom on) I disable rotating (rotate3d off).
To see this: plot something and press the button for zoom. Now press the button for rotate (and you will see that the zoom button is released).
Julián Francisco
Julián Francisco il 4 Gen 2012
@Amit Kumar: Thank you for your interest in helping me.

Accedi per commentare.

Categorie

Scopri di più su Visual Exploration in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by