Author Topic: Rotate a group of objects from one vector to another  (Read 1952 times)

Offline HammerNL

  • byte
  • *
  • Posts: 15
    • View Profile
Rotate a group of objects from one vector to another
« on: April 23, 2013, 03:38:41 pm »
Hi,

I have a group of Object3D's which I want to rotate "as a whole" into a different direction.

First, I'm giving all the objects the same rotation pivot point.
Then, I come up with a single SimpleVector which represents the current direction of the object group.
Then, after some calculations, I come up with a new SimpleVector, which indicates the desired new direction of my objects.

My question now is, how to use these 2 vectors to rotate my objects?

So let's say:

Code: [Select]
Object3D[] group = something1;
SimpleVector original = something2;
SimpleVector destination = something3;

for (Object3D o: group)
{
   // what to do with o?
}

Tnx!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Rotate a group of objects from one vector to another
« Reply #1 on: April 23, 2013, 08:09:44 pm »
You mean you want to somehow interpolate from the initial vector to the target direction?

Offline HammerNL

  • byte
  • *
  • Posts: 15
    • View Profile
Re: Rotate a group of objects from one vector to another
« Reply #2 on: April 23, 2013, 09:12:19 pm »
Hi Egon,

I'm not sure that I understand what you mean by that, but I'd say that is not what I want.
Let me try to explain my problem a bit more practically:

Imagine a persons' lower arm, from the elbow to the wrist. The initial position of the arm is represented by vector 1. Now my "hero" moves, and I've calculated a new vector (vector 2) that represents the new position the arm should be in.

So now, somehow it must be possible to use the difference in angles between those two vectors and use those angles to rotate the objects that actually make up the lower arm. All those objects have the same pivot point, which is of course the elbow.

I hope this clarifies what I'm trying to do :)

Tnx!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Rotate a group of objects from one vector to another
« Reply #3 on: April 24, 2013, 07:30:06 am »
So, you have an initial rotation and a final one (more or less described by the direction vector in which the arm is pointing) and you want to have a rotation that transforms one into the other!? If you have both vectors, you can calculate the angle between them and if you have the actual rotation axis, you can rotate with that angle around that axis.
Another option might be to use SimpleVector.getRotationMatrix() on the final vector and apply the resulting matrix. Depending on the orientation of the arm, this might require some additional transformations.
Or step back from what you have and rethink if you can't calculate the actual rotation directly instead of the final position.

Offline HammerNL

  • byte
  • *
  • Posts: 15
    • View Profile
Re: Rotate a group of objects from one vector to another
« Reply #4 on: April 25, 2013, 12:04:17 am »
Hi Egon,

It's a good idea to come up with the needed angles right away from the calculations I'm doing anyway, still need to look at that. Meanwhile I took a look at the SimpleVector.getRotationMatrix() method you suggested... wondering what I could do with it, it turned out, that this was the solution for my question 8)

I thought I'd post the solution here, just in case someone stumbles upon this page with a similar question.

Code: [Select]
Object3D[] group = something1;
SimpleVector original = something2;
SimpleVector destination = something3;

Matrix matrix = original.getRotationMatrix().invert();
matrix.matMul(destination.getRotationMatrix());

for (Object3D o: group)
{
  o.setRotationMatrix(matrix);
}

Tnx 4 your help!