GetCentroid

Syntax

//
//   Strong typing definition
//
double          GetCentroid(
                        OwlInstance             owlInstance,
                        const void              * vertexBuffer,
                        const void              * indexBuffer,
                        double                  * centroid
                    );

static  inline  double  GetCentroid(
                                OwlInstance             owlInstance,
                                double                  * centroid
                            )
{
    const void * vertexBuffer = nullptr,
                * indexBuffer = nullptr;
    return  GetCentroid(
                    owlInstance,
                    vertexBuffer,
                    indexBuffer,
                    centroid
                );
}


//
//   Weak typing definition
//
double  __declspec(dllexport) __stdcall GetCentroid(
                                                int64_t                 owlInstance,
                                                const void              * vertexBuffer,
                                                const void              * indexBuffer,
                                                double                  * centroid
                                            );

static  inline  double  GetCentroid(
                                int64_t                 owlInstance,
                                double                  * centroid
                            )
{
    const void * vertexBuffer = nullptr,
                * indexBuffer = nullptr;
    return  GetCentroid(
                    owlInstance,
                    vertexBuffer,
                    indexBuffer,
                    centroid
                );
}
    

Property owlInstance

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 vertexBuffer

Size: 64 bit / 8 byte (reference)
The array of vertices, this array is allocated by the host application. Depending on SetFormat() the array exists of 32 bit (4 byte) single precision floats or 64 bit (8 byte) double precision floats. Each vertex elements exists of several elemens, i.e. X, Y, Z values, but optionally also nX, nY, nZ, texture coordinates, bitangent / binormal coordinates, colors etc. What is contained is defined by SetFormat() and can be retrieved via GetFormat(). The host application has to make sure enough memory is allocated for the vertexBuffer array.

Property indexBuffer

Size: 64 bit / 8 byte (reference)
The array of indices, this array is allocated by the host application. Depending on SetFormat() the array exists of 32 bit (4 byte) integers or 64 bit (8 byte) integeres.

Property centroid

Size: 64 bit / 8 byte (reference)
The centroid is expected to be a 3 element double value allocated by the host (i.e. 24 bytes). The function will fill in X, Y, Z as thew centroid coordinate in double precision.

Example (based on pure API calls)

Here you can find code snippits that show how the API call GetCentroid 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");

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

        //
        //  Instances (creating)
        //
        int64_t instanceBox = CreateInstance(classBox, nullptr);

        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);

        //
        //  Simple use of the derived information functions
        //
        double  centroid[3],
                volume = GetCentroid(instanceBox, nullptr, nullptr, &centroid);

        int64_t vertexBufferSize = 0,
                indexBufferSize = 0;
        CalculateInstance(instanceBox, &vertexBufferSize, &indexBufferSize, 0);
        if (vertexBufferSize && indexBufferSize) {
            float   * vertexBuffer = new float[6 * vertexBufferSize];
            UpdateInstanceVertexBuffer(instanceBox, vertexBuffer);

            int32_t * indexBuffer = new int32_t[indexBufferSize];
            UpdateInstanceIndexBuffer(instanceBox, indexBuffer);

            //
            //  Reuse knowledge to improve performance (in case of single precision, with less accuracy)
            //
            volume = GetCentroid(instanceBox, vertexBuffer, indexBuffer, &centroid);
        }

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