• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
proanim

math problems

9 posts in this topic

I am trying to implement accurate selection tool for my level editor that would be able to use both isometric tiles and isometric hexagons. with the same sprite dimensions. I am now focusing on getting regular isometric tile to work properly.

 

Below is the color coded isometric tile that i will be using (it will be transparent with only lines visible, this one is for explanation only). I want my program to register specific tile if the cursor is only in green area.

 

tile_spr.jpg

 

The sprite has dimensions of 192x96. How do I calculate if the mouse is only in green area? Since from what I find everything is based on rectangle logic, because I check X, and Y coordinates of the mouse.

 

From here I have something like

 

if(mouse.x > 0 && mouse.y < 48)

  if(mouse.x < 96 && mouse.y < 48)

    select tile

 

but these coordinates also catch stuff from red triangle area in top left.

0

Share this post


Link to post
Share on other sites

Im not an expert on the subject, but i beleive what you want is a test to check if a point is inside a polygon. Here's some code that should work.

0

Share this post


Link to post
Share on other sites

I'm curious, how are you storing the tile information in memory?  Is this a 3D engine with the view set to this 2.5D viewing angle, or are you displaying everything in 2D?  I only ask because while it would be easy to take the four corners of each tile and perform a point-in-polygon test, if the tiles are not drawn in pixel space, but a world space mapped to the screen space, the mouse coordinates will need to be converted, in which case probably a ray cast or a picking algorithm would be easier.

 

But again, this could go from really easy to really hard, depending on where the engine goes and how the level is stored for use in the game.  

0

Share this post


Link to post
Share on other sites

Another common technique is to store a copy of that image above (simplified to save memory)

 

Then to test for a click on a tile you build a list of tiles it could be (usually only two) convert the coordinate into a relative one for the tile and pick from the stored image.

 

If the colour you pick up is green, you have the tile.

 

I think it would probably be easier to do a ray polygon check, but this is the way we used to do it when floating point was expensive.

 

have a look at http://content.gpwiki.org/OpenGL_Selection_Using_Unique_Color_IDs

Edited by Stainless
1

Share this post


Link to post
Share on other sites

This is all completely 2D stuff. What I did is, I created grid using one sprite and simply placing it on calculated X and Y coordinates to form a grid.

 

I am looking into point in polygon stuff, but I am not sure how to do this yet. This is what I am testing with

// triangle to test against
sf::ConvexShape hex;
hex.setPointCount(3);
hex.setPoint(0, sf::Vector2f(0, 0));
hex.setPoint(1, sf::Vector2f(96, 0));
hex.setPoint(2, sf::Vector2f(0, 48));


// check coordinates if inside the triangle
if(Mouse.x >= hex.getPoint(0).x && Mouse.y >= hex.getPoint(0).y)
  if(Mouse.x <= hex.getPoint(1).x && Mouse.y >= hex.getPoint(1).y)
    if(Mouse.x >= hex.getPoint(2).x && Mouse.y <= hex.getPoint(2).y)
    {
	diamond.setPosition(0, 0); // this is tile marker - it will highlight the tile mouse pointer hovers over
    }

Something is off since I am still in rectangle calculation and not triangle. Am I on the right track?

 

EDIT: I found this - http://www.geeksforgeeks.org/how-to-check-if-a-given-point-lies-inside-a-polygon/ - looks close to the first reply, and this does answer my question. Thanks for help everyone.

Edited by proanim
0

Share this post


Link to post
Share on other sites

If your map is diamond shaped and all tiles are flat and regular, the easiest way is to just convert from world to tile coordinates without fancy look ups or unnecessarily generic point-in-geometry tests.

 

const int tile_x = x/192 + y/96;
const int tile_y = y/96 - x/192;
 
x and y are world coordinates in relation to the rectangle around your map (so mouse coordinates need to be adjusted for scrolling and zooming). 
 
Or just base your math on the simple idea that your map is a rectangular grid rotated by 45° and 60°, transform your mouse coordinates accordingly and you should get the same result (essentially the above).
 
Getting a feeling for this mapping/transformation also helps if you want to combine 3D objects with a 2D iso map or visualize internal 3D info for debugging. For example, the internal data used in Jagged Alliance 2 for line of sight etc. (video)
Edited by Trienco
1

Share this post


Link to post
Share on other sites

const int tile_x = x/192 + y/96;
const int tile_y = y/96 - x/192;


Be careful with integer division. If x and y are integers, you may want to do the computations differently. For instance:
const int tile_x = round(x/192.0 + y/96.0);
const int tile_y = round(y/96.0 - x/192.0);
0

Share this post


Link to post
Share on other sites

Be careful with integer division. If x and y are integers, you may want to do the computations differently. For instance:

const int tile_x = round(x/192.0 + y/96.0);
const int tile_y = round(y/96.0 - x/192.0);

 

Good point, I neglected to mention that x and y were meant to be float (in my code the zooming and scrolling was already applied).

 

I also should have pointed out that the result is the x and y index of the selected tile (not any kind of transformed coordinate within the iso map). So (0,0) would be the topmost tile, with x going right and down and y going left and down.

 

Generally the only time you want to treat the map as anything but a rectangular grid of squares is to draw the map and for picking (and technically you're transforming the mouse position to the simple non-iso grid). Things can get less neat if you decide that picking should handle irregular tiles or overlapping sprites.

Edited by Trienco
0

Share this post


Link to post
Share on other sites

 

 

Or just base your math on the simple idea that your map is a rectangular grid rotated by 45° and 60°, transform your mouse coordinates accordingly and you should get the same result

 

Wouldn't this actually be more complicated? I would need to create regular greed and rotate it 45 degrees, and than additionally transform mouse coordinates. Seems interesting but I am not quite sure how I would handle data in this case. Would I save out all data as if it was square greed and transform it on run-time?

0

Share this post


Link to post
Share on other sites

 

Wouldn't this actually be more complicated? I would need to create regular greed and rotate it 45 degrees, and than additionally transform mouse coordinates. Seems interesting but I am not quite sure how I would handle data in this case. Would I save out all data as if it was square greed and transform it on run-time?

 

 

You need to separate the internal logic of your game and how you visualize it. When your characters move from tile to tile, you don't think "iso". When you determine line-of-sight, you don't think "iso". The iso perspective only exists on your screen and the only time you should give yourself an iso-head ache is for rendering and mouse input.

 

I'm not saying "draw a rectangular grid and transform it", I'm saying "think of the non-rotated top-down view as much as you can".

 

How are you storing your grid in memory?

1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0