Thursday, June 17, 2010

global 좌표를 특정 오브젝트의 local 좌표로 변환하는 법

float $v[]=`getAttr $attr`;
matrix $mat[4][4]=<<$v[0], $v[1], $v[2], $v[3]; $v[4], $v[5], $v[6], $v[7]; $v[8], $v[9], $v[10], $v[11]; $v[12], $v[13], $v[14], $v[15]>>;
return $mat;
}

// Multiply the vector v by the 4x4 matrix m, this is probably
// already in mel but I cant find it.
proc vector myVecMult(vector $v, matrix $m){
matrix $v1[1][4]=<<$v.x, $v.y, $v.z, 1>>;
matrix $v2[1][4]=$v1*$m;
return <<$v2[0][0], $v2[0][1], $v2[0][2]>>;
}

matrix $mat[4][4] = myGetMatrix("pPlane2.worldInverseMatrix");
print $mat;
$v = <<0, 24, -7>>;
$result = myVecMult($v, $mat);
코드 출처 : Convert a 3d point to 2d Screen Space in Maya
키워드 : MBM://100617global 좌표를 특정 오브젝트의 local 좌표로.html

No comments:

Post a Comment