// Create a group record
mgrec *groupRec = mgNewRec(fltGroup);
// Get the pointer to fltBoundingBox record
mgrec *bBoxRec = mgGetAttRec(groupRec, fltBoundingBox, MG_NULL);
// Get the pointer to bounding sphere record
mgrec *bSphereRec = mgGetAttRec(bBoxRec, fltBoundingSphere, MG_NULL);
double radius = 10;
// Set fltBSRadius attribute
int nAttrBSphere = mgSetAttList(bSphereRec, fltBSRadius, radius, MG_NULL);
I always get nAttrBSphere = 0, i.e it failed setting fltBSRadius attribute.
What I am doing wrong?
I think what is happening, is that the bounding sphere rec has not been attached yet. The method you are attempting to do requires too much work and is not the suggested approach. It is much easier just to set the attribute on the group node and let the api do its magic for you. You don't need to get the bounding box rec, then the bounding sphere rec. Just set the fltBSRadius attribute on the group node. This works for all nested attributes with one exception. If there are two attributes with the same name nested under a node, then you can't use this method. (For example two nested records that have a fltCoord3d, the api would not know what one you want to set.) This is uncommon however, and not necessary in this case.
See the OpenFlight_API_Users_Guide_Vol1.pdf for a mor detailed explanation:
Attribute records are arranged hierarchically. For example, the fltPolygon record code
describes a recordÃ¢â¬â¢s node type; within fltPolygon there are record codes such as
fltPolyColor and fltPolyMaterial, which describe drawing attributes of the
Some attributes have further nesting; for example, the fltGroup node type has a
fltBoundingBox record, which in turn has attributes of type fltCoord3d and
fltBoundingSphere. You can access nested attributes in the same way as you access
simple ones; the nesting is transparent to you. You need to specify only the node record and
the desired attributeÃ¢â¬â¢s record code. For example:
mgGetAttList (groupNode, fltGrpPrio, &prio;, fltBCRadius,&radius;,
fltBCHeight,&height;, fltBYaw, yaw, MG_NULL);
The same holds true for record creation. When you specify the values for a nested attribute,
the API creates the nested records for you:
mgSetAttList (groupNode, fltGrpPrio, prio, fltBCRadius, radius,
fltBCHeight, height, fltBYaw, yaw, MG_NULL);
Thanks for the prompt reply!
It is clear now how to work with nested attributes.