[Help] how can i rotate my tank?

Hi guys here!I'm making a tank battle game with java2D. I need the tank can move forward or backward, that is not difficilt, but I need it can rotate an angle, which is hard for me. I don't know how i can do it , can anyone here give me some adivice?! Thank you !!
[280 byte] By [cjrena] at [2007-10-2 17:25:00]
# 1

You have a couple different options, the easiest is probably to make transitional sprites--all angles of the tank you wish to show and transition them along the same idea as a shot animation/movie.

If you have a line graph plotted tank/object, then you can get familiar with sin/cos functions and how they relate to your angle of view and project the verticies from a common point of observation.

morgalra at 2007-7-13 18:41:20 > top of Java-index,Other Topics,Java Game Development...
# 2
I would read up on AffineTransforms.
mbishop78a at 2007-7-13 18:41:20 > top of Java-index,Other Topics,Java Game Development...
# 3

Hi cjren,

If you want smooth rotational movement use affine transform as morgair suggested. There's loads of posts on the forums on how to do that specifically for tank games.

When you want to move your tank you'd do something like this . . .

AffineTransform imageLocation = new AffineTransform();

...

dx=Math.cos(Math.toRadians(angle))*velocity;

dy=Math.sin(Math.toRadians(angle))*velocity;

pX=pX+dx;

pY=pY+dy;

imageLocation=AffineTransform.getTranslateInstance(pX,pY);

imageLocation.rotate(Math.toRadians(angle)+Math.PI/2, CENTRE_IMAGE_WIDTH, CENTRE_IMAGE_HEIGHT);

Good luck,

Has

hasman001a at 2007-7-13 18:41:20 > top of Java-index,Other Topics,Java Game Development...
# 4
Correction"If you want smooth rotational movement use affine transform as" mbishop78 suggested.Thanks,Has
hasman001a at 2007-7-13 18:41:20 > top of Java-index,Other Topics,Java Game Development...
# 5

:-) finally, My tank is built up as a polygon, so I write a method rotateVertex(Point2D p2d) to transform the angle of the tank. But for tank is not built up by image, so the look of is ugly.

"affine transform " is a good thing, but from the tutorial I think it was used for coordinate transform.

thx.

cjrena at 2007-7-13 18:41:20 > top of Java-index,Other Topics,Java Game Development...