Jump to content

[SOLVED] How to change the terrain from C++ API


photo

Recommended Posts

Hi there,

 

I'm writing a plugin which reads out a list of airport locations and at each of this spots a dummy airport should be placed. I'm loading the airport as a Node of type ObjectMeshStatic and set the specific translation values in the transformation matrix.

 

So far so good: post-1459-0-28819700-1422888405_thumb.png Now, I'd like to adjust the terrain below this node. I was looking at the ObjectTerrain class, but didn't found an approach to what I'm looking for. Is the an approach by creating a bounding box around my dummy airport and change the height below it?

 

Hope for some hints...

 

Thanks a lot,

Renato

Link to comment

Hi Renato!

 

You need to use ObjectTerrain::setHeight method (https://developer.unigine.com/en/docs/1.0/cpp_api/reference/api_objectterrain_class#c_setHeight_int_int_float). But make sure you converted your world position to terrain grid coordinates before calling this function.

 

To convert the coordinates you need to multiply your position vector by inverse terrain world transform and then divide by terrain grid step.

Link to comment

Hi Andrey

 

To use the ObjectTerrain::setHeight method, I need to call first the ObjectTerrain constructor create with the NodePtr pointing at my dummy airport node, right? As return value I get a Ptr<ObjectTerrain> and on this I call the setHeight(int, int, float) method. But my Ptr<ObjectTerrain> is also after the cstor NULL.

Unigine::NodePtr nPtr = world->loadNode(path);    // dummy airport

Unigine::Ptr<Unigine::ObjectTerrain> objTerrain;
objTerrain = ObjectTerrain::create(nPtr);

if (objTerrain.get() != NULL) {
		objTerrain->setHeight(10, 10, 1000.0f);
}

Kind regards,

Renato

 

(P.S. Should I have used the new helpdesk?)

Link to comment

Hey Renano, my friend!

 

Looks like you're trying to do the wrong thing because it's not possible to cast your airport node (which I assume is not ObjectTerrain) to ObjectTerrain unless it's a real ObjectTerrain node and not the other type.

 

I assume you have ObjectTerrain in your world and you added it to the editor via Editor::addNode or just by using the editor itself. That means you're able to get that node via Editor::getNodeByName function.

Unigine::Editor *editor = Unigine::Editor::get();

// I assume you have ObjectTerrain with "terrain_node_name_here" name and it's available in the editor
Unigine::NodePtr nodeTerrain = editor->getNodeByName("terrain_node_name_here");
Unigine::ObjectTerrainPtr objTerrain = ObjectTerrain::create(nodeTerrain); // cast our node to proper type

// set height

(P.S. Yes! Go ahead!)

Link to comment

Hey Andrey

 

Thanks a lot!

 

I realize that I'm missing a piece to understand the situation completely..

 

As I understand your proposition correctly, I have to know the name of the node below my "airport". I created my world with the landscape plugin and I know the node name of my ObjectTerrain tiles. But I don't want to flatten out a whole tile... How do I define a limited area below a node, where f.ex. the height should be flattened out?

 

And if I call the ObjectTerrain::setHeight method with coordinates inside of one of my tiles, the application freezes and crashes without an error in the log..

 

(P.S. Next time!! )

Link to comment

Ahh, sorry!

 

Now I get some results! I'm operating now in the world coordinate system, right? Which starts at (0,0)! Do I have to call the method multiple times to get to adjust a specific area? And I have to transform as you described above from my airport node coordinate system to the one of the world, right?

 

Kind regards,

Renato

Link to comment

Hi Renato!

 

Let me clarify the steps for you:

 

1) First of all you need to get your airport WorldBoundBox as that will allow you to determine which ObjectTerrain you need to pick;

2) Determine which ObjectTerrain (or a group of) lies below airport node, by intersecting airport bounds with engine.world.getIntersectionNodes (don't forget to set proper type filter), probably it'll be better to expand the bounds across z axis so it'll intersect some of terrain nodes for sure;

3) For each ObjectTerrain you've found:

3.1) Convert WorldBoundBox from the airport to terrain grid coordinates (that means multiplication by inverse word transform of terrain and division by terrain grid step);

3.2) Take a nested loops across x and y coordinates and fill terrain height with Terrain::setHeight method.

Link to comment
×
×
  • Create New...