Results 1 to 4 of 4

Thread: Picking a scene node in Irrlicht from mouse coordinates

  1. #1
    Lesser Wizard
    Join Date
    Nov 2010
    Location
    Los Angeles, California, United States, United States
    Posts
    126

    Default Picking a scene node in Irrlicht from mouse coordinates

    I've found a number of posts on the Irrlicht forum on how to do this, but it doesn't seem to be working correctly.

    Has anyone successfully found a collision node/triangle/point from a tap/click?

    Here's my signal handler for a click:

    Code:
    void OnViewOverStart(VariantList *pVList)
    {
    	CL_Vec2i v2fPos = pVList->m_variant[0].GetVector2();
    	LogMsg("VeiwOverStart: %x, %x", v2fPos.x, v2fPos.y);
    
    	// convert to Irrlicht friendly struct
    	irr::core::position2di mousePos(v2fPos.x, v2fPos.y);
    
    	// get our scene manager
    	scene::ISceneManager* pSceneMgr = GetIrrlichtManager()->GetScene();
    	scene::ISceneCollisionManager* pCollMgr = pSceneMgr->getSceneCollisionManager();
    
    	// get the ray from the screen point
        irr::core::line3df collRay;
    
    	collRay = pCollMgr->getRayFromScreenCoordinates(mousePos, pSceneMgr->getActiveCamera()); // this appears to be getting unique values
    	
    	// get the collision 
    	core::vector3df collPoint; 
    	core::triangle3df collTriangle; 
    	scene::ISceneNode* pNode = 0; 
    	
    	pNode = pCollMgr->getSceneNodeAndCollisionPointFromRay(collRay, collPoint, collTriangle); // I'm always getting null here
    
    	if( pNode )
    		LogMsg("	Selected Node: %s", pNode->getName());
    	else
    	{
    		pNode = pCollMgr->getSceneNodeFromScreenCoordinatesBB(mousePos,0,true);	// but this is returning a node... ***
    		if( pNode )
    			LogMsg("	Selected Node: %s", pNode->getName());
    	}
    
    	LogMsg("	Selected Point: %f, %f, %f", collPoint.X, collPoint.Y, collPoint.Z);
    }

  2. #2
    Lesser Wizard
    Join Date
    Nov 2010
    Location
    Los Angeles, California, United States, United States
    Posts
    126

    Default

    Still having problems with this. I think it's coming down to the function getRayFromScreenCoordinates. I'm noticing a few suspicious things stepping into that function:

    1. I'm in landscape mode, but Irrlicht uses the device's natural screen space, so I have to pass x, y values in reverse.

    2. When getRayFromScreenCoordinates calculates intersection values of the far plane, the "up-to-down" line doesn't seem right. One of the x, y, z values should be zero (my camera does not rotate along z so the line should be straight up and down).

    3. My camera is not registering as Orthogonal, but based on some very elementary debugging (just rendering a node at the start/end points), it seems that my collision ray is going through the center of the view frustum near plane.

    Has anyone got the Irrlicht Quake tutorial on collision working? That's where I'm headed next. Any help would be greatly appreciated!!!

  3. #3
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,340

    Default

    Hmm, sorry haven't done anything with picking yet. Might run into it a bit later though!
    Seth A. Robinson
    Robinson Technologies

  4. #4
    Lesser Wizard
    Join Date
    Nov 2010
    Location
    Los Angeles, California, United States, United States
    Posts
    126

    Default

    Darn

    I'm rendering spheres for the start/end of the collision ray and it appears the function is not interpreting the right aspect ratio or fov. I get results near to where I'm pointing, but the ray is definitely skewed somehow.

Similar Threads

  1. Big update comitted, Irrlicht updated
    By Seth in forum Proton SDK
    Replies: 1
    Last Post: 12-29-2010, 10:05 AM
  2. Strange input coordinates on Android
    By rzuf in forum Proton SDK
    Replies: 3
    Last Post: 11-09-2010, 09:37 AM
  3. mouse
    By attle in forum Novashell Game Creation System
    Replies: 5
    Last Post: 05-29-2008, 07:39 AM
  4. Mouse Input
    By Soudeus in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 04-25-2007, 01:57 PM
  5. picking up items using keyboard
    By rpgnut in forum Dink Smallwood HD
    Replies: 3
    Last Post: 01-31-2005, 04:16 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •