refresh/drawnow leaves out patches or draws them incorrectly when camera is moved

2 views (last 30 days)
I have a kitchen design using about 150 patches all with alpha = 1. I'm doing a "walk through" by moving the camera position and camera target slowly in a for loop. At each drawnow in the loop the colors might be missing from patches or they are transparent or only partially drawn or they are not drawn at all. The errors change at each iteration.
Am I missing some property setting or something else?
The initial plot is perfect and using the rotation or zoom buttons on the figure works correctly. So does only changing the view angles.
I'm using only Matlab R2009b. I wrote a short script (below) that reproduces some of the problems % ------------------------------------------- % Script demonstrating a problem with rendering % Example is simplified to use only 2 boxes. % Author: Scott Smith, Date: 19 Jan 2013
clear all
% Create two adjacent floating boxes as patches
F = [1 2 5 3; % the 6 faces
1 2 7 4;
3 5 8 6;
1 3 6 4;
2 5 8 7;
4 6 8 7];
V1 = [130 48 46; % the 8 vertices
155 48 46;
130 63 46;
130 48 51;
155 63 46;
130 63 51;
155 48 51;
155 63 51];
V1(:,1) = V1(:,1) + 0.0001; % Separate the boxes so no patches touch
C1 = [0 1 0]; % green
A1 = 1; % opaque
% Faces use the same vertex combinations as box 1
V2 = [100 50 48;
130 50 48;
100 70 48;
100 50 58;
130 70 48;
100 70 58;
130 50 58;
130 70 58];
C2 = [1 0 0]; % red
A2 = 1; % opaque
% Start the plot
figure(1);
clf
cla
set(gcf, 'Color', [1, 1, 1]); % window background
set(gca, 'Color', [1, 1, 1]); % plot background
axis equal
axis vis3d
grid on
axis off
set(gca, 'CameraViewAngleMode', 'manual');
camproj perspective;
camva(80);
% Plot the two boxes using the patch function
patch('Faces', F, 'Vertices', V1,'FaceColor', C1, 'FaceAlpha', A1);
patch('Faces', F, 'Vertices', V2,'FaceColor', C2, 'FaceAlpha', A2);
viewerH = 65; % Viewer's eyes are 5' 5" from floor.
downTh = pi/30; % Viewer looks down at 6 degrees.
stepS = 1; %incremental distance traveled in each i iteration
rT = -30; % (approx) Radius from camera position to target
% Rough diagram of camera paths. Target is mostly towards the boxes.
% ^ y -<--<--<--<--<--<--<--<- Line 1
% |
% | RedBox|GreenBox
% o----> x
% ->-->-->-->-->-->-->-->- Line 2
wVec = [175, 97, viewerH; % Line 1 start
22, 97, viewerH; % " end
22, 18, viewerH; % Line 2 start
175, 18, viewerH]; % " end
% Test parameters: line in wVec to use, starting angle towards target
% start and end values for the i for loop
testParm = [1, (0/4)*pi, 0, 105;
2, (3/4)*pi, 40, 153];
nV = size(wVec, 1);
for k = 1:size(testParm, 1)
% Extract the parameters
n = 2*testParm(k,1);
lastTh = testParm(k,2);
xPos = wVec(n-1,:); % starting camera position
xEnd = wVec(n,:);
dist = max(abs(xPos - xEnd)); % line are in axis directions
dir = sign(xEnd - xPos);
pR = 50; % radius from camera position to target
nSteps = floor(dist/stepS);
dTh = pi/(2*nSteps); % dTh turn each i iteration = turn 90 deg in nSteps
for i = testParm(k,3):testParm(k,4) % loop shortened to only include interesting bits
th = lastTh + i*dTh; % update angle
xPos = xPos + stepS*dir; % Move xPos along the line
ds = rT*[cos(th), sin(th), -sin(pi/30)]; % Angles and diatance to target
xTarget = xPos + ds;
campos(xPos);
camtarget(xTarget);
drawnow;
pause(0.1); % Change to slow down or speed up the walk
end
fprintf(1, 'Paused after test %d\n', k);
pause
end

Answers (1)

Jan
Jan on 15 Jan 2013
Do you use the ZBuffer or OpenGL renderer? In the latter case the software or the hardware drivers? Did you install the newest drivers for aour graphics board?
Do any corners of the objects move behind the camera? If so, increase the camera distance and modify the view angle.
Are there objects in direct contact? This can confuse the calculation of the distance to the camera and in consequence the visibility of objects. It can help, if there are eps('single') gaps between the objects.
  1 Comment
Scott Smith
Scott Smith on 17 Jan 2013
Edited: Scott Smith on 19 Jan 2013
Thanks Jan for your response. Here is some additional information.
I tried both ZBuffer and OpenGL and they both misbehaved in the same way. I wrote a script that isolates the problem using only two 6-sided boxes. However, the sides of the boxes touch. I have an explode function that I will try which ensures no patches touch.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!