本文整理汇总了C++中ModelPosition类的典型用法代码示例。如果您正苦于以下问题:C++ ModelPosition类的具体用法?C++ ModelPosition怎么用?C++ ModelPosition使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ModelPosition类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getModelPosition
bool TileAssembler::fillModelIntoTree(AABSPTree<SubModel *> *pMainTree, const Vector3& pBasePos, std::string& pPos, std::string& pModelFilename)
{
ModelPosition modelPosition;
getModelPosition(pPos, modelPosition);
// all should be relative to object base position
modelPosition.moveToBasePos(pBasePos);
modelPosition.init();
return readRawFile(pModelFilename, modelPosition, pMainTree);
}
示例2: modelFilename
bool TileAssembler::calculateTransformedBound(ModelSpawn &spawn)
{
std::string modelFilename(iSrcDir);
modelFilename.push_back('/');
modelFilename.append(spawn.name);
ModelPosition modelPosition;
modelPosition.iDir = spawn.iRot;
modelPosition.iScale = spawn.iScale;
modelPosition.init();
WorldModel_Raw raw_model;
if (!raw_model.Read(modelFilename.c_str()))
return false;
G3D::uint32 groups = raw_model.groupsArray.size();
#ifdef _DEBUG
if (groups != 1)
printf("Warning: '%s' does not seem to be a M2 model!\n", modelFilename.c_str());
#endif
AABox modelBound;
bool boundEmpty=true;
for (G3D::uint32 g=0; g<groups; ++g) // should be only one for M2 files...
{
std::vector<Vector3>& vertices = raw_model.groupsArray[g].vertexArray;
if (vertices.empty())
{
std::cout << "error: model '" << spawn.name << "' has no geometry!" << std::endl;
continue;
}
G3D::uint32 nvectors = vertices.size();
for (G3D::uint32 i = 0; i < nvectors; ++i)
{
Vector3 v = modelPosition.transform(vertices[i]);
if (boundEmpty)
modelBound = AABox(v, v), boundEmpty=false;
else
modelBound.merge(v);
}
}
spawn.iBound = modelBound + spawn.iPos;
spawn.flags |= MOD_HAS_BOUND;
return true;
}
示例3: getModelPosition
bool TileAssembler::fillModelIntoTree(AABSPTree<SubModel *> *pMainTree, const Vector3& pBasePos, std::string& pPos, std::string& pModelFilename)
{
bool result = false;
ModelPosition modelPosition;
getModelPosition(pPos, modelPosition);
// all should be relative to object base position
modelPosition.moveToBasePos(pBasePos);
modelPosition.init();
if(readRawFile(pModelFilename, modelPosition, pMainTree))
{
result = true;
}
else
printf("readRawFile(%s) failed.\n", pModelFilename.c_str());
return result;
}
示例4: calculateTransformedBound
bool TileAssembler::calculateTransformedBound(ModelSpawn& spawn, const char *RAW_VMAP_MAGIC)
{
std::string modelFilename = iSrcDir + "/" + spawn.name;
ModelPosition modelPosition;
modelPosition.iDir = spawn.iRot;
modelPosition.iScale = spawn.iScale;
modelPosition.init();
WorldModel_Raw raw_model;
if (!raw_model.Read(modelFilename.c_str(), RAW_VMAP_MAGIC))
{ return false; }
uint32 groups = raw_model.groupsArray.size();
if (groups != 1)
{ printf("Warning: '%s' does not seem to be a M2 model!\n", modelFilename.c_str()); }
AABox modelBound;
bool boundEmpty = true;
for (uint32 g = 0; g < groups; ++g) // should be only one for M2 files...
{
std::vector<Vector3>& vertices = raw_model.groupsArray[g].vertexArray;
if (vertices.empty())
{
std::cout << "error: model '" << spawn.name << "' has no geometry!" << std::endl;
continue;
}
uint32 nvectors = vertices.size();
for (uint32 i = 0; i < nvectors; ++i)
{
Vector3 v = modelPosition.transform(vertices[i]);
if (boundEmpty)
{ modelBound = AABox(v, v), boundEmpty = false; }
else
{ modelBound.merge(v); }
}
}
spawn.iBound = modelBound + spawn.iPos;
spawn.flags |= MOD_HAS_BOUND;
return true;
}
示例5: calculateTransformedBound
bool TileAssembler::calculateTransformedBound(ModelSpawn &spawn)
{
std::string modelFilename = iSrcDir + "/" + spawn.name;
ModelPosition modelPosition;
modelPosition.iDir = spawn.iRot;
modelPosition.iScale = spawn.iScale;
modelPosition.init();
FILE *rf = fopen(modelFilename.c_str(), "rb");
if (!rf)
{
printf("ERROR: Can't open model file: %s\n", modelFilename.c_str());
return false;
}
AABox modelBound;
bool boundEmpty=true;
char ident[8];
int readOperation = 1;
// temporary use defines to simplify read/check code (close file and return at fail)
#define READ_OR_RETURN(V,S) if(fread((V), (S), 1, rf) != 1) { \
fclose(rf); printf("readfail, op = %i\n", readOperation); return(false); }readOperation++;
#define CMP_OR_RETURN(V,S) if(strcmp((V),(S)) != 0) { \
fclose(rf); printf("cmpfail, %s!=%s\n", V, S);return(false); }
READ_OR_RETURN(&ident, 8);
CMP_OR_RETURN(ident, "VMAP003");
// we have to read one int. This is needed during the export and we have to skip it here
uint32 tempNVectors;
READ_OR_RETURN(&tempNVectors, sizeof(tempNVectors));
uint32 groups, wmoRootId;
char blockId[5];
blockId[4] = 0;
int blocksize;
float *vectorarray = 0;
READ_OR_RETURN(&groups, sizeof(uint32));
READ_OR_RETURN(&wmoRootId, sizeof(uint32));
if (groups != 1) printf("Warning: '%s' does not seem to be a M2 model!\n", modelFilename.c_str());
for (uint32 g=0; g<groups; ++g) // should be only one for M2 files...
{
fseek(rf, 3*sizeof(uint32) + 6*sizeof(float), SEEK_CUR);
READ_OR_RETURN(&blockId, 4);
CMP_OR_RETURN(blockId, "GRP ");
READ_OR_RETURN(&blocksize, sizeof(int));
fseek(rf, blocksize, SEEK_CUR);
// ---- indexes
READ_OR_RETURN(&blockId, 4);
CMP_OR_RETURN(blockId, "INDX");
READ_OR_RETURN(&blocksize, sizeof(int));
fseek(rf, blocksize, SEEK_CUR);
// ---- vectors
READ_OR_RETURN(&blockId, 4);
CMP_OR_RETURN(blockId, "VERT");
READ_OR_RETURN(&blocksize, sizeof(int));
uint32 nvectors;
READ_OR_RETURN(&nvectors, sizeof(uint32));
if (nvectors >0)
{
vectorarray = new float[nvectors*3];
READ_OR_RETURN(vectorarray, nvectors*sizeof(float)*3);
}
else
{
std::cout << "error: model '" << spawn.name << "' has no geometry!" << std::endl;
return false;
}
for (uint32 i=0, indexNo=0; indexNo<nvectors; indexNo++, i+=3)
{
Vector3 v = Vector3(vectorarray[i+0], vectorarray[i+1], vectorarray[i+2]);
v = modelPosition.transform(v);
if (boundEmpty)
modelBound = AABox(v, v), boundEmpty=false;
else
modelBound.merge(v);
}
delete[] vectorarray;
// drop of temporary use defines
#undef READ_OR_RETURN
#undef CMP_OR_RETURN
}
spawn.iBound = modelBound + spawn.iPos;
spawn.flags |= MOD_HAS_BOUND;
fclose(rf);
return true;
}
示例6: fopen
//=================================================================
bool TileAssembler::readRawFile(std::string& pModelFilename, ModelPosition& pModelPosition, AABSPTree<SubModel *> *pMainTree)
{
bool result = false;
std::string filename = iSrcDir;
if(filename.length() >0)
filename.append("/");
filename.append(pModelFilename);
FILE *rf = fopen(filename.c_str(), "rb");
if(!rf)
{
// depending on the extractor version, the data could be located in the root dir
std::string baseModelFilename = pModelFilename.substr((pModelFilename.find_first_of("/")+1),pModelFilename.length());
filename = iSrcDir;
if(filename.length() >0)
filename.append("/");
filename.append(baseModelFilename);
rf = fopen(filename.c_str(), "rb");
}
char ident[8];
int trianglecount =0;
#ifdef _ASSEMBLER_DEBUG
int startgroup = 0; //2;
int endgroup = INT_MAX; //2;
fprintf(::g_df,"-------------------------------------------------\n");
fprintf(::g_df,"%s\n", pModelFilename.c_str());
fprintf(::g_df,"-------------------------------------------------\n");
#else
int startgroup = 0;
int endgroup = INT_MAX;
#endif
if(rf)
{
if(fread(&ident, 8, 1, rf) != 1) { fclose(rf); return(false); }
if(strcmp(ident, "VMAP001") == 0)
{
// OK, do nothing
}
else if(strcmp(ident, "VMAP002") == 0)
{
// we have to read one int. This is needed during the export and we have to skip it here
int tempNVectors;
if(fread(&tempNVectors, sizeof(int), 1, rf) != 1) { fclose(rf); return(false); }
}
else
{
// wrong version
fclose(rf);
return(false);
}
uint32 groups;
char blockId[5];
blockId[4] = 0;
int blocksize;
if(fread(&groups, sizeof(uint32), 1, rf) != 1) { fclose(rf); return(false); }
for(int g=0;g<(int)groups;g++)
{
// group MUST NOT have more then 65536 indexes !! Array will have a problem with that !! (strange ...)
Array<int> tempIndexArray;
Array<Vector3> tempVertexArray;
AABSPTree<Triangle> *gtree = new AABSPTree<Triangle>();
uint32 flags;
uint32 isindoor = 0;
uint32 branches;
if(fread(&flags, sizeof(uint32), 1, rf) != 1)
{
fclose(rf);
return(false);
}
if(flags & 1) {
if(fread(&isindoor, sizeof(uint32), 1, rf) != 1)
{
fclose(rf);
return(false);
}
}
if(fread(&blockId, 4, 1, rf) != 1) { fclose(rf); return(false); }
if(strcmp(blockId, "GRP ") != 0)
{
if(fread(&blockId, 4, 1, rf) != 1) { fclose(rf); return(false); }
}
if(strcmp(blockId, "GRP ") != 0) { printf("BUG: (%s)\n",blockId); fclose(rf); return(false); }
if(fread(&blocksize, sizeof(int), 1, rf) != 1) { fclose(rf); return(false); }
if(fread(&branches, sizeof(uint32), 1, rf) != 1) { fclose(rf); return(false); }
for(int b=0;b<(int)branches; b++)
{
uint32 indexes;
// indexes for each branch (not used jet)
if(fread(&indexes, sizeof(uint32), 1, rf) != 1) { fclose(rf); return(false); }
//.........这里部分代码省略.........
示例7: fopen
//=================================================================
bool TileAssembler::readRawFile(std::string& pModelFilename, ModelPosition& pModelPosition, AABSPTree<SubModel *> *pMainTree)
{
std::string filename = iSrcDir;
if (filename.length() >0)
filename.append("/");
filename.append(pModelFilename);
FILE *rf = fopen(filename.c_str(), "rb");
if (!rf)
{
// depending on the extractor version, the data could be located in the root dir
std::string baseModelFilename = pModelFilename.substr((pModelFilename.find_first_of("/")+1),pModelFilename.length());
filename = iSrcDir;
if (filename.length() >0)
filename.append("/");
filename.append(baseModelFilename);
rf = fopen(filename.c_str(), "rb");
}
if (!rf)
{
printf("ERROR: Can't open model file in form: %s",pModelFilename.c_str());
printf("... or form: %s",filename.c_str() );
return false;
}
char ident[8];
int trianglecount =0;
#ifdef _ASSEMBLER_DEBUG
int startgroup = 0; //2;
int endgroup = INT_MAX; //2;
fprintf(::g_df,"-------------------------------------------------\n");
fprintf(::g_df,"%s\n", pModelFilename.c_str());
fprintf(::g_df,"-------------------------------------------------\n");
#else
int startgroup = 0;
int endgroup = INT_MAX;
#endif
// temporary use defines to simplify read/check code (close file and return at fail)
#define READ_OR_RETURN(V,S) if (fread((V), (S), 1, rf) != 1) { \
fclose(rf); return(false); }
#define CMP_OR_RETURN(V,S) if (strcmp((V),(S)) != 0) { \
fclose(rf); return(false); }
READ_OR_RETURN(&ident, 8);
if (strcmp(ident, "VMAP001") == 0)
{
// OK, do nothing
}
else if (strcmp(ident, "VMAP002") == 0)
{
// we have to read one int. This is needed during the export and we have to skip it here
int tempNVectors;
READ_OR_RETURN(&tempNVectors, sizeof(int));
}
else
{
// wrong version
fclose(rf);
return(false);
}
G3D::uint32 groups;
char blockId[5];
blockId[4] = 0;
int blocksize;
READ_OR_RETURN(&groups, sizeof(G3D::uint32));
for (int g=0;g<(int)groups;g++)
{
// group MUST NOT have more then 65536 indexes !! Array will have a problem with that !! (strange ...)
Array<int> tempIndexArray;
Array<Vector3> tempVertexArray;
AABSPTree<Triangle> *gtree = new AABSPTree<Triangle>();
// add free gtree at fail
#undef READ_OR_RETURN
#undef CMP_OR_RETURN
#define READ_OR_RETURN(V,S) if (fread((V), (S), 1, rf) != 1) { \
fclose(rf); delete gtree; return(false); }
#define CMP_OR_RETURN(V,S) if (strcmp((V),(S)) != 0) { \
fclose(rf); delete gtree; return(false); }
G3D::uint32 flags;
READ_OR_RETURN(&flags, sizeof(G3D::uint32));
G3D::uint32 branches;
READ_OR_RETURN(&blockId, 4);
CMP_OR_RETURN(blockId, "GRP ");
READ_OR_RETURN(&blocksize, sizeof(int));
READ_OR_RETURN(&branches, sizeof(G3D::uint32));
for (int b=0;b<(int)branches; b++)
{
G3D::uint32 indexes;
// indexes for each branch (not used jet)
//.........这里部分代码省略.........