Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (595) Games in Android Showcase (168) games submitted by our members Games in WIP (646) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 [Libgdx] Screen coordinates -> Isometric world coordinates  (Read 1328 times) 0 Members and 1 Guest are viewing this topic.
trollwarrior1
 « Posted 2014-05-25 09:53:38 »

I made this little thingy, which display kinda isometric floor. Here is how it looks without rotating the matrices.

As expected, finding on which tile mouse is currently at is really easy. Just divide mouse coordinates by tile size..

Here is the image of how it looks when I do my 'isometric' rotations (not sure if this is called isometric )

Here is the code for making this 'isometric' ground.
 1  2  3  4  5  6  7  8  9  10  11  12 `Matrix4 projectionMatrix = new Matrix4();      projectionMatrix.setToOrtho(0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), 0, -1, 1);            Matrix4 modelviewMatrix = new Matrix4();      modelviewMatrix.rotate(1, 0, 0, 35);      modelviewMatrix.rotate(0, 0, 1, 45);      projectionMatrix.tra();      modelviewMatrix.tra();            isoShader.setUniformMatrix(isoShader.getUniformLocation("u_projectionMatrix"), projectionMatrix, false);      isoShader.setUniformMatrix(isoShader.getUniformLocation("u_modelViewMatrix"), modelviewMatrix, false);`

How do I transform screen mouse coordinates to these world coordinates?

 1  2  3  4  5  6  7  8  9  10 `      float x = Gdx.input.getX();      float y = Gdx.input.getY();      float[] vec = { x, y, 0 };      Matrix4 transformationMatrix = projectionMatrix.cpy();      transformationMatrix.mul(modelviewMatrix);      Matrix4.mulVec(transformationMatrix.val, vec);      System.out.println(vec[0] + "  " + vec[1]);`

I tried this code, and in my head, it should work. But it gives not correct values.. As I point along the horizontal axis of the map, the Y is increasing..
trollwarrior1
 « Reply #1 - Posted 2014-05-31 19:19:15 »

Can somebody give me a medal? I managed to come up with a question that no one on this forum can answer
BurntPizza

« JGO Bitwise Duke »

Medals: 415
Exp: 6 years

 « Reply #2 - Posted 2014-05-31 19:22:43 »

Since the projection matrix takes screen coordinates to world coordinates, you need the inverse of the projection matrix to invert the process.

Spacebeans
 « Reply #3 - Posted 2014-05-31 19:24:21 »

I'm just a noobie to matrices, but this is the only information I found a long time ago on isometric mouse coordinates;

http://stackoverflow.com/questions/6915555/how-to-transform-mouse-location-in-isometric-tiling-map
UprightPath
 « Reply #4 - Posted 2014-05-31 19:36:08 »

Also, if you just need to know which of the tiles, and perhaps which of the objects, has been touched you can do something like give each tile a bounding box and check which the screen ray passes through first. You can also give your entities their own bounding boxes for this. There are many optimizations, such as if you know which tiles are being shown (Such as if you track which of your tiles are being culled during projection).

What you get? If you rotate your screen you use the same method of checking. If you make it a 2.5d game where there is a Z component for objects (Such as hills) you will get the 'higher' tiles if you click on them rather than the tiles behind them.

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16 `public Tile getTileTouched(float screenX, float screenY) {   Ray pickRay = camera.getPickRay(screenX, screenY);      Vector3 intersection = new Vector3();   Tile closestTile = null;   boolean distance = Float.MAX_NUMBER;   for(int i = 0; i < tiles.size; i++) {      if(Intersector.intersectRayBounds(pickRay, tile.get(i).boundingBox, intersection)) {         if(intersection.dst2(ray.origin) < distance) {            distance = intersection.dst2(ray.origin);            closestTile = tile.get(i);         }      }   }   return closestTile;}`

ctomni231

JGO Wizard

Medals: 99
Projects: 1
Exp: 7 years

Not a glitch. Just have a lil' pixelexia...

 « Reply #5 - Posted 2014-05-31 22:31:00 »

Edit: thanks matheus23, silly tablet auto correct...

matheus23

JGO Kernel

Medals: 122
Projects: 3

You think about my Avatar right now!

 « Reply #6 - Posted 2014-06-01 20:24:37 »

See my:
My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 deepthought (47 views) 2015-06-30 15:39:44 deepthought (50 views) 2015-06-30 15:39:09 deepthought (62 views) 2015-06-30 15:36:52 Za\'Anzabar (37 views) 2015-06-29 05:44:54 TritonDreyja (46 views) 2015-06-24 17:10:40 CopyableCougar4 (46 views) 2015-06-23 00:34:45 BurntPizza (52 views) 2015-06-21 20:36:46 cookiecompiler (93 views) 2015-06-11 15:42:53 cookiecompiler (55 views) 2015-06-11 15:41:14 NegativeZero (80 views) 2015-06-11 09:49:18
 princec 29x wessles 22x BurntPizza 19x CopyableCougar4 19x opiop65 17x nsigma 15x EgonOlsen 14x ags1 14x Riven 13x theagentd 12x KaiHH 12x SauronWatchesYou 11x KevinWorkman 11x Archive 11x sunburn 11x NegativeZero 10x
 How Do I Expand My Game?by bashfrog2015-06-14 11:34:43List of Learning Resources2015-05-31 05:37:30Intersection Methodsby Roquen2015-05-29 08:19:33List of Learning Resources2015-05-05 10:20:32How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14
 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