Path: utzoo!mnetor!tmsoft!masnet!canremote!mark.williston From: mark.williston@canremote.uucp (MARK WILLISTON) Newsgroups: comp.graphics Subject: Re: 3-D Rotation Algorithm Message-ID: <89101604163968@masnet.uucp> Date: 16 Oct 89 00:46:00 GMT Organization: Canada Remote Systems Limited, Mississauga, ON, Canada Lines: 48 int x, y, z, xa, ya, za, angle; double d, r, convert=3.141593/180; int Sin[360], Cos[360]; void rot(void) { int t; t = ((Cos[xa]*x)>>8)-((Sin[xa]*z)>>8); /* Rotate around the X Axis */ z = ((Sin[xa]*x)>>8)+((Cos[xa]*z)>>8); x = t; t = ((Cos[ya]*y)>>8)+((Sin[ya]*z)>>8); /* Rotate around the Y Axis */ z =-((Sin[ya]*y)>>8)+((Cos[ya]*z)>>8); y = t; t = ((Cos[za]*x)>>8)+((Sin[za]*y)>>8); /* Rotate around the Z Axis */ y =-((Sin[za]*x)>>8)+((Cos[za]*y)>>8); x = t; } void main(void) { Call_Set_Vid_Mode( Your_Mode ); for(angle=0; angle<360; angle++) /* table of shiftwise degs */ { r=(double)angle*convert; Cos[angle]=(int)(cos(r)*256); Sin[angle]=(int)(sin(r)*256); } while(you_want_to_rotate_points) { x=xval; /* fill x from somewhere! */ y=yval; /* fill y from somewhere! */ z=zval; /* fill z from somewhere! */ /* With this pseudodegree method, x, y and z must not overflow the integer. This works well with small numbers. Using long ints would give a larger capacity. */ rot(); /* rotate them */ x+=screen_centre; /* bring the point into view */ y+=screen_centre; /* bring the point into view */ CallYourPlot(x,y,color); } Mark Williston --- * QDeLuxe 1.10 #3694 <\/>ark illiston - Author of 2-Bit Poker [EGA]