Path: chuka.playstation.co.uk!news From: James Russell Newsgroups: scee.yaroze.programming.3d_graphics Subject: Re: creation of tmds Date: Thu, 02 Jul 1998 10:22:57 +0100 Organization: Sony Computer Entertainment Europe Lines: 77 Message-ID: <359B5171.8BBDAB1C@scee.sony.co.uk> References: <354f8520.24963808@www.netyaroze-europe.com> <35527A2E.72F907B4@home.com> <6n904u$4sn1@scea> <359965bc.370444681@news.scea.sony.com> <359b0284.176613649@news.scea.sony.com> NNTP-Posting-Host: camfw01.millennium.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.05 [en] (Win95; I) Jamin Frederick wrote: > > 10) How do I rotate an object? > > First you have to know that all models rotate about the origin (0,0,0) of your > model's coordinate system (do rsdform -v mymodel.rsd). This means that > however your primitives are placed in your RSD, they will rotate around this > point. So if the "center" of your model (representing the actual center of > your model) is not (0,0,0), translate it there first before you rotate > it. Correct. Translation occurs AFTER rotation. From here on what you are doing is technically correct, but not used very often because of the distortion involved due to the cumulative error that builds up. The 'correct' way is to store a rotation vector (as an SVECTOR), then to use RotMatrix to turn that SVECTOR into a fullblown rotation matrix. Thus, if you want to rotate the object around the Y axis by 5 degree more, you just _add_ (5*360/4096) to the rotation vector's vy component. It might look something like this: GsCOORDINATE2 Coord; SVECTOR RotVector = { 0, 0, 0 }; SVECTOR Position = { 0, 0, 0 }; I want to rotate this object by 100 degrees around the Y, and move it to the position X=20, Y=30, Z= 50; MATRIX TempMatrix; SVECTOR RotVector; RotVector.vy = 100 * 360 / 4096; (4096 = 360 degrees) Position.vx = 20; Position.vy = 30; Position.vz = 50; RotMatrix(&RotVector, &Coord.coord); // Creates the rotation matrix. RotVector.coord.t[0] = Position.vx; // Fills in the Translation part of the rotation matrix. RotVector.coord.t[1] = Position.vy; RotVector.coord.t[2] = Position.vz; // Let the system know that this matrix has changed. Coord.flg = 0; /* For your information, the Flg variable is used to indicate that the 'workm' matrix in the GsCOORDINATE2 is valid. The 'workm' matrix is identical to the 'coord' matrix for the top coordinate system in a heirarchical model, but in coordinate systems further down the tree it is the matrix you get when you multiply the 'coord' matrix and all this GsCOORDINATE2's parent's coord matrices together - thus creating a matrix which will translate this coord system's to WORLD coordinates. The flg variable is used to determine whether or not it should recalculate some or all these matrix multiplications (which is performed internally by the libraries), because if one matrix changes, all it's children must change too. */ // GsGetLs() will create the Local to Screen matrix. It also checks the flg variable and // recalculates the product of the parent matrices if necessary. This means the // coordinate system hierarchy will contain the correct Local to World matrices. // After the function call, TempMatrix will contain a matrix which will translate // this coordinate system to Screen coords. GsGetLs(&Coord, &TempMatrix); // GsSetLs() sets up the Local -> Screen matrix in the GTE. Any subsequent GsSortObject() // calls will use this matrix. GsSetLs(&TempMatrix); GsSortObject(my3Dobject...); This is all off the top of my head, so apologies if I've missed anything out. -- James_Russell@scee.sony.co.uk +44 (171) 447-1626 Developer Support Engineer - Sony Computer Entertainment Europe Frank: Limbless man on a barbeque