Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

CloudNine

Values changing in a std::vector?

This topic is 5422 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Yo, I''ve been working on my lwstodml converter, and I''ve come across a problem. I''m reading keyframe data from the file, and it reads ok (or so it seems), but when I cycle through all the joints and keyframes, some time values are wrong, even though I definitely wrote them to the same memory address! Here''s a snippet of code, which may help (and this time, I am opening my files correctly ) Reading from the file:

    for (int i=0; i<numChannels; i++)
    {
     //Skip Channel n and

     //{ Envelope

     fgets(buffer,255,in);
     fgets(buffer,255,in);
     
     //Get number of keys

     fgets(buffer,255,in);
     sscanf(buffer,"%d",&objectMotion.numKeys);
    
     if (objectMotion.keys==NULL)
      objectMotion.keys=new Keyframe[objectMotion.numKeys];
    
     //Read key data

     for (int j=0; j<objectMotion.numKeys; j++)
     {
      fgets(buffer,255,in);
    
      float* value=NULL;
      
      //Optimize!

      
      switch (i)
      {
       case 0: //X

        value=&objectMotion.keys[j].vPosition.x;
       break;
       
       case 1: //Y

        value=&objectMotion.keys[j].vPosition.y;
       break;
       
       case 2: //Z

        value=&objectMotion.keys[j].vPosition.z;
       break; 
        
       case 3:
        value=&objectMotion.keys[j].vRotation.x;
       break;
       
       case 4:
        value=&objectMotion.keys[j].vRotation.y;
       break;
       
       case 5:
        value=&objectMotion.keys[j].vRotation.z;
       break;
       
       default:
       //Bit hacky. Skips through the whole key since we don''t

       //want to know about scale data

        continue;
      }
    
      char* keyData=strstr(buffer,"Key");
      sscanf(keyData,"Key %f %f",value,&objectMotion.keys[j].time); 
      }
     fgets(buffer,255,in); //Ignore behaviours

     fgets(buffer,255,in); //Ignore }

    }
    fgets(buffer,255,in); //Ignore empty line after motion data

   }
The code to print the keyframe data is just a simple for loop which cycles through all keyframe and data. This is what the typical bone data from a lws file looks like:
AddBone
BoneName center_pivot
ShowBone 1 4
BoneActive 1
BoneRestPosition 0 0.121 -0.022
BoneRestDirection 0 0 0
BoneRestLength 0.027
BoneStrength 1
ScaleBoneStrength 1
BoneMotion
NumChannels 9
Channel 0
{ Envelope
  13
  Key 0 0 0 0 0 0 0 0 0
  Key 0 0.16666667 0 0 0 0 0 0 0
  Key 0 0.2 0 0 0 0 0 0 0
  Key 0 2.0333333 0 0 0 0 0 0 0
  Key 0 3.6666667 0 0 0 0 0 0 0
  Key 0 4.6333332 0 0 0 0 0 0 0
  Key 0 4.6666665 0 0 0 0 0 0 0
  Key 0 4.8666668 0 0 0 0 0 0 0
  Key 0 5.0666666 0 0 0 0 0 0 0
  Key 0 5.1866665 0 0 0 0 0 0 0
  Key 0 5.3466668 0 0 0 0 0 0 0
  Key 0 5.4266667 0 0 0 0 0 0 0
  Key 0 5.6666665 0 0 0 0 0 0 0
  Behaviors 1 1
}
Channel 1
{ Envelope
  13
  Key 0.121 0 0 0 0 0 0 0 0
  Key 0.121 0.16666667 0 0 0 0 0 0 0
  Key 0.121 0.2 0 0 0 0 0 0 0
  Key 0.121 2.0333333 0 0 0 0 0 0 0
  Key 0.121 3.6666667 0 0 0 0 0 0 0
  Key 0.121 4.6333332 0 0 0 0 0 0 0
  Key 0.121 4.6666665 0 0 0 0 0 0 0
  Key 0.121 4.8666668 0 0 0 0 0 0 0
  Key 0.121 5.0666666 0 0 0 0 0 0 0
  Key 0.121 5.1866665 0 0 0 0 0 0 0
  Key 0.121 5.3466668 0 0 0 0 0 0 0
  Key 0.121 5.4266667 0 0 0 0 0 0 0
  Key 0.121 5.6666665 0 0 0 0 0 0 0
  Behaviors 1 1
}
Channel 2
{ Envelope
  13
  Key -0.022 0 0 0 0 0 0 0 0
  Key -0.022 0.16666667 0 0 0 0 0 0 0
  Key -0.022 0.2 0 0 0 0 0 0 0
  Key -0.022 2.0333333 0 0 0 0 0 0 0
  Key -0.022 3.6666667 0 0 0 0 0 0 0
  Key -0.022 4.6333332 0 0 0 0 0 0 0
  Key -0.022 4.6666665 0 0 0 0 0 0 0
  Key -0.022 4.8666668 0 0 0 0 0 0 0
  Key -0.022 5.0666666 0 0 0 0 0 0 0
  Key -0.022 5.1866665 0 0 0 0 0 0 0
  Key -0.022 5.3466668 0 0 0 0 0 0 0
  Key -0.022 5.4266667 0 0 0 0 0 0 0
  Key -0.022 5.6666665 0 0 0 0 0 0 0
  Behaviors 1 1
}
Channel 3
{ Envelope
  13
  Key 0 0 0 0 0 0 0 0 0
  Key 0 0.16666667 0 0 0 0 0 0 0
  Key 0 0.2 0 0 0 0 0 0 0
  Key 0 2.0333333 0 0 0 0 0 0 0
  Key 0 3.6666667 0 0 0 0 0 0 0
  Key 0 4.6333332 0 0 0 0 0 0 0
  Key 0 4.6666665 0 0 0 0 0 0 0
  Key 0 4.8666668 0 0 0 0 0 0 0
  Key 0 5.0666666 0 0 0 0 0 0 0
  Key 0 5.1866665 0 0 0 0 0 0 0
  Key 0 5.3466668 0 0 0 0 0 0 0
  Key 0 5.4266667 0 0 0 0 0 0 0
  Key 0 5.6666665 0 0 0 0 0 0 0
  Behaviors 1 1
}
Channel 4
{ Envelope
  13
  Key 0 0 0 0 0 0 0 0 0
  Key 0 0.16666667 0 0 0 0 0 0 0
  Key 0 0.2 0 0 0 0 0 0 0
  Key 0 2.0333333 0 0 0 0 0 0 0
  Key 0 3.6666667 0 0 0 0 0 0 0
  Key 0 4.6333332 0 0 0 0 0 0 0
  Key 0 4.6666665 0 0 0 0 0 0 0
  Key 0 4.8666668 0 0 0 0 0 0 0
  Key 0 5.0666666 0 0 0 0 0 0 0
  Key 0 5.1866665 0 0 0 0 0 0 0
  Key 0 5.3466668 0 0 0 0 0 0 0
  Key 0 5.4266667 0 0 0 0 0 0 0
  Key 0 5.6666665 0 0 0 0 0 0 0
  Behaviors 1 1
}
Channel 5
{ Envelope
  13
  Key 0 0 0 0 0 0 0 0 0
  Key 0 0.16666667 0 0 0 0 0 0 0
  Key 0 0.2 0 0 0 0 0 0 0
  Key 0 2.0333333 0 0 0 0 0 0 0
  Key 0 3.6666667 0 0 0 0 0 0 0
  Key 0 4.6333332 0 0 0 0 0 0 0
  Key 0 4.6666665 0 0 0 0 0 0 0
  Key 0 4.8666668 0 0 0 0 0 0 0
  Key 0 5.0666666 0 0 0 0 0 0 0
  Key 0 5.1866665 0 0 0 0 0 0 0
  Key 0 5.3466668 0 0 0 0 0 0 0
  Key 0 5.4266667 0 0 0 0 0 0 0
  Key 0 5.6666665 0 0 0 0 0 0 0
  Behaviors 1 1
}
Channel 6
{ Envelope
  13
  Key 1 0 0 0 0 0 0 0 0
  Key 1 0.16666667 0 0 0 0 0 0 0
  Key 1 0.2 0 0 0 0 0 0 0
  Key 1 2.0333333 0 0 0 0 0 0 0
  Key 1 3.6666667 0 0 0 0 0 0 0
  Key 1 4.6333332 0 0 0 0 0 0 0
  Key 1 4.6666665 0 0 0 0 0 0 0
  Key 1 4.8666668 0 0 0 0 0 0 0
  Key 1 5.0666666 0 0 0 0 0 0 0
  Key 1 5.1866665 0 0 0 0 0 0 0
  Key 1 5.3466668 0 0 0 0 0 0 0
  Key 1 5.4266667 0 0 0 0 0 0 0
  Key 1 5.6666665 0 0 0 0 0 0 0
  Behaviors 1 1
}
Channel 7
{ Envelope
  13
  Key 1 0 0 0 0 0 0 0 0
  Key 1 0.16666667 0 0 0 0 0 0 0
  Key 1 0.2 0 0 0 0 0 0 0
  Key 1 2.0333333 0 0 0 0 0 0 0
  Key 1 3.6666667 0 0 0 0 0 0 0
  Key 1 4.6333332 0 0 0 0 0 0 0
  Key 1 4.6666665 0 0 0 0 0 0 0
  Key 1 4.8666668 0 0 0 0 0 0 0
  Key 1 5.0666666 0 0 0 0 0 0 0
  Key 1 5.1866665 0 0 0 0 0 0 0
  Key 1 5.3466668 0 0 0 0 0 0 0
  Key 1 5.4266667 0 0 0 0 0 0 0
  Key 1 5.6666665 0 0 0 0 0 0 0
  Behaviors 1 1
}
Channel 8
{ Envelope
  13
  Key 1 0 0 0 0 0 0 0 0
  Key 1 0.16666667 0 0 0 0 0 0 0
  Key 1 0.2 0 0 0 0 0 0 0
  Key 1 2.0333333 0 0 0 0 0 0 0
  Key 1 3.6666667 0 0 0 0 0 0 0
  Key 1 4.6333332 0 0 0 0 0 0 0
  Key 1 4.6666665 0 0 0 0 0 0 0
  Key 1 4.8666668 0 0 0 0 0 0 0
  Key 1 5.0666666 0 0 0 0 0 0 0
  Key 1 5.1866665 0 0 0 0 0 0 0
  Key 1 5.3466668 0 0 0 0 0 0 0
  Key 1 5.4266667 0 0 0 0 0 0 0
  Key 1 5.6666665 0 0 0 0 0 0 0
  Behaviors 1 1
}

PivotRotation 0 0 -180
ParentItem 10000000
GoalObject 5
GoalStrength 1
I push_back the joints vector whenever I come across an AddBone char string, and there doesn''t seem to be any irregularities. Here''s an example I got from my log data of what the problem is:
//After reading it from the file


0 0 0x890cf4 0
0 1 0x890d14 166
0 2 0x890d34 200
0 3 0x890d54 2033
0 4 0x890d74 3666
0 5 0x890d94 4633
0 6 0x890db4 4666
0 7 0x890dd4 4866
0 8 0x890df4 5066
0 9 0x890e14 5186
0 10 0x890e34 5346
0 11 0x890e54 5426
0 12 0x890e74 5666

//Printing it out later


0 0 0x890cf4 1
0 1 0x890d14 0
0 2 0x890d34 0
0 3 0x890d54 166
0 4 0x890d74 200
0 5 0x890d94 2033
0 6 0x890db4 3666
0 7 0x890dd4 4633
0 8 0x890df4 4666
0 9 0x890e14 4866
0 10 0x890e34 5066
0 11 0x890e54 5186
0 12 0x890e74 5346
Sorry for the really long post, but this issue has been bugging me for the past week or so, and I can''t see a reason why the values should change. CloudNine

Share this post


Link to post
Share on other sites
Advertisement
The fact is, I do nothing to my Joints vector after I print those values. Here's another example of how it goes wrong (the majority of them are correct):


//When reading

26 0 0x8925d4 0
26 1 0x8925f4 166
26 2 0x892614 200
26 3 0x892634 2033
26 4 0x892654 3666
26 5 0x892674 4633
26 6 0x892694 4666
26 7 0x8926b4 4866
26 8 0x8926d4 5066
26 9 0x8926f4 5186
26 10 0x892714 5346
26 11 0x892734 5426
26 12 0x892754 5666

27 0 0x892c44 0
27 1 0x892c64 166
27 2 0x892c84 200
27 3 0x892ca4 2033
27 4 0x892cc4 3666
27 5 0x892ce4 4633
27 6 0x892d04 4666
27 7 0x892d24 4866
27 8 0x892d44 5066
27 9 0x892d64 5186
27 10 0x892d84 5346
27 11 0x892da4 5426
27 12 0x892dc4 5666

//When printing out

26 0 0x8925d4 3222170426
26 1 0x8925f4 3222170426
26 2 0x892614 2013508224
26 3 0x892634 0
26 4 0x892654 0
26 5 0x892674 0
26 6 0x892694 0
26 7 0x8926b4 0
26 8 0x8926d4 0
26 9 0x8926f4 0
26 10 0x892714 0
26 11 0x892734 0
26 12 0x892754 0

27 0 0x892c44 5186
27 1 0x892c64 5346
27 2 0x892c84 5426
27 3 0x892ca4 5666
27 4 0x892cc4 0
27 5 0x892ce4 1
27 6 0x892d04 0
27 7 0x892d24 0
27 8 0x892d44 1
27 9 0x892d64 0
27 10 0x892d84 0
27 11 0x892da4 0
27 12 0x892dc4 2013508224


It just beats me. Also, the keyframe data (including the times, as shown above), new'ed when I read the BoneMotion data. How could the values change?

[edited by - CloudNine on December 13, 2003 4:39:47 AM]

Share this post


Link to post
Share on other sites
I''m confused... I don''t see you using a std::vector anywhere in your code.


"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post


Link to post
Share on other sites
I store my joints in a std::vector (which contains keyframe data which is dynamically allocated) and I push_back the vector when I come across a AddBone line.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!