delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/05/14:58:24

Date: Wed, 5 Mar 1997 13:19:25 -0500 (EST)
From: Guess <times9 AT clark DOT net>
Cc: djgpp AT delorie DOT com
Subject: Rotation problem
In-Reply-To: <331c1847.1675577@ursa.smsu.edu>
Message-Id: <Pine.GSO.3.95.970305131547.2365A-100000@explorer2.clark.net>
Mime-Version: 1.0
content-length: 0

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!
--
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>
#include <allegro.h>

#define RAD_TO_DEG(x) ((x)*(180/3.14159265359))
#define DEG_TO_RAD(x) ((x)*(3.14159265359/180))

struct {
   float x, y;
} pix[100];

float sin_t[360], cos_t[360];

void init();
void create_tables();

void create_tables()
{
  int i;
  for(i = 0; i < 360; i++) {
    sin_t[i] = sin(DEG_TO_RAD(i));
    cos_t[i] = cos(DEG_TO_RAD(i));
  }
}

void init()
{
   int i;
   for(i = 0; i < 100; i++) {
      pix[i].x = (rand() % 320) - 160;
      pix[i].y = (rand() % 200) - 100;
   }
}

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 draw()
{
   int i;
   for(i = 0; i < 100; i++)
      putpixel(screen, 160+pix[i].x, 100+pix[i].y, 13);
}

int main()
{
   int i;
   allegro_init();
   set_gfx_mode(GFX_VGA, 320, 200, 0, 0);
   clear(screen);
   init();
   create_tables();
   while(!kbhit()) {
      clear(screen);
      draw();
      rotate();
   }
   allegro_exit();
   return 0;
}
----
The fountains mingle with the river,
   And the rivers with the ocean;
The winds of heaven mix for ever
   With a sweet emotion;
Nothing in the world is single;
   All things, by a law divine,
In one another's being mingle--
  Why not I with thine?
          -- P B Shelley, _Love's Philosophy_

http://www.clark.net/pub/times9
http://nothing.home.ml.org
http://nowhere.base.org
ftp://ftp.clark.net/pub/times9
SigGenre (signature and plan generator)

- Raw text -


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