Path: chuka.playstation.co.uk!news From: "Andrew Murray" Newsgroups: scee.yaroze.freetalk.english Subject: Re: Local Rotation Date: Mon, 10 Mar 2003 09:59:18 -0000 Organization: PlayStation Net Yaroze (SCEE) Lines: 120 Message-ID: References: NNTP-Posting-Host: pc-62-31-88-170-dn.blueyonder.co.uk X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Solved this one a while ago but I figured that I should post a solution since I couldn't find anything on this before. This is the function that was being used to set the rotation matrix of the GsCOORDINATE2 structure. The tempMatrix is merely assigned to the matrix inside the GsCOORDINATE2 structure that represents the model's local coordinate system. void UpdateObjectCoordinates (ObjectHandler * obj) { MATRIX tempMatrix; // calculate the rotation matrix from rotation vector RotMatrix(&(obj->rotate), &tempMatrix); // assign new matrix to coordinate system // specifying the new rotation components obj->coord.coord = tempMatrix; // set position by absolute coordinates // t[0],t[1],t[2] are the position components of the coordinate matrix obj->coord.coord.t[0] = obj->position.vx; obj->coord.coord.t[1] = obj->position.vy; obj->coord.coord.t[2] = obj->position.vz; // tell GTE that coordinate system has been updated obj->coord.flg = 0; } The solution is to zero the rotation vector (obj->rotate) every frame then store the amount of change in rotation around each axis. Like so... void ModelRotate(PadInfo *padStatus) { obj.rotAxis.vx = obj.rotAxis.vy = obj.rotAxis.vz = 0; if(padStatus->state & PadUp) obj.rotAxis.vx = -ROT_STEP; if(padStatus->state & PadDown) obj.rotAxis.vx = ROT_STEP; if(padStatus->state & PadLeft) obj.rotAxis.vy = -ROT_STEP; if(padStatus->state & PadRight) obj.rotAxis.vy = ROT_STEP; if(padStatus->state & PadL1) obj.rotAxis.vz = -ROT_STEP; if(padStatus->state & PadL2) obj.rotAxis.vz = ROT_STEP; } With this change in rotation a new matrix can be made which stores the change in rotation as a matrix. This is then concatenated onto the matrix inside the GsCOORDINATE2 structure. void UpdateObjectCoords(object3D *obj3d) { // temporary matrix to hold the change in rotation // used if matrix rotation is enabled MATRIX tempMatrix; // check to see if the rotation vector has changed // this avoids recalculating rotation values if((obj3d->rotAxis.vx != 0) || (obj3d->rotAxis.vy != 0) || (obj3d->rotAxis.vz != 0)) { // execute matrix code // calculate the rotation matrix from rotation vector RotMatrix(&(obj3d->rotAxis), &tempMatrix); // concatenate the resutlts of the new rotation matrix onto the old one MulMatrix0(&(obj3d->coord.coord), &tempMatrix, &(obj3d->coord.coord)); // fix the matrix error problem by cross producting and normalising // the x, y and z components of the rotation matrix AdjustCoordinate2(&(obj3d->coord)); } // set position by absolute coordinates i.e. relative to WORLD // t[0],t[1],t[2] are the position components of the coordinate matrix obj3d->coord.coord.t[0] = obj3d->position.vx; obj3d->coord.coord.t[1] = obj3d->position.vy; obj3d->coord.coord.t[2] = obj3d->position.vz; // tell GTE that coordinate system has been updated obj3d->coord.flg = 0; } Like so. There is also an optimisation in that the rotation vector is checked to see if it actually contains any new values otherwise the rotation stays the same and it shouldn't be recalculated. Hope this helps to someone eventually. Andy. "Andrew Murray" wrote in message news:b38uq2$6ma1@www.netyaroze-europe.com... > How would it be possible to have an object in a 3D world on the Yaroze to > rotate around its own local axis? For example (grab a pen) if you rotate > around the x axis first say by 45 degrees, then rotate around the z axis by > 45 degrees, rotating around the y axis would make the object spin around the > the new y axis, however just now my code is making the object spin around > the world y axis which is giving some pretty wierd results. > > Can anyone specify a process that they have went through in code to obtain > rotation based on local axis? > > Thanks in advance, > Andy. > >