Am 06.05.2011, 12:25 Uhr, schrieb meliuss <[email protected]>:

> Hallo,
>
> i like to use Floatcanvas2 with collision-detection.
> I create some Polygons with a list of Contourpoints.
> Now in Navcanvas i switch to GUI-Mode Move.
> I start move a Polygon
> - How can I get the real-world(2d-Transformed) Polygonpoints (or for
> speed the Boundingbox) from the moving Node to check if there is a
> Collision with other Polygons(Nodes) or there Boundingboxes H
> How I can i get to the onMoving-function or a onFinishMoving-function.
> Are there some examples.

I am aware that Christoper has already given an answer. However, his  
answer seems to be for fc1 while you seem to ask for fc2 specifically  
(correct me if I'm wrong). So I'll try to give it a quick shot:

The simple way, detecting collision via bounding boxes:

To get all the nodes within a certain bounding box just do something like:

     bbox = boundingBox.BoundingBox(...)
     query = QueryWithPrimitive( primitive = bbox, exact = False )
     intersectingNodes = canvas.performSpatialQuery( query, order = False )

So a simple test for intersection of two polygons (by their bounding  
boxes) looks like:

     query = QueryWithPrimitive( primitive = moving_node.boundingBox, exact  
= False )
     doCollide = len(canvas.performSpatialQuery( query, order = False )) > 0


The more complex way to detect exact collisions between polygons:

The points are accessible through polygon_node.model.points if memory  
serves right. To get the transformed points of the polygon you can just  
multiply each point by polygon_node.worldTransform. This should yield the  
transformed world coordinate. It's up to you to perform the collision  
detection between the polygons. The underlying wxWidgets layer didn't  
allow for better collision detection than that when I wrote fc2. However,  
it provides an exact "is point in shape" function which I am using for the  
object picking.

To see any examples, run the fc2 demo. Especially, look at  
demo\FloatCanvasDemo\02-Demos\07-CustomizedGUIMode\CustomizedGUIMode.py.  
Your code would then look similar to this:

class MoveNodeWithCollisionDetection(fc.guiMode.GUIModeMoveObjects):
     def on_move(self, event):
         query = QueryWithPrimitive( primitive = event.node.boundingBox,  
exact = False )
         if not canvas.performSpatialQuery( query, order = False ):
             fc.guiMode.GUIModeMoveObjects.on_move( self, event )

Note: I haven't tested any of the code above, it's written from top of my  
head.

Finally, you need to be willing to look into fc2 yourself a bit if you  
really want to use it. I have written it for the Google Summer of Code  
2008 and I'm afraid it hasn't had very much public exposure since then. It  
has certain performance shortcomings as it stands.

As an alternative, you may want to look at the original FloatCanvas which  
is also used more widely.

-Matthias
_______________________________________________
FloatCanvas mailing list
[email protected]
http://paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas

Reply via email to