MTNFile.cc

Go to the documentation of this file.
00001 //
00002 // Copyright 2002 Sony Corporation 
00003 //
00004 // Permission to use, copy, modify, and redistribute this software for
00005 // non-commercial use is hereby granted.
00006 //
00007 // This software is provided "as is" without warranty of any kind,
00008 // either expressed or implied, including but not limited to the
00009 // implied warranties of fitness for a particular purpose.
00010 //
00011 
00012 #include <string.h>
00013 #include "MTNFile.h"
00014 
00015 word
00016 MTNFile::GetNumJoints()
00017 {
00018     return (GetSection2())->numJoints;
00019 }
00020 
00021 word
00022 MTNFile::GetNumKeyFrames()
00023 {
00024     return section0.numKeyFrames;
00025 }
00026 
00027 word
00028 MTNFile::GetFrameRate()
00029 {
00030     return section0.frameRate;
00031 }
00032 
00033 char*
00034 MTNFile::GetName()
00035 {
00036     MTNString* motion = &(section1.motion);
00037     return string_access(motion);
00038 }
00039 
00040 char*
00041 MTNFile::GetAuthor()
00042 {
00043     MTNString* tmp = &(section1.motion);
00044     MTNString* author = (MTNString*)((byte*)tmp->name + tmp->length);
00045     return string_access(author);
00046 }
00047 
00048 char*
00049 MTNFile::GetRobotDesign()
00050 {
00051     MTNString* tmp = &(section1.motion);
00052     tmp = (MTNString*)((byte*)tmp->name + tmp->length);
00053     MTNString* design = (MTNString*)((byte*)tmp->name + tmp->length);
00054     return string_access(design);
00055 }
00056 
00057 char*
00058 MTNFile::GetLocator(int index)
00059 {
00060     MTNString* locator = (GetSection2())->locator;
00061     for (int i = 0; i < index; i++)
00062         locator = (MTNString*)((byte*)locator->name + locator->length);
00063 
00064     return string_access(locator);
00065 }
00066 
00067 MTNString*
00068 MTNFile::GetLocator2(int index)
00069 {
00070     MTNString* locator = (GetSection2())->locator;
00071     for (int i = 0; i < index; i++)
00072         locator = (MTNString*)((byte*)locator->name + locator->length);
00073 
00074     return locator;
00075 }
00076 
00077 longword
00078 MTNFile::GetDataType()
00079 {
00080     return (GetSection3())->dataType;
00081 }
00082 
00083 int
00084 MTNFile::GetEachKeyFrameSize()
00085 {
00086     int sizeofKeyFrame = (3 + GetNumJoints()) * sizeof(slongword);
00087     return sizeofKeyFrame;
00088 }
00089 
00090 int
00091 MTNFile::GetTotalKeyFrameSize()
00092 {
00093     int numKeyFrames = GetNumKeyFrames();
00094     int keyFrameSize = GetEachKeyFrameSize() * numKeyFrames
00095         + sizeof(slongword) * (numKeyFrames-1); // numInterpolate
00096     return keyFrameSize;
00097 }
00098 
00099 MTNKeyFrame*
00100 MTNFile::GetKeyFrame(int index)
00101 {
00102     byte* ptr = (GetSection3())->keyFrame;
00103     ptr = ptr + (GetEachKeyFrameSize() + sizeof(slongword)) * index;
00104     return (MTNKeyFrame*)ptr;
00105 }
00106 
00107 int
00108 MTNFile::GetNumInterpolate(int index)
00109 {
00110     if (index >= GetNumKeyFrames() - 1) return -1;
00111 
00112     byte* ptr = (GetSection3())->keyFrame;
00113     int offset = GetEachKeyFrameSize() + sizeof(slongword);
00114     ptr = ptr + (index + 1) * offset - 4;
00115     return (int)*((int*)ptr);
00116 }
00117 
00118 int
00119 MTNFile::GetNumInterpolate8ms(int index)
00120 {
00121     int n = GetNumInterpolate(index);
00122     return 2 * n + 1;
00123 }
00124 
00125 slongword
00126 MTNFile::GetJointValue(int index, int jointIndex)
00127 {
00128     MTNKeyFrame* kf = GetKeyFrame(index);
00129     return kf->data[jointIndex];
00130 }
00131 
00132 MTNSection2*
00133 MTNFile::GetSection2()
00134 {
00135     byte* ptr = (byte*)&section1;
00136     int offset = section1.sectionSize;
00137     return (MTNSection2*)(ptr + offset);
00138 }
00139 
00140 MTNSection3*
00141 MTNFile::GetSection3()
00142 {
00143     byte* ptr = (byte*)GetSection2();
00144     int offset = (GetSection2())->sectionSize;
00145     return (MTNSection3*)(ptr + offset);
00146 }
00147 
00148 char*
00149 MTNFile::string_access(MTNString* mstr)
00150 {
00151     static char buffer[256];    // magic number !! Improve later
00152 
00153     memcpy(buffer, mstr->name, mstr->length);
00154     buffer[mstr->length] = 0;
00155     return buffer;
00156 }

Generated on Sun Dec 2 23:04:29 2007 for openSDK by  doxygen 1.3.9.1