Jump to content

[SOLVED] Detecting clicks on nodes


photo

Recommended Posts

In my previous posts I talked about rendering single pixel lines in 3D space.  I need to detect clicking on those lines.  The trouble is, renderline3d doesn't create a node in the scene to interact with.

 

My first idea was to create an invisible capsule node underneath each 3D line and detect click events on this capsule.  I have used the example code outlined here:

 

https://developer.unigine.com/en/docs/1.0/scripting/library/class.gameintersection

 

Trouble is, even setting up all of the collision masks, I can't seem to get a click to register on the capsule.  Is this the "best" way to detect clicks on one pixel poly lines?  Is there a better way that doesn't involve creating and manipulating underlying dummy nodes?

 

Thank you,

Andrew

Link to comment

Maybe a 2D approach provides a much simpler problem solution:

 

On mouse click (= mouse x/y screen coordinate) transform all 3D line x/y/z coordinates of your "clickable" polylines to x/y screen coordinates using active camera modelview-projection matrix. Then calculate minimum 2D point-to-line segment distance between mouse click x/y screen point and each screen-space tranformed line-segment for finding the nearest line segment. This will also allow easy non-exact user line segment selection within some pixel offset limit, as exact-line pixel selection requirement will for sure drive users crazy...

 

Of course this 2D approach does not handle 3D line-object blocking scenarios properly, but - depending on your specific usage pattern for these 3D lines - this might be no practical problem.         

Link to comment

Mmkay.  Any thoughts on why the ray cast node click detection isn't working?  The code in the mouse click callback looks like this:

void OnButtonPressed(int button)
{
	if (engine.controls.isMouseEnabled())
	{
		log.message("Mouse is enabled\n");
		Player player = engine.game.getPlayer();
		switch (button)
		{
			case APP_BUTTON_LEFT:
			case APP_BUTTON_DCLICK:
				dvec3 p0, p1;
				Unigine::getPlayerMouseDirection(p0, p1);
				
				log.message("p0: %s\n", typeinfo(p0));
				log.message("p1: %s\n", typeinfo(p1));
				
				GameIntersection intersection = new GameIntersection();
				Obstacle obstacle = engine.game.getIntersection(p0, p1, 0.2f, 1, intersection);
				
				if (obstacle != NULL)
				{
					log.message("The intersection with obstacle was here: %s\n", typeinfo(intersection.getPoint()));
				}
				break;
			default:
				break;
		}
	}
}

The masks are all set to, "1," on the objects I'm trying to click on.  Am I missing something?

 

Thank you for your time,

Andrew

Link to comment
×
×
  • Create New...