Creating an object

In C++ objects are created with 'new' operator. In Realsoft 3D you call R3New() function. The prototype of the function is:

    R3OBJ *R3New(R3CLID classid, ...);

The first parameter is 32 bit integer identifying the class. Rest of the parameters define initial parameters for the object. Each parameter is defined by an attribute identifier and the corresponding attribute value. The last parameter must be R3TAG_END.

If R3New is successful, it returns a handle to a new sphere object. Otherwise, it returns NULL.

Below you can find an example for creating a sphere:

    #include <real/objects/r3sphere.h>

    R3FLOAT radius = 0.1;
    R3VECTOR origin = {0.1, 0.2, 0.0};
    R3OBJ *sphere;

    if(R3RegisterSphereClass(app)) {

        sphere = R3New(R3CLID_SPHERE,
	               R3RA_Name,     "my sphere",
                       R3SPHA_Radius, &radius,
                       R3SPHA_Center, &origin,
                       R3TAG_END);
    }

[Note] Note
All 32 bit types or smaller are passed by value. Bigger types (R3FLOAT, R3VECTOR etc.) are passed by reference!