Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: texture mapping images on the faces of a cube
Replies: 1   Last Post: Jan 31, 2013 6:46 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Ravi

Posts: 10
Registered: 5/3/12
texture mapping images on the faces of a cube
Posted: Jan 30, 2013 10:47 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.