www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: DaveAnd on May 04, 2013, 09:48:02 PM

Title: Translating an object based on a rotation
Post by: DaveAnd on May 04, 2013, 09:48:02 PM
Hi - I have been wresting with rotating an object and then translating it along that rotated axis but with no joy. I have searched for this but havent found actual code.

So what I would really like is code to give an angle of rotation and then translate according to that rotation.

Cool project btw :)

Dave
Title: Re: Translating an object based on a rotation
Post by: Thomas. on May 04, 2013, 09:55:33 PM
You can use something like...

SimpleVector vector = SimpleVector.create();
object.getRotationMatrix().getZAxis(vector);
vector.scalarMul(10);
object.translate(vector);
Title: Re: Translating an object based on a rotation
Post by: DaveAnd on May 04, 2013, 10:03:39 PM
does that specify the angle of rotation or translation? am looking for a way to do one followed by the other (with the translation following the resulting rotated axis)

Thanks!
Title: Re: Translating an object based on a rotation
Post by: Thomas. on May 04, 2013, 10:12:07 PM
The attribute in method vector.scalarMul(10) is how large move of object will be.
Title: Re: Translating an object based on a rotation
Post by: DaveAnd on May 04, 2013, 10:15:08 PM
ok so would you need to rotate before this code?
Title: Re: Translating an object based on a rotation
Post by: Thomas. on May 04, 2013, 10:21:52 PM
You can use this code anywhere, before, after rotation, it does not matter. This is useful ex. for car. You may rotate with car, but car will go always forward.