The bounding-box action computes a 3D bounding box that encloses the shapes in a subgraph under a node or defined by a path. This action also computes the center point of these shapes (see Example 8.1, “ Setting the Center Field of a Transform Node ”). SoGet-BoundingBoxAction is typically called on a path, which enables you to obtain a bounding box for a specific object in world coordinates. This action returns an SbBox3f SbBox3f , which specifies a 3D box aligned with the x-, y-, and z-axes in world coordinate space.
An example of creating an instance of SoGetBoundingBoxAction SoGetBoundingBoxAction SoGetBoundingBoxAction is
SbViewportRegion vpReg; vpReg.setWindowSize(300, 200); SoGetBoundingBoxAction bboxAction (vpReg);
SbViewportRegion vpReg = new SbViewportRegion(); vpReg.SetWindowSize(300, 200); SoGetBoundingBoxAction bboxAction = new SoGetBoundingBoxAction(vpReg);
SbViewportRegion vpReg = new SbViewportRegion(); vpReg.setWindowSize((short)300, (short)200); SoGetBoundingBoxAction bboxAction = new SoGetBoundingBoxAction(vpReg);
This constructor has one parameter, the viewport region. This information is needed for computing the bounding box of screen-aligned or screen-sized objects, such as SoText2 SoText2 SoText2 .
SoGetBoundingBoxAction SoGetBoundingBoxAction SoGetBoundingBoxAction can be applied to the root node of a subgraph, to a path, or to a path list.
Three methods access the results of SoGetBoundingBoxAction SoGetBoundingBoxAction SoGetBoundingBoxAction :
returns an SbBox3f SbBox3f bounding box that encloses the shape or shapes | |
returns the computed center point for the shapes | |
The center point returned by getCenter() is defined differently for different objects. For example, the center of an SoFaceSet SoFaceSet SoFaceSet is defined as the average of its vertices' coordinates. The center of a group is defined as the average of the centers of the objects in the group.
An SbXfBox3f SbXfBox3f stores the original bounding box for a shape and the matrix that transforms it to the correct world space. The advantage to using an SbXfBox3f SbXfBox3f instead of an SbBox3f SbBox3f is that the bounding box isn't enlarged unnecessarily. You may want to use this class if you need to perform additional transformations on the bounding box.
Example 8.1, “ Setting the Center Field of a Transform Node ” shows using an SoGetBoundingBoxAction SoGetBoundingBoxAction SoGetBoundingBoxAction (bboxAction) to return the center of the graph rooted by a node so that rotations can be made around it.
Example 8.1. Setting the Center Field of a Transform Node
SbViewportRegion myViewport; SoTransform *myTransform; SoGetBoundingBoxAction bboxAction(myViewport); bboxAction.apply(root); myTransform->center = bboxAction.getCenter();
SbViewportRegion myViewport = new SbViewportRegion(); SoTransform myTransform = new SoTransform(); SoGetBoundingBoxAction bboxAction = new SoGetBoundingBoxAction(myViewport); bboxAction.Apply(root); myTransform.center.Value = bboxAction.GetCenter();
SbViewportRegion myViewport = new SbViewportRegion(); SoTransform myTransform = new SoTransform(); SoGetBoundingBoxAction bboxAction = new SoGetBoundingBoxAction(myViewport); bboxAction.apply(root); myTransform.center.setValue(bboxAction.getCenter());