From: "Sly" Newsgroups: comp.os.msdos.djgpp Subject: Re: Rotation problem Date: 6 Mar 1997 04:23:59 GMT Organization: Sly Lines: 76 Message-ID: <01bc29e6$bc0e4540$8a081ecb@sly> References: NNTP-Posting-Host: max0ppp08.bne.aussie.net To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Guess wrote in article ... > Hello again! > I have a small (?) problem. I'm plotting 100 points in mode 13h and > rotating them in increments of 1 degree. It works, only the rotating > pixels get smaller and smaller until it becomes a little dot on the > screen. What am I doing wrong? :) I'm figuring it's due to the > rounding error...or am I wrong? It seemed to work fine when i was > rotating a triangle with the line() function. *Shrug* Here is the > code..thank you in advance for any help! > -- I figure it would most probably be due to cumulative rounding errors. That is, the longer the program runs, the larger the rounding error gets, as it is adding *all* the previous rotations rounding errors. Try using two arrays of pixels, where one is the original pixels and the other is the rotated pixels. I have made some suggested changes to the following code... > > struct { > float x, y; > } pix[100]; > struct { float x, y; } pix[100], rotated_pix[100]; /* Used later in rotate() */ int angle = 0; > void rotate() > { > int i; > for(i = 0; i < 100; i++) { > pix[i].x = pix[i].x * cos_t[1] - pix[i].y * sin_t[1]; > pix[i].y = pix[i].y * cos_t[1] + pix[i].x * sin_t[1]; > } > } void rotate() { int i; /* Increase rotation by one degree */ angle++; if (angle >= 360) angle = 0; /* Rotate all the points into the rotated pixel array */ for(i = 0; i < 100; i++) { rotated_pix[i].x = pix[i].x * cos_t[angle] - pix[i].y * sin_t[angle]; rotated_pix[i].y = pix[i].y * cos_t[angle] + pix[i].x * sin_t[angle]; } } > void draw() > { > int i; > for(i = 0; i < 100; i++) > putpixel(screen, 160+pix[i].x, 100+pix[i].y, 13); > } void draw() { int i; for(i = 0; i < 100; i++) putpixel(screen, 160+rotated_pix[i].x, 100+rotated_pix[i].y, 13); } Hope this helps... -- TTFN Sly (Steve)