% Author : Jan Markowski % % This MATLAB program simply shows how the raw coordinates that are % inputted into the Wii-remote become translated to correspond to specific % coordinates on the screen. These are the same calculations that are made % in the Java program, wiiBoardJ.java. % % When you run this default program, zoom into the bottom left of the plot % to see the original raw coordinates. % Sample of x,y source coordinates for Points 1, 2, 3, and 4. ssc = [0.02932551319648094,0.6675358539765319; 0.4066471163245357,0.6597131681877445; 0.42130987292277616,0.2920469361147327; 0.03421309872922776,0.34159061277705344] % Sample of x,y coordinates of a random point (for curiosity of how it gets % translated.) sp = [0.1495601173020528,0.4511082138200782] % Input the screen size screenx = 1680; screeny = 1250; % Translate Coordinates sscTrans = ssc; spTrans = sp; sscTrans(:,1) = sscTrans(:,1)-ssc(4,1); spTrans(1) = spTrans(1)-ssc(4,1); sscTrans(:,2) = sscTrans(:,2)-ssc(4,2); spTrans(2) = spTrans(2)-ssc(4,2); % Shear vertically shearY = sscTrans(3,2)/sscTrans(3,1); sscShear = sscTrans; spShear = spTrans; sscShear(:,2) = sscShear(:,2)-sscShear(:,1)*shearY; spShear(2) = spShear(2)-spShear(1)*shearY; % Shear horizontally shearX = sscShear(1,1)/sscShear(1,2); sscShear(:,1) = sscShear(:,1)-sscShear(:,2)*shearX; spShear(1) = spShear(1)-spShear(2)*shearX; % Make top segment parallel to bottom. slope12 = (1-sscShear(2,2)/sscShear(1,2))/sscShear(2,1); inter12 = sscShear(2,2)/sscShear(1,2); sscShear(1,2) = sscShear(1,2)*(slope12*sscShear(1,1) + inter12); spShear(2) = spShear(2)*(slope12*spShear(1) + inter12); % Make right segment parallel to right. slope23 = (1-sscShear(2,1)/sscShear(3,1))/sscShear(2,2); inter23 = sscShear(2,1)/sscShear(3,1); sscShear(3,1) = sscShear(3,1)*(slope23*sscShear(3,2) + inter23); spShear(1) = spShear(1)*(slope23*spShear(2) + inter23); % Scale scaleX = screenx/sscShear(2,1); scaleY = screeny/sscShear(2,2); sscShear(:,1) = sscShear(:,1)*scaleX; sscShear(:,2) = sscShear(:,2)*scaleY; spShear(1) = spShear(1)*scaleX; spShear(2) = spShear(2)*scaleY; plot(ssc(:,1),ssc(:,2),'-b', sp(1), sp(2), 'ob', sscTrans(:,1),sscTrans(:,2),'-r', spTrans(1), spTrans(2), 'or', sscShear(:,1),sscShear(:,2),'-m', spShear(1), spShear(2), 'om')