problem creating a ray scene query mask

Problems building or running the engine, queries about how to use features etc.
Post Reply
Mafioso
Kobold
Posts: 29
Joined: Mon Mar 21, 2011 4:49 pm

problem creating a ray scene query mask

Post by Mafioso »

Hi, I got a problem making ray query mask, it gets all entities that intersect with the given ray. Can anybody say what's wrong with my code:

Code: Select all

// enum in header file
enum queryFlags 
{
	GROUND_ENTITY = 1<<0
};

// after creating an entity
entity->setQueryFlags(GROUND_ENTITY); 

// in method that casts a ray
rayQuery = sceneManager->createRayQuery(Ogre::Ray()); 
rayQuery->setQueryMask(GROUND_ENTITY);

Ogre::Ray heightRay(ballPosition, Ogre::Vector3::NEGATIVE_UNIT_Y);
queryResult = rayQuery->execute();
And after execution in queryResult I get 2 entities, but only one have GROUND_ENTITY mask. Can anybody help with this?

P.S. Can I cast multiple rays in different direction instantly with Ogre::RaySceneQuery and after execution get some sort of array of those rays and what they intersect with?

Thanks.
Anno1989
Goblin
Posts: 299
Joined: Mon Aug 25, 2008 2:50 pm
Location: Germany
x 6
Contact:

Re: problem creating a ray scene query mask

Post by Anno1989 »

I dont know why this happens, but maybe it could be a submesh or something else. Try modifying the create function with this:

Code: Select all

createRayQuery(Ray(), Ogre::SceneManager::ENTITY_TYPE_MASK);
In additition to that, I assume that heightRay is the Ray you want to cast? Then you need to call this, so that this Ray is really used in the query.

Code: Select all

rayQuery->setRay(heightRay);
I dont really know if it is possible to cast in multiple directions, but you can use setRay with modified ray params and just add the results to the queryresults by yourself. If you want to specify more than one flag you can add them with a bitwise | (OR) like this:

Code: Select all

entity->setQueryFlags(GROUND_ENTITY | OBJECT_ENTITY); //Assuming you defined OBJECT_ENTITY too
Maybe this helps.
http://www.espadon-online.eu/ MMORPG using Ogre3D
Mafioso
Kobold
Posts: 29
Joined: Mon Mar 21, 2011 4:49 pm

Re: problem creating a ray scene query mask

Post by Mafioso »

Thanks for your help Anno1989, I forgot to use

Code: Select all

rayQuery->setRay(heightRay);
However that doesn't fix the problem. I noticed that any created entities have mask set to some numbers (uninitialised) and if I set

Code: Select all

entity->setQueryFlags(NULL);
It starts working, so how can I bypass setting query flag to NULL?

P.S. There isn't nothing about this in tutorials, so I still think that I'm missing something in my code

EDIT: And also I'm getting 0.0 distance :(
Anno1989
Goblin
Posts: 299
Joined: Mon Aug 25, 2008 2:50 pm
Location: Germany
x 6
Contact:

Re: problem creating a ray scene query mask

Post by Anno1989 »

Seems to be the camera? I dont know the rest of your code, but if I am correct 1<<0 is the Ogre default flag, sorry I didn't saw it. So try using 1<<1 for your GROUND_ENTITY flag.
http://www.espadon-online.eu/ MMORPG using Ogre3D
daarkron
Gnoblar
Posts: 16
Joined: Fri Nov 01, 2013 12:00 pm
Location: Switzerland

Re: problem creating a ray scene query mask

Post by daarkron »

By the way Mafioso instead of setting all entities query flags yourself you can set the default query flags for all future MovableObject instances:

Code: Select all

MovableObject::setDefaultQueryFlags(0);
But I personally think this value should be 0 by default... Papercut issue ?
Post Reply