desperate need of rotation help - applying rotation on pre-existing rotation
by Steve · in General Discussion · 10/03/2010 (8:44 am) · 1 replies
hi everyone and thank you for taking the time to open this thread.
i have purchased the second edition of 3D game programming all in one and have been trying very hard for weeks to get a rotation to work in the demo game supplied with the disk.
basically i am making a function that moves a called object (building example) up in the air(off ground), turning it upside down, and shrinking it by 50%. the problem is that the building has a pre-existing rotation on it; for example, (last 4) 0 0 1 49.2744. so when i do my transformation with the below code, the building loses its pre-existing rotation.
%object.setScale(0.5 SPC 0.5 SPC 0.5);
%object.setTransform(%locX SPC %locY SPC %locZ SPC 1 SPC 0 SPC 0 SPC 3.141592654);
i have tried in a following line of code to re-instate the pre-existing rotation but it just reverses my upside down effect while keeping the building in the air at a 50% scale:
%object.setScale(0.5 SPC 0.5 SPC 0.5);
%object.setTransform(%locX SPC %locY SPC %locZ SPC 1 SPC 0 SPC 0 SPC 3.141592654);
%object.setTransform(%locX SPC %locY SPC %locZ SPC 0 SPC 0 SPC 1 SPC %origRotDegree);
--where %origRotDegree is pulled from a getTransform()
i don't understand why rotation was set up this way. why not add parameters for each axis rotation x, y, and z, so that all rotations can take place in one simple statement such as:
%object.setTransform(%locX SPC %locY SPC %locZ SPC 1 SPC 0 SPC 1 SPC 3.141592654 SPC 0 SPC %origRotDegree);
anyhow after 3 weekends of trying to figure this out i am about to throw this book out... is there a line of code i am missing to apply the pre-existing / changes to rotations as they occur before attempting another or?
thank you very much for your time friends.
-Kris
i have purchased the second edition of 3D game programming all in one and have been trying very hard for weeks to get a rotation to work in the demo game supplied with the disk.
basically i am making a function that moves a called object (building example) up in the air(off ground), turning it upside down, and shrinking it by 50%. the problem is that the building has a pre-existing rotation on it; for example, (last 4) 0 0 1 49.2744. so when i do my transformation with the below code, the building loses its pre-existing rotation.
%object.setScale(0.5 SPC 0.5 SPC 0.5);
%object.setTransform(%locX SPC %locY SPC %locZ SPC 1 SPC 0 SPC 0 SPC 3.141592654);
i have tried in a following line of code to re-instate the pre-existing rotation but it just reverses my upside down effect while keeping the building in the air at a 50% scale:
%object.setScale(0.5 SPC 0.5 SPC 0.5);
%object.setTransform(%locX SPC %locY SPC %locZ SPC 1 SPC 0 SPC 0 SPC 3.141592654);
%object.setTransform(%locX SPC %locY SPC %locZ SPC 0 SPC 0 SPC 1 SPC %origRotDegree);
--where %origRotDegree is pulled from a getTransform()
i don't understand why rotation was set up this way. why not add parameters for each axis rotation x, y, and z, so that all rotations can take place in one simple statement such as:
%object.setTransform(%locX SPC %locY SPC %locZ SPC 1 SPC 0 SPC 1 SPC 3.141592654 SPC 0 SPC %origRotDegree);
anyhow after 3 weekends of trying to figure this out i am about to throw this book out... is there a line of code i am missing to apply the pre-existing / changes to rotations as they occur before attempting another or?
thank you very much for your time friends.
-Kris
Steve
MatrixF %objTx = control->getTransform();
// Get rotations from transform matrix
VectorF vec;
objTx.getColumn(1,&vec);
// Get X-vector for roll calculation
Point3F xv;
objTx.getColumn(0,&xv);
// Calculate PRH (x = pitch, y = roll, z = heading)
Point3F rot(-mAtan(vec.z, mSqrt(vec.x*vec.x + vec.y*vec.y)),
mDot(xv,Point3F(0,0,1)), -mAtan(-vec.x,vec.y) );
// Set up vars
F32 pitch = mRadToDeg(rot.x); // Pitch
F32 yaw = mRadToDeg(rot.z); // Heading
F32 roll = mRadToDeg(rot.y); // Roll
While this is all fairly new to me, it seems a bit much! I am kind of baffled by the lack of information/examples pertaining to this subject as it relates to the torque engine but yet I continue on...