Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Current »

HOOPS Exchange provides 2 different kinds of matrices: A3DMiscCartesianTransformationData and A3DMiscGeneralTransformationData. The first one’s structure separates each type of transformation (scaling, rotation, translation) while the second consists in a simple double[16] pointer.

How to convert a A3DMiscCartesianTransformationData into a A3DMiscGeneralTransformationData ?

Here’s a code snippet that show how to convert an A3DMiscCartesian matrix into a generic 4x4 one.

A3DVector3dData CrossProduct(const A3DVector3dData* X, const A3DVector3dData* Y)
{
    A3DVector3dData Z;
    Z.m_dX = X->m_dY*Y->m_dZ - X->m_dZ*Y->m_dY;
    Z.m_dY = X->m_dZ*Y->m_dX - X->m_dX*Y->m_dZ;
    Z.m_dZ = X->m_dX*Y->m_dY - X->m_dY*Y->m_dX;
    return Z;
}

double* ConvertMiscCartesianTransfoInto4x4Matrix(A3DMiscCartesianTransformation *pMiscCaterianTransfo)
{
    // The matrix defined below is considered as column major
    double *adMatrix = malloc(16*sizeof(double))
    memset(adMatrix, 0, 16*sizeof(double));

    A3DMiscCartesianTransformationData sData;
    A3D_INITIALIZE_DATA( A3DMiscCartesianTransformationData, sData);
    A3DMiscCartesianTransformationGet(pMiscCaterianTransfo, &sData);
					
    double dScale = sData.m_sScale.m_dX;  // We assume that the scale is uniform
    double dMirror = (sData.m_ucBehaviour & kA3DTransformationMirror) ? -1.0: 1.0;
    
    A3DVector3dData sZVector;
    sZVector = CrossProduct(&(sData.m_sXVector), &(sData.m_sYVector));  
    
    adMatrix[0] = sData.m_sXVector.m_dX * dScale;
    adMatrix[1] = sData.m_sXVector.m_dY * dScale;
    adMatrix[2] = sData.m_sXVector.m_dZ * dScale;
    
    adMatrix[4] = sData.m_sYVector.m_dX * dScale;
    adMatrix[5] = sData.m_sYVector.m_dY * dScale;
    adMatrix[6] = sData.m_sYVector.m_dZ * dScale;
    
    adMatrix[8] = dMirror * sZVector.m_dX * dScale;
    adMatrix[9] = dMirror * sZVector.m_dY * dScale;
    adMatrix[10] = dMirror * sZVector.m_dZ * dScale;
    
    adMatrix[12] = sData.m_sOrigin.m_dX;
    adMatrix[13] = sData.m_sOrigin.m_dY;
    adMatrix[14] = sData.m_sOrigin.m_dZ;
    
    adMatrix[15] = 1.0;
    
    returns adMatrix;
}
  • No labels