Raaajjj,
thanks.
Now... converting a vetor to a rotation ANSWER:
CODE
float $camXYZ[] =xform -q -a -ws -t camera1
;
vector $camLoc = <>;
vector $dir = (particleShape1.worldPosition - $camLoc) * -1;
vector $normal = <>;
float $rot[] = vector2rot $dir $normal
;
particleShape1.rotationPP = <>;
And the code that makes it possible:
CODE
// vector2rot.mel
// script for converting vector into worldspace rotations.
// adrian@kolektiv.com Jun 20/04
// AWGUA Maya Seminar August 2004
// Description: An essential script for converting velocity and up vectors into
// Euler rotations.
// NOTE: If you're using this for particle instancing, make sure to convert rotational
// values in degrees to radians twice, due to a little legacy bug. Like this:
// vector $direction = worldVelocity;
// vector $up = normalPP;
// float $rot[] = vector2rot $direction $up
;
// float $rotX = deg_to_rad( deg_to_rad( $rot[0] ) );
// float $rotY = deg_to_rad( deg_to_rad( $rot[1] ) );
// float $rotZ = deg_to_rad( deg_to_rad( $rot[2] ) );
// Special thanks goes out to Steve Hwan for providing the guts, I just Maya-nized it.
////
// main proc
global proc float[] vector2rot( vector $direction, vector $up ) {
// normalize vectors first
$direction = unit( $direction );
$up = unit( $up );
// calculate the side vector
vector $sideVec = cross( $up, $direction );
vector $upVec = cross( $direction, $sideVec );
float $cosY = sqrt( ($sideVec.x)($sideVec.x) + ($sideVec.y)($sideVec.y) );
// solve each angle
float $rotZ = atan2( ($sideVec.y), ($sideVec.x) );
float $rotY = atan2( -($sideVec.z), ( (($sideVec.x)+($sideVec.y)) / (cos( $rotZ ) + sin( $rotZ ) ) ) );
float $rotX = atan2( ($upVec.z), ($direction.z) );
// convert to degrees
$rotX = rad_to_deg( $rotX );
$rotY = rad_to_deg( $rotY );
$rotZ = rad_to_deg( $rotZ );
// return x,y,z rotations
return { $rotX, $rotY, $rotZ };
} // vector2rot