Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Accessing The X And Y On A 1d Vector, Noobish I know...  (Read 736 times)

0 Members and 1 Guest are viewing this topic.
Accessing The X And Y On A 1d Vector, Noobish I ...
« on: February 11, 2007, 09:08:34 pm »
  • (y)(;>.<;)(y)
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3293
Okay, I get the complicated stuff but I'm stuck on the simple stuff XD

I have an std::vector containing the map information of a map larger than the screen can display.

What I wanna do is access what is contained at the Vector based on the given X and Y location of the full map.

Say the map is 100 * 100 in size, the vector being 10000, and I wanna access the part of the map which is 14 * 53. How would I do this?

the_Vector.at(14*53) clearly wouldn't work, so what would?

Help a person who always gets stuck when it's so simple, please!
Logged
Re: Accessing The X And Y On A 1d Vector, Noobis...
« Reply #1 on: February 11, 2007, 09:21:34 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
Just index it using this formula: x + (y * width). Personally I prefer arrays, but I guess its a matter of choice.
« Last Edit: February 11, 2007, 09:26:54 pm by Infinitus »
Logged
Re: Accessing The X And Y On A 1d Vector, Noobis...
« Reply #2 on: February 11, 2007, 09:31:51 pm »
  • (y)(;>.<;)(y)
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3293
I wanted to make the map size (theoretically) limitless, so I figured a Linked list, or an std::Vector, would be best.

Anyway, thanks. I knew it was something simple like that, I just couldn't remember it XD
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.059 seconds with 43 queries.