Pointmatrixmult Bug?

I have a simple cube which is grouped.
the local translation for the cube is {0 -1.5 0} and {0 1.5 0} for the group
(so the world position of the cube is 0 0 0)
I'd like to compute the position of the cube in world space
so i do:

CODE
pointMatrixMult ( $pos, $mat );

where $pos is the cube's translation (which is in local space)
and $mat in the cube's parentMatrix (which is in world space)

And i get wrong results!!!! (ie {0,-1.5,0})
i had done my own point * matrix procedure and it give me the right result.

pointMatrixMult create a node in order to compute the result
is there any difference between mel's matrix and api's matrix?
where can i get more information on maya's matrix representation?

thanks

use worldMatrix instead of parentMatrix

hey benoitj

why don't you take

CODE
xform -query -worldSpace -translation;
?

In general this doesn't give you world position of the point ( but may work in translation only case )

hi.

Failure,
i'm not sure about the world matrix:

Cube(world) = Cube(local) * Cube(parentWorld)
and
Cube(translationWorld) = Cube(translationLocal) * Cube(parentWorld)
(i'm in this case)

I'm not using xform because xform is using the cube's translateX, translateY,...
(which , in this case is fine...)
But i added attributes to save keyframe animations (which are local transforms)
and i wanted to have them back in world space

here is my procedure
(note that xform is giving me the same result that my operation)

CODE
global proc float[] transformPoint( float $point[], float $mat[] )
{
    float $result[3] = {0.0,0.0,0.0};

    if ( size($point) != 3 || size($mat) != 16 )
    {
 warning("Point must be an array of 3 doubles and matrix must be an array of 16 doubles.");
 return $result;
    }
    $result[0] = $point[0]$mat[0] + $point[1]$mat[4] + $point[2]*$mat[8] + $mat[12];
    $result[1] = $point[0]$mat[1] + $point[1]$mat[5] + $point[2]*$mat[9] + $mat[13];
    $result[2] = $point[0]$mat[2] + $point[1]$mat[6] + $point[2]*$mat[10] + $mat[14];

    return $result;
}

thx

CODE
polyCube -n cube;
move -a 1 0 0;
group;
xform -os -piv 0 0 0;
move -a -1 0 0;

float $mat[] = getAttr cube.worldMatrix;
float $p[] = { 0, 0, 0 };
print (pointMatrixMult( $p, $mat ));

Works as expected. You need to multiply (0,0,0) with world matrix, not local translation. That's because position of the cube transform is always zero in it's own coordinate space

ok let's try this code:
(the difference is i'm not moving the cube here, just the group)

CODE
polyCube -n cube;
group;
xform -os -piv 0 0 0;
move -a -1 0 0;

float $mat[] = getAttr cube.worldMatrix;
float $p[] = { 0, 0, 0 };
print (pointMatrixMult( $p, $mat ));

result = {0,0,0} <= wrong!!!
using my procedure transformPoint
result = {-1 ,0,0,} <=right

yes theres s light glitch in the script, its actulay doing a vector matrix multiplication not a point matrix multiplication. THis has been discussed eralier.

Se the FACTORY melscript looks as follows:

CODE
global proc float[] pointMatrixMult( float $point[], float $matrix[] )
//
//  Description:
//      Multiplies a point by a matrix and returns the result.
//
{
   float $result[];

    $result[0] = 0.0;
    $result[1] = 0.0;
    $result[2] = 0.0;

    if ( size($point) != 3 || size($matrix) != 16 )
    {
 warning("Point must be an array of 3 doubles and matrix must be an array of 16 doubles.");
 return $result;
    }

    // create the node that will do the actual computation
    //
   string $multNode;
    if ( catch($multNode = createNode pointMatrixMult) )
    {
 warning("Could not create pointMatrixMult node.");
 return $result;
    }

    // set the matrix and point inputs to the node
    //

   setAttr ($multNode+".vectorMultiply") true; // note this is set to true it should be false.

   setAttr ($multNode+".inPoint") -type "double3" $point[0] $point[1] $point[2];
   setAttr ($multNode+".inMatrix") -type "matrix" $matrix[0] $matrix[1] $matrix[2] $matrix[3] $matrix[4] $matrix[5] $matrix[6] $matrix[7] $matrix[8] $matrix[9] $matrix[10] $matrix[11] $matrix[12] $matrix[13] $matrix[14] $matrix[15];

    // get the result and delete the node since it is no longer required
    //
   $result = getAttr ($multNode+".output");
   delete $multNode;

   return $result;
}

now the line setAttr ($multNode+".vectorMultiply") true; is ovoiusly worng! so copy the scriipt into ypur own script directory and change true on that line to false. Adn it then works correctly

hm, works fine here. Maybe someone fixed the script. Anyway I'd prefer custom multiplication proc over one that set up nodes on each call.

yes thats smart as its MUCH faster, to use expressivity than use the temp node build discard. (unless you leve ot IN pplace in wich case you can jsut read it when you need it)

for example matricx playground has a full set of just this.