本文整理汇总了C++中Box3f::add方法的典型用法代码示例。如果您正苦于以下问题:C++ Box3f::add方法的具体用法?C++ Box3f::add怎么用?C++ Box3f::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Box3f
的用法示例。
在下文中一共展示了Box3f::add方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: saveObj
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void Batch::saveObj(std::string filename,std::vector<SmartPointer<Batch> > batches)
{
FILE* file=fopen(FileSystem::FullPath(filename).c_str(),"wt");
XgeReleaseAssert(file);
Box3f box;
for (int I=0;I<(int)batches.size();I++)
{
SmartPointer<Batch> batch=batches[I];
box.add(batch->getBox());
}
Mat4f ToUnitBox= Mat4f::scale(1.0f/box.size().x,1.0f/box.size().y,1.0f/box.size().z) * Mat4f::translate(-box.p1.x,-box.p1.y,-box.p1.z);
int Cont=1;
for (int I=0;I<(int)batches.size();I++)
{
SmartPointer<Batch> batch=batches[I];
//TODO: all other cases
XgeReleaseAssert(batch->primitive==Batch::TRIANGLES);
Mat4f matrix=batch->matrix;
matrix=ToUnitBox * matrix;
Mat4f inv=matrix.invert();
/*XgeReleaseAssert(batch->texture1);
XgeReleaseAssert(batch->texture1->width==batch->texture1->height);
int texturedim=batch->texture1->width;*/
int nv=batch->vertices->size()/3;
int nt=nv/3;
XgeReleaseAssert(batch->vertices);
XgeReleaseAssert(batch->normals);
//XgeReleaseAssert(batch->texture1coords);
float* vertex = batch->vertices->mem();
float* normal = batch->normals ->mem();
//float* lightcoord = batch->texture1coords->mem();
for (int i=0;i<nt;i++,vertex+=9,normal+=9)
{
Vec3f v0(vertex[0],vertex[1],vertex[2]) ; v0=matrix * v0;
Vec3f v1(vertex[3],vertex[4],vertex[5]) ; v1=matrix * v1;
Vec3f v2(vertex[6],vertex[7],vertex[8]) ; v2=matrix * v2;
Vec4f _n0(normal[0],normal[1],normal[2],0.0); _n0=_n0 * inv; Vec3f n0=Vec3f(_n0.x,_n0.y,_n0.z).normalize();
Vec4f _n1(normal[3],normal[4],normal[5],0.0); _n1=_n1 * inv; Vec3f n1=Vec3f(_n1.x,_n1.y,_n1.z).normalize();
Vec4f _n2(normal[6],normal[7],normal[8],0.0); _n2=_n2 * inv; Vec3f n2=Vec3f(_n2.x,_n2.y,_n2.z).normalize();
/*float s0=lightcoord[i*6+0],t0=lightcoord[i*6+1];
float s1=lightcoord[i*6+2],t1=lightcoord[i*6+3];
float s2=lightcoord[i*6+4],t2=lightcoord[i*6+5];*/
// force the regeneration of float values (seems perfect for opengl/ renderman scan line conversion!)
/*s0=(0.5f/(float)texturedim)+(((int)(s0*(float)texturedim))/(float)texturedim);t0=(0.5f/(float)texturedim)+(((int)(t0*(float)texturedim))/(float)texturedim);
s1=(0.5f/(float)texturedim)+(((int)(s1*(float)texturedim))/(float)texturedim);t1=(0.5f/(float)texturedim)+(((int)(t1*(float)texturedim))/(float)texturedim);
s2=(0.5f/(float)texturedim)+(((int)(s2*(float)texturedim))/(float)texturedim);t2=(0.5f/(float)texturedim)+(((int)(t2*(float)texturedim))/(float)texturedim);
*/
fprintf(file,Utils::Format("v %e %e %e\n",v0.x,v0.y,v0.z).c_str());
fprintf(file,Utils::Format("v %e %e %e\n",v1.x,v1.y,v1.z).c_str());
fprintf(file,Utils::Format("v %e %e %e\n",v2.x,v2.y,v2.z).c_str());
//fprintf(file,Utils::Format("vt %e %e\n",s0,t0).c_str());
//fprintf(file,Utils::Format("vt %e %e\n",s1,t1).c_str());
//fprintf(file,Utils::Format("vt %e %e\n",s2,t2).c_str());
fprintf(file,Utils::Format("vn %e %e %e\n",n0.x,n0.y,n0.z).c_str());
fprintf(file,Utils::Format("vn %e %e %e\n",n1.x,n1.y,n1.z).c_str());
fprintf(file,Utils::Format("vn %e %e %e\n",n2.x,n2.y,n2.z).c_str());
fprintf(file,Utils::Format("f %d//%d %d//%d %d//%d\n",
Cont+0,Cont+0,
Cont+1,Cont+1,
Cont+2,Cont+2).c_str());
/*fprintf(file,Utils::Format("f %d/%d/%d %d/%d/%d %d/%d/%d\n",
Cont+0,Cont+0,Cont+0,
Cont+1,Cont+1,Cont+1,
Cont+2,Cont+2,Cont+2).c_str());*/
Cont+=3;
}
}
fclose(file);
}