delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/05/18:23:40

Message-ID: <331DFE26.5DC0@rangenet.com>
Date: Wed, 05 Mar 1997 17:13:43 -0600
From: "Dan M. Hedlund" <markiv AT rangenet DOT com>
Reply-To: markiv AT rangenet DOT com
Organization: Range Net
MIME-Version: 1.0
To: Guess <times9 AT clark DOT net>
CC: djgpp AT delorie DOT com
Subject: Re: Rotation problem
References: <Pine DOT GSO DOT 3 DOT 95 DOT 970305131547 DOT 2365A-100000 AT explorer2 DOT clark DOT net>

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019