Xref: utzoo rec.games.programmer:3346 comp.os.msdos.programmer:4501 Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!mcsun!unido!ira.uka.de!smurf!altger!chiuur!cmk From: cmk@chi.sub.org (Christian Kaiser) Newsgroups: rec.games.programmer,comp.os.msdos.programmer Subject: Re: 3D Rotation Keywords: 3D, rotation, real Message-ID: Date: 7 Apr 91 06:35:44 GMT References: <1991Apr05.224711.12750@lynx.CS.ORST.EDU> Followup-To: comp.graphics Organization: Home sweet home, Munich, Germany Lines: 49 [ Followup to comp.graphics... ] In article <1991Apr05.224711.12750@lynx.CS.ORST.EDU> murrayk@prism.CS.ORST.EDU writes: [... 3D graphics & rotation ...] )created my own code. All to no avail. I can rotate things up the )yin-yang but the rotations are not correct. They seem to be absolute to )the screen, not to the actual object. I have tried every thing I can )think of to remedy this problem, but I have had no luck. I don't know if )I am just missing something elemental or if there is actually a big idea )that I just don't see... If I have understood your problem, you seem to be doing the rotations with matrices. You can rotate a set of points around the origin(!) of your coordinate system using a simple matrix multiplication. For simplicity, here is an example for the 2D case (3D is mostly analogous). x', y' = coordinates after rotation x , y = coordinates before rotation phi = angle of rotation | cos(phi) sin(phi) 0 | [ x' y' 1 ] = [ x y 1 ] * | -sin(phi) cos(phi) 0 | | 0 0 1 | Now, the key point is that this transformation rotates around the ORIGIN ( [ 0 0 ] ) of your coordinate system. To rotate around an arbitrary point [ u v ], which may in your case be the center of the object, first translate the rotation center point to the origin, then rotate, then translate it back to where it was before. The equation changes as follows: u , v = coordinates of rotation center | 1 0 0 | | cos(phi) sin(phi) 0 | | 1 0 0 | [ x' y' 1 ] = [ x y 1 ] * | 0 1 0 | * |-sin(phi) cos(phi) 0 | * | 0 1 0 | |-u -v 1 | | 0 0 1 | | u v 1 | You can, of course, multiply the matrices beforehand to get ONE transform- ation matrix in order to save time... For an excellent (really!) introduction into these things try to get D.F. Rogers, J.A. Adams, "Mathematical Elements for Computer Graphics", Second Edition, McGraw Hill 1990, ISBN 0-07-100289-8 . Gruesse, Christian -- Christian Kaiser, Munich, Germany Mail: cmk@chi.sub.org, cmk@chiuur.UUCP