Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (407)
games submitted by our members
Games in WIP (293)
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 1107 times)
0 Members and 1 Guest are viewing this topic.
Offline LordChandar

Junior Member


Projects: 1



« Posted 2012-11-16 04: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 05: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 05: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 05: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 05: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 05: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 05: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 05: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 05:40:19 »

My code now works.  I am in your debt.

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

Remember to use [ code ] tag next time.

Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline LordChandar

Junior Member


Projects: 1



« Reply #10 - Posted 2012-11-16 14: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
Online gimbal

JGO Coder


Medals: 15



« Reply #11 - Posted 2012-11-16 16: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 23: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.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (94 views)
2013-05-17 21:29:12

alaslipknot (102 views)
2013-05-16 21:24:48

gouessej (132 views)
2013-05-16 00:53:38

gouessej (127 views)
2013-05-16 00:17:58

theagentd (138 views)
2013-05-15 15:01:13

theagentd (126 views)
2013-05-15 15:00:54

StreetDoggy (168 views)
2013-05-14 15:56:26

kutucuk (189 views)
2013-05-12 17:10:36

kutucuk (192 views)
2013-05-12 15:36:09

UnluckyDevil (199 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.162 seconds with 21 queries.