Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches

C3DSceneNode are entities linked together hierarchically by the scene.
A node makes a reference to a C3DBaseObject giving it, in particular, a name and a matrix transformation.

So one of the important thing to know is how to create nodes and how to retrieve them using scene traversal.

Get / set node object

Whereas a node can have no object attached to it, this is not recommended unless because such nodes are ignored during traversal unless using NODEPOS_ALLOW_EMPTY_NODES flag.

Creating a node and adding it to the scene

This simple code creates an object group and add it to the scene.

groupNode->SetObject(group);
groupNode->SetName("My group");
scene->AddNode(NULL, groupNode); // node is a child of the scene root
C3DCurve *curve = xNew(C3DCurve);
C3DPointList *points = xNew(C3DPointList);
points->SetSize(10);
for (int j=0; j<10; j++)
{
pt = &(*points)[j];
pt->x = j;
pt->y = j*2.0f;
pt->z = j*3.0f;
}
curve->SetPointList(points);
curveNode->SetObject(curve);
curveNode->SetName("My curve");
scene->AddNode(groupNode, curveNode); // Curve is child of "My group"
A 3D curve is a list of C3DPoint. It has specific flags and material.
Definition 3DCurve.h:20
virtual void SetPointList(C3DPointList *pointslist, bool deletePrevious=true)
Set the object point list and delete existing one, unless deletePrevious = false.
C3DGroup class is an object without geometry. C3DGroup allows to organize the scene hierarchically.
Definition 3DGroup.h:22
Definition 3DPointList.h:267
A node matches one element that is part of the C3DScene graph. It references a C3DBaseObject and has ...
Definition 3DSceneNode.h:64
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27
virtual void SetSize(int size, bool growOnly=false, int growSize=CElementArray::GROW_KEEP_MODE)
growOnly = false means that memory block is shrink down if specified size is below existing size....

Instantiation

Several nodes can reference the same C3DBaseObject. This means that the scene contains the same object several times at different position. Instantiation is a simple way to save memory usage.
C3DSceneNode::IsObjectIntanciated allows to know if the node object is referenced several times, whereas C3DSceneNode::DeleteObjectInstanciation attach a copy of the instantiated object to the node (the object instantiation count decrease by one).

Transformations

Transformations are associated to node using KEYFRAME_MATRIX (C3DMatrixKey) or a combination of KEYFRAME_ROT (C3DRotateKey), KEYFRAME_TRANS (C3DTranslateKey), KEYFRAME_SCALE (C3DScaleKey), KEYFRAME_PIVOT (C3DVectorKey).
The transformation associated to the node are the local transformation. It can be retrieved using C3DSceneNode::GetObjectLocalTM or C3DSceneNode::GetNodeLocalTM.
You can retrieve a world transformation matrix using C3DSceneNode::GetNodeTM which accumulates matrices along the hierarchy. Finally you can modify the node transformation using C3DSceneNode::SetObjectLocalTM.

Transformation are defined at a given time, which means that you'll have to define the time in most of the method. C3DScene::GetCurrentTime returns the current time.
It is possible to remove any transformation using C3DSceneNode::ConvertToGlobalCoordinates.

C3DPointList *points = object->GetPointList();
if (points)
{
C4x4Matrix matrix;
node->GetNodeTM(scene->GetCurrentTime(), matrix);
int i, size = points->SetSize(10);
for (int j=0; j<10; j++)
{
pt = &(*points)[j];
pt=matrix*pt; // pt has now world coordinates
}
}