Ray casting and multiple Objects

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Mr_Ridd
Posts: 63
Joined: Tue Sep 28, 2004 5:16 am

Ray casting and multiple Objects

Post by Mr_Ridd »

Hey

I think I'm posting to much. Hope you guys aren't saying, "Ahh, not Mr_Ridd again." Anyway, I'm here to learn.

Ok, ray casting. It works fine except if one object is in front of another object. I've tried to hide the foremost object and then test again but it doesn't work. I've also tried to remove it and that didn't work.

What could I do to solve this problem?

Thanks
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

well what exactly is your problem? Something to do with raycasting and objects being in front of other objects obviously, but what exactly are u trying to do?
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
Mr_Ridd
Posts: 63
Joined: Tue Sep 28, 2004 5:16 am

Post by Mr_Ridd »

Well, basically I'm writing a level editor. In short, if one object is in front of another object and it is locked then I don't want to test it for an intersection with the cast. I know you are probably saying that I could just rotate the camera but in some instances that won't work.

All models are in a array. Thats how I do my testing. I run through the array and test every model untill one hits. If one hits but it is locked, I hide that model, redo the test and then show it again.

Sometimes it works and sometimes it doesn't.
erSitzt
Posts: 52
Joined: Sun May 09, 2004 11:59 am

Post by erSitzt »

Did you try using the SceneNode-IDs ?

For example group your scenenodes in two groups :
Enabled : (0x0001)
Disabled : (0x0010)

check this post too :
http://irrlicht.sourceforge.net/phpBB2/ ... php?t=2859
Hardwarespecs in signatures suck !
Mr_Ridd
Posts: 63
Joined: Tue Sep 28, 2004 5:16 am

Post by Mr_Ridd »

Well, that whole discussion confused my brain.

One thing I did see was how they did the tests.

if( current->isVisible() ) etc...

As I said in an earlier post, I hide the locked objects and then redo the test. It's odd because sometimes it works and sometimes it doesn't work. The reason why I hide, test, unhide is so that you can still see the object even though it is locked.

Take this for example:

I load a tree, at 0,0,0. I then add another tree at 0,0,0. So I can only see one tree even though there are two. I then click on one, it doesn't matter which one gets selected and I lock it. This leaves one tree selectable. Now this is the confusing part. If I click on the tree I can't select it, if I rotate the camera a bit and click on it I can. How does this work? It's not like the one tree is a bit off centre.
erSitzt
Posts: 52
Joined: Sun May 09, 2004 11:59 am

Post by erSitzt »

Sry for posting...

i'll ignore your answers too if you post some...
Hardwarespecs in signatures suck !
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

It's not difficult, follow to that link.

0001 = 1
0010 = 2

There is a filter for bits in the ID's in the collision function, so if you set the nodes that you want to clip to 2 and the one's you want to ignore to 1, then filter out the nodes with ID = 1.
Mr_Ridd
Posts: 63
Joined: Tue Sep 28, 2004 5:16 am

Post by Mr_Ridd »

Bru, what's up with this
Sry for posting...

i'll ignore your answers too if you post some...
Where did you think I got isVisible() thing from. I don't know anything about Scenenode ID's. So saying "No I havn't tried it", wouldn't help. I didn't ignore your post.

I'm not here to make enemies, I'm sorry if you took offence. I do apologise.

Now to erSitzt and Tyn, so I don't get my head bitten off again. How do you set the id's, and then of couse get them. Is it with node->setID() and node->getID().

Once again... I'm sorry erSitzt
Guest

Post by Guest »

@Mr_Ridd, by me some irrlicht "ray" function are buggy. So, look at irrlicht source.
All is ok, only when node is near to center of coordinate system.
etcaptor
Posts: 871
Joined: Fri Apr 09, 2004 10:32 pm
Location: Valhalla
Contact:

Post by etcaptor »

Sorry, it was me ;-)
puh
Posts: 356
Joined: Tue Aug 26, 2003 3:53 pm

Post by puh »

etcaptor, how did you resolve this problem in your world editor? Could you explain a little bit?
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

Mr_Ridd wrote: Now to erSitzt and Tyn, so I don't get my head bitten off again. How do you set the id's, and then of couse get them. Is it with node->setID() and node->getID().
That's the one, yep. If you set the id bit mask to 2 and then set all nodes that you want to display at 2, the rest set to 1 and it will work fine. It works by masking any node that's ID has the masked figure inside it. So if you had the bitmask set to 2 then the following ID's would all be tested:

0x0010 = 2
0x0110 = 6
0x0111 = 7
0x1111 = 15

The following are examples of one's that would not be tested:

0x0000 = 0
0x0100 = 4
0x0101 = 5
0x1101 = 13

I'm not biting your head off but all the information is either in the API or in that link that was posted, you could have checked it out and tried to do it on your own steam.
Mr_Ridd
Posts: 63
Joined: Tue Sep 28, 2004 5:16 am

Post by Mr_Ridd »

If you set the id bit mask to 2 and then set all nodes that you want to display at 2, the rest set to 1 and it will work fine.
I'm still a bit confused. I've read the link but I'm still confused about what you said. In the quote above it appears that I have to set two things. Ok, I know I must use node->setID(), I presume that refers to , "and then set all nodes that you want to display at 2". But then how do I set the bit mask?

I'm still quite new the engine. :idea:

Edit: I just found this now... getSceneNodeFromScreenCoordinatesBB(). I can pass a bit mask into it. Is this how I set the bit mask?

Thanks
erSitzt
Posts: 52
Joined: Sun May 09, 2004 11:59 am

Post by erSitzt »

Assume you have only two stati for SceneNodes :
Enabled (0x0001)
Disabled (0x0010)

1. ) Whenever you create a SceneNode use a ID (Enabled) in the constructor ( Have a look at the API which param it is )

2. ) Create a ray that selects all SceneNode with a specific ID.

Thats it.

To disable SceneNodes you can do this :
mynode->setID(0x0010)

P.S.
This is from the API
virtual ISceneNode * getSceneNodeFromRayBB (core::line3d< f32 > ray, s32 idBitMask=0)=0

and you would use :
YourCollMgr->getSceneNodeFromRayBB(yourline, 0x0001)

as you can see
0x0001 and
0x0010
do not match , so disabled nodes are not selected...

Got it ?
Hardwarespecs in signatures suck !
etcaptor
Posts: 871
Joined: Fri Apr 09, 2004 10:32 pm
Location: Valhalla
Contact:

Post by etcaptor »

puh wrote:etcaptor, how did you resolve this problem in your world editor? Could you explain a little bit?
I have copied some functions from Irrlicht, include in my code and modified some parameters. Well, some results are more experimental then clean fundamental ;-)

In function
getSceneNodeFromRayBB(core::line3d<f32> ray, s32 idBitMask)
i add one parameter
getSceneNodeFromRayBB(core::line3d<f32> ray, s32 idBitMask, bool OtrhoView)
after then change some of parameters

Code: Select all

ISceneNode* getSceneNodeFromRayBB(core::line3d<f32> ray, s32 idBitMask, bool OtrhoView)
{
	ISceneNode* best = 0;
	f32 dist = 9999999999.0f;

  if(OtrhoView)
	getPickedNodeBB(smgr->getRootSceneNode(), ray.getVector(),//ray.getVector() instead ray.getMiddle()
	     ray.start , ray.end, (f32)(ray.getLength() * 0.5),
		idBitMask, dist, best);

  else
	getPickedNodeBB(smgr->getRootSceneNode(), ray.getMiddle(),
	     ray.getVector().normalize() , ray.start, (f32)(ray.getLength() * 0.5),
		idBitMask, dist, best);


	return best;
}

in function getPickedNodeBB

remove those row
//if (dist < outbestdistance)
Post Reply