1

Solution:

strtod instead of atof solved it. Thanks!

TODO: make this an answer for acceptance


I'm loading a value from an XML file that tells how much the texture should be rotated.

It looks like this:

string rotv = ItemElem->FirstChild("Rotation")->FirstChild()->Value();
rotation = -(atof(rotv.c_str()))*57.2957795;

In my level editor the textures are rotated properly; pi equals 180 degrees and so on. But in the engine; they are not, it seems like the decimals are ignored. So for example, a texture that should be rotated 3.14 radians is only rotated 3 radians and so on. I've tried many different approaches to make sure the decimals are included, but I can't get it to work.

I rotate the textures like this:

glBindTexture(GL_TEXTURE_2D, texture->GetImage());
glMatrixMode(GL_TEXTURE);

glLoadIdentity();
glTranslatef(0.5, 0.5, 0);
glRotatef(rotation, 0, 0, 1);
glTranslatef(-0.5, -0.5, 0);

glMatrixMode(GL_PROJECTION);

The value in the xml file uses a dot instead of coma and I convert it like this, I also store the decimals separately just for debugging.

 for (int x = 0; x < rotv.size(); x++)
     {
          if (afterComa)
          {
                  int temp = (int) rotv[x] - '0';
              if (temp <10 && temp >= 0)
              {
                  decimals[decimalPos] = temp;
                  decimalPos++;
              }
              else
              {
                  break;
              }

          }
         if (rotv[x] == '.')
         {
             rotv[x] = ',';
             afterComa = true;
          }
      }

float decimalValue = decimals[0]/10 + decimals[1]/100 + decimals[2]/1000 + decimals[3]/10000 + decimals[4]/100000 + decimals[5]/1000000;

The decimals are stored properly and I add them to the rotation value but it still doesn't help.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
Orujimaru
  • 835
  • 2
  • 13
  • 18

2 Answers2

1

Break it out, make sure what you think is happening is really happening:

string rot_str = ItemElem->FirstChild("Rotation")->FirstChild()->Value();
float rot_rad = atof( rotv.c_str() );
float rot_deg = rot_rad * 57.295779;
rotation = rot_deg;

Use your debugger to step through each operation and verify the values are as expected.

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • Hi, thanks for replying. I did that however my debugger won't show me the value, I don't know why. – Orujimaru Dec 29 '11 at 08:39
  • @Orujimaru please check if the project is running in debug-mode to see the values. – Lucian Dec 29 '11 at 09:53
  • Yeah, it's not running in debug mode, I'm moving the solution between many computers and the one I'm currently on doesn't support my debug settings for some reason. – Orujimaru Dec 29 '11 at 11:03
0

You can use strtod instead of atof. It has better localization so you don't have to change the "." to ","

Lucian
  • 3,407
  • 2
  • 21
  • 18