Author Topic: Translating an object based on a rotation  (Read 2284 times)

Offline DaveAnd

  • byte
  • *
  • Posts: 3
    • View Profile
Translating an object based on a rotation
« 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

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Translating an object based on a rotation
« Reply #1 on: May 04, 2013, 09:55:33 pm »
You can use something like...

Code: [Select]
SimpleVector vector = SimpleVector.create();
object.getRotationMatrix().getZAxis(vector);
vector.scalarMul(10);
object.translate(vector);

Offline DaveAnd

  • byte
  • *
  • Posts: 3
    • View Profile
Re: Translating an object based on a rotation
« Reply #2 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!

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Translating an object based on a rotation
« Reply #3 on: May 04, 2013, 10:12:07 pm »
The attribute in method vector.scalarMul(10) is how large move of object will be.

Offline DaveAnd

  • byte
  • *
  • Posts: 3
    • View Profile
Re: Translating an object based on a rotation
« Reply #4 on: May 04, 2013, 10:15:08 pm »
ok so would you need to rotate before this code?

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Translating an object based on a rotation
« Reply #5 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.