Reflect transform on XZ plane

Hi



I have two geometries. One has a rigidbody and is under physics control. For the second, I want it to mirror the position and rotation of the first, on the XZ plane.



Looking up plane reflection transformation on google I learnt that its a simply matrix multiplication:



[java]Matrix3f reflect = new Matrix3f();

reflect.getRow(1).y = -1f;[/java]



How do I get the transform of the first geometry, multiply it by this matrix and apply it to the second geomtery? Here what I tried which doesnt work, as the translation is not transformed:



[java] Matrix3f reflect = new Matrix3f();

reflect.getRow(1).y = -1f;

Transform t = geometry.getLocalTransform();

Matrix3f m = t.getRotation().toRotationMatrix();



m.multLocal(reflect);

reflection.setLocalRotation(m);[/java]



Thanks for the advice

Check the plane class, it has methods for that.

Hi Normen, thanks for the idea.



Unfortunately, the Plane.reflect method only reflects a Vector3f point. This is a trivial operation for an XZ plane (invert y position!).



My particular problem is not with the position reflection but the rotation. Matrix math shows me that it is easy to reflect a transformation matrix by multiplying by the reflection matrix.



So my question boils down to:

  1. How do I get a matrix from a Geometry contains BOTH position and rotation information?
  2. How do I apply this matrix, once modified, to set the position and rotation of a second geometry?



    Thanks

Maybe you can use direction and up vectors instead of going for rotations or one matrix, I think just mirroring them as well should work.

So basically (pseudo-code):

[java]

//get vectors from spatial

Vector3f location = spatial.getLocalTranslation().clone()

Vector3f direction = spatial.getLocalRotation().mult(Vector3f.UNIT_Z);

Vector3f up = spatial.getLocalRotation().mult(Vector3f.UNIT_Y);

Plane plane = new Plane(); //…



//mirror the new vectors

plane.mirrorLocal(location); //does mirrorLocal exist?



//only works if plane is going though 0/0/0, else need to construct same plane at 0/0/0

plane.mirrorLocal(direction);

plane.mirrorLocal(up);



//construct new rotation from new up/direction

Quaternion rotation = new Quaternion().lookAt(direction, up);



mirrorSpatial.setLocalTranslation(location);

mirrorSpatial.setLocalRotation(rotation);

[/java]



…maybe you also find some function that works with Transforms on plane, they store rotation and location.

Great approach normen,



Actually the reflect operation turned out to be even simpler, not requiring a Plane object. I could just reverse the Y of each of the vectors:



[java] //get vectors from spatial

Vector3f position = geometry.getLocalTranslation().clone();

Vector3f direction = geometry.getLocalRotation().mult(Vector3f.UNIT_Z);

Vector3f up = geometry.getLocalRotation().mult(Vector3f.UNIT_Y);



//mirror the new vectors

position.y = -position.y;

direction.y = -direction.y;

up.y = -up.y;



//construct new rotation from new up/direction

reflectionRotation.lookAt(direction, up);



reflection.setLocalTranslation(position);

reflection.setLocalRotation(reflectionRotation);[/java]