Page 2 of 4

Re: Segment Query (raycasting) API requests

Posted: Fri Jul 10, 2009 4:58 am
by dieterweb
Hi,

it turned out that raycasting would be the best thing for my current problem. Is this implemented in the trunk and usable?

Thomas

Re: Segment Query (raycasting) API requests

Posted: Fri Jul 10, 2009 12:19 pm
by slembcke
Yes, and no. I've implemented the segment/primitive collision functions, but it's missing a way to work efficiently with the spatial hash. I started out with a simple AABB version that generated a AABB for the segment, then checked against all objects returned by the hash. This works, but it's very non-optimal for long diagonal segments.

I started working on stepping through the spatial hash to check only cells that the line hits, but there was a bug causing it to miss some collisions. I haven't had time to work on it for a couple of weeks. Eventually I also want to be able to short circuit the search when you know you've hit the closest object.

If you want to look at the work in progress code, it's in demo/query.c. I've been marshaling the new code there before adding it to the final API.

Re: Segment Query (raycasting) API requests

Posted: Sun Jul 12, 2009 3:38 am
by dieterweb
Hi,

I now use your code form Query.c for raycasting. It nearly works perfect. The problem I have is the following:

When I call cpSpaceShapeSegmentQueryFirst(space, start, end, -1, 0, &info)) it finds the nearest shape. However when I call it again (directly after the first call) It says there is no shape between start and end (which is wrong).

I do not need to call the function two times after each other, but the same happens, when I call it too fast, maybe before the next spaceStep.

What is the difference between those calls? Any ideas?

Edit: It really seems to happen then and only then when there is no spaceStep called between two cpSpaceShapeSegmentQueryFirst calls.

Thomas
They are coming... - Follow me on Twitter: http://twitter.com/ZombieSmash

Re: Segment Query (raycasting) API requests

Posted: Mon Jul 13, 2009 10:33 am
by slembcke
Weird. I'm not sure. :( Like I said, it's not finished quite yet, and there seems to be some bugs.

Re: Segment Query (raycasting) API requests

Posted: Mon Jul 13, 2009 10:43 am
by dieterweb
Is such a query chnaging some states? I couldnt find anything that would be different between two calls after each other.

Re: Segment Query (raycasting) API requests

Posted: Mon Jul 13, 2009 1:07 pm
by dieterweb
The problem is in

static inline void query(cpSpaceHash *hash, cpSpaceHashBin *bin, void *obj, cpSpaceHashQueryFunc func, void *data)

hand->stamp = hash->stamp;

There you set a stamp to not check a object twice. When I remove this it works. But I think performance will suffer as you had a reason to do this. How can I reset(?) the stamp?

Edit: I added the line

hash->stamp++ to the end of the raycasting method. Seems to work fine.

Thomas

Re: Segment Query (raycasting) API requests

Posted: Mon Jul 13, 2009 5:51 pm
by slembcke
Aha! I wouldn't have thought of that right away. Thanks for catching that.

Re: Segment Query (raycasting) API requests

Posted: Thu Oct 22, 2009 8:18 am
by ShiftZ
Hi, im experiencing problmems with raytracing. It's just not working for me.
ive found if modify demo sample Query.c as following

113: cpVect start = cpvzero; ->>> cpVect start = cpv(0.0f, -1.0f);
157: cpSpaceResizeStaticHash(space, 40.0, 999); ->> cpSpaceResizeStaticHash(space, 40.0, 2053);
158: cpSpaceResizeActiveHash(space, 30.0, 2999); ->> cpSpaceResizeActiveHash(space, 40.0, 2053);
175: body->p = cpv(0.0f, 100.0f); ->> body->p = cpv(0.0f, -31.0);

segment shape become invisible for raytracing. This bug dissapear sometimes, and it hard to say what it depends on.
ive tried bullet implementation with ray tracing and found that bullets hits rarely, no matter what type of shapes it is.

Re: Segment Query (raycasting) API requests

Posted: Thu Oct 22, 2009 9:24 am
by slembcke
There are still bugs in that code, that's why there is no real API for it yet.

I've been trying to focus my attention on contract work and our Twilight Golf game. So I haven't made any progress on this lately.

Re: Segment Query (raycasting) API requests

Posted: Fri Oct 23, 2009 2:06 am
by dieterweb
Hi,

I use raycasting without problems. One change I made some time ago was:

I added the line
hash->stamp++;
to the end of the raycasting method in cpSpaceHash.c

I updated chipmunk to the recent trunk and lost this change. That made some of my raycasting not working anymore. Putting this back in and everything is working fine. It so long ago I made this (did I made it?) that I have no idea why I have done it.

EDIT: Just saw that I wrote that in this same thread a few month ago :)

Thomas