So I am trying to get a dynamic rotated rectangle with velocity to glide along a static rectangles surface after collision, but I am having trouble with rotating the surface normal vector to the surface vector.
Hopefully this helps. minTime.getStaticAxis() above would be the green vector in this picture and I am having a problem rotating the green vector to the yellow vector. Essentially after i get the yellow vector I will project the blue vector (velocity) onto the yellow vector (or its negative if it matters).
Part of the problem may be that you are wrapped up in angles… which 99.9% of the time is a sign you are doing something wrong already (unless you are doing it to display in a UI.)
For example, if the yellow vector is 90 degrees from the green and you want to know the yellow vector:
Vector3f yellow = green.cross(Vector3f.UNIT_Z).normalizeLocal();
(which is really just a fancy way of swapping x, y to -y, x)
Note: yellow may be 180 degrees rotated in which case you can do Vector3f.UNIT_Z.cross(green) instead… I always have to try both before I get it right.
…the point is that you never need to leave the vectors as the angles are irrelevant. They are an unnecessary step.
But if you do want to know the angle in x,y for a vector (maybe for debugging) then that’s easy enough:
float rads = FastMath.atan2(yellow.y, yellow.x);
Turns out that what I originally did was correct, however I prefer your way. The tip on using atan2 rather than anglebetween() showed that the error was in angleBetween(), it did not say whether the angle was negative or not.
I am still running into some problems (sometimes the dynamic rectangle gets stuck on the surface) but these are most likely from not adding enough of a “buffer” to seperate the shapes that I am playing with now.
I heard many good things of dyn4j but I need my physics for this game to be deterministic across machines, I am even going to fork jme vector3f down the road and add strictfp and replace fastMath with StrictMath. This example is also getting close to the end of what i need for physics.
Turns out the only thing working is if I find surface vector (yellow) by rotating just shy of 90 degrees to help it get out of the way of. Is there a way to do this with cross products? or just go back to quaternion?
EDIT: SCRATCH THIS, was just something silly on my part it works without varying degrees.