I’m trying to convert some C++ libraries that deals with automation. After reviewing several online references, I realize that I’m beyond my education to figure out the concepts of generating (or regenerating) an orthonormal basis given a new forward.

Is anyone familiar with this and will you be kind enough to explain what exactly its used for and what is the Javascript equivalent to computing it.

The code I’ve done so far (which is wrong I’m sure) is the following:

function RegenOrthonormalBasis (rightHanded: boolean, newForward: Vector3) {
var oldUp = transform.TransformDirection (Vector3.up);
var oldRight = transform.TransformDirection (Vector3.right);
if (rightHanded)
return oldUp.Cross(oldRight, newUnitForward);
else
return oldUp.Cross(newForward, -oldRight);
// what does this just do?
// what is rightHanded (is there a left?)
}

I know the functions – I’m just not sure on how to use them to accomplish this conversion; primarily because I’m not even sure on what the entire thing does. If I did, it may be possible for me to find the right function/methods to do it – hence why I asked if someone could explain it to me as this seems to be used a lot in 3D game programming (which is something I’m just getting started in).

The C function appears to have rather confusing naming. It generates an up vector from two known vectors newForward and _side (the function pretends to use only newForward, but _side needs to be set to some value as well, or the function will fail). Since there is nothing in the code to guarantee _side and forward are perpendicular, the resulting _up, _side, _forward set is not even guaranteed to be orthonormal.

If you ask me, the function is just used to create a valid up vector when _forward changes.

At any rate, transform.up, transform.forward and transform.right are your _up, _forward and _side. These three properties always define the ortho normal basis of the transform. Unity makes sure they are ‘regenerated’ for you.