Object Attributes

Attributes can be set using R3SetAttrs() function. The following code sets two attributes for 'sphere' object:

    R3FLOAT newrad = 1.5;
    R3SetAttrs(sphere,
               R3RA_Name, "my sphere",
               R3SPHA_Radius, &newrad,
               R3TAG_END);

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

    R3INT age = 23;
    R3FLOAT weight = 1.2;

    R3SetAttrs(sphere,
               R3FOOA_Age, age, /* 32 bit value, pass by value */
               R3FOOA_Weight, &weight,  /* 64 bit value, pass by reference */
               R3TAG_END);

You can fetch attributes using R3GetAttrs() function. For example, to ask the name and the radius of a sphere:


    R3FLOAT rad;
    char *name;

    R3GetAttrs(sphere,
               R3RA_Name, &name,
               R3SPHA_Radius, &rad,
               R3TAG_END);

R3RA_Name is defined by the root class (r3root.h), hence the prefix R3RA_ (Root Attribute). The sphere recognizes also this attribute because the root class is one of the super classes of the sphere.