本文整理汇总了C++中SubModel类的典型用法代码示例。如果您正苦于以下问题:C++ SubModel类的具体用法?C++ SubModel怎么用?C++ SubModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SubModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fillSubModelArary
void fillSubModelArary(const ModelContainer* pModelContainer, const TreeNode *root, Array<SubModel>& array, Vector3& pLo, Vector3& pHi) {
Vector3 lo = Vector3(inf(), inf(), inf());
Vector3 hi = Vector3(-inf(), -inf(), -inf());
for(int i=0; i< root->getNValues(); i++) {
SubModel sm = pModelContainer->getSubModel(root->getStartPosition() + i);
lo = lo.min(sm.getAABoxBounds().low());
hi = hi.max(sm.getAABoxBounds().high());
array.append(sm);
}
if(root->getChild((TreeNode *) &pModelContainer->getTreeNode(0), 0)) {
fillSubModelArary(pModelContainer, root->getChild((TreeNode *)&pModelContainer->getTreeNode(0), 0), array, lo, hi);
}
if(root->getChild((TreeNode *)&pModelContainer->getTreeNode(0), 1)) {
fillSubModelArary(pModelContainer, root->getChild((TreeNode *)&pModelContainer->getTreeNode(0), 1), array, lo, hi);
}
float dist1 = (hi -lo).magnitude();
AABox b;
root->getBounds(b);
float dist2 = (b.high() -b.low()).magnitude();
if(dist1 > dist2) {
// error
int xxx = 0;
}
}
示例2: getViewPos
//===================================================
Vector3 getViewPos(const ModelContainer* mc, unsigned int pModelNr = 0) {
if(mc->getNSubModel() < pModelNr) {
pModelNr = mc->getNSubModel();
}
const SubModel sm = mc->getSubModel(pModelNr);
return (sm.getAABoxBounds().low());
}
示例3: fillVertexAndIndexArrays
void ModelContainerView::fillVertexAndIndexArrays(const SubModel& pSm, Array<Vector3>& vArray, Array<int>& iArray) {
Array<TriangleBox> tbarray;
fillRenderArray(pSm, tbarray, &pSm.getTreeNode(0));
MeshBuilder builder;
int len = tbarray.size();
int count = 0;
for(int i=0;i<len;++i) {
Triangle t = Triangle(tbarray[i].vertex(0).getVector3() + pSm.getBasePosition(),
tbarray[i].vertex(1).getVector3() + pSm.getBasePosition(),
tbarray[i].vertex(2).getVector3() + pSm.getBasePosition());
vArray.append(t.vertex(0));
vArray.append(t.vertex(1));
vArray.append(t.vertex(2));
iArray.append(count+0);
iArray.append(count+1);
iArray.append(count+1);
iArray.append(count+2);
iArray.append(count+2);
iArray.append(count+0);
count+=3;
}
}
示例4: fillSubModelArary
void
fillSubModelArary (const ModelContainer* pModelContainer, const TreeNode *root, Array<SubModel>& array, Vector3& pLo, Vector3& pHi)
{
Vector3 lo = Vector3 (inf (), inf (), inf ());
Vector3 hi = Vector3 (-inf (), -inf (), -inf ());
//printf("[VMAP] %i Submodels\n", root->getNValues ());
for (int i = 0; i < root->getNValues (); i++)
{
SubModel sm = pModelContainer->getSubModel (root->getStartPosition () + i);
lo = lo.min (sm.getAABoxBounds ().low ());
hi = hi.max (sm.getAABoxBounds ().high ());
array.append (sm);
}
if (root->getChild ((TreeNode *) & pModelContainer->getTreeNode (0), 0))
{
fillSubModelArary (pModelContainer, root->getChild ((TreeNode *) & pModelContainer->getTreeNode (0), 0), array, lo, hi);
}
if (root->getChild ((TreeNode *) & pModelContainer->getTreeNode (0), 1))
{
fillSubModelArary (pModelContainer, root->getChild ((TreeNode *) & pModelContainer->getTreeNode (0), 1), array, lo, hi);
}
float dist1 = (hi - lo).magnitude ();
AABox b;
root->getBounds (b);
float dist2 = (b.high () - b.low ()).magnitude ();
if (dist1 > dist2)
{
// error
//printf("error in boundingbox size vs. hi-lo size.");
// this error seems to happen alot! maybe need to do something against it?
int xxx = 0;
}
}
示例5: getSubModel
RealTime ModelContainer::getIntersectionTime(const Ray& pRay, bool pExitAtFirst, float pMaxDist) const
{
#ifdef _DEBUG_VMAPS
for(unsigned int i=0; i<getNSubModel(); i++)
{
SubModel model = getSubModel(i);
bool insiteOk;
Vector3 mynormal;
Vector3 location;
bool hitval = MyCollisionDetection::collisionLocationForMovingPointFixedAABox(
pRay.origin, pRay.direction,
model.getAABoxBounds(),
location,insiteOk, mynormal);
if(hitval)
{
float len2 = (location - pRay.origin).squaredLength();
int a = 0; // just to be able to set a breakpoint
}
}
TreeNode tn = getTreeNode(0);
for(int i=0; i<tn.getNValues(); i++)
{
SubModel mysm = getSubModel(tn.getStartPosition() + i);
AABox testbox = mysm.getAABoxBounds();
gBoxArray.append(AABox(testbox.low(), testbox.high()));
}
#endif
double firstDistance = inf();
Ray relativeRay = Ray::fromOriginAndDirection(pRay.origin - getBasePosition(), pRay.direction);
const IT end = endRayIntersection();
IT obj = beginRayIntersection(pRay, pMaxDist);
for ( ;obj != end; ++obj) // (preincrement is *much* faster than postincrement!)
{
/*
Call your accurate intersection test here. It is guaranteed
that the ray hits the bounding box of obj. (*obj) has type T,
so you can call methods directly using the "->" operator.
*/
SubModel const *model = &(*obj);
RealTime t = model->getIntersectionTime(pRay, pExitAtFirst, pMaxDist);
if(t > 0 && t < inf())
{
obj.markBreakNode();
if(firstDistance > t && pMaxDist >= t)
{
firstDistance = t;
if(pExitAtFirst) { break; }
}
}
}
return(firstDistance);
}
示例6: fillRenderArray
void ModelContainerView::fillRenderArray(const SubModel& pSm, Array<TriangleBox> &pArray, const TreeNode* pTreeNode) {
for(int i=0;i<pTreeNode->getNValues(); i++) {
pArray.append(pSm.getTriangles()[i+pTreeNode->getStartPosition()]);
}
if(pTreeNode->getChild(pSm.getTreeNodes(), 0) != 0) {
fillRenderArray(pSm, pArray, pTreeNode->getChild(pSm.getTreeNodes(), 0));
}
if(pTreeNode->getChild(pSm.getTreeNodes(), 1) != 0) {
fillRenderArray(pSm, pArray, pTreeNode->getChild(pSm.getTreeNodes(), 1));
}
}
示例7: getNTriangles
bool SubModel::operator==(const SubModel& pSm2) const
{
bool result = false;
if(getNNodes() == pSm2.getNNodes() &&
getNTriangles() == pSm2.getNTriangles() &&
getBasePosition() == pSm2.getBasePosition() &&
getNodesPos() == pSm2.getNodesPos() &&
getTrianglesPos() == pSm2.getTrianglesPos())
{
result = true;
}
return result;
}
示例8: fillRenderArray
void
ModelContainerView::fillVertexArray (const SubModel& pSm, Array<Vector3>& vArray)
{
//printf("fillVertexArray for %i-%i\n",VMAP::hashCode(SubModel),5);
//printf("fillVertexArray for %i\n",VMAP::hashCode(pSm));
Array<TriangleBox> tbarray;
fillRenderArray (pSm, tbarray, &pSm.getTreeNode (0));
int len = tbarray.size ();
Vector3 toconvert[3];
for (int i = 0; i < len; ++i)
{
// TODO: Get correct Conversion of position values.
// The system between vmaps and MaNGOS differs in that:
/* from iinternal(xyz) -> MaNGOS(xyz)
float pos[3];
pos[0] = z;
pos[1] = x;
pos[2] = y;
double full = 64.0*533.33333333;
double mid = full/2.0;
pos[0] = -((mid+pos[0])-full); -> -mid -pos[0] + full -> mid - z
pos[1] = -((mid+pos[1])-full); -> -mid -pos[0] + full -> mid - x
*/
TriangleBox old = tbarray[i];
toconvert[0] = old.vertex(0).getVector3 () + pSm.getBasePosition ();
toconvert[1] = old.vertex(1).getVector3 () + pSm.getBasePosition ();
toconvert[2] = old.vertex(2).getVector3 () + pSm.getBasePosition ();
for (int j = 0; j < 3; j++) {
toconvert[j] = toconvert[j].zxy();
toconvert[j].x = MID - toconvert[j].x;
toconvert[j].y = MID - toconvert[j].y;
}
//TODO: playing around with correct range of triangles for detour
Triangle t = Triangle(toconvert[0],toconvert[1],toconvert[2]);
Triangle t1 = Triangle(toconvert[2],toconvert[1],toconvert[0]);
globalTriangleArray.append(t,t1);
/*
for (int j = 2; j>= 0; j--) {
Vector3 vertex = tbarray[i].vertex(j).getVector3() + pSm.getBasePosition();
// x = [expr {-(($::mid+$x)-$::full)}]
//printf("x[%.2f] y[%.2f] z[%.2f]",vertex.x,vertex.y,vertex.z);
// v 152.333 60.0304 -9561.67
vertex = Vector3(-((64*533.333333333/2 + vertex.z) - 64*533.333333333),
-((64*533.333333333/2 + vertex.x) - 64*533.333333333),
vertex.y);
vArray.append(vertex);
}
*/
}
}
示例9: countSubModelsAndNodesAndTriangles
void ModelContainer::countSubModelsAndNodesAndTriangles(AABSPTree<SubModel *>::Node& pNode, int& nSubModels, int& nNodes, int& nTriangles)
{
// For this node we will need a TreeNode as well as for the internal nodes
++nNodes;
nSubModels += pNode.valueArray.size();
for (int i=0; i<pNode.valueArray.size(); i++)
{
G3D::_AABSPTree::Handle<SubModel*>* h= pNode.valueArray[i];
SubModel *m = h->value;
// add the internal nodes as well
nNodes += m->getNNodes();
nTriangles += m->getNTriangles();
}
if(pNode.child[0] != 0)
{
countSubModelsAndNodesAndTriangles(*pNode.child[0], nSubModels, nNodes, nTriangles);
}
if(pNode.child[1] != 0)
{
countSubModelsAndNodesAndTriangles(*pNode.child[1], nSubModels, nNodes, nTriangles);
}
}
示例10: Vector3
bool MapTree::isOutDoors(const Vector3& pos)
{
Vector3 dir = Vector3(0,-1,0);
Ray ray = Ray::fromOriginAndDirection(pos, dir); // direction with length of 1
unsigned int flags;
AABSPTree<ModelContainer*>::RayIntersectionIterator MITR;
AABSPTree<ModelContainer*>::RayIntersectionIterator MITREND;
RayIntersectionIterator<TreeNode, SubModel> SMITR;
RayIntersectionIterator<TreeNode, SubModel> SMITREND;
ModelContainer * mc;
SubModel * sm;
MITR = iTree->beginRayIntersection( ray, MAX_CAN_FALL_DISTANCE );
MITREND = iTree->endRayIntersection();
for(; MITR != MITREND; ++MITR)
{
mc = ((ModelContainer*)*MITR);
Ray relativeRay = Ray::fromOriginAndDirection(ray.origin - mc->getBasePosition(), ray.direction);
SMITR = mc->beginRayIntersection( relativeRay, MAX_CAN_FALL_DISTANCE );
SMITREND = mc->endRayIntersection();
for( ; SMITR != SMITREND; ++SMITR )
{
sm = ((SubModel*)&(*SMITR));
#if 0
if( sm->getIndoorFlag() != 0 )
{
unsigned int i = sm->getIndoorFlag();
printf("=========================================================\n");
printf("Model indoor flags: %u\n", sm->getIndoorFlag());
unsigned int z, b;
for(z = 1, b = 1; b < 32;)
{
if(i & z)
printf(" Bit %u (0x%.8X or %u) is set!\n", b, z, z);
z <<= 1;
b+=1;
}
printf("=========================================================\n");
}
#else
flags = sm->getIndoorFlag();
if( flags != 0 )
{
/* From WoWdev:
Flag Meaning
0x1 Always set
0x4 Has vertex colors (MOCV chunk)
0x8 Outdoor
0x200 Has lights (MOLR chunk)
0x800 Has doodads (MODR chunk)
0x1000 Has water (MLIQ chunk)
0x2000 Indoor
0x40000 Show skybox
**********************
0x8000 seems to be set in the areas in citys (while it has the indoor flag, its not
an indoor area
*/
if( !(flags & 0x8) )
return false;
}
#endif
}
}
return true;
}
示例11: getBounds
void getBounds(const SubModel& pSm, G3D::AABox& pAABox)
{
ShortBox box = pSm.getReletiveBounds();
pAABox.set(box.getLo().getVector3()+pSm.getBasePosition(), box.getHi().getVector3()+pSm.getBasePosition());
}
示例12: hashCode
/**
Functions to use ModelContainer with a AABSPTree
*/
unsigned int hashCode(const SubModel& pSm)
{
return pSm.getNTriangles();
}
示例13: TreeNode
void ModelContainer::fillContainer(const AABSPTree<SubModel *>::Node& pNode, int &pSubModelPos, int &pTreeNodePos, int &pTrianglePos, Vector3& pLo, Vector3& pHi, Vector3& pFinalLo, Vector3& pFinalHi)
{
// TreeNode for the SubModel
TreeNode treeNode = TreeNode(pNode.valueArray.size(), pSubModelPos);
treeNode.setSplitAxis(pNode.splitAxis);
treeNode.setSplitLocation(pNode.splitLocation);
int currentTreeNodePos = pTreeNodePos++;
Vector3 lo = Vector3(inf(),inf(),inf());
Vector3 hi = Vector3(-inf(),-inf(),-inf());
for (int i=0; i<pNode.valueArray.size(); i++)
{
G3D::_AABSPTree::Handle<SubModel*>* h= pNode.valueArray[i];
SubModel *m = h->value;
memcpy(&getTreeNodes()[pTreeNodePos], &m->getTreeNode(0), sizeof(TreeNode) * m->getNNodes());
memcpy(&getTriangles()[pTrianglePos], &m->getTriangle(0), sizeof(TriangleBox) * m->getNTriangles());
SubModel newModel = SubModel(m->getNTriangles(), getTriangles(), pTrianglePos, m->getNNodes(), getTreeNodes(), pTreeNodePos);
newModel.setReletiveBounds(m->getReletiveBounds().getLo(), m->getReletiveBounds().getHi());
newModel.setBasePosition(m->getBasePosition());
iSubModel[pSubModelPos++] = newModel;
pTreeNodePos += m->getNNodes();
pTrianglePos += m->getNTriangles();
AABox box = m->getAABoxBounds();
lo = lo.min(box.low());
hi = hi.max(box.high());
pFinalLo = pFinalLo.min(lo);
pFinalHi = pFinalHi.max(hi);
}
/*
if(pNode.valueArray.size() == 0) {
int xxx = 0; // just for the breakpoint
}
*/
// get absolute bounds
if(pNode.child[0] != 0)
{
treeNode.setChildPos(0, pTreeNodePos);
fillContainer(*pNode.child[0], pSubModelPos, pTreeNodePos, pTrianglePos, lo, hi,pFinalLo,pFinalHi);
}
if(pNode.child[1] != 0)
{
treeNode.setChildPos(1, pTreeNodePos);
fillContainer(*pNode.child[1], pSubModelPos, pTreeNodePos, pTrianglePos, lo, hi,pFinalLo,pFinalHi);
}
pLo = pLo.min(lo);
pHi = pHi.max(hi);
treeNode.setBounds(lo,hi);
setTreeNode(treeNode, currentTreeNodePos);
}
示例14: 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); }
//.........这里部分代码省略.........
示例15: 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)
//.........这里部分代码省略.........