Jump to content

[SOLVED] Detecting clicks on nodes


photo

Recommended Posts

Posted

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

Posted

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.         

Posted

How would you handle overlapping lines?  Say, a wireframe over a transparent node with intersecting lines?

Posted

Depth sort of detected line segments in relation to the player position and selection of nearest ? You know your specific use case 

Posted

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

Posted

Ah, never mind, I figured it out.  I was using a GameIntersection when I should have been using a WorldIntersection to detect clicks.

×
×
  • Create New...