GetRelativeTransformation

This function returns the relative transformation matrix between two instances, i.e. in practise this means the matrices connected to the Transformation instances in the path in between.
The matrix is only given when a unique path through inverse relations can be found, otherwise the identity matrix is returned. owlInstanceHead is allowed to be not defined, i.e. zero.

Syntax

//
//   Strong typing definition
//
void            GetRelativeTransformation(
                        OwlInstance             owlInstanceHead,
                        OwlInstance             owlInstanceTail,
                        double                  * transformationMatrix
                    );


//
//   Weak typing definition
//
void    __declspec(dllexport) __stdcall GetRelativeTransformation(
                                                int64_t                 owlInstanceHead,
                                                int64_t                 owlInstanceTail,
                                                double                  * transformationMatrix
                                            );
    

Property owlInstanceHead

Size: 64 bit / 8 byte (value)
The handle to the specific instance in the design tree. The instance handle is static within one open model but is most probably different when the same instance is opened in another model. The instance is always exactly of one unique class.

Property owlInstanceTail

Size: 64 bit / 8 byte (value)
The handle to the specific instance in the design tree. The instance handle is static within one open model but is most probably different when the same instance is opened in another model. The instance is always exactly of one unique class.

Property transformationMatrix

Size: 32 bit / 4 byte (reference)
The transformationMatrix is expected to be nullptr or a 12 element double value allocated by the host (i.e. 96 bytes / 12 doubles). The matrix values are defined column by column as is common for DirectX, OpenGL and VULKAN, i.e. _11, _12, _13, _21, ... _42, _43.

Example (based on pure API calls)

Here you can find code snippits that show how the API call GetRelativeTransformation can be used.

#include    "./include/engine.h"
#include    <assert.h>

void    main()
{
    int64_t model = CreateModel();

    if (model) {
        //
        //  Classes 
        //
        int64_t classBox = GetClassByName(model, "Box"),
                classMatrix = GetClassByName(model, "Matrix"),
                classMatrixMultiplication = GetClassByName(model, "MatrixMultiplication"),
                classTransformation = GetClassByName(model, "Transformation");

        //
        //  Object Properties (relations)
        //
        int64_t propertyFirstMatrix = GetPropertyByName(model, "firstMatrix"),
                propertyMatrix = GetPropertyByName(model, "matrix"),
                propertyObject = GetPropertyByName(model, "object"),
                propertySecondMatrix = GetPropertyByName(model, "secondMatrix");

        //
        //  Datatype Properties (attributes)
        //
        int64_t property_42 = GetPropertyByName(model, "_42"),
                propertyLength = GetPropertyByName(model, "length"),
                propertyWidth = GetPropertyByName(model, "width"),
                propertyHeight = GetPropertyByName(model, "height");

        //
        //  Instances (creating)
        //
        int64_t instanceBox = CreateInstance(classBox, nullptr),
                instanceMatrixI = CreateInstance(classMatrix, nullptr),
                instanceMatrixII = CreateInstance(classMatrix, nullptr),
                instanceMatrixIII = CreateInstance(classMatrix, nullptr),
                instanceMatrixMultiplication = CreateInstance(classMatrixMultiplication, nullptr),
                instanceTransformationI = CreateInstance(classTransformation, nullptr),
                instanceTransformationII = CreateInstance(classTransformation, nullptr);

        SetObjectProperty(instanceTransformationI, propertyObject, &instanceTransformationII, 1);
        SetObjectProperty(instanceTransformationI, propertyMatrix, &instanceMatrixMultiplication, 1);

        SetObjectProperty(instanceTransformationII, propertyObject, &instanceBox, 1);
        SetObjectProperty(instanceTransformationII, propertyMatrix, &instanceMatrixIII, 1);

        SetObjectProperty(instanceMatrixMultiplication, propertyFirstMatrix, &instanceMatrixI, 1);
        SetObjectProperty(instanceMatrixMultiplication, propertySecondMatrix, &instanceMatrixII, 1);

        double  length = 2.8,
                width = 1.3,
                height = 1.4;

        SetDatatypeProperty(instanceBox, propertyLength, &length, 1);
        SetDatatypeProperty(instanceBox, propertyWidth, &width, 1);
        SetDatatypeProperty(instanceBox, propertyHeight, &height, 1);

        //
        //  As a simple case we only apply vertical translation
        //
        double  verticalTranslationMatrixI = 3.05,
                verticalTranslationMatrixII = 2.2,
                verticalTranslationMatrixIII = 7.4;

        SetDatatypeProperty(instanceMatrixI, property_42, &verticalTranslationMatrixI, 1);
        SetDatatypeProperty(instanceMatrixII, property_42, &verticalTranslationMatrixII, 1);
        SetDatatypeProperty(instanceMatrixIII, property_42, &verticalTranslationMatrixIII, 1);

        UpdateInstance(instanceTransformationI);

        double  transformationMatrix[12];
        GetRelativeTransformation(instanceTransformationI, instanceBox, transformationMatrix);
        assert(transformationMatrix[3 * 3 + 1] == verticalTranslationMatrixI + verticalTranslationMatrixII + verticalTranslationMatrixIII);

        GetRelativeTransformation(instanceTransformationII, instanceBox, transformationMatrix);
        assert(transformationMatrix[3 * 3 + 1] == verticalTranslationMatrixIII);

        GetRelativeTransformation(instanceTransformationI, instanceTransformationII, transformationMatrix);
        assert(transformationMatrix[3 * 3 + 1] == verticalTranslationMatrixI + verticalTranslationMatrixII);

        //
        //  The resulting model can be viewed in 3D-Editor.exe
        //
        SaveModel(model, "c:\\created\\myFile.bin");
        CloseModel(model);
    }
}