Page 1 of 1

A 'for' Problem

Posted: Fri Jul 31, 2009 8:25 am
by zapakitul
I loaded an object [square-like model] and copied it 9 times into the memory using GDK. What I'm trying to do is position that object, something like this:
Image
But I can't do it right.
Here's what I tried so far:
Attempt1:

Code: Select all

	for(WorldObjects = 1; WorldObjects <= 9; WorldObjects++)
	{
		for(SizeX = 1; SizeX <= 3; SizeX++)
		{
			for(SizeZ = 1; SizeZ <= 3; SizeZ++)
			{
		 dbPositionObject(WorldObjects,dbObjectPositionX(WorldObjects)+SizeX,dbObjectPositionY(WorldObjects),			dbObjectPositionZ(WorldObjects)+SizeZ);
			}
		}
	}
Attempts2:

Code: Select all

float offset=0.35;
int i;
int j;
..........................................................................
for(WorldObjects = 1; WorldObjects <= 9; WorldObjects++)
	{	
		for(i=0;i<3;i++)
		{
			for(j=0;j<3;j++){
			dbPositionObject(WorldObjects,0+offset*i,0,0+offset*j);
			}
		}
	}
Any ideas what am I doing wrong?

Re: A 'for' Problem

Posted: Fri Jul 31, 2009 9:11 am
by avansc
mmm... i didnt read over your code. but i'll give you a generic listing..

i'll assume that surface[9] holds the images/surfaces.
i'll assume that they are 50 units wide.
i'll assume that the print function is screen->displaySurface(arg image, arg x, arg y);

Code: Select all

for(int y = 0;y < 3;y++)
{
    for(int x = 0;x < 3;x++)
    {
        screen->displaySurface(surface[y*3+x], x*50, y*50);
    } 
}
i think that will work but i kinds just went off of memory.