2011年12月2日 星期五

Maxscript : Right-Handed to Left-Handed


正解!!Right to Left or Left to Right:by cmann

Let me try to explain it a little better. I need to export from Blender, in which the z axis is facing, to OpenGL where the y axis is facing up.
For every coordinate (x, y, z) it's simple, swap the y and z values: (x, z, y).
Because I have swapped the all of the y and z values any matrix that I use also needs to be flipped so that it has the same affect .
After a lot of searching I've eventually found a solution here:
http://www.gamedev.net/community/forums/topic.asp?topic_id=537664
If your matrix looks like this:
{ rx, ry, rz, 0 }
{ ux, uy, uz, 0 }
{ lx, ly, lz, 0 }
{ px, py, pz, 1 }
To change it from left to right or right to left, flip it like this:
{ rx, rz, ry, 0 }
{ lx, lz, ly, 0 }
{ ux, uz, uy, 0 }
{ px, pz, py, 1 }





Matrix3
The Matrix3 class implements a 4x3 3D transformation matrix object. The transform matrix is a 3D homogeneous matrix typically used to hold object coordinate systems and transformations.

如要把Z與Y軸對調(Zup vs Yup),方法是:
.transform *= matrix3 [1,0,0] [0,0,1] [0,1,0] [0,0,0]
-- 將row2及row3的y,z值對調
X → +X = [1,0,0]→[1,0,0]
Y → +Z = [0,1,0]→[0,0,1]
Z → +Y = [0,0,1]→[0,1,0]
-- 尚未驗證軸向是否正確無誤
-- 可能答案(等同對X軸旋轉-90度)
*= matrix3 [1,0,0] [0,0,-1] [0,1,0] [0,0,0]
-- 
X → +X = [1,0,0]→[1,0,0]
Y → -Z = [0,1,0]→[0,0,-1]
Z → +Y = [0,0,1]→[0,1,0]

複製一個新的matrix3
newMatrix3 = copy .transform



arbAxis
Returns a Matrix3 value representing an arbitrary axis system using point3 as the "up" direction.
arbAxis [0,1,0] -- return (matrix3 [-1,0,0] [0,0,1] [0,1,0] [0,0,0])


xformMat
Returns the transform matrix transformed into a particular space. For example, say you have a rotation you want to apply, but you want to perform the rotation in another coordinate system. To do this, you typically transform into the space of the coordinate system, then apply the transformation, and then transform out of that coordinate system. This method transformats matrix transform_matrix3 into the space of matrix space_matrix3. The resulting matrix3 value is calculated as space_matrix3 * transform_matrix3 * inverse(space_matrix3).

參考資料
笛卡爾向量
右手座標系轉左手座標系
3D 圖學引擎 設計初步*
Converting between left and right handcoordinate systems
Conversion of Left-Handed Coordinates toRight-Handed Coordinates by David Ederly (pdf)

沒有留言:

張貼留言