Bounding Box Rotation Using AffineTransform

Hi everyone,
I'm making a 2D overhead view tank game (lots of those around, hey?). The problem I have is with collision detection using bounding boxes.
I use the AffineTransform that I rotate the sprite image with to rotate that sprite's bounding box. The problem is that the bounding box doesn't anchor itself to the sprite. Instead, when the tank rotates, the bounding box leaves the sprite and moves alongside it. As you can imagine, this doesn't lead to good collision detection.
How can I anchor the bounding box to its sprite so that whatever rotation or movement the sprite does, the bounding box stays on the sprite and moves with it?
The code fragment that deals with rotating the bounding box and drawing it is below.
tankShape = new Rectangle2D.Double(enemy.getX(), enemy.getY(), enemy.getWidth(), enemy.getHeight());
at = AffineTransform.getRotateInstance((Math.toRadians(enemy.getAngle())+Math.PI/2),
(enemy.getX()+11), (enemy.getY()-24));  //+11 and -24 are to anchor the bounding box at the centre of the sprite
tankShape = at.createTransformedShape(tankShape);
g.draw(tankShape);Thanks,
Has

Note to myself, this is how it's done:
public void paintHitBoxes(Graphics2D g)
     double x = player.getX();
     double y = player.getY();
     x += Math.cos(Math.toRadians(player.getAngle()));
     y += Math.sin(Math.toRadians(player.getAngle()));
     Rectangle2D.Double tankShape = new Rectangle2D.Double(x, y, player.getWidth(), player.getHeight());
     g.setPaint(Color.red);
     imageLocation =
          AffineTransform.getRotateInstance(Math.toRadians(player.getAngle())+Math.PI/2, x+(player.getWidth()/2), y+(player.getHeight()/2)); //7, 14
g.draw(imageLocation.createTransformedShape(tankShape));
}

Similar Messages

  • Unwanted bounding box resets

    I'm having a rather infuriating issue with Bounding Box resets.
    Image here:
    http://img848.imageshack.us/i/unled3j.jpg/
    Sorry—I can’t get it to show up in this message.
    The first row of the linked image shows a roughly isometric view of a machine decal, followed by straight on views of a red box and a newer version of the decal.
    To turn this new decal into a similar perspective, I normally:
    1-rotate the decal using the black/closed arrow hovering over a corner handle
    2-use the Free Transform tool on the rotated side handle of the bounding box to skew the rotated image
    The second row shows what happens to the red box and its Bounding Box after rotation.I would normally use the handle that had been the middle right to Free Transform this object
    The third row shows the new decal rotated. It's bounding box has reset itself automatically and is no longer useful with the Free Transform tool.
    These two objects are on the same document, so I'm guessing the Bounding Box reset has something to do with some attribute of the new decal. Whatever it is, an operation that normally take 10 seconds has become suddenly impossible. Anybody know what to do to fix this?
    Thanks.
    Matt
    http://img848.imageshack.us/i/unled3j.jpg/

    I had this problem as well, and it was driving me crazy. This happens when you have multiple objects sellected that have bounding boxes set at different rotations. They can be grouped or ungrouped, it makes no difference, and the bounding box will automatically reset. I found that resetting the bounding box (before applying the transform) fixes the problem. This seems counter intuitive, because the bounding box doesn't look like it needs to be reset. It already appears straight, so there is no noticable change after applying the reset bounding box command. However, afterwards the bounding box will stay in the correctly rotated position because all objects have the same bounding box rotation.

  • Can you change the colour of an 'image' bounding box?

    This concerns bounding boxes not 'strokes'.
    Is it possible to customise the default colour of a bounding box around an image?
    I know that the default 'rectangle image frame' matches the Layer colour (eg: Layer 1 - Light Blue, with an the image bounded by a brown box) which is easily changed by moving it to another layer (eg: Layer 2 - Red, which displays an image bounding box of Cyan). What defines the colour of the bounding box of an image that is placed inside the 'rectangle image frame' and can it be changed?
    I have no real necessity to change it, I just wondered if it was possible?
    Steve

    I'm not sure you understand the terminology.
    The bounding box is an imaginary rectangle that encloses the shape of an object or group of objects. For a simple graphics frame this is the same size and shape as the frame and is poisitioned on the frame edge (and it's what you see when you select the frame). The bounding box is used for calculating object positioning. When dispalyed, it takes on the color assigned to the layer.
    The frame edge is also fictitious. It's a screen display aid that can be tuned on or off to help you locate objects and also uses the color assigned to the layer. It corresponds to the path that describes the edge of the frame, so might not be rectangular (a bounding box is always rectangular).
    The stroke is an attribute assigned to the path describing the perimeter of a closed object or the path itself of an open path. Stokes can be assigned a weight, color, and stroke style such as dotted or striped.
    An image placed inside a frame has it's own bounding box, but not a frame edge or stroke. To see the image bounding box use the direct select tool to select the image inside the frame. If you crop an image so it is larger than the containing frame, or or enlarge the frame so the image does not completely fill it, you can see the differnce between the bounding boxes very easily. The color of the image bounding box is also tied to the layer color and is not editable by the user.

  • Placing AI files Bounding Box vs Crop

    I've wished and not found a global preference for AI files to place with Crop To set as Bounding Box.
    Using Bridge to drag files into a layout is not helping as ID is defaulting the image frame to the AI page size. I've got strong objections to leaving a frame three to ten times the image size and of course Fitting > Fit Frame To does not respect the bounding box, but rather the page frame.
    Is there a best way to handle a large number of AI files (with cryptic names) needing to be placed?
    Along these lines, things I would like to change;
    In the Place dialog, Show Import Options is unchecked by default.
    Using Preview during Place isn't that great for an AI image one inch square in a letter size page.
    PC running Creative Suite 4, InDesign CS3

    I don't use Bridge, but the first time I Place an Illustrator file, I set the import options to "Art", and then the next time I Place one I uncheck the box and the import options remain set on "Art" until I change them again (or restore preferences). Doesn't dragging from Bridge work the same way?
    Ken Benson

  • 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.

    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
    ox xo
    x x
    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,

  • I have 4 equal oblong shape created with borders How do I go about knowing what size the selection area is so that I can crop an image to fit. I don't want to use paste in then adjust the bounding box to suit

    I have 4 equal oblong shape created with borders How do I go about knowing what size the selection area is so that I can crop an image to fit. I don't want to use paste in then adjust the bounding box to suit

    What do you mean a moderator

  • CS6 - Pattern making. How can I use a bounding box to define the pattern size?

    I want to create a pattern in cs6. As in the previous versions of illustrator, I'd like to be able to use a bounding box to tell the computer where I want the pattern to start etc. In cs6 I can't seem to be able to do this. Once I hit 'make pattern' the bounding box is different and it becomes really difficult to define where I want the pattern to start. The pattern making part of illustrator seems to get confused and ends up throwing out my pattern completely. Any ideas?
    Thanks!

    Zehgut,
    Create a nofill/nostroke rectangle where you want to have the boundaries, then move it down beneath the artwork in the Layers palette and include it in the swatch. That is the way to define the boudaries.

  • Resizing in photoshop using bounding box

    How can I resize shapes or text using the bounding box with out getting pixeled or modifided? thanks!

    goldny wrote:
    How can I resize shapes or text using the bounding box with out getting pixeled or modifided? thanks!
    Shapes and Text Layers should not pixilate when they are resized.  However if you have flattened them or rasterzised them or converted them to a smart object layer if you greatly increase their size those types of layer can become pixilated.   Vector layer types like Shape layers and text layers are resized using vector graphics where pixel layers are transformed in size using interpolation which results in all new pixels for those layers.
    The only time resizing does not change pixels is when you only change the documents DPI resolution without resampling. All that changes then is the print size.  The pixel remain the same only their print size is change.
    100DPI means pixels are 1/100"x1/100" like on you desktop display. There are 10,000 pixel per square inch.
    300DPI means pixels are 1/300"x1/300" the DPI often used for print images there are 90,000 pixels per square inch
    You print is 9 time smaller printed then when displayed on your display using actual pixels for your display does not support print DPI it can only display pixels the size its manufactured with,

  • Resizing in Illustrator CC using the Bounding Box is no longer accurate. What happened?

    In Illustrator CC, resizing an object using the bounding box is no longer accurate. Snapping to other objects or the grid or anything is completely wrong and, worse, inconsistent. Here is a single box being resized 3 times to the same object. Each time, it becomes a different size.
    I used the center-left handle to resize the black box, snapping it to the right edge of the red box. You can see that, each time, it "snaps" to the edge incorrectly. My 80 pt box becomes 78.479 pt, then 79.295 pt, then 79.518 pt.
    This is totally unacceptable, obviously. I'm not sure what the point of guides are if they aren't actually guiding. Does anyone have a fix for this?

    Ethan,
    Did you reinstall after updating to Yosemite? I believe the right order/way is to update the OS first, then reinstall the applications, see 6) below.
    Or you may have a look at the list since something is obviously wrong.
    The following is a general list of things you may try when the issue is not in a specific file (you may have tried/done some of them already); 1) and 2) are the easy ones for temporary strangenesses, and 3) and 4) are specifically aimed at possibly corrupt preferences); 5) is a list in itself, and 6) is the last resort.
    1) Close down Illy and open again;
    2) Restart the computer (you may do that up to 3 times);
    3) Close down Illy and press Ctrl+Alt+Shift/Cmd+Option+Shift during startup (easy but irreversible);
    4) Move the folder (follow the link with that name) with Illy closed (more tedious but also more thorough and reversible);
    5) Look through and try out the relevant among the Other options (follow the link with that name, Item 7) is a list of usual suspects among other applications that may disturb and confuse Illy, Item 15) applies to CC, CS6, and maybe CS5);
    Even more seriously, you may:
    6) Uninstall, run the Cleaner Tool (if you have CS3/CS4/CS5/CS6/CC), and reinstall.
    http://www.adobe.com/support/contact/cscleanertool.html

  • Is there a way of resizing the contents of multiple bounding boxes at the same time using the number fields in the tool bar?

    I'musing cs6 and need to resize an image and two text boxes to a specific pixel width.
    I try selecting all of the boxes and punching in 960 px in the resizing field in the tool bar but only the bounding boxes and not their contents get resized...

    Use the horizontal scale field (and include the units) rather than the width field.

  • Unable to set bounding box using rectangle tool on small rectangles

    I just upgraded to InDesign CC and keep getting an error message "Unable to set bounding box" when I try to create a small rectangle. The tool works fine when creating a larger rectangle -- it only gives me the error when creating a very small rectangle. Never had this problem in CS5.
    Anyone else run across this?

    Check what your default stroke weight is. If the stroke weight is to wide for the size of the box you are trying to draw, you will get that message.

  • Bounding Box of Triangle

    I am looking for a way I can calculate the bounding box of a triangle?
    For example I have a set of three points and it will return the bounds even if the triangle is rotated.
    I understand that their is a method that you can use built-in but I need to be able to calculate it myself for reasons of my project.
    Kind Regards

    Isn't the bounding rectangle always (minx, miny, maxx, maxy) for any shape?

  • How to create bounding box over part of path

    Hi,
    need to create a bounding box over part of path as done by Wade ; http://forums.adobe.com/servlet/JiveServlet/showImage/2-4305034-180560/Screen+Shot+2012-03 -31+at+6.01.24+PM.png
    tnx,

    The other two posters are absolutely correct.
    But you have two choices to do what you want as far as I know since your path is not an effect as mine was.
    You can use the scissor tool to cut the segment you want to be able to select. I assume you want to move it or rotate it or perhaps resize it or a combination of those.
    If you need the original path to remain intact you can take the lasso tool and select that segment of the path and do a copy and then a paste in front and you will have a copy of that segment sitting on top of the original segment which will still be part of the original path.
    If you intend to alter the segment and then rejoin it to the original path then use the scissor tool approach.

  • Scopes limited to a bounding box!

    I've put in a wishform request (  https://www.adobe.com/cfusion/mmform/index.cfm?event=processform&name=wishform#wishprodlan g  ) for something that would have a HUGE effect on the speed of my grading: being able to have the scopes limited to the data in a drawn bounding-box! I'd want it to be a key-boarded shortcut, but one you could set to "on" and just leave as you wanted to.
    Think of how this would assist you in  skin-tone corrections/controls, being able to at any moment draw a quick bounding-box and see where on the vector-scope your "skin" falls, both for rotational degree (hue) and saturation!
    Think of the way this could work in checking for secondary corrections ... both in determining IF you need to do the work of making a secondary, and ... if so ... showing you where you need to start AND where you need to go.
    Currently the only way to do this is to make a top-level primary layer, create a mask on it futzing around to make the mask fit exactly the area you need to "see" in the scope, set the layer for controlling the outside of the mask, and then "grade" the outer area to black.
    You need to do all this anytime you want to restrict the scopes to one small section of the image. The control as I've suggested, only because I've learned it is something available in some other software and is slicker than SNOT to use (    ) ... well, it would be available INSTANTLY all the time. What a huge time-saver this would be for me.
    Y'all are welcome to post this on to Adobe also ... 
    Neil

    FWIW Neil
    In my experience ..."skin tone" and any other is ultimately CC and graded to the "eye-ometer"
    Key to subtleties and control  is the use of Secondaries thru HSL qualifiers and masks.
    Personally ..once I get into areas such as skin tone...its all eye and not a glance at a scope ...apart from the constant eye on Black and highlight levels.
    I would like to see Adobe gain scope consistency across the apps.  SG , PPRO and AEFX
    I am not adverse to a "floating point scope" as an optional tool. ( Another scope).
    If you can get a look at DVRack (Serious Magic)  or Adobe On Location scopes... do so.

  • Bounding box bug CS6 (Creative Cloud)

    Anyone else have the bounding box occassionally stick to an object? I can select other objects but the bounding box will extend across the artboard from the new object and group the older object with it. I can't click off of the object either. I think it's mainly a text box problem, I can't recall having this problem with shapes or path drawn objects. I just fixed it by isolating it then immediately jumping out of that isolation, it was suddenly unselected. Anyway, just checking in with other users, wanted to catalog this at least.
    EDIT: Just had this happen with a photo in illustrator, as well as a circle I just clicked off from creating. The only hinderance it brings is that scaling, rotating, etc. is directly correlated to both selected objects rather than the one I intend to scale or rotate, etc.

    I've seen this happen on and off since the original CS. On both Mac and Windows systems across several OS versions. Sad to hear it's still with us in CC. I've seen it blamed on all sorts of things; text objects, clipping masks, imbedded / non-imbedded objects, a particular OS, etc. None of which have ever held true in all cases.
    Anyway, one way that (sometimes) solves it is to;
    Create another object, even a small square.
    Align the new object with the 'stuck' one - use any alignment at all. If another object moves, you can immediately undo.
    In any case, once you deselect and delete your dummy object after the align (or align and undo), four times out of five the stuck bounding box is gone (for a while, anyway).
    good luck.
    --OB

Maybe you are looking for

  • When i am trying to download something it is diaplaying downloads window but not saving the file in that why?

    i tried cache clearing and application tools settings and all. it is asking for want to save ur binary file eventhough i press save button also it is not saving anywhere please resove my problem as soon as possible. And i tried pop3 blockers settings

  • Ipod Restore help. PLEASE. I'M DESPERATE

    Okay so I have an 80 gb IPod classic. Not sure what generation it is, but I've had it for about 6 years. It has all my music on it, some that I cannot get back unfortunately. I cannot remember the last time (if ever) that I voluntarily backed up the

  • Bootcamp rebooting...wear and tear

    Hi all, I'm now 2 weeks into my new macbook pro (i am a PC switcher), and still lovin it. I just wanted to get people's opinions on something. I have installed XP using bootcamp for the sole purpose of playing a few games and using 1 online app that

  • HELP! Connecting shuffle to cradle turns off monitor

    Hi, I've been having this intermittent problem that really starting to annoy. Sometimes while connecting my shuffle to the USB cradle my monitor will loose the video signal and go blank (looses video signal). Seems that the shuffle needs only to touc

  • Equium A110-233 - I need select manually the boot device from menu

    In the last few days when I turn on my laptop the Toshiba screen appears but I need to manually go in and select the boot device to start windows. (Down the bottom the message 'Press F2 for set up. Entering boot device selection menu') Why has this s