Jump to content

[SOLVED] Clicking Events on Terrain (and other nodes)


photo

Recommended Posts

Hi Forum

Not sure where to start on this one.

 

I am building a new toolbar to aid productivity in building worlds, one of the processes is a quick 'Add Node' that will repeatedly add a particular node, with particular scale and rotation parameters,  at the location on the terrain that the user clicks on.

 

I cant seem to find where to begin on this?

 

I was expecting to be able to add a click event to the terrain node, but that may not be how it works

 

Any pointers, once again, appreciated.

 

Paul

Link to comment

Hey Paul,

 

Basically, there're no callbacks for mouse in Terrain, so you need to to do some simple steps:

 

1) Convert mouse coordinates to world mouse direction, we have a Unigine::getPlayerMouseDirection function in UnigineScript located in core/scripts/utils.h file which will do the job for you;

2) Do a raycast by caling engine.word.getIntersection (https://developer.unigine.com/en/docs/1.0/scripting/library/engine/engine.world#engine.world.getIntersection_vec3_vec3_int_variable, UnigineScript) or World::getIntersection (https://developer.unigine.com/en/docs/1.0/cpp_api/reference/api_world_class#c_getIntersection_constUNIGINE_VEC3n_constUNIGINE_VEC3n_int_UNIGINE_VEC3m_vec3m_vec4m_intm_intm, C++) and feeding it with the direction calculated on first step and current camera position;

3) If the hit was successful then you can get the intersection point and spawn your node.

Link to comment
×
×
  • Create New...