Beispiel #1
0
const Matrix2x2 slerp(const Matrix2x2& a, const Matrix2x2& b, const float t)
{
    const Matrix2x2 c = timesTranspose(a, b);
    const float angle = rotationAngle(c);

    return a * Matrix2x2::rotation(t * angle);
}
Beispiel #2
0
const Transform2 transformByInverse(const Transform2& a, const Transform2& b)
{
    GEOMETRY_RUNTIME_ASSERT(a.scaling > 0.0f);
    GEOMETRY_RUNTIME_ASSERT(b.scaling > 0.0f);

    return Transform2(
        transformByInverse(a.translation, b),
        timesTranspose(a.rotation, b.rotation),
        a.scaling / b.scaling
    );
}
Beispiel #3
0
const Vector2 transformByInverse(const Vector2& q, const Transform2& t)
{
    GEOMETRY_RUNTIME_ASSERT(t.scaling > 0.0f);
    return timesTranspose(q - t.translation, t.rotation) / t.scaling;
}
int Test_3x3timesTranspose(void)
{
    // Init an array flanked by guard pages
    btMatrix3x3 in1[ARRAY_SIZE];
    btMatrix3x3 in2[ARRAY_SIZE];
    btMatrix3x3 out[ARRAY_SIZE];
    btMatrix3x3 out2[ARRAY_SIZE];
    
    // Init the data
    size_t i, j;
    for( i = 0; i < ARRAY_SIZE; i++ )
    {
        in1[i] = btMatrix3x3(rand_f4(), rand_f4(), rand_f4() );   
        in2[i] = btMatrix3x3(rand_f4(), rand_f4(), rand_f4() );   
        
        out[i] = timesTranspose(in1[i], in2[i]);
        out2[i] = in1[i].timesTranspose(in2[i]);
        
        if( out[i] != out2[i] )
        {
            printf( "failure @ %ld\n", i);
            return -1;
        }
    }
    
    uint64_t scalarTime, vectorTime;
    uint64_t startTime, bestTime, currentTime;
    bestTime = -1LL;
    scalarTime = 0;
    for (j = 0; j < LOOPCOUNT; j++) {
        startTime = ReadTicks();
        for( i = 0; i < ARRAY_SIZE; i++ )
            out[i] = timesTranspose(in1[i], in2[i]);
        currentTime = ReadTicks() - startTime;
        scalarTime += currentTime;
        if( currentTime < bestTime )
            bestTime = currentTime;
    }
    if( 0 == gReportAverageTimes )
        scalarTime = bestTime;        
    else
        scalarTime /= LOOPCOUNT;
    
    bestTime = -1LL;
    vectorTime = 0;
    for (j = 0; j < LOOPCOUNT; j++) {
        startTime = ReadTicks();
        for( i = 0; i < ARRAY_SIZE; i++ )
            out[i] = in1[i].timesTranspose(in2[i]);
        currentTime = ReadTicks() - startTime;
        vectorTime += currentTime;
        if( currentTime < bestTime )
            bestTime = currentTime;
    }
    if( 0 == gReportAverageTimes )
        vectorTime = bestTime;        
    else
        vectorTime /= LOOPCOUNT;
    
    vlog( "Timing:\n" );
    vlog( "\t    scalar\t    vector\n" );
    vlog( "\t%10.2f\t%10.2f\n", TicksToCycles( scalarTime ) / ARRAY_SIZE, TicksToCycles( vectorTime ) / ARRAY_SIZE );
    
    return 0;
}