Data Management Questions

Started by
2 comments, last by haegarr 18 years, 5 months ago
Alright, so I've done it and learned... If you have three nights, three sections per night, and 14 columns per night, and 28 rows per night... you don't do this s[3][3][14][28] and then do this to translate each and every object (opengl)

				s[0][k][j].x=k*19.0f;	
				s[0][k][j].y=j*19.0f;					
				glTranslatef(s[0][k][j].x,s[0][k][j].y,0.0f);	
Because if you loop to change k/j 14x28 times, you're doing like 3 multiplication operations per iteration, which eventually turns into, alot.. 3x3x(multiplication to move thru matrix)x14x28... just to move through the matrix, its alot... but honestly, what else can you do to create 3x3x14x28 different objects? how else do you write code to do this? but still keep that many seperate objects...
----------------------------------------------------------Rating me down will only make me stronger.----------------------------------------------------------
Advertisement
Well assuming that all of the objects are different then there is no other way. How long does it take anyways?

ace
it does it fine, if it were only doing it once, but singe its a translatef loop, its rendering that 392 times per frame, now multiply that by the row operations required for the matrix, 392*3 or 4 or 5 PER FRAME, what else can i do?!
----------------------------------------------------------Rating me down will only make me stronger.----------------------------------------------------------
Could you describe the context a little bit more?

I see these multiplications that may play a role:

(1) The compiler will insert multiplication to access the particular fields of the multi-dimensional array. You may split the multi-dimensional array into several one-dimensional arrays of pointers into the next lower level arrays. This way, of course costs some RAM, but allow the CPU to access pointer fields only which _may_ be more efficiently implemented by. However, on modern CPU's also multiplications are a single cycle op, so it need not to perform faster.

(2) With a similar meaning of (1), it may be good to re-arrange the array, so that most accessed data are reached at prior array parts.

(3) The translation need not be implemented by multiplying the offset into the current modelview matrix. If the OpenGL implementation is somewhat smart, it can handle glTranslatef by addition.

This topic is closed to new replies.

Advertisement