Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (117)
games submitted by our members
Games in WIP (563)
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  
  Stupid Question... Screen/Mouse to Isometric tile?  (Read 2555 times)
0 Members and 1 Guest are viewing this topic.
Offline LordChandar

Junior Member


Projects: 1



« Posted 2012-11-16 03:59:55 »

Need a little help, if someone has the time :-)

I am drawing my isometric tiles in an actual diamond shape.  This is the method in use:

public Point isoPosToScreen(int tilex, int tiley)
    {
        int x =  (this.tiles_width/2)*(tilex-tiley);
        int y = (this.tiles_height/2)*(tilex+tiley);

        return new Point(x, y);
    }
   

I cannot seem to reverse it correctly however to change a screen X, screen Y back out to an isometric tile coordinate. 

If someone can help me reverse this process so I can get the tileX, tileY back out, I would be very grateful.

Cheers,

Graham
Offline Agro
« Reply #1 - Posted 2012-11-16 04:01:12 »

Here, I posted this thread a few days ago back. http://www.java-gaming.org/topics/isometric-screen-space/27698/view.html

Hope I helped. Smiley

Offline LordChandar

Junior Member


Projects: 1



« Reply #2 - Posted 2012-11-16 04:12:53 »

Unfortunately, your method is not quite working with the way I am rendering the tiles.

Sad panda.

Thanks for the link though.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Agro
« Reply #3 - Posted 2012-11-16 04:13:29 »

Oh, LordChandar, how are you rendering the tiles? I can easily modify the equation. Are you rendering it from the top of the tile?

Offline LordChandar

Junior Member


Projects: 1



« Reply #4 - Posted 2012-11-16 04:15:09 »

This is the method that is putting the tiles on the screen.

I cannot seem to reverse this.

public Point isoPosToScreen(int tilex, int tiley)
    {
        int x =  (this.tiles_width/2)*(tilex-tiley);
        int y = (this.tiles_height/2)*(tilex+tiley);

        return new Point(x, y);
    }
   

Offline LordChandar

Junior Member


Projects: 1



« Reply #5 - Posted 2012-11-16 04:16:34 »

My method basically starts the diamond in the center of the screen at the top.

The whole method is this:

public void WriteTile(Image i, int tilex, int tiley)
    {
        Point xy = getScreenIsoPos(tilex, tiley);
       
        xy.x+=(short)(this.vp_startX);
        xy.y+=(short)(this.vp_startY);
       
        xy.x -= (i.getWidth(null)-terrain_width);
        xy.y -= (i.getHeight(null)-terrain_height);
       
        vp.WriteImage(i, xy.x,xy.y);
        //vp.WriteDebug(i, xy.x,xy.y,tilex,tiley);
       
        if (tilex == 0)
        {
            if (tiley == 0)
            {
                System.out.printf("0:0 was written at %d:%d\n", (xy.x)+terrain_width,xy.y);
            }
        }
       
    }
Offline Agro
« Reply #6 - Posted 2012-11-16 04:25:56 »

Okay, I reversed your equation and got this:

Its just solving for linear equations.

1  
2  
tX = ((screenX) / (tileWidth / 2) + (screenY) / (tileHeight / 2)) / 2
tY = ((screenY) / (tileHeight / 2) - (screenX) / (tileWidth / 2)) / 2


I didn't simplify, sorry.

Offline LordChandar

Junior Member


Projects: 1



« Reply #7 - Posted 2012-11-16 04:35:22 »

I really appreciate the help.

Math is hard for me. :-)

I don't get how I have managed to write as much code as I have.
Offline LordChandar

Junior Member


Projects: 1



« Reply #8 - Posted 2012-11-16 04:40:19 »

My code now works.  I am in your debt.

Many thanks.
Offline ReBirth
« Reply #9 - Posted 2012-11-16 11:46:47 »

Remember to use [ code ] tag next time.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline LordChandar

Junior Member


Projects: 1



« Reply #10 - Posted 2012-11-16 13:47:11 »

One more question...

If I try to translate the mouse coordinates it rounds weirdly... Any hints, tips etc?  This function works great if the coordinates given are on the edge...

I'd like a function that translates the mouse/inner screen coordinates as well...

Thanks as always,
Graham
Offline gimbal

JGO Knight


Medals: 25



« Reply #11 - Posted 2012-11-16 15:38:15 »

One more question...

If I try to translate the mouse coordinates it rounds weirdly...

That is hardly specific, it is very similar to "it doesn't work". Such a problem description does not help anyone help you.

Why don't you give an example of what you get and what you expect?
Offline Agro
« Reply #12 - Posted 2012-11-16 22:13:29 »

I think you have to round down. In my case, I had to render a bit less than it actually was also.

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.

radar3301 (12 views)
2014-09-21 23:33:17

BurntPizza (30 views)
2014-09-21 02:42:18

BurntPizza (22 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (28 views)
2014-09-20 20:14:06

BurntPizza (33 views)
2014-09-19 03:14:18

Dwinin (48 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (103 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24:56
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!