Date: Jan 30, 2013 10:47 AM
Author: Ravi
Subject: texture mapping images on the faces of a cube

I am interested in mapping 6 different images on the faces of a cube. I found the following code from a previous posting on the newsgroup:

cdata = flipdim( imread('peppers.png'), 1 );
cdatar = flipdim( cdata, 2 );
% bottom
surface([-1 1; -1 1], [-1 -1; 1 1], [-1 -1; -1 -1], ...
'FaceColor', 'texturemap', 'CData', cdatar );
% top
surface([-1 1; -1 1], [-1 -1; 1 1], [1 1; 1 1], ...
'FaceColor', 'texturemap', 'CData', cdata );
% front
surface([-1 1; -1 1], [-1 -1; -1 -1], [-1 -1; 1 1], ...
'FaceColor', 'texturemap', 'CData', cdata );
% back
surface([-1 1; -1 1], [1 1; 1 1], [-1 -1; 1 1], ...
'FaceColor', 'texturemap', 'CData', cdatar );
% left
surface([-1 -1; -1 -1], [-1 1; -1 1], [-1 -1; 1 1], ...
'FaceColor', 'texturemap', 'CData', cdatar );
% right
surface([1 1; 1 1], [-1 1; -1 1], [-1 -1; 1 1], ...
'FaceColor', 'texturemap', 'CData', cdata );
view(3);
%%%%%%%%%%%%%%%%
In order to adapt the above code in the right way (for example, to know when and how I should flip the image matrix), I would like to understand better the mapping method.
How do I read and understand the following code :
surface([-1 1; -1 1], [-1 -1; 1 1], [1 1; 1 1], ...
How does this represent the top? How should I understand the indexing of cube surface from the three 2*2 matrices?

I am actually interested in mapping images on a cuboid. How should the above code be modified then?
Would appreciate any help that I can get.
Thanks,
Ravi