Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (541)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
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  
  Isometric issues  (Read 505 times)
0 Members and 1 Guest are viewing this topic.
Offline wookoouk

Senior Newbie





« Posted 2013-10-18 22:31:59 »

I have a little project, I am rendering paths over an isometric map using:


1  
2  
3  
4  
5  
6  
7  
8  
      xOffset = GameMap.tileWidth * GameMap.unitScale;
      yOffset = GameMap.tileHeight * GameMap.unitScale;

public static Vector2 orthToIso(float x, float y) {
      float drawingPosX = x * xOffset / 2 + y * xOffset / 2;
      float drawingPosY = y * yOffset / 2 - x * yOffset / 2;
      return new Vector2(drawingPosX, drawingPosY);
   }


This works great, the issue I have is being able to have a path go to the tile the mouse/touch is over

the mouse/touch position is going to be translated to iso via the above as part of the render loop. What I need help with is offseting the above code so that when the orth->iso kicks in, it lines up...

I hope this makes sense Smiley
Offline wookoouk

Senior Newbie





« Reply #1 - Posted 2013-10-20 18:37:38 »

Anybody?
Offline CodeHead

JGO Knight


Medals: 41


From rags to riches...to rags.


« Reply #2 - Posted 2013-10-20 19:07:33 »

the mouse/touch position is going to be translated to iso via the above as part of the render loop. What I need help with is offseting the above code so that when the orth->iso kicks in, it lines up...

The mouse position is already in Isometric space, you need to translate that back to orthographic space to determine the click point. I have 3 functions that I use in my engine for this.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
public static Point isoToCoarseWorld(Point isoPoint, Point viewportOrigin, Dimension isoDims) {
   int xOrg = viewportOrigin.x + (isoDims.width >> 1);
   int yOrg = viewportOrigin.y;

   int i = (int)Math.floor(((isoPoint.y - yOrg)/(double)isoDims.height
           + (isoPoint.x - xOrg)/(double)isoDims.width) * 32);
   int j = (int)Math.floor(((isoPoint.y - yOrg)/(double)isoDims.height
           - (isoPoint.x - xOrg)/(double)isoDims.width) * 32);

   return new Point(i, j);
}

public static Point coarseWorldToTile(Point coarseWorldPoint, Dimension worldTileDims) {
   return new Point((int)Math.floor(coarseWorldPoint.x / worldTileDims.width)
           ,(int)Math.floor(coarseWorldPoint.y / worldTileDims.height));
}

public static Point coarseWorldToTileFine(Point coarseWorldPoint, Dimension worldTileDims) {
   return new Point((coarseWorldPoint.x % worldTileDims.width)
           ,(coarseWorldPoint.y % worldTileDims.height));
}


Where the worldTileDims are 32x32 and the isoDims are 64x32. isoToCoarseWorld takes an isometric point and converts it into raw orthographic space. The other two functions are used to determine which tile that raw point is in, and the offset within the tile respectively.

When working out any path finding or logic, you should be working in orthographic space. Isometric space is only used for viewing. I think this is what you were asking about. If not could you clarify a bit?

Arthur: Are all men from the future loud-mouthed braggarts?
Ash: Nope. Just me baby...Just me.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline wookoouk

Senior Newbie





« Reply #3 - Posted 2013-10-20 19:23:32 »

Thank you for your fantastic reply. I have spent hours trying to figure this out. (Math is not my strong point). Thanks again.
Offline CodeHead

JGO Knight


Medals: 41


From rags to riches...to rags.


« Reply #4 - Posted 2013-10-20 19:39:52 »

No problem. Math isn't my strong point either. I had to dig around on the Internet for what seems like forever before finally finding out what those functions should look like. They seem to work reliably. Smiley

Arthur: Are all men from the future loud-mouthed braggarts?
Ash: Nope. Just me baby...Just me.
Offline wookoouk

Senior Newbie





« Reply #5 - Posted 2013-10-20 19:54:34 »

I have to rewrite it a little (due to float positions and Vector2 over Point). Could you please clarify what: isoPoint, viewportOrigin and isoDims are please. Thank you
Offline CodeHead

JGO Knight


Medals: 41


From rags to riches...to rags.


« Reply #6 - Posted 2013-10-20 20:02:07 »

Sure thing. isoDims are the dimensions of my isometric tiles (64x32px in my case). isoPoint is any point in isometric space; basically use the point that you get through a Java mouse event. viewportOrigin is an orthographic based measurement of how far the map is offset in the X and Y directions. This is used when scrolling the map. Please let me know if I can be of further assistance. Smiley

Arthur: Are all men from the future loud-mouthed braggarts?
Ash: Nope. Just me baby...Just me.
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.

Mr.CodeIt (10 views)
2014-12-27 04:03:04

TheDudeFromCI (13 views)
2014-12-27 02:14:49

Mr.CodeIt (25 views)
2014-12-23 03:34:11

rwatson462 (56 views)
2014-12-15 09:26:44

Mr.CodeIt (46 views)
2014-12-14 19:50:38

BurntPizza (92 views)
2014-12-09 22:41:13

BurntPizza (113 views)
2014-12-08 04:46:31

JscottyBieshaar (85 views)
2014-12-05 12:39:02

SHC (95 views)
2014-12-03 16:27:13

CopyableCougar4 (102 views)
2014-11-29 21:32:03
Resources for WIP games
by kpars
2014-12-18 10:26:14

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
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!