Anonymous avatar Anonymous committed 67d53dc

NOW skeletons work - previous version looked correct, but matrix setup was bad.

Comments (0)

Files changed (4)

Terrain/CFigure.cpp

 
   for (i = 0; i < BONE_COUNT; i++) 
     _bone_index[i] = BONE_INVALID;
-  PushBone (BONE_ROOT, BONE_ROOT, glVector (0.0f, 0.0f, 0.0f));
+  //PushBone (BONE_ROOT, BONE_ROOT, glVector (0.0f, 0.0f, 0.0f));
   _unknown_count = 0;
 
 }
   unsigned    i;
   unsigned    parent;
 
-  glLineWidth (17.0f);
+  glLineWidth (5.0f);
   glColor3f (1,1,1);
   glPushMatrix ();
   glTranslatef (_position.x, _position.y, _position.z); 
   unsigned          frame_depth;
   GLmatrix          matrix;
   vector<GLmatrix>  matrix_stack;
+  BoneId            queued_bone;
+  BoneId            queued_parent;
+
 
   buffer = FileLoad (filename, &size);
   if (!buffer)
     if ((!skel_done) && (find = strstr (token, "FRAME "))) {
       GLvector pusher = glVector (0.0f, 0.0f, 0.0f);
       frame_depth = 0;
-      _bone[_bone_index[BONE_ROOT]]._matrix.Identity ();
+      //_bone[_bone_index[BONE_ROOT]]._matrix.Identity ();
+      matrix.Identity ();
+      matrix_stack.push_back (matrix);
+      _bone.clear ();
       while (!skel_done) {
         if (find = strstr (token, "}")) {
           frame_depth--;
           hierarchy.pop_back ();
+          matrix_stack.pop_back ();
         }
         if (find = strstr (token, "FRAMETRANSFORMMATRIX ")) {
-          //We don't care about the rotational data
           matrix.Identity ();
           token = strtok (NULL, NEWLINE);
           clean_chars (token, ";,");
           token = strtok (NULL, NEWLINE);
           clean_chars (token, ";,");
           sscanf (token, "%f %f %f", &matrix.elements[3][0], &matrix.elements[3][1], &matrix.elements[3][2], &matrix.elements[3][3]);
-          sscanf (token, "%f %f %f", &pos.x, &pos.y, &pos.z);
-          //only add this to our model if it's actually a known bone
-          bone = hierarchy.back ();
-          if (bone != BONE_INVALID) {
-            //Find the last valid bone in the chain.
-            vector<BoneId>::reverse_iterator rit;
-            parent_id = BONE_ROOT;
-            for (rit = hierarchy.rbegin(); rit < hierarchy.rend(); ++rit) {
-              if (*rit != BONE_INVALID && *rit != bone) {
-                  parent_id = *rit;
-                  break;
-              }
-            }
-            
-            pos = glVector (0.0f, 0.0f, 0.0f);
-            //pos.x = matrix.elements[3][0];
-            //pos.y = matrix.elements[3][1];
-            //pos.z = matrix.elements[3][2];
-            
-            //pos = glMatrixTransformPoint (matrix, pos);
-            /*
-            for (rit = hierarchy.rbegin(); rit < hierarchy.rend(); ++rit) {
-              if (*rit != BONE_INVALID && *rit != bone) {
-                pos = glMatrixTransformPoint (_bone[_bone_index[*rit]]._matrix, pos);
-                break;
-              }
-            }
-            */
-            if (bone != BONE_ROOT) {
-              matrix = glMatrixMultiply (_bone[_bone_index[parent_id]]._matrix, matrix);
-              //pos = pos - _bone[_bone_index[parent_id]]._position;
-              pos = glMatrixTransformPoint (_bone[_bone_index[parent_id]]._matrix, pos);
-              //pos = glMatrixTransformPoint (matrix, _bone[_bone_index[parent_id]]._position);
-              //pos = glMatrixTransformPoint (matrix, pos) + _bone[_bone_index[parent_id]]._position;
-              //pos += _bone[_bone_index[parent_id]]._position;
-            }
 
-            //matrix = glMatrixMultiply (matrix,  _bone[_bone_index[parent_id]]._matrix);
-            
-            pos += pusher;
-            //pusher += glVector (0.0f, 0.0f, 0.01f);
-            //pos += _bone[_bone_index[parent_id]]._position ;
-            PushBone (bone, parent_id, pos);
-            _bone[_bone_index[bone]]._matrix = matrix;
-          }
+          //matrix = glMatrixMultiply (matrix,  matrix_stack.back ());
+          matrix_stack.push_back (matrix);
           //Now plow through until we find the closing brace
+
+
+          matrix.Identity ();
+          for (i = 0; i < matrix_stack.size (); i++)           
+            matrix = glMatrixMultiply (matrix,  matrix_stack[i]);
+          pos = glMatrixTransformPoint (matrix, glVector (0.0f, 0.0f, 0.0f));
+          pos.x = -pos.x;
+          PushBone (queued_bone, queued_parent, pos);
+
+
           while (!(find = strstr (token, "}"))) 
             token = strtok (NULL, NEWLINE);
         }
         if (find = strstr (token, "FRAME ")) {
           frame_depth++;
           bone = IdentifyBone (find + 6);
-          //bone = CAnim::BoneFromString (find + 6);
           hierarchy.push_back (bone);
+          //pos = glMatrixTransformPoint (matrix_stack.back (), glVector (0.0f, 0.0f, 0.0f));
+          
+          pos = glVector (0.0f, 0.0f, 0.0f);
+          for (i = 0; i < matrix_stack.size (); i++)           
+            pos = glMatrixTransformPoint (matrix_stack[i], pos);
+
+          matrix.Identity ();
+          for (i = 0; i < matrix_stack.size (); i++)           
+            matrix = glMatrixMultiply (matrix,  matrix_stack[i]);
+          pos = glMatrixTransformPoint (matrix, glVector (0.0f, 0.0f, 0.0f));
+
+          //Find the last valid bone in the chain.
+          vector<BoneId>::reverse_iterator rit;
+          parent_id = BONE_ROOT;
+          for (rit = hierarchy.rbegin(); rit < hierarchy.rend(); ++rit) {
+            if (*rit != BONE_INVALID && *rit != bone) {
+                parent_id = *rit;
+                break;
+            }
+          }
+          queued_bone = bone;
+          queued_parent = parent_id;
+          //PushBone (bone, parent_id, pos);
         }
         token = strtok (NULL, NEWLINE);
         if (find = strstr (token, "MESH ")) 
     if (!token)
       done = true;
   }
+  _skin_static.CalculateNormalsSeamless ();
   free (buffer);
   return true;
 

Terrain/CFigure.h

   GLmatrix          _matrix;
 };
 
+struct Skeleton
+{
+  vector<Bone>      _bone;
+  unsigned          _unknown_count;
+};
+
 class CFigure
 {
-  vector<Bone>      _bone;
   GLvector          _position;
   unsigned          _bone_index[BONE_COUNT];
   unsigned          _unknown_count;
   void              RotateHierarchy (unsigned id, GLvector offset, GLmatrix m);
   void              RotatePoints (unsigned id, GLvector offset, GLmatrix m);
 public:
+  vector<Bone>      _bone;
   
 
   CFigure ();

Terrain/Figure.cpp

 
 static BoneList  bl[] =
 {
+  0.0f, 0.0f, 0.0f,     BONE_ROOT,      BONE_ROOT,
   0.0f, 0.0f, 1.1f,     BONE_PELVIS,    BONE_ROOT,
   0.1f, 0.0f, 1.0f,     BONE_RHIP,      BONE_PELVIS,
   0.1f, 0.0f, 0.5f,     BONE_RKNEE,     BONE_RHIP,
   anim_stand.LoadBvh ("Anims//stand.bvh");
 
   fig2.LoadX ("models//male.x");
-  /*
+  
   {
 
     FILE*             file;
     fprintf (file, "\n");
     fclose (file);
   }
-  */
+  
 
 
 
 
   if (moveit)
     nn += 0.01f;
-  /*
-  fig.RotateBone (BONE_SPINE1, glVector (0.0f, 0.0f, sin (nn * 3) * 25.0f));
-  fig.RotateBone (BONE_RSHOULDER, glVector (0.0f, abs (sin (nn * 1)) * -80.0f, 0.0f));
-  fig.RotateBone (BONE_RELBOW, glVector (abs (cos (nn * 1)) * 45.0f, 0.0f, 0.0f));
-  fig.RotateBone (BONE_LSHOULDER, glVector (0.0f, abs (sin (nn * 3)) * 80.0f, 0.0f));
-  fig.RotateBone (BONE_LELBOW, glVector (abs (cos (nn * 2)) * 90.0f, 0.0f, 0.0f));
-  fig.RotateBone (BONE_RHIP, glVector (sin (nn) * 25.0f, 0.0f,  0.0f));
-  fig.RotateBone (BONE_RKNEE, glVector (-abs (cos (nn * 2) * 45.0f), 0.0f,  0.0f));
-  */
+  
+  //fig2.RotateBone (BONE_SPINE1, glVector (0.0f, 0.0f, sin (nn * 3) * 25.0f));
+  //fig2.RotateBone (BONE_RSHOULDER, glVector (0.0f, abs (sin (nn * 1)) * -80.0f, 0.0f));
+  //fig2.RotateBone (BONE_RELBOW, glVector (abs (cos (nn * 1)) * 45.0f, 0.0f, 0.0f));
+  //fig2.RotateBone (BONE_LSHOULDER, glVector (0.0f, abs (sin (nn * 3)) * 80.0f, 0.0f));
+  //fig2.RotateBone (BONE_LELBOW, glVector (abs (cos (nn * 2)) * 90.0f, 0.0f, 0.0f));
+  //fig2.RotateBone (BONE_RHIP, glVector (sin (nn) * 25.0f, 0.0f,  0.0f));
+  fig2.RotateBone (BONE_RKNEE, glVector (-abs (cos (nn * 2) * 45.0f), 0.0f,  0.0f));
+  
   
   /*
   for (unsigned i = 0; i < anim._frame[frame].joint.size (); i++) {
       fig.RotateBone (anim._frame[frame].joint[i].id, anim._frame[frame].joint[i].rotation);
   }
   */
-  if (stand)
+  if (stand) {
     fig.Animate (&anim_stand, nn);
-  else
+    fig2.Animate (&anim_stand, nn);
+  } else {
     fig.Animate (&anim, nn);
+    fig2.Animate (&anim, nn);
+  }
   frame++;
   frame %= anim._frame.size ();
   fig.Update ();

Terrain/Terrain.vcxproj

     <ClCompile Include="Env.cpp" />
     <ClCompile Include="Figure.cpp" />
     <ClCompile Include="File.cpp" />
+    <ClCompile Include="FileX.cpp" />
     <ClCompile Include="glBbox.cpp" />
     <ClCompile Include="glCoord.cpp" />
     <ClCompile Include="glFont.cpp" />
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.