Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (636)
Games in Android Showcase (178)
games submitted by our members
Games in WIP (688)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Complicated transformation  (Read 934 times)
0 Members and 1 Guest are viewing this topic.
Offline Malohkan

Senior Devvie

while (true) System.out.println("WOO!!!!");

« Posted 2004-11-18 01:02:30 »

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!

Admin and Game Developer at
Play Rimscape!    |    Play Conquer!
Offline CaptainJester

JGO Knight

Medals: 12
Projects: 2
Exp: 14 years

Make it work; make it better.

« Reply #1 - Posted 2004-11-19 10:10:38 »

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

Offline Malohkan

Senior Devvie

while (true) System.out.println("WOO!!!!");

« Reply #2 - Posted 2004-11-20 13:16:56 »

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

Admin and Game Developer at
Play Rimscape!    |    Play Conquer!
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Dwinin (74 views)
2015-11-07 13:29:08

Rems19 (81 views)
2015-10-31 01:36:56

Rems19 (79 views)
2015-10-31 01:32:37

williamwoles (107 views)
2015-10-23 10:42:59

williamwoles (93 views)
2015-10-23 10:42:45

Jervac_ (111 views)
2015-10-18 23:29:12

DarkCart (137 views)
2015-10-16 00:58:11

KaiHH (118 views)
2015-10-11 14:10:14

KaiHH (158 views)
2015-10-11 13:26:18

BurntPizza (173 views)
2015-10-08 03:11:46
Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30

Rendering resources
by Roquen
2015-10-15 07:40:48

Math: Inequality properties
by Roquen
2015-10-01 13:30:46

Math: Inequality properties
by Roquen
2015-09-30 16:06:05

HotSpot Options
by Roquen
2015-08-29 11:33:11 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!