Box2D Forums

It is currently Tue May 21, 2013 4:19 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Mon Jun 06, 2011 3:36 am 
Offline

Joined: Tue May 24, 2011 1:05 pm
Posts: 3
Hi all!
I hope someone could help me. I have problem with RayCast function.

Code:
var fixtList : Vector.<b2Fixture> = new Vector.<b2Fixture>();
------------------

var cb : Function = function(fixture:b2Fixture, point:V2, normal:V2, fraction:Number):Number{
  f = fixture;
  fixtList.push(f);
  lambda = fraction
  return fraction;
}

this.RayCast(cb, new V2(startPos.x, startPos.y), new V2(endPos.x, endPos.y));
var count : int =  fixtList.length
trace (count);


I have three bodies, and check the same point. My ray intersects all the objects. This code is executed in mouse-up event handler. all the bodies sleeping. But I get different results :

Code:
start pos : (x=2.9942219257354736, y=7.695000648498535)
end pos : (x=8.443902015686035, y=7.695000648498535)
2
start pos : (x=2.9942219257354736, y=7.695000648498535)
end pos : (x=8.443902015686035, y=7.695000648498535)
1
start pos : (x=2.9942219257354736, y=7.695000648498535)
end pos : (x=8.443902015686035, y=7.695000648498535)
1
start pos : (x=2.9942219257354736, y=7.695000648498535)
end pos : (x=8.443902015686035, y=7.695000648498535)
1
start pos : (x=2.9942219257354736, y=7.695000648498535)
end pos : (x=8.443902015686035, y=7.695000648498535)
3
start pos : (x=2.9942219257354736, y=7.695000648498535)
end pos : (x=8.443902015686035, y=7.695000648498535)
2


could you please tell why the number of fixtures changes, although the ray doesn't move ?

Thanks!


Top
 Profile  
 
PostPosted: Mon Jun 06, 2011 7:36 pm 
Offline

Joined: Tue Feb 24, 2009 4:10 pm
Posts: 564
Location: Michigan
Code:
var cb : Function = function(fixture:b2Fixture, point:V2, normal:V2, fraction:Number):Number{
  f = fixture;
  fixtList.push(f);
  lambda = fraction
  return fraction;
}


for the purpose of this conversation i will be using the word "contacts" as being a returned callback group of {fixture, point, normal, fraction}.
not at all related to box2d or wck contact.as class(s)
just saying "fixture" or "point" would be too vague since it finds all of these elements for the callback funciton.

keep in mind that the contacts returned are not in order of distance.
it should be assumed that they are not in any order.

raycast is commonly used to find the closest contact
by returning fraction you are telling the raycast to search again for anything closer than the last found contact.

that should explain the reason for fixtList:Array being different each time.
for example of items, 1,2,3,4,5
perhaps it finds 3 first, then it is only looking at 1 or 2 next.
another time it might find 1 first, and have no where else to look.

i'm not sure what you are planning to do with fixtList, more details may help find a solution.

for now looking at what you have, i would suggest comparing the fixture to your array
if it is not on the array, add it and return 1
if it is on the array return -1 to skip it.

i think that might give you all the fixtures in range of the raycast. i hope it doesn't endless loop or something odd. i haven't tried to do that yet, all the raycasts i make so far just care about the first valid contact.

I hope that helps explain things, raycasts are a bit obscure, and sadly have no debug-draw that I'm aware of. but I like this method better than previous implementations of raycast for what its worth.

also this may have gotten more response at the Flash forum, since there is nothing wck specific about raycasts (yet).
that said, i mostly check the wck forum, so i may not have answered it there :P


Top
 Profile  
 
PostPosted: Mon Jun 06, 2011 9:36 pm 
Offline

Joined: Tue May 24, 2011 1:05 pm
Posts: 3
Thanks for you answer! :)

sketchbookgames wrote:
i'm not sure what you are planning to do with fixtList, more details may help find a solution.



I do a game like this:
http://armorgames.com/play/11027/splitter-pals
sequence does not matter to me, I just want to get all fixtures to be cut.

you are right, info about WCK very little :( I may be stupid, but I have a lot of problems with him and not enough answers :(

anyway, thanks!


Top
 Profile  
 
PostPosted: Wed Jun 08, 2011 6:33 pm 
Offline

Joined: Tue Feb 24, 2009 4:10 pm
Posts: 564
Location: Michigan
hmm trying to split shapes, raycast might be the right way to go, I'm not sure right now. anyway you may want to just try QuickB2 for this project since it has a split function built in,
http://code.google.com/p/quickb2/

their slice does a little extra by storeing partial slices.
but it had a few bugs if you let the user make too many partial slices
as i reported to them at the bottom of this page of the forum.
viewtopic.php?f=8&t=1547&start=30


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group