This is a noob question: how do I make a model perpendicular to the terrain? I am creating a world editor, where I can choose a model that follows my mouse. Now I tried to use lookAt() using the contactNormal() (from raycasting), mult quaternions with contact points, but with no results.
A Quaternion is a rotation… but so is a 3x3 matrix… and a 3x3 matrix is nicely the three orthogonal vectors representing the rotated coordinate axes x, y, and z. So if you can find those then you can make a rotation.
You already have up:
Vector3f up = contactNormal;
Now you just need the other two:
Vectof3f temp = tree.getLocalRotation().mult(Vector3f.Z); // forward rotation in its current view
Vector3f left = up.cross(temp); // should be left axis
Vector3f forward = left.cross(up);
Quaternion newRotation = new Quaternion().fromAxes(left, up, forward);
Edit: there is always the chance that I got the cross products backwards… if you see strange results then try printing the values.