Rotate a group of objects from one vector to another

Started by HammerNL, April 23, 2013, 03:38:41 PM

Previous topic - Next topic

HammerNL

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:


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

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


Tnx!

EgonOlsen

You mean you want to somehow interpolate from the initial vector to the target direction?

HammerNL

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!

EgonOlsen

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.

HammerNL

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.

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!