Jump to content

Casting in Unigine


photo

Recommended Posts

Hi I have a simple question.  I'm not sure what is the best way to typecast in Unigine.  Searching through the list of nodes, I found the ObjectTerrain, but it gives me a NodePtr and I want to typecast it to be a ObjectTerrainPtr.

 

I tried something like this, but it causes a crash.

 

ObjectTerrainPtr terrain = ObjectTerrainPtr(reinterpret_cast<ObjectTerrain*>(node.operator->()));

 

Thanks

Link to comment

I believe you should use the static create(NodePtr) function found in each node-derived class to effectively cast up to the type you want.

 

In your case, you probably want something like the following:

Unigine::NodePtr node;
...
if(node->getType()==Unigine::Node::OBJECT_TERRAIN){
	Unigine::ObjectTerrainPtr terrain=Unigine::ObjectTerrain::create(node);
	// do stuff with terrain
}

Link to comment
×
×
  • Create New...