Complicated transformation

I have my ship flying around in Rimscape, and now I want a thruster to fire out the back. I can get it to decently follow the back of the thing with:

int x = (int)( s.getX() - screen.getX() - (ship.getWidth())*Math.cos(theta));
int y = (int)( s.getY() - screen.getY() - (ship.getWidth())*Math.sin(theta));
Rimscape.TRANS.setTransform(scale, 0, 0, scale, x, y);
Rimscape.TRANS.rotate(theta, 0, 0);

However it’s still shifted so that the top of the image lines up with the middle of the ship. This is as far as I can get it to work.

The next problem is that I’m scaling the thruster image from 0 to 1 depending on how it’s being used, so that the longer you fire it the further it scales out until it reaches maximum. That means not only do I have to figure out how to position this image correctly centered in the back of my rotating ship, but I also have to make it line up correctly even when the image is scaled to different sizes.

I’m so brain dead from looking at this thing and trying different ideas that I don’t feel I can adequately explain what I’ve tried and what results I’ve gotten. Hopefully someone can give me a good explanation of how I can go about making my desired transformation? Thanks to any response!

If I understand your problem correctly, you just need to shift your object center. The center of the object does not have to be within the bounds of the object. So match the center of the thruster to the center of the ship and it will follow the ship precisly. Also offset the center of the thruster it is drawn at the back of the ship.

The only problem with this is scaling. If you scale, then the thruster will move off the back of the ship.

ps. My answer is based on my guess what your problem is. If I am way off, just ignore me. :slight_smile:


double theta = s.getTheta();
double width = WIDTH*.5;
double height = HEIGHT*.5;

int x = (int)( s.getX() - screen.getX() - WIDTH*scale - (s.getWidth()/2)*Math.cos(theta));
int y = (int)( s.getY() - screen.getY() - height*scale - (s.getWidth()/2)*Math.sin(theta));

Rimscape.TRANS.setToIdentity();
Rimscape.TRANS.translate(x, y);
Rimscape.TRANS.rotate(theta, WIDTH*scale, height*scale);
Rimscape.TRANS.scale(scale, scale);

That code does it! The main thing I couldn’t figure out at first was that I needed to scale AFTER the rotation. That solved my problems :slight_smile: