Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
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 592 times)
0 Members and 1 Guest are viewing this topic.
Offline Malohkan

Senior Member




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


« Posted 2004-11-18 02: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:
1  
2  
3  
4  
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
GameLizard.com
Play Rimscape!    |    Play Conquer!
Offline CaptainJester

JGO Knight


Medals: 10
Projects: 2


Make it work; make it better.


« Reply #1 - Posted 2004-11-19 11: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 Member




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


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

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
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 Smiley

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

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Try the Free Demo of Revenge of the Titans

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (77 views)
2013-05-17 21:29:12

alaslipknot (89 views)
2013-05-16 21:24:48

gouessej (119 views)
2013-05-16 00:53:38

gouessej (113 views)
2013-05-16 00:17:58

theagentd (126 views)
2013-05-15 15:01:13

theagentd (113 views)
2013-05-15 15:00:54

StreetDoggy (156 views)
2013-05-14 15:56:26

kutucuk (179 views)
2013-05-12 17:10:36

kutucuk (179 views)
2013-05-12 15:36:09

UnluckyDevil (186 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.11 seconds with 20 queries.