• Remix
  • Share
  • New Entry

on 10 Nov 2023
  • 12
  • 22
  • 0
  • 0
  • 898
Tumble Anything that fits in a unit sphere by remixing this!
Just be sure to parent your objects to TX2, the transform objects that moves and bounces and tumbles.
function drawframe(f)
if f==1
clf
% A MATLAB demo that creates a surface
knot;
TX = hgtransform('tag','bounce');
TX2 = hgtransform('tag','tumble','parent',TX);
% Find the thing created by knot and move it so we can transform it
set(findobj('type','surface'),'parent',TX2);
shading interp
material([ .6, .9, .3, 2, .5 ])
lighting g
%% Axes setup
axis([-2 2 -2 2 -.5 10])
daspect([1 1 1])
view(3)
colormap(hsv)
set(gca,'clipping','off','visible','off','xdir','r');
light('position',[ 0 -10 5],'style','local');
%% Motion Context
ctxt.Z = 9;
ctxt.Q = 0;
ctxt.Zv = 0;
ctxt.B = 0;
setappdata(gcf,'ctxt',ctxt);
else
TX = findobj('tag','bounce');
TX2 = findobj('tag','tumble');
end
ctxt = getappdata(gcf,'ctxt');
%% Compute cheap-o velocity, bounce, and squish
ctxt.Zv=ctxt.Zv+.032; % Cheap Gravity
ctxt.Z=ctxt.Z-ctxt.Zv; % Motion
if ctxt.Z<0 % bounce!
ctxt.Z=ctxt.Zv+ctxt.Z; % Push up by amount pushed below
ctxt.Zv = -ctxt.Zv;
ctxt.Q = 1;
end
ctxt.B = ctxt.B + 1/4;
bounce=cospi(ctxt.B);
ctxt.Q=max(ctxt.Q-.036,0); % Q tracks the magnitude of squish
bscale = (ctxt.Q*bounce)/2;
%% Create transform to move and squish the pumpkin
set(TX, 'Matrix', makehgtform('translate',[0 0 ctxt.Z], 'scale', [1+bscale 1+bscale 1-bscale]));
%% Create the transform to tumple the pumpkin
% divide by 12 for 2 tumbles, and 24 for a single tumble.
set(TX2, 'Matrix', makehgtform('xrotate',(f-24)/12*pi, ...
... % The knot is big, so scale it down a bunch
'scale',.15));
setappdata(gcf,'ctxt',ctxt);
end
Animation
Remix Tree