Problem with some really simple math

Started by
2 comments, last by ghotirein 16 years, 11 months ago
Hi folks, I have this really strange problem :S here is my code: switch(MenuItem) { case 1: engine2d->Render2DImageOn3D(122.0f, 142.0f, 186.0f, 206.0f, exitBig); //2 engine2d->Render2DImageOn3D(186.0f, 110.0f, 314.0f, 238.0f, gameBig); //3 engine2d->Render2DImageOn3D(304.0f, 142.0f, 368.0f, 206.0f, psBig); //4 break; case 11: // do the rotate :) inc++; if(inc == STEPSIZE) { inc = 0; MenuItem = 2; } else { engine2d->Render2DImageOn3D((float)(336 - ((32/STEPSIZE) * inc)), (float)174 - ((32/STEPSIZE) * inc), (float)(336 + ((32/STEPSIZE) * inc)), (float)174 + ((32/STEPSIZE) * inc), btBig); //4 engine2d->Render2DImageOn3D((float)(122 + ((32/STEPSIZE) * inc)), (float)142 + ((32/STEPSIZE) * inc), (float)(186 - ((32/STEPSIZE) * inc)), (float)206 - ((32/STEPSIZE) * inc), exitBig); //1 engine2d->Render2DImageOn3D((float)(186 - ((64/STEPSIZE) * inc)), (float)110 + ((32/STEPSIZE) * inc), (float)(314 - (((64/STEPSIZE) * inc) * 2)), (float)238 - ((32/STEPSIZE) * inc), gameBig); //2 engine2d->Render2DImageOn3D((float)(304 - ((128/STEPSIZE) * inc)), (float)142 - ((32/STEPSIZE) * inc), (float)(368 - ((54/STEPSIZE) * inc)), (float)206 + ((32/STEPSIZE) * inc), psBig); //3 } break; case 2: engine2d->Render2DImageOn3D((float)(122), (float)142, (float)(186), (float)206, gameBig); //2 engine2d->Render2DImageOn3D((float)(186), (float)110, (float)(314), (float)238, psBig); //3 engine2d->Render2DImageOn3D((float)(304), (float)142, (float)(368), (float)206, btBig); //4 break; I go in my menu from 1 to 11 to 2. however the positions from 1 to 11 go without problems, from 11 to 2 however the exact change between them is in positions huge!!, like it is not smooth as is with 1 to 11, it like jumps from the end position from 11 to the position of 2, where i thought it should be smooth and the same position :S any ideas ? (i hope i explained correctly)
Advertisement
What exactly is your menu supposed to do? Currently your design isn't very flexible, but if you let me know what you are trying to do then I might be able to suggest improvements.

In general it is a bad idea to hard code things like you are doing. A reason for this is what happens if you want to add a fourth menu option or perhaps add two or three more? Well then your code keeps growing exponentially.
Hi yes, well i do it hardcoded because i don't know what is going wrong :S my other code just does it with an array for the pictures so i need a lot less code but to see what is going wrong i wrote it hardcoded.

the problem is that i have a menu with n items. a item is a 128x128 squad with a texture. in the middle it is rendered as 128x128 but next to the middle on both sides there is rendered amenu item only that is scaled to 64x64, when i press right, the menuitem on the most right goes to the middle and changes from 64x64 to 128x128, the middle goes to the left and goes from 128x128 to 64x64, however it does not seem to go right.

I have solved the problem, it was a rounding error (well forgetting a casting to float)

thanks for the replies

This topic is closed to new replies.

Advertisement