peic@core.north.de (Peter Eichler) (07/01/91)
Hi fellas!
Some days ago I read a question about rotating a logo (or other stuff)
on the screen. I'm doing now the same stuff on my Amiga, so I here are
real cude procedures, which will help you to rotate 2D/3D stuff and
display it. The routines are rather easy. They are using floating point,
but you can easily do this winth long ints. Oh, I forgot: These Procedures
using trig-functions. Faster than that are sine & cosine table. Also, this
functions of sine and cosine assuming angles with DEGREES as input. To
convert radians sine to degrees sine use simply:
#include <math.h>
double Sin(double angle)
{
return sin((PI/180.0) * angle);
}
And the same way for doing it with cosine. Okidoki, here we go:
struct Point /* Usual 3D coordinates */
{ double X, Y, Z;
};
/* Converts a 3D coordinates into a 2D coordinates.
NO(!) clipping is performed. You have to check this for yourself!
*/
void CalcPoint(struct Point *p,long *x, long *y)
{
*x=p->X*(1.0-p->Z/Z0);
*y=p->Y*(1.0-p->Z/Z0);
/* where Z0 -> Distance between origin (0,0,0) and aim point.
Z0 modifies the 3D look very large; setting Z0 to MAXLONG performs nearly no
3D look (pure paralell perspective), a small value may distort the view.
*/
}
/* Rotates a point around the X-axis */
void RotatePointX(struct Point *p,short angle)
{ long y,z,c,s;
y=p->Y;
z=p->Z;
c=Cos(angle);
s=Sin(angle);
p->Y=(y*c-z*s)>>10;
p->Z=(y*s+z*c)>>10;
}
/* Rotates a point around the Y-axis */
void RotatePointY(struct Point *p,short angle)
{ long x,z,c,s;
x=p->X;
z=p->Z;
c=Cos(angle);
s=Sin(angle);
p->X=(x*c+z*s)>>10;
p->Z=(z*c-x*s)>>10;
}
/* Rotates a point around the Z-axis */
void RotatePointZ(struct Point *p,short angle)
{ long x,y,c,s;
x=p->X;
y=p->Y;
c=Cos(angle);
s=Sin(angle);
p->X=(x*c-y*s)>>10;
p->Y=(x*s+y*c)>>10;
}
---------------------------------
That was all folks,
Peter
Since pleasure is the Unique, to reveal Pleasure is itself a unique duty. FGTH
------------------------------------------------------------------------------
SNAIL:Peter Eichler \ Hegelstrasse 3 \ 2800 Bremen 1 \ Germany Amiga 3000
EMAIL:peic@core.north.de OR peic@skuld.north.de: VOICE:(+)49 421 530642