Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
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 755 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: 12
Projects: 2
Exp: 14 years


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.

 

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

The first screenshot will be displayed as a thumbnail.

Riven (12 views)
2014-07-29 18:09:19

Riven (9 views)
2014-07-29 18:08:52

Dwinin (9 views)
2014-07-29 10:59:34

E.R. Fleming (26 views)
2014-07-29 03:07:13

E.R. Fleming (10 views)
2014-07-29 03:06:25

pw (40 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (27 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org 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‑gaming.org
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!