Advertisement

to scan from a cell position

Started by April 12, 2002 10:33 AM
3 comments, last by edwinnie 22 years, 5 months ago
i am using the WGPFD book. for the part about
int Load_Frame_BOB(BOB_PTR bob, // bob to load with data
                   BITMAP_FILE_PTR bitmap, // bitmap to scan image data from
                   int frame,       // frame to load
                   int cx,int cy,   // cell or absolute pos. to scan image from
                   int mode)        // if 0 then cx,cy is cell position, else 
                                    // cx,cy are absolute coords 
i was wondering why was % and / being used for cx & cy respectively>
// load animation frames
for (int frame=0; frame < 20; frame++)
     Load_Frame_BOB(&rocks[0],&bitmap8bit,frame,frame%6,frame/6,BITMAP_EXTRACT_MODE_CELL); 
the bitmap provided was about of 3 rows of 6 columns, with the 4th row having 3 cells only. thus, total no.of available frames is 21. and using frame%6 only gives a remainder of either 0 or less than 1. so how does frame%6 and frame/6 make sense?
Ok, since there are 6 cells per row, frame%6 gives you the column (cx) of that frame, and frame/6 gives you the row (cy) of that frame. Plug some numbers in for the frame and you'll see. It saves you from having to keep track of what column and row you're currently in. Otherwise you'd have to have something like:


    int x = 0, y = 0;for (int frame=0; frame < 20; frame++)     {   Load_Frame_BOB(&rocks [0],&bitmap8bit,frame,x,y,BITMAP_EXTRACT_MODE_CELL);   if(++x == 6)   {      x = 0;      ++y;    }}  


/*=========*/
/* Chem0sh */
/*=========*/


[edited by - Chem0sh on April 12, 2002 11:57:44 AM]
/*=========================================// Chem0sh// Lead Software Engineer & Tech Support// http://www.eFaces.biz=========================================*/
Advertisement
lets see
hmm...

(0-5)%6 is 0 times 6, r-6
6%6 is 1 times 6, r-0
7%6 is 1 times 6, r-1
8%6 is 1 times 6, r-2
9%6 is 1 times 6, r-3
10%6 is 1 times 6, r-4
11%6 is 1 times 6, r-5

(0-5)/6 is 0 times 6, y-0
(6-11)/6 is 1 times 6, y-1
(12-17)/6 is 2 times 6, y-2
(18-20)/6 is 3 times 6, y-3

great! i am finally gettin it.
thx
quote: Original post by edwinnie
(0-5)%6 is 0 times 6, r-6


Atculy (0-5)%6 is 0 times 6, r-(0-5)
1%6 == 1, 2%6 == 2, 3%6 == 3, 4%6 == 4, 5%6 == 5, 6%6 == 0, 7%6 == 1, etc.



[edited by - Spearhawk on April 12, 2002 12:37:24 PM]
oh ya hor!
thx

This topic is closed to new replies.

Advertisement