delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/10/09/23:20:03

Date: Sun, 9 Oct 1994 22:20:43 -0400 (EDT)
From: Kimberley Burchett <OKRA AT max DOT tiac DOT net>
Subject: keyboard messups!!!! :(
To: DJGPP Mailing List <djgpp AT sun DOT soe DOT clarkson DOT edu>

  A little while ago, I spent HOURS trying to figure out how come my 
fixed point 2d rotation code wasn't working.  I never figured out what 
was wrong with it, but eventually I rewrote the program and everything 
went fine.  
  When I rewrote it, I made it wait for a keypress after every rotation.  
Tonight I decided I wanted to see it rotate out of control, so I took out 
the getch() call.  TADA!  the problem was back again!

Code that works:

#include "graph.h" /* graphics routines */
#include "fixed.h" /* fixed point routines */
#include "trig.h"  /* fixed point trig routines (has FixRotate() in it */
 
int main() {
 
  fixed x,y;         /* position of point */
  fixed angle;       /* how much to rotate the point */
 
  StartX_240();      /* start mode X 320x240 */
  x = Int2Fix(100);  /* start with radius of 100 pixels */
  y = Int2Fix(0);
  angle = FixPI/5;   /* rotate by pi/5 */
  do {
    FixRotate(x,y,angle,&x,&y);  /* cumulative rotations */
    PutPixel(FixWhole(x)+160, FixWhole(y)+120, 15);  /* draw the point */
  } while(kbhit() == 0);         /* do this until a button is pressed */
  CloseVGA();        /* back to text mode */
}

Code that doesn't work:

#include "graph.h"
#include "fixed.h"
#include "trig.h"
 
int main() {
 
  fixed x,y;
  fixed angle;
 
  StartX_240();
  x = Int2Fix(100);
  y = Int2Fix(0);
  angle = FixPI/5;
  do {
    FixRotate(x,y,angle,&x,&y);
    PutPixel(FixWhole(x)+160, FixWhole(y)+120, 15);
    while(kbhit() == 0);
  } while(getch() != 'q');
  CloseVGA();
}


  The code that works will make a point go around the circle in steps of 
pi/5 (10 steps per rotation).  The code that doesn't work makes the point 
spiral in to the center after about 10 rotations.
  The only difference between them is the line with getch() in it.
  I've noticed problems before with using the do...while construct and
kbhit() at the same time that have gone away when I change to a regular
while construct, but I can't remember what they were exactly and I can't
find them in my code (since I changed them to while's).
  Does anybody have anything to say in the compiler's defence?  Is this
something about C I don't know about and it's not _supposed_ to work?  Is 
it a problem with the DOS version of kbhit()?  *pout*
							Kim

- Raw text -


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