xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bibek Sahu <scor...@dodds.net>
Subject Re: detecting shape collision?
Date Wed, 04 Feb 2004 22:03:18 GMT

I don't believe it's in the spec for SVG, though I could be wrong; anybody
know otherwise?  As near as I can tell, there is no code in either Batik
or in Java to do precise 2D collision-detection, or deliver events upon
that.  You asked about checking two objects, not about recieving events on
an arbitrarily-large number of objects.

Given that collision events are not in the SVG spec, you could:

	(1) use Java3D, which does have collision events.  You would, of
course, have to write a bit of glue code for it...

	(2) come up with a more practical implementation of the check.
There might even be a Java-based system out there which will fire
collision events when two Shape objects collide.  I don't know of any, but
I'm no graphics expert; I'm sure the algorithms have been researched,
though.  You could find/write an implementation of such an algorithm, then
write a custom bridge for Batik so you could access it.  [of course, it'd
only work with Batik at that point...]

Good luck.
- Bibek

On Wed, 4 Feb 2004, don undeen wrote:

> So you're saying that while there isn't code in batik to see if to SVG shapes intersect,
I can turn them into java.awt.Shapes, and use code like jPong.PongObject.collides(shape1,
shape2) to see if they collide?
> that makes sense; I wonder if that will ulitimately be practical for my
> system, where I intend to to have LOTs of shapes moving around. For N
> objects, I have to do (n+(n-1)+(n-2)+...+2+1 (i forget, is that what
> they'd call "O(log(n))" ?) comparisons every iteration to see if there
> are any new intersections. I've been able trying to avoid loops like
> that where possible.

> What I really wanted to have was a way to register a "collisionEvent"
> with a shape, so that collisions are just "announced" when they occur.
> Would something like that ever be in the works for SVG?
> Bibek Sahu <scorpio@dodds.net> wrote:
> Howdy,
> On Wed, 4 Feb 2004, don undeen wrote:
> > Is there any way with batik/java/svg to detect if two svg shapes have
> > "collided" or overlap? For example, if you have two circles of some
> > radius, and you move them closer together, I'd like an alert to go up
> > when the edges collide. Or perhaps I'd like to know if two lines
> > overlap.
> In principle, in SVG, the SVGSVGElement methods 'getEnclosureList()',
> 'getIntersectionList()', 'checkEnclosure()', and 'checkIntersection()' might
> be useful (though I don't know if they'd be enough)... but in practice I
> don't think they're implemented in Batik yet (at least, that the impression
> I got from what I've seen on this list).
> In practice with Batik, you can get the GraphicsNode associated with an
> SVGElement, and then use GraphicsNode.getOutline() (or if it's a
> ShapeNode, use ShapeNode.getShape()) for both nodes, then check if the
> returned Shape objects intersect:
> BridgeContext bc = svgComponent.getUpdateManager().getBridgeContext();
> SVGElement circle1=...., circle2=....;
> GraphicsNode g1 = bc.getGraphicsNode(circle1);
> GraphicsNode g2 = bc.getGraphicsNode(circle2);
> Shape outline1 = g1.getGlobalTransform().createTransformedShape( g1.getOutline() );
> Shape outline2 = g2.getGlobalTransform().createTransformedShape( g2.getOutline() );
> if(outline1.intersects(outline2.getBounds2D()))
> // the first shape intersects the bounding-box of the second
> else
> // blah blah blah
> Note that it doesn't actually check if the two /shapes/ intersect, and
> especially with circles this could get to be a problem, but at least you now
> have Shape objects to work with. :-)
> If you need a method to see if two Shapes collide, Mr. Google is your
> friend. (e.g., http://www.risrani.com/programs/pong/doc-Pong/jPong/PongObject.htmlhttp://www.risrani.com/programs/pong/doc-Pong/jPong/PongObject.html
> ;-)
> Good luck!
> - Bibek
> > Is there a method to do this that doesn't involve explicitly calculating
> > the areas covered by each of my shapes?
> >
> > I'm guessing the answer is "no," but I'd sure like it to be "yes"!
> >
> >
> >
> > thanks for everything,
> >
> > Don Undeen
> >
> >
> >
> >
> > ---------------------------------
> > Do you Yahoo!?
> > Yahoo! SiteBuilder - Free web site building tool. Try it!
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
> ---------------------------------
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free web site building tool. Try it!

To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org

View raw message