Mail Archives: djgpp/1997/04/01/00:24:49
I don't know if this will help - but heres the code I've got to move a
pixel around in a circle - I was also having the 'skipping' problem, and it
turned out to be because I was using COS and SIN with Degrees instead of
Radians.
#include <stdlib.h>
#include <stdio.h>
#include <allegro.h>
#include <math.h>
float result = 0.0;
float sintable[360];
float costable[360];
float rads = 57.29577951;
int x_coord, y_coord,d,theta,= 0;
int newx,newy = 0;
int main()
{
BITMAP *buffer;
PALLETE pal;
pal[0].r = 0;
pal[0].g = 0;
pal[0].b = 0;
for (d = 1; d < 4; d++) {
pal[d].r = 63;
pal[d].g = 63;
pal[d].b = 63;
}
allegro_init();
set_gfx_mode(GFX_VGA, 320, 200, 0, 0);
set_pallete(pal);
buffer = create_bitmap(SCREEN_W, SCREEN_H);
clear(buffer);
install_keyboard();
x_coord = 45;
y_coord = 45;
theta = 0;
while (theta < 361)
{
result = sin(theta / rads);
sintable[theta] = result;
result = cos(theta / rads);
costable[theta] = result;
theta++;
}
theta = 0;
while (!keypressed()) {
theta++;
if ( theta == 360 )
theta = 0;
newx = (costable[theta]*x_coord);
newy = (sintable[theta]*y_coord);
newx = newx + 160;
newy = 100 - newy;
putpixel(buffer, newx, newy, 240);
vsync();
blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
clear(buffer);
}
return 0;
}
dberry AT dca DOT gov DOT au
Dept. of Communications and the Arts
-------------
Original Text
From: C=US/A=INTERNET/DDA=ID/tudor(a)cam.org, on 04-01-97 2:56 PM:
Henri Ossi wrote:
> But when the ball moves across the screen, I can see this "jumping
> around".
> It isn't steady.
> How can I "smooth" it?
I have the exact same problem but I don't hink it has anything to do
with what you said... I'm using only floats and, depending on what type
of movement I do, the optimisations I add and the DPMI host, it jumps
around more or less.
IE. only X movement with no optimisations, fine under both CWSDPMI &
windoze95.
X and Y movement: jumps. Add optimisations: Fine under CWSDPMI, less
jumps under windoze.
X,Y and Z movement + heavy optimisations: less jumps under CWSDPMI,
"heavy" jumps under windoze.
I know this doesn't help,though...
BTW: Are U using the allegro functions? If so, how did you create your
model for the object? I would be interested in discussing different
approaches to creating primitives and objects etc.
> Thanks for your answers.
--
tudor 'at' cam 'dot' org
http://www.cam.org/~tudor
'This is Scott Nudds of the Borg. C is irrelevant.'
- Raw text -