rotation of bounding box ?
I know I can get the transformation info on a sprite to work out the position of a bounding box used for collision detection, but if the image is being rotated, how can I rotate the bounding box for a more accurate collision test.
the image is rectangular so a square(ish) bounding box won't do.
Alright, think about it this way.
A bounding "box" is not a box, persay. It is a set of four bounding lines that have common coordinates.
A series of bounding lines which close as a polygon can be represented as a Polygon object in the java.awt package. The Polygon object has a method which determines if a given point is contained within the Polygon or not.
Each bounding "box" will have four bounding lines, each of which contains two of the four critical points (the corners of the box).
For any two Polygon objects (a series of bounding lines containing a closed space), intersection occurs only if one of the critical points from one Polygon is contained within the other.
You can perform a rotation transformation on the bounding points of an object in the same manner as you rotated the image. Once you have a series of points representing the bounding polygons of your object, you simply need to perform two tests. First, determine if any critical points from the first polygon are contained within the second; next, determine if any critical points from the second polygon are contained within the first. If any of these points are contained, the polygons are intersecting. If none of these points are contained, no intersection has occurred.
At least that's the most abstract way to do it that I can think of. :)
tvynr at 2007-7-5 22:28:50 >

'course, if you wanted to make things really easy, you could always use bounding circles and just to distance checks. :)
tvynr at 2007-7-5 22:28:50 >

I know what a bounding box is and how it works. What I need to know is how to rotate it. I'm using pretty much a square bounding box at the moment, but as I said the sprite is a long rectangular shape. If I can't rotate the bounding box the collisions look ok sometimes and rubbish if the sprite is at 90 degrees to its bounding box.
So...How do I apply a rotation to a Polygon object ?
I apply it to the sprite like this.....
xForm1.setToIdentity();
xForm1.translate(xpos1, ypos1);
xForm1.rotate(angle);
xForm1.scale(scale, scale);
xForm1.translate(-myImage.getWidth(this)/2, -myImage.getHeight(this)/2);
offscreen.drawImage(myImage, xForm1, this);
..I can't do that with a polygon object
You could use Polygon.getPathIterator(AffineTransform) to get the points of the polygon after applying the transform, and construct a new polygon with the transformed points.
When i get home tonight, I will send you the course slides I was given back in uni - they explain a hell of alot, OBBs(Oreinted Bounding Boxs) are included in there.but in the mean time, dont waste your time even thinking about the Polygon class - it is the *wrong* way to do it.
Abuse at 2007-7-5 22:28:50 >

1. Are we operating under the same definition of "bounding box?" My experience has always been that a bounding box is the region in which a sprite is counted as existing for the purpose of collision detection. I didn't see any collision detection in that code.
2. If we -are- talking about collision detection, I will now (after review) agree with you that the Polygon object doesn't have all of the functionality needed. However, an object which represents a bounding polygon could be used quite nicely in this situation, as it could be freely rotated internally and fixed to a given point on the sprite. Additionally, the most significant content of my post was the corner detection; no two bounding polygons, regardless of their orientation, can be intersecting if none of the corners for either polygon is contained within the other.
Am I misunderstood as to the purpose of a bounding box? Let me know, please. :) Thanks!
tvynr at 2007-7-5 22:28:50 >

> 1. Are we operating under the same definition of
> "bounding box?" My experience has always been that a
> bounding box is the region in which a sprite is
> counted as existing for the purpose of collision
> detection. I didn't see any collision detection in
> that code.
>
> 2. If we -are- talking about collision detection, I
> will now (after review) agree with you that the
> Polygon object doesn't have all of the functionality
> needed. However, an object which represents a
> bounding polygon could be used quite nicely in this
> situation, as it could be freely rotated internally
> and fixed to a given point on the sprite.
yes, bounding polgons are sometimes used - but the point of bounding rectangles, or bounding circles, is that they are cheap in terms of computation.
calculating in the intersection of 2 polygons is not simple, and not cheap.
> Additionally, the most significant content of my post
> was the corner detection; no two bounding polygons,
> regardless of their orientation, can be intersecting
> if none of the corners for either polygon is
> contained within the other.
yes they can, very easily infact.
not sure how good this is going to look /me tries some ascii art ;]
1
4oox xoo5
oxxo
xx
3xxxxxxx2
6
its 2 triangles {1,2,3} and {4,5,6} arranged to overlay each other (they form a star shape).
>
> Am I misunderstood as to the purpose of a bounding
> box? Let me know, please. :) Thanks!
rob,
Abuse at 2007-7-5 22:28:50 >

1 4oox xoo5 oxxoxx3xxxxxxx2 6
Abuse at 2007-7-5 22:28:50 >

You present a good case; I noticed a similar example this weekend (when I was without internet access).
+--+
|\\|
+-*--*-+
|/|XX|/|
|/|XX|/|
+-*--*-+
|\\|
+--+
Is the appropriate behavior to determine intersection of line segments between the two polygons?
tvynr at 2007-7-5 22:28:50 >

its a way, but can be abit expensive. A point to note, if your not using descrete motion, I don't think it is possible for polygons to get into the states that have been highlighted above.Good topic 2 search for info on the net me thinks ;]
Abuse at 2007-7-5 22:28:50 >

> its a way, but can be abit expensive. A point
> to note, if your not using descrete motion, I don't
> think it is possible for polygons to get into the
> states that have been highlighted above.
>
> Good topic 2 search for info on the net me thinks ;]
What if they're moving really fast? :) (Imagine a missile hitting a target in a 2D side-scroller.)
tvynr at 2007-7-5 22:28:50 >

> > its a way, but can be abit expensive. A
> point
> > to note, if your not using descrete motion, I don't
> > think it is possible for polygons to get into the
> > states that have been highlighted above.
> >
> > Good topic 2 search for info on the net me thinks
> ;]
>
> What if they're moving really fast? :)
> (Imagine a missile hitting a target in a 2D
> side-scroller.)
speed only makes a difference if your modelling motion with discrete values (e.g. x+=dx; y+=dy;).
if instead you model your motion by doing intersection from 1 frame to the next, speed is irrelevant (though technically a fast moving object will require more computation)
rob,
Abuse at 2007-7-5 22:28:50 >

Thx for setting me straight on that lot. ;)
tvynr at 2007-7-5 22:28:50 >
