From: ellman AT xs4all DOT nl () Newsgroups: comp.os.msdos.djgpp Subject: Re: rotation Q: Date: 30 Mar 1997 20:32:46 GMT Organization: XS4ALL Message-ID: <5hmile$54f$1@news0.xs4all.nl> References: <333DF207 DOT 8B3 AT cam DOT org> NNTP-Posting-Host: xs1.xs4all.nl Lines: 53 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp In article <333DF207 DOT 8B3 AT cam DOT org>, Tudor wrote: >I have this Q: How can I do rotations however I want? >Like ,when I rotate a cube(classic :) I have no ideea after what point >the cube gets rotated(probably the origin). The cube gets rotated around the origin of whatever space you're rotating it. The cube is usually defined in object-space and translated to world-space, then to view-space, and then projected to screen-space (if the camera remains fixed at the origin in world-space, then world-space and view space are equivalent). >Let's say you have a stick and the points A and B are its extremities: >(C is just another point) > > A ----------- B C :) > >Now you can rotate the stick by the middle and A and B will move in >opposite directions. You can rotate it after C so A and B will move in >the same direction. Or you can take any other point to rotate your >stuff. (the example is stupid but at least it explains what I want) >How can I do something like this in Allegro? The solution is to translate the points of the object to a new space where the point you want to rotate around is the origin (if you only want to rotate your object around a single point, then make that the origin so that translation isn't necessary). After the translation, do the rotation, and then translate the points back using the reverse of the translation. This means: + Let A be the point in object-space you want to rotate around. + Subtract A from all points in object. + Rotate all points in object. + Add A to all points in object. The last 3 steps can be combined into one by creating translating matrices for the two translations and a rotation matrix. Multiply the 3 matrices. Note: the order of the multiplication is important. Use: M(subtract_A) * M(rotate) * M(add_A) The resulting matrix rotates points around A. Apply this to all of the points (with very small numbers of points, it might be quicker to subtract and add A to the points by hand, as building the matrices takes time). After this, the points can be translated to world-space (or in the case of a hierarcical object, the space of the next object). AE. -- Andrei Ellman - URL: http://www.xs4all.nl/~ellman/ae-a - ae1 AT york DOT ac DOT uk "All I wanna do is have some fun :-) || ae-a AT minster DOT york DOT ac DOT uk I've got the feeling I'm not the only one" || mailto:ellman AT xs4all DOT nl -- Sheryl Crow :-) || It's what you make of it.