In 3D, we have a total of 48 different combinations of space coordinates to choose from:-
2 handed (or single axis flipped) systems x 3 axis x 4 (90 degree possible rotations around each (generally)) x 2 (possible 2 flipped axis variations on the same hand same rotation) = 48 possibilities.
There are 6 ways to notate xyz in a file but this would essentially replicate one of the 48 possibilities simply converting it from one possibility to another.
The functions below will only cover converting the 6 basic types (2 handed (or single axis flipped) systems x 3 axis) to Y-Up Left Hand system used by unity, so discounting the one that unity uses equals five conversions & one non conversion, also presuming all notation is written x,y,z irrespective of direction.
I am still not entirely convinced this is the best way to approach the problem, and i am pretty sure a matrix based solution would serve as a much better solution, however to date this is what I have to offer deem it right or wrong:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
//RightHanded=true if converting from Right handed Coordinate //UpAxis 0=x,1=y,2=z; private Vector3 PositionToYUpLH(Vector3 v,bool RightHanded,int UpAxis) { Vector3 r=new Vector3(); if (!RightHanded) { r=UpAxis==0?new Vector3(v.z,v.x,v.y):UpAxis==1?new Vector3(v.x,v.y,v.z):new Vector3(v.y,v.z,v.x); } else { r=UpAxis==0?new Vector3(0-v.z,v.x,v.y):UpAxis==1?new Vector3(0-v.x,v.y,v.z):new Vector3(0-v.y,v.z,v.x); } return r; } private Vector3 RotationToYUpLH(Vector3 v,bool RightHanded,int UpAxis) { Vector3 r=new Vector3(); if (!RightHanded) { r=UpAxis==0?new Vector3(v.z,v.x,v.y):UpAxis==1?new Vector3(v.x,v.y,v.z):new Vector3(v.y,v.z,v.x); } else { r=UpAxis==0?new Vector3(v.z,0-v.x,0-v.y):UpAxis==1?new Vector3(v.x,0-v.y,0-v.z):new Vector3(v.y,0-v.z,0-v.x); } return r; } private Vector3 ConvertScaleToYUpLH(Vector3 v,bool RightHanded,int UpAxis) { Vector3 r=new Vector3(); r=UpAxis==0?new Vector3(v.z,v.x,v.y):UpAxis==1?new Vector3(v.x,v.y,v.z):new Vector3(v.y,v.z,v.x); return r; } |