%Camera GUI -- calls CameraFun % function CameraFun(LookFrom, LookTo, UpVectApprox, d, f, h) clear ; close ; % %default values for CameraFun LookFrom = [.5 .5 5]; % Camera position LookTo = [.5 .5 .5]; % Camera Aim point UpVectApprox = [0,1,0]; % Approx up vector d = 4 ; % dist camera to near clip plane f= 10 ; % dist camera to far clip plane h=.7 ; % height of view volume % a default grey R=0.2;G=0.2;B=0.2 ; %== The main window ========================== fig=figure(1); clf %== window setup =========================== set(fig,'Position',[60,100,600,600],... 'Name','Graphics Camera Demo',... 'NumberTitle','off',... 'Resize', 'off', ... 'Color','white'); %== drawing box ============================== set(0, 'DefaultAxesCreateFcn', ... 'CameraFun(LookFrom, LookTo, UpVectApprox, d, f, h)') ah=axes( 'Position', [0.3 0.1, 0.65 0.65],... 'Box', 'on', ... 'Color','white',... 'XColor',[0,0,0],'YColor',[0,0,0]); axis square axis( [-1 1 -1 1]) %=== Header text ========================== t1 = uicontrol(gcf,'Style','text', ... 'String',... 'Computer Graphics Camera Simulator ',... 'HorizontalAlignment','Center',... 'Position',[140,550,320,30],... 'BackgroundColor','white', ... 'FontSize', 18 ... ); %== End button =========================== st = uicontrol(gcf,'Style','Pushbutton', ... 'String','End',... 'Position',[500,5,70,20],... 'BackgroundColor',[0.8,0.8,0.8], ... 'CallBack', ... 'close' ); % %== h slider =========================== b1 = uicontrol(gcf,'Style','text', ... 'String','h = view height',... 'Position',[10,50,110,20],... 'BackgroundColor',[0.8,0.8,.8], ... 'FontSize', 12 ); b2 = uicontrol(gcf,'Style','text',... 'String',num2str(h,2),... 'FontSize', 12, ... 'BackgroundColor',[0.8,0.8,.8], ... 'Position',[10,30,110,20]); b3 = uicontrol(gcf,... 'Style','slider',... 'Min' ,.1 ,'Max', 10, ... 'Position',[10,10,110,20], ... 'Value', h,... 'CallBack', ... ['h = get(b3,''Value'');' ... 'set(b2, ''String'',num2str(h,2));' ... 'CameraFun(LookFrom, LookTo, UpVectApprox, d, f, h);' ... ] ); % %== f slider =========================== g1 = uicontrol(gcf,'Style','text', ... 'String','f = far clip dist',... 'Position',[10,120,110,20],... 'FontSize', 12, ... 'BackgroundColor',[0.8,.8,0.8]); g2 = uicontrol(gcf,'Style','text',... 'String',num2str(f,2),... 'FontSize', 12, ... 'BackgroundColor',[0.8,0.8,.8], ... 'Position',[10,100,110,20]); g3 = uicontrol(gcf,... 'Style','slider',... 'Min' ,1,'Max', 20, ... 'Position',[10,80,110,20], ... 'Value', f,... 'CallBack', ... ['f = get(g3,''Value'');' ... 'set(g2,''String'',num2str(f,2));' ... 'CameraFun(LookFrom, LookTo, UpVectApprox, d, f, h);' ... ]); % %== d slider =========================== r1 = uicontrol(gcf,'Style','text', ... 'String','d = near clip dist',... 'FontSize', 12, ... 'BackgroundColor',[0.8,0.8,.8], ... 'Position',[10,190,110,20],'BackgroundColor',[0.8,0.8,0.8]); r2 = uicontrol(gcf,'Style','text',... 'String',num2str(d,2),... 'FontSize', 12, ... 'BackgroundColor',[0.8,0.8,.8], ... 'Position',[10,170,110,20]); r3 = uicontrol(gcf,... 'Style','slider',... 'Min' ,1,'Max',20, ... 'Position',[10,150,110,20], ... 'Value', d,... 'CallBack', ... ['d = get(r3,''Value'');' ... 'set(r2,''String'',num2str(d,2) );' ... 'CameraFun(LookFrom, LookTo, UpVectApprox, d, f, h);' ... ]); % %== Approx Up Vector =========================== s1 = uicontrol(gcf,'Style','text', ... 'String','Approx Up',... 'FontSize', 12, ... 'BackgroundColor',[0.8,0.8,.8], ... 'Position',[10,300,110,20]); s2 = uicontrol(gcf,'Style','text',... 'String',num2str(UpVectApprox,2),... 'FontSize', 10, ... 'BackgroundColor',[0.8,0.8,.8], ... 'Position',[10,280,110,20]); s3 = uicontrol(gcf,... 'Style','slider',... 'Min' ,-1,'Max',1, ... 'Position',[10,260,110,20], ... 'Value', UpVectApprox(1),... 'CallBack', ... ['UPx = get(s3,''Value'');'... 'UpVectApprox(1) = UPx;' ... 'set(s2,''String'',num2str(UpVectApprox,''%2.2f '') );'... 'CameraFun(LookFrom, LookTo, UpVectApprox, d, f, h);' ... ] ); s4 = uicontrol(gcf,... 'Style','slider',... 'Min' ,-1,'Max',1, ... 'Position',[10,240,110,20], ... 'Value',UpVectApprox(2),... 'CallBack', ... ['UPy = get(s4,''Value'');'... 'UpVectApprox(2) = UPy;' ... 'set(s2,''String'',num2str(UpVectApprox,''%2.2f '') );'... 'CameraFun(LookFrom, LookTo, UpVectApprox, d, f, h);' ... ] ); s5 = uicontrol(gcf,... 'Style','slider',... 'Min' ,-1,'Max',1, ... 'Position',[10,220,110,20], ... 'Value', UpVectApprox(3),... 'CallBack', ... ['UPz = get(s5,''Value'');'... 'UpVectApprox(3) = UPz;' ... 'set(s2,''String'',num2str(UpVectApprox,''%2.2f '') );'... 'CameraFun(LookFrom, LookTo, UpVectApprox, d, f, h);' ... ] ); %== Look To Point =========================== to1 = uicontrol(gcf,'Style','text', ... 'String','Look To',... 'FontSize', 12, ... 'BackgroundColor',[0.8,0.8,.8], ... 'Position',[10,410,110,20]); to2 = uicontrol(gcf,'Style','text',... 'String',num2str(LookTo,2),... 'FontSize', 10, ... 'BackgroundColor',[0.8,0.8,.8], ... 'Position',[10,390,110,20]); to3 = uicontrol(gcf,... 'Style','slider',... 'Min' ,-1,'Max',1, ... 'Position',[10,370,110,20], ... 'Value', LookTo(1),... 'CallBack', ... ['UPx = get(to3,''Value'');'... 'LookTo(1) = UPx;' ... 'set(to2,''String'',num2str(LookTo,''%2.2f '') );'... 'CameraFun(LookFrom, LookTo, UpVectApprox, d, f, h);' ... ] ); to4 = uicontrol(gcf,... 'Style','slider',... 'Min' ,-1,'Max',1, ... 'Position',[10,350,110,20], ... 'Value', LookTo(2),... 'CallBack', ... ['UPy = get(to4,''Value'');'... 'LookTo(2) = UPy;' ... 'set(to2,''String'',num2str(LookTo,''%2.2f '') );'... 'CameraFun(LookFrom, LookTo, UpVectApprox, d, f, h);' ... ] ); to5 = uicontrol(gcf,... 'Style','slider',... 'Min' ,-1,'Max',1, ... 'Position',[10,330,110,20], ... 'Value', LookTo(3),... 'CallBack', ... ['UPz = get(to5,''Value'');'... 'LookTo(3) = UPz;' ... 'set(to2,''String'',num2str(LookTo,''%2.2f '') );'... 'CameraFun(LookFrom, LookTo, UpVectApprox, d, f, h);' ... ] ); %== Look from Point =========================== from1 = uicontrol(gcf,'Style','text', ... 'String','Look From',... 'FontSize', 12, ... 'BackgroundColor',[0.8,0.8,.8], ... 'Position',[10,520,110,20]); from2 = uicontrol(gcf,'Style','text',... 'String',num2str(LookFrom,2),... 'FontSize', 10, ... 'BackgroundColor',[0.8,0.8,.8], ... 'Position',[10,500,110,20]); from3 = uicontrol(gcf,... 'Style','slider',... 'Min' ,-10,'Max',10, ... 'Position',[10,480,110,20], ... 'Value', LookFrom(1),... 'CallBack', ... ['UPx = get(from3,''Value'');'... 'LookFrom(1) = UPx;' ... 'set(from2,''String'',num2str(LookFrom,''%2.2f '') );'... 'CameraFun(LookFrom, LookTo, UpVectApprox, d, f, h);' ... ] ); from4 = uicontrol(gcf,... 'Style','slider',... 'Min' ,-10,'Max',10, ... 'Position',[10,460,110,20], ... 'Value', LookFrom(2),... 'CallBack', ... ['UPy = get(from4,''Value'');'... 'LookFrom(2) = UPy;' ... 'set(from2,''String'',num2str(LookFrom,''%2.2f '') );'... 'CameraFun(LookFrom, LookTo, UpVectApprox, d, f, h);' ... ] ); from5 = uicontrol(gcf,... 'Style','slider',... 'Min' ,-10,'Max',10, ... 'Position',[10,440,110,20], ... 'Value', LookFrom(3),... 'CallBack', ... ['UPz = get(from5,''Value'');'... 'LookFrom(3) = UPz;' ... 'set(from2,''String'',num2str(LookFrom,''%2.2f '') );'... 'CameraFun(LookFrom, LookTo, UpVectApprox, d, f, h);' ... ] );