Skip to main content
GameDev.net gamedev.net
🔒 Locked

Array Question

Started by pluto_knight Aug 7, 2005 at 11:08 AM 1 replies 600+ views
Original Post
pluto_knight
pluto_knight
how to determine which row and column is 14 in in the m x n 2D-Array?
Fruny
Fruny
m rows, n columns

Language is likely to be row-major (unless it's Fortran)

row = index / n (rounded down)
column = index % n
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
JohnBolton
JohnBolton
It depends whether the matrix is "row-major" or "column-major". For example:

OpenGL --
     0  4  8  12     1  5  9  13     2  6 10  14     3  7 11  15 
DirectX --
     0  1  2  3     4  5  6  7     8  9 10 11    12 13 14 15 
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.