Mail Archives: djgpp/1997/03/05/18:23:40
Guess wrote:
>
> 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!
> --
> 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];
> }
> }
Your changing the pixels value before you have finished using the old
one. Try this:
void rotate ()
{
int i;
float tx, ty;
for (i = 0; a < 100; ++i)
{
tx = pix [i].x;
ty = pix [i].y;
pix [i].x = tx * cos_t [1] - ty * sin_t [1];
pix [i].y = ty * cos_t [1] + tx * sin_t [1];
}
}
Also, after a while, rounding errors might appear. If they do, try
using one static table to hold the original points, and create another
with the rotated points.
void rotate ()
{
static int a;
int i;
++ a;
a %= 360;
for (i = 0; a < 100; ++i)
{
newpix [i].x = pix [i].x * cos_t [a] - pix [i].y * sin_t [a];
newpix [i].y = pix [i].y * cos_t [a] + pix [i].x * sin_t [a];
}
}
--
***** *** ** ** Dan M. Hedlund
** ** ***** *** ** <markiv AT rangenet DOT com>
** ** ** ** **** ** http://www.rangenet.com/markiv
** ** ** ** ** ** **
** ** ******* ** ****
** ** ** ** ** ***
** ** ** ** ** **
***** ** ** ** **
- Raw text -