Path: chuka.playstation.co.uk!news From: James Russell Newsgroups: scee.yaroze.programming.3d_graphics,scea.yaroze.programming.3d_graphics Subject: Re: Converting 3D Vector to rotation matrix. Date: Wed, 12 Aug 1998 08:56:51 +0100 Organization: Sony Computer Entertainment Europe Lines: 34 Message-ID: <35D14AC3.C7F70F5C@scee.sony.co.uk> References: NNTP-Posting-Host: mailgate.scee.sony.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.5b1 [en] (Win95; I) X-Accept-Language: en Xref: chuka.playstation.co.uk scee.yaroze.programming.3d_graphics:806 scea.yaroze.programming.3d_graphics:280 Cary Brisebois wrote: > > I obtain a normal vector from a polygon. I then want to place a cube > tangent to this polygon with its z-axis (in its local coordinates) > parallel to the normal vector. If you put the cube into the same coord system as the polygon, you won't need to create a different rotation vector. However, animating that cube (rotating it around its Z) will be difficult if your polygon is not axis aligned. So alternatively, you can make the coordinate system of the cube a child of the coordinate system of the polygon. The translation of the child system will be the position (in the parent) where you want the cube to be on the polygon. The 3x3 rotation matrix will (U,V,N), where U,V,N are 1x3 vectors stacked on top of one another to create a 3x3 matrix. The values of U, V and N are as follows. If you are looking at the cube it its coordinate system: U is the right (X axis) vector. V is the down (Y axis) vector. N is the in (Z axis) vector. You already know N, it's the normal. You can calculate V by doing a projection onto some standard 'up' vector, and U will be the cross product of V and N. Make sure all 3 are normalised afterwards. All 3 should be perpendicular to each other. If that doesn't work, try using the transpose of the matrix. (To be honest, I couldn't get this approach to work when I tried it, but I didn't spend very long on it.) The full theory is well described in "Computer Graphics" by FS Hill Jr. Decomposing this matrix into Euler coordinates (3 angles of rotation) is non-trival. Cheers, James -- == James_Russell@scee.sony.co.uk +44 (171) 447-1626 == Developer Support Engineer - Sony Computer Entertainment Europe Other than that, how'd you like the play, Mrs. Lincoln?