Hello,

attached you will find an image, which depicts my problem. I have got two spatials, s1 and s2 in universe. The axes of the spatials are parallel to the universe (this is not necessary but it simplifies the problem). Now, I want to put a third spatial, s3 in between. This works with this code.

[java]

…

Vector3f direction= s2.getLocalTranslation().subtract(s1.getLocalTranslation());

Vector3f s3LocalTranslation=s1.getlocalTranslation().add(direction.mult(0.5f));

s3.setLocalTranslation(s3LocalTranslation);

…

[/java]

but now, I want to orientate the coordinate system of s3 so that the x-axis (red axis) points always in direction of, let’s say s2. Of course, if s2 changes, no matter in which quadrant in relation to s1, the coordinate system should change accordingly. I tried following…

[java]

…

Vector3f s3XAxis = direction.normalize();

Vector3f s3YAxis = new Vector3f(s3XAxis .y, -s3XAxis .x, s3XAxis.z);

Vector3f s3ZAxis = s3XAxis .cross(s3YAxis );

Quaternion s3Quaternion = new Quaternion();

s3Quaternion = s3Quaternion .fromAxes(s3XAxis , s3YAxis , s3ZAxis );

s3.setLocalRotation(s3Quaternion );

…

[/java]

Indeed, it approximetely directs into the correct direction, but not exactly and if the quadrant position of s2 changes in relation to s1, sometimes it goes crazy.

Every help is appreciated.

Thanks a lot.

Regards,

Equi

Uuuups,

I got it.

[java]

…

Vector3f s3XAxis = direction.normalize();

Vector3f s3YAxis = new Vector3f(s3XAxis .y, -s3XAxis .x, 0);

Vector3f s3ZAxis = s3XAxis .cross(s3YAxis );

Quaternion s3Quaternion = new Quaternion();

s3Quaternion = s3Quaternion .fromAxes(s3XAxis , s3YAxis , s3ZAxis );

s3.setLocalRotation(s3Quaternion );

…

[/java]

There must be a zero at z-Position in the second line of course.

1 Like