Mail Archives: djgpp/1997/03/06/00:40:00
Guess <times9 AT clark DOT net> wrote in article
<Pine DOT GSO DOT 3 DOT 95 DOT 970305131547 DOT 2365A-100000 AT explorer2 DOT clark DOT net>...
> 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)
- Raw text -