Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (524)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
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  
  AffineTransform...  (Read 1140 times)
0 Members and 1 Guest are viewing this topic.
Offline DarkMortar

Junior Devvie




Java Padawan


« Posted 2006-12-12 06:47:48 »

Ok, this function has bothered me, because it doesnt make too much sense, especially when im using an external class to manage my images ect.

I need to be able to scale my map tiles due to zooming in, zooming out ect, but AffineTransform doesnt make complete sense to me. i have searched the forums and google, but I need persoanl assistance.

Offline pepijnve

Junior Devvie




Java games rock!


« Reply #1 - Posted 2006-12-12 07:36:57 »

Asking an actual question might help. Wink
Offline purpleguitar

Junior Devvie





« Reply #2 - Posted 2006-12-12 12:55:49 »

If you need scaling, why not just use Graphics2D.scale(double,double)?  Call it before doing your drawing commands, and all of your drawing will be scaled by the factor your desire.  This will turn into an AffineTransform behind the scenes, but you don't need to master matrix multiplication to do scaling.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline DarkMortar

Junior Devvie




Java Padawan


« Reply #3 - Posted 2006-12-13 01:46:38 »

ok the Graphics2D.scale thing work, BUT it does it to the ENTIRE screen, as i found out, the work around is the scale it again, but it doesnt work that way,
unless i go below 1.0 to scale the interface to stay normal. So i must learn AffineTransform.

here is a method that i want to zoom into ONLY the tiles, yet the does nothing. i dont understand how the identity object is supposed to know what images to use?

i know this doesnt work at all, because i cant even zoom in  at all now, because it doesnt know what to scale with... i have to use AffineTransform so i dont scale the interface WITH the tiles.

Actually this method is used to understand what tile to draw according the array, and then draw it at the proper position(it works fine in that sense).

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
/**
    * Draw this tile to the graphics context provided
    *
    * @param g The graphics context on which to draw
    */

   public void draw(Graphics2D g, boolean showCoords, boolean showBoundrys, double zoom) {
     
      for (int i = 0; i < this.MAP_WIDTH; i++) {
         for (int j = 0; j < this.MAP_HEIGHT; j++) {
               
            if (this.tile[i][j] == NODRAW) { this.tileVis[i][j] = HIDDEN; }
           
            if (this.tileVis[i][j] == VISIBLE) {[b]AffineTransform identity = new AffineTransform();[/b]
               if (this.tile[i][j] == LIGHT_GRASS) { this.tileGraphic = SpriteStore.get().getSprite("\\tile_textures\\lightGrass.png","TILE"); }
               if (this.tile[i][j] == DARK_GRASS)  { this.tileGraphic = SpriteStore.get().getSprite("\\tile_textures\\darkGrass.png","TILE");  }
               if (this.tile[i][j] == DIRT)        { this.tileGraphic = SpriteStore.get().getSprite("\\tile_textures\\dirt.png","TILE");       }
               if (this.tile[i][j] == SAND)        { this.tileGraphic = SpriteStore.get().getSprite("\\tile_textures\\sand.png","TILE");       }
               if (this.tile[i][j] == WATER)       { this.tileGraphic = SpriteStore.get().getSprite("\\tile_textures\\water.png","TILE");      }
               if (this.tile[i][j] == YELLOW_GRASS){ this.tileGraphic = SpriteStore.get().getSprite("\\tile_textures\\yellowGrass.png","TILE");      }
               if (this.tile[i][j] == ROCK_GRASS)  { this.tileGraphic = SpriteStore.get().getSprite("\\tile_textures\\rockGrass.png","TILE");      }
               if (this.tile[i][j] == GY_GRASS)    { this.tileGraphic = SpriteStore.get().getSprite("\\tile_textures\\gyGrass.png","TILE");      }
               if (this.tile[i][j] == GRASS_2)    { this.tileGraphic = SpriteStore.get().getSprite("\\tile_textures\\grass2.png","TILE");      }
               if (this.tile[i][j] == DARK_SAND)    { this.tileGraphic = SpriteStore.get().getSprite("\\tile_textures\\darkSand.png","TILE");      }
               if (this.tile[i][j] == RED_SAND)    { this.tileGraphic = SpriteStore.get().getSprite("\\tile_textures\\redSand.png","TILE");      }
               if (this.tile[i][j] == BRICK)    { this.tileGraphic = SpriteStore.get().getSprite("\\tile_textures\\brick.png","TILE");      }
               if (this.tile[i][j] == TRACK)    { this.tileGraphic = SpriteStore.get().getSprite("\\tile_textures\\track.png","TILE");      }
               if (this.tile[i][j] == FARM)    { this.tileGraphic = SpriteStore.get().getSprite("\\tile_textures\\farm.png","TILE");      }
               [b]AffineTransform transform = new AffineTransform();
               transform.setTransform(identity);
               transform.scale(this.zoomLevel, this.zoomLevel); [/b]
               
               this.tileGraphic.draw(g, (int)this.xPos+(this.tileGraphic.getWidth()*i), (int)this.yPos+(this.tileGraphic.getHeight()*j));
               
               if (showCoords) {
                  coordDraw = "(" + i + "," + j + ")";
                  g.drawString(coordDraw,getTileXPos(i)+(TILE_SIZE/2)-coordDraw.length()*3+(int)this.xPos,getTileYPos(j)+(TILE_SIZE/2)+(int)this.yPos+3);
               }
               if (showBoundrys) {
                  g.drawRect(getTileXPos(i-1)+(int)this.xPos+TILE_SIZE,getTileYPos(j-1)+(int)this.yPos+TILE_SIZE,TILE_SIZE,TILE_SIZE);
               }
            }
         }
      }
   }

Offline pepijnve

Junior Devvie




Java games rock!


« Reply #4 - Posted 2006-12-13 08:44:38 »

Each Graphics2D object has a current transformation. By default this is an identity transformation, i.e. do nothing. This transformation is represented by an instance of AffineTransform. You can modify this transformation implictly using methods like Graphics2D#scale, Graphics2D#translate, Graphics2D#shear, ... or explicitly set a transformation using Graphics2D#setTransform.
The problem in your code is that you do
1  
2  
3  
AffineTransform transform = new AffineTransform();
transform.setTransform(identity);
transform.scale(this.zoomLevel, this.zoomLevel);

but after that you don't do anything with the transformation. Depending on what you're trying to exactly you'll have to pass this transformation to the Graphics2D object somewhere using one of the methods I mentioned above.
If you want some more info on the mathematics behind all this stuff Martin Baker's math site is a pretty good starting point. I would recommend you make sure you thoroughly understand this stuff. It will all make a lot more sense then...
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.

toopeicgaming1999 (54 views)
2014-11-26 15:22:04

toopeicgaming1999 (47 views)
2014-11-26 15:20:36

toopeicgaming1999 (8 views)
2014-11-26 15:20:08

SHC (24 views)
2014-11-25 12:00:59

SHC (24 views)
2014-11-25 11:53:45

Norakomi (26 views)
2014-11-25 11:26:43

Gibbo3771 (23 views)
2014-11-24 19:59:16

trollwarrior1 (36 views)
2014-11-22 12:13:56

xFryIx (75 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!