RaySceneQuery Help

Problems building or running the engine, queries about how to use features etc.
Post Reply
WWJD
Gnoblar
Posts: 14
Joined: Tue Aug 04, 2015 2:17 am
x 1

RaySceneQuery Help

Post by WWJD »

Hey,
So I have a very strange issue going on that maybe one of you could help with. I'm working on making an entity selectable, and thus am setting up a Ray Scene Query. I'm following the tutorial3 as well as another post from someone here. The issue comes when I run the application. At any point if I click the application just quits. It doesn't crash, it just closes. There is no audio of it crashing, no notification pops up, and nothing in the ogre.log even remotely says anything happened. Here is my code:

Code: Select all

bool MetalFuryGameManager::mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
{
	if (mTrayMgr->injectMouseDown(arg, id)) return true;
	mCameraMan->injectMouseDown(arg, id);

	//camera movement binding
	if (arg.state.buttonDown(OIS::MB_Middle)) {

		camMove = true;
	}

	if (id == OIS::MB_Left) {

		Viewport* vp = mSceneMgr->getCurrentViewport();

		Real x = arg.state.X.abs / Real(vp->getActualWidth());
		Real y = arg.state.Y.abs / Real(vp->getActualHeight());

		// Turn off bounding box.
		if (mCurrentObject)
			mCurrentObject->showBoundingBox(false);
		// Setup the ray scene query
		Ray mouseRay = mCam->getCameraToViewportRay(x,y);
		mainLog.MetalFuryLogMainMessenger("Test");
		mRaySceneQuery->setRay(mouseRay);
		mainLog.MetalFuryLogMainMessenger("Test");
		mRaySceneQuery->setSortByDistance(true);

		// Execute query
		RaySceneQueryResult &result = mRaySceneQuery->execute();
		RaySceneQueryResult::iterator itr;
		// Get results, create a node/entity on the position
		for (itr = result.begin(); itr != result.end(); itr++)
		{
			if (itr->movable)
			{
				mCurrentObject = itr->movable->getParentSceneNode();
				break;
			} // if
		} // for

		  // Show the bounding box to highlight the selected object
		if (mCurrentObject)
			mCurrentObject->showBoundingBox(true);
	}
	//MyGUI code initilization
	MyGUI::InputManager::getInstance().injectMousePress(arg.state.X.abs, arg.state.Y.abs, MyGUI::MouseButton::Enum(id));

	return true;
}
I know the issue is during "mRaySceneQuery->setRay(mouseRay);" you can see where I put two outputs to my own log file. The first line shows up, but not the second line.

I'll keep working on it and post back when I have a solution, but if anyone here notices anything obvious please let me know.

Thanks,
WWJD
rpgplayerrobin
Gnoll
Posts: 619
Joined: Wed Mar 18, 2009 3:03 am
x 355

Re: RaySceneQuery Help

Post by rpgplayerrobin »

I can try to help you solve this but I first have a couple of questions:
1. How do you create/initialize mRaySceneQuery? If it is not initialized somewhere, you cannot use its functions. Show the code where you initialize it.
2. Are you using a debug or release build? You should be using debug here.

If you do initialize mRaySceneQuery correctly and if you are using a debug build, see if you can compile the Ogre source code and then just go into the function (using F11 in Visual Studio) and see what happens.
WWJD
Gnoblar
Posts: 14
Joined: Tue Aug 04, 2015 2:17 am
x 1

Re: RaySceneQuery Help

Post by WWJD »

Hey,

I actually managed to get the crash to stop, but now I'm running into where the only thing that gets selected is the world box itself. I'm using hydrax and skyx, but I don't know why that would have an impact. I'll post the fixed in it's entirety once I get it working completely.

I tested and know that the ray does select the entity, but it's not the first intersect, so I need to add a mask, but that's proving to be more of a challenge than I thought LOL. Would there be a reason you know of that would cause a mask not to filter entities? I've assigned a flat to the entity I want to be selected, and I've added the mask to the query, but it still ignores the entity and selects the world as a whole.

Thanks,
WWJD
rpgplayerrobin
Gnoll
Posts: 619
Joined: Wed Mar 18, 2009 3:03 am
x 355

Re: RaySceneQuery Help

Post by rpgplayerrobin »

Are you using "setQueryMask" for the MovableObjects (entities for example) with a correct mask?
Are you using "createRayQuery" to create the RaySceneQuery with the same mask as the above one?

I actually never use that class or function myself, so I do not know how to answer these more advanced questions.

I do it manually by getting the mesh information of all entities (cached per mesh so I only do it once per mesh type), I want to be able to pick from the scene (or area pick, like in an RTS game), then rotating/translating/scaling it before testing vs the ray (ray vs triangle, or planes vs triangle for area picking).

This is still very fast as my version checks for AABB vs the ray first to see if they can be picked.
It also then sorts the intersection based on distance, and picks from the closest one to the ray first (and then skips all the next ones if it picked correctly). This way I can filter out entities I do not want to be picked for that specific purpose.
Post Reply