home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2003 March / VPR0303A.ISO / AIBO / MoNet / common / libMTN / MTNFile.cc < prev   
C/C++ Source or Header  |  2002-12-19  |  3KB  |  157 lines

  1. //
  2. // Copyright 2002 Sony Corporation 
  3. //
  4. // Permission to use, copy, modify, and redistribute this software for
  5. // non-commercial use is hereby granted.
  6. //
  7. // This software is provided "as is" without warranty of any kind,
  8. // either expressed or implied, including but not limited to the
  9. // implied warranties of fitness for a particular purpose.
  10. //
  11.  
  12. #include <string.h>
  13. #include "MTNFile.h"
  14.  
  15. word
  16. MTNFile::GetNumJoints()
  17. {
  18.     return (GetSection2())->numJoints;
  19. }
  20.  
  21. word
  22. MTNFile::GetNumKeyFrames()
  23. {
  24.     return section0.numKeyFrames;
  25. }
  26.  
  27. word
  28. MTNFile::GetFrameRate()
  29. {
  30.     return section0.frameRate;
  31. }
  32.  
  33. char*
  34. MTNFile::GetName()
  35. {
  36.     MTNString* motion = &(section1.motion);
  37.     return string_access(motion);
  38. }
  39.  
  40. char*
  41. MTNFile::GetAuthor()
  42. {
  43.     MTNString* tmp = &(section1.motion);
  44.     MTNString* author = (MTNString*)((byte*)tmp->name + tmp->length);
  45.     return string_access(author);
  46. }
  47.  
  48. char*
  49. MTNFile::GetRobotDesign()
  50. {
  51.     MTNString* tmp = &(section1.motion);
  52.     tmp = (MTNString*)((byte*)tmp->name + tmp->length);
  53.     MTNString* design = (MTNString*)((byte*)tmp->name + tmp->length);
  54.     return string_access(design);
  55. }
  56.  
  57. char*
  58. MTNFile::GetLocator(int index)
  59. {
  60.     MTNString* locator = (GetSection2())->locator;
  61.     for (int i = 0; i < index; i++)
  62.         locator = (MTNString*)((byte*)locator->name + locator->length);
  63.  
  64.     return string_access(locator);
  65. }
  66.  
  67. MTNString*
  68. MTNFile::GetLocator2(int index)
  69. {
  70.     MTNString* locator = (GetSection2())->locator;
  71.     for (int i = 0; i < index; i++)
  72.         locator = (MTNString*)((byte*)locator->name + locator->length);
  73.  
  74.     return locator;
  75. }
  76.  
  77. longword
  78. MTNFile::GetDataType()
  79. {
  80.     return (GetSection3())->dataType;
  81. }
  82.  
  83. int
  84. MTNFile::GetEachKeyFrameSize()
  85. {
  86.     int sizeofKeyFrame = (3 + GetNumJoints()) * sizeof(slongword);
  87.     return sizeofKeyFrame;
  88. }
  89.  
  90. int
  91. MTNFile::GetTotalKeyFrameSize()
  92. {
  93.     int numKeyFrames = GetNumKeyFrames();
  94.     int keyFrameSize = GetEachKeyFrameSize() * numKeyFrames
  95.         + sizeof(slongword) * (numKeyFrames-1); // numInterpolate
  96.     return keyFrameSize;
  97. }
  98.  
  99. MTNKeyFrame*
  100. MTNFile::GetKeyFrame(int index)
  101. {
  102.     byte* ptr = (GetSection3())->keyFrame;
  103.     ptr = ptr + (GetEachKeyFrameSize() + sizeof(slongword)) * index;
  104.     return (MTNKeyFrame*)ptr;
  105. }
  106.  
  107. int
  108. MTNFile::GetNumInterpolate(int index)
  109. {
  110.     if (index >= GetNumKeyFrames() - 1) return -1;
  111.  
  112.     byte* ptr = (GetSection3())->keyFrame;
  113.     int offset = GetEachKeyFrameSize() + sizeof(slongword);
  114.     ptr = ptr + (index + 1) * offset - 4;
  115.     return (int)*((int*)ptr);
  116. }
  117.  
  118. int
  119. MTNFile::GetNumInterpolate8ms(int index)
  120. {
  121.     int n = GetNumInterpolate(index);
  122.     return 2 * n + 1;
  123. }
  124.  
  125. slongword
  126. MTNFile::GetJointValue(int index, int jointIndex)
  127. {
  128.     MTNKeyFrame* kf = GetKeyFrame(index);
  129.     return kf->data[jointIndex];
  130. }
  131.  
  132. MTNSection2*
  133. MTNFile::GetSection2()
  134. {
  135.     byte* ptr = (byte*)§ion1;
  136.     int offset = section1.sectionSize;
  137.     return (MTNSection2*)(ptr + offset);
  138. }
  139.  
  140. MTNSection3*
  141. MTNFile::GetSection3()
  142. {
  143.     byte* ptr = (byte*)GetSection2();
  144.     int offset = (GetSection2())->sectionSize;
  145.     return (MTNSection3*)(ptr + offset);
  146. }
  147.  
  148. char*
  149. MTNFile::string_access(MTNString* mstr)
  150. {
  151.     static char buffer[256];    // magic number !! Improve later
  152.  
  153.     memcpy(buffer, mstr->name, mstr->length);
  154.     buffer[mstr->length] = 0;
  155.     return buffer;
  156. }
  157.