Placing objects in space Vector and Matrix and TransientGeometry

Top  Previous  Next

When you add an occurrence of a part you can specify the placement using Vector and Matrix. The example below places the part at 20,2,2:


    // Need some transient geometry to add in a part...

    CComPtr<TransientGeometry> pTransGeom;

    hr = pInvApp->get_TransientGeometry(&pTransGeom);


    CComPtr<Matrix> pMatrix; // Defaults to 0,0,0 position

    hr = pTransGeom->CreateMatrix(&pMatrix);


    CComPtr<Vector> pVector; // Create a Vector to modify the Matrix

    hr = pTransGeom->CreateVector(20,2,2,&pVector);

    pMatrix->SetTranslation (pVector,VARIANT_TRUE) ;


    CComPtr<ComponentOccurrence> pOcc2;

    hr = pOccs->Add(csFileName,pMatrix,&pOcc2) ;


The TransientGeometry pTransGeom object is an object which creates Vector and Matrix etc. It is a machine for making these abstract objects.


Also note that the second parameter of SetTranslation is set to VARIANT_TRUE. That means "Yes, reset any rotation components in the matrix". If you've only just created the matrix as in the above example, there will be no rotation components inside the matrix, but I generally do the call with VARIANT_TRUE.


You can rotate and move an occurrence of a part like this:


   CComPtr<TransientGeometry> pGeom = GetTransGeomPtr () ;   



   // First rotate ...

   CComPtr<Vector> pZAxis = nullptr;

   pGeom->CreateVector(0, 0, 1, &pZAxis);


   CComPtr<Point> pOrigin = nullptr;

   pGeom->CreatePoint(0, 0, 0, &pOrigin);

   pFinalMatrix->SetToRotation(kRadians, pZAxis, pOrigin);


   // Then shift ....

   CComPtr<Matrix> pTransMatrix;


   CComPtr<Vector> pTransVector; // Create a Vector to modify the Matrix


   pTransMatrix->SetTranslation (pTransVector,VARIANT_TRUE) ;











Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)