Just rotation by btTransform

User avatar
frca
Posts: 39
Joined: Sat May 02, 2009 9:38 am

Just rotation by btTransform

Post by frca »

Hello.
Is there a simpler way of doing this?

Code: Select all

btTransform transf;
btVector3 vect;
...
btVector3 rotatedVect = transf*vect-transf.getOrigin();
(I don't like that there is transf twice.)
Thanks.
robagar
Posts: 48
Joined: Fri May 21, 2010 1:49 am

Re: Just rotation by btTransform

Post by robagar »

How about this?

Code: Select all

transf.getRotation() * vect
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Just rotation by btTransform

Post by Flix »

frca wrote:btVector3 rotatedVect = transf*vect-transf.getOrigin();
(I don't like that there is transf twice.)
I would write:

Code: Select all

btVector3 rotatedVect = transf.getBasis() * vect;
so that I can just use the btMatrix3x3 reference that's already embedded inside the btTransform (without using its "origin" component).
I must check, but I think that "transf.getRotation()" converts the btMatrix3x3 to a btQuaternion (which is not needed); but I'm sure
robagar's intention was to point out the right approach (i.e. if you need to rotate a vector around a transform, you can just use its rotation).
robagar
Posts: 48
Joined: Fri May 21, 2010 1:49 am

Re: Just rotation by btTransform

Post by robagar »

yup you're right - using getBasis() is more efficient since it returns a reference & avoids the btQuaternion construction. Personally I'd use the quat anyway 'cos the intention is more clear (it's got the word "rotation" in there), unless I really needed it to be quick