Jump to content
  • Advertisement
Sign in to follow this  
Wan

Storing a 3-dimensional array on a flat image

This topic is 5040 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I could have posted this in the isometric forum, but since it is a theoretical problem rather then a graphical problem, I've posted it here. image 1: image 2: I've have a set of tiles that can be described by the following (see images):
  • Each tile has three corners.
  • Each of these corners has a certain color (in the image I've used 5 different colors, but that's totally arbitrary), a color can appear on a tile more than once (3 red corners for example).
What I need is one large image that contains every possible tile in an ordered way. By 'ordered' I mean that I can retrieve the position of a tile by using an algortihm. However, there are two more conditions that have to be met:
  • I can't rotate a tile (and that way decreasing the number of tiles).
  • Tiles cannot overlap: a bounding square of a tile should not include a part of another tile (see second image).
I've been thinking about this for quit some time now, but I don't seem to get to a solution. Since it contains three corners it can be easily stored in 3d array, so in code I wouldn't have a problem. But in an image... The only reasonable approach I came up with, is to create 5 ( == number of colors) seperate images and create a normal 2d-array of tiles in each image. This however would lead to duplicate tiles in different images. Since all this is a critical part of a game (I'll announce it when finished [smile]), I really have to nail this problem. I welcome any suggestion.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by WanMaster
The only reasonable approach I came up with, is to create 5 ( == number of colors) seperate images and create a normal 2d-array of tiles in each image. This however would lead to duplicate tiles in different images.
I don't follow how this would lead to duplicate tiles. I think this should work perfectly fine.

And you could actually just combine each of these individual images into one big image, or just have a super wide, one-tile-high image, and still manage any number of dimensions. Let's say that the width of one tile is 32 pixels. And lets say that you have 5 colors. Then, as you pointed out, you have three dimensions, based on the colors of the three corners. If the colors are numbered 0 through 4, and any tile can be represented by a 3-tuple (a, b, c), then the x-location of any given tile within the image could be (a * 5 * 5 + b * 5 + c) * 32. The y-location would always be 0 (of the top-left of the tile, of course). Make sense?

Share this post


Link to post
Share on other sites
Quote:
Original post by Agony
(a * 5 * 5 + b * 5 + c) * 32.

But ofcourse! How stupid am I?
I guess I was focusing too much on putting them into a 2d-grid. The method I used did lead to duplicates. I won't go into that, since it would take another long explanation and hey, the problem is solved.
And I can still adjust this formula a little to allow me to use multiple rows. It would make the image a little easier to manage.

Thank you very much!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!