Re: [script] Comparing two transforms

Date : Tue, 9 Jan 2007 23:15:32 +0100
To : XSI(at)Softimage.COM
From : "guillaume laforge" <guillaume.laforge.3d(at)gmail.com>
Subject : Re: [script] Comparing two transforms
Hi Bernard,

Maybe take a look to the matrix way. You can loop into the matrix to compare the values. It is a little bit shorter and maybe faster ?

function CompareMatrix( oObjA, oObjB )
{
    var oTransA = oObjA.Kinematics.Global.Transform;
    var oMatrixA = XSIMath.CreateMatrix4();
    oTransA.GetMatrix4( oMatrixA );

    var oTransB = oObjB.Kinematics.Global.Transform;
    var oMatrixB = XSIMath.CreateMatrix4();
    oTransB.GetMatrix4( oMatrixB );

    for ( var row = 0 ; row < 4 ; row++ )
    {
        for( var col = 0 ; col < 4 ; col++ )
        {
            if( Math.round( oMatrixA.Value( row, col ) ) != Math.round( oMatrixB.Value( row, col )) )
            return false ;
        }
    }
    return true ;
}


1/2

--
Guillaume Laforge
freelance TD | cg Artist
my blog ! http://vol2blog.blogspot.com/



On 1/9/07, Bernard Lebel <3dbernard(at)gmail.com> wrote:
Salut Christopher ;-)


Thanks for the advice.

Right now I'm using a somewhat ugly but effective approach:



def compareTransforms( oTransform1, oTransform2 ):
   
    """
    RETURN VALUE: boolean
    """
   
    bSame = True
   
    if round( oTransform1.PosX, 4 ) != round( oTransform2.PosX, 4 ):
        bSame = False
   
    elif round( oTransform1.PosY, 4 ) != round( oTransform2.PosY , 4 ):
        bSame = False
   
    elif round( oTransform1.PosZ, 4 ) != round( oTransform2.PosZ, 4 ):
        bSame = False
   
    elif round( oTransform1.RotX, 4 ) != round( oTransform2.RotX, 4 ):
        bSame = False
   
    elif round( oTransform1.RotY, 4 ) != round( oTransform2.RotY, 4 ):
        bSame = False
   
    elif round( oTransform1.RotZ, 4 ) != round( oTransform2.RotZ , 4 ):
        bSame = False
   
    elif round( oTransform1.SclX, 4 ) != round( oTransform2.SclX, 4 ):
        bSame = False
   
    elif round( oTransform1.SclY, 4 ) != round( oTransform2.SclY, 4 ):
        bSame = False
   
    elif round( oTransform1.SclZ, 4 ) != round( oTransform2.SclZ, 4 ):
        bSame = False
   
   
    #~ if not bSame:
        #~ xsi.logmessage( '< bb_ReplaceModels > :: Not same transforms.', c.siWarning )
    #~ else:
        #~ xsi.logmessage( '   < bb_ReplaceModels > :: Same transforms.' )
   
    return bSame



I wish there was a one-liner way to do this.


Bernard





On 1/9/07, Christopher Crouzet < christopher.crouzet(at)gmail.com> wrote:
> A such function that compare two CTransformation objects exists in the C++
> API.
>
> However, in scripting language I don't see anything equivalent (in 5.1),
> except the 'Equals' method that applies on SIVector3 and SIQuaternion
> objects which means that you have to first extract them from the
> SITransformation object by using the 'GetRotation', 'GetTranslation' and
> 'GetScaling' methods.
>
>
> Hope it helps,
> Christopher.
>
> (wouhou, my first post on this list, hello everyone !!)
>
>
>
> On 1/9/07, Bernard Lebel < 3dbernard(at)gmail.com> wrote:
> >
> > Hello,
> >
> > Is there a quick way, say a one-liner, to determine if two transforms
> > hold the same values?
> >
> > I have two objects, I just want to know if they have the same
> > transforms. If they do, then do something. If not, do something else.
> >
> >
> > Thanks
> > Bernard
> > ---
> > Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in body:
> > unsubscribe xsi
> >
>
>  




Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available.
This site supposedly brought to you by Benjamin Grosser and the Imaging Technology Group.