Segment Query (raycasting) API requests

Discuss new features and future development.

Re: Segment Query (raycasting) API requests

Postby dieterweb » Fri Jul 10, 2009 4:58 am

Hi,

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

Thomas
Visit our game Blog: http://zombiesmash.gamedrs.com or follow us on twitter: http://twitter.com/zombiesmash
dieterweb
 
Posts: 176
Joined: Fri Feb 27, 2009 7:12 am
Location: Germany

Re: Segment Query (raycasting) API requests

Postby slembcke » Fri Jul 10, 2009 12:19 pm

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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Segment Query (raycasting) API requests

Postby dieterweb » Sun Jul 12, 2009 3:38 am

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
Visit our game Blog: http://zombiesmash.gamedrs.com or follow us on twitter: http://twitter.com/zombiesmash
dieterweb
 
Posts: 176
Joined: Fri Feb 27, 2009 7:12 am
Location: Germany

Re: Segment Query (raycasting) API requests

Postby slembcke » Mon Jul 13, 2009 10:33 am

Weird. I'm not sure. :( Like I said, it's not finished quite yet, and there seems to be some bugs.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Segment Query (raycasting) API requests

Postby dieterweb » Mon Jul 13, 2009 10:43 am

Is such a query chnaging some states? I couldnt find anything that would be different between two calls after each other.
Visit our game Blog: http://zombiesmash.gamedrs.com or follow us on twitter: http://twitter.com/zombiesmash
dieterweb
 
Posts: 176
Joined: Fri Feb 27, 2009 7:12 am
Location: Germany

Re: Segment Query (raycasting) API requests

Postby dieterweb » Mon Jul 13, 2009 1:07 pm

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
Visit our game Blog: http://zombiesmash.gamedrs.com or follow us on twitter: http://twitter.com/zombiesmash
dieterweb
 
Posts: 176
Joined: Fri Feb 27, 2009 7:12 am
Location: Germany

Re: Segment Query (raycasting) API requests

Postby slembcke » Mon Jul 13, 2009 5:51 pm

Aha! I wouldn't have thought of that right away. Thanks for catching that.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Segment Query (raycasting) API requests

Postby ShiftZ » Thu Oct 22, 2009 8:18 am

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.
ShiftZ
 
Posts: 114
Joined: Sat Mar 07, 2009 7:23 am

Re: Segment Query (raycasting) API requests

Postby slembcke » Thu Oct 22, 2009 9:24 am

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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Segment Query (raycasting) API requests

Postby dieterweb » Fri Oct 23, 2009 2:06 am

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
Last edited by dieterweb on Sat Oct 24, 2009 4:45 pm, edited 1 time in total.
Visit our game Blog: http://zombiesmash.gamedrs.com or follow us on twitter: http://twitter.com/zombiesmash
dieterweb
 
Posts: 176
Joined: Fri Feb 27, 2009 7:12 am
Location: Germany

PreviousNext

Return to Features/Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron